* feat(forge): name worktree branches, start them from remote branches, and show changes being read The New Session worktree option's base menu now searches local branches and each remote's branches, pins the current branch and every remote's default branch, and names each remote group by its repository. Its last row opens a dialog that names the new branch, starting from `worktreePrefix` and checking Git's branch-name rules; the Host refuses an invalid or taken name. A request records the full ref of its base and the optional name; every attempt uses the name. A remote-tracking base is fetched first: the worktree service gains a `fetch` request field and a `fetch` phase, fetching only that branch without tags. A failed fetch leaves the message waiting with Retry, Use the last fetched version, and Continue without a worktree; a taken name offers Rename. While the changes view reads changes it has not shown yet, it says "Reading changes" above file card placeholders, and the files menu names no count. * fix(worktree): forward only the declared create_worktree arguments The create_worktree parameter object is open, and the tool passed it to the worktree runtime unchanged. Now that a runtime request can ask to fetch, an undeclared `fetch: true` from the model would have fetched, or refused a local `from`. The tool now forwards only `name` and `from`, so it never fetches. * docs(forge): say that only generated worktree branch names come from the Session id * fix(forge): keep the collapsed change request status on one line In the Session panel the collapsed card's number line kept every part at full width inside a clipping row, so a narrow panel cut the most urgent flag off without an ellipsis, such as "有冲突" after "3 项检查失败". The number and status now form one MarqueeText line as wide as the row. While the line with failed checks does not fit, they take the shorter wording without their count; a line that still does not fit ends in an ellipsis and crawls into view with the title while the pointer rests on the card's head. The line measures again when its width or the fonts change. Expanded cards keep their branch names as before. * fix(forge): hide remote credentials and read the branch a tag shares its name with The base menu named an unrecognized remote's group by its fetch URL as `git remote -v` prints it, so a token in the URL, such as `https://oauth2:[email protected]/...`, reached the browser and showed in the menu. The group now shows the URL without its user name and password. Inspection read the checked-out branch with `symbolic-ref --short HEAD`, which prints `heads/main` while a tag is also named `main`; the New Session option then requested `refs/heads/heads/main` and every worktree attempt failed. Inspection now reads the full ref and takes the name under `refs/heads/`, so the option, the pinned current branch, and the checkout row name `main`. HEAD that names a ref outside `refs/heads/` reads as no branch. * test(worktree): set up nested remotes and line endings the CI runners' Git accepts Git 2.55 on the CI runners refuses `git remote add team` next to an existing `team/fork` remote; the check runs only in `git remote add`, so the longest-remote case now writes the second remote with `git config`, as configuration written earlier or by hand holds it. The test clone also turns off `core.autocrlf`, as `repository` does, because the Windows runner's global setting checked the fetched file out with CRLF.
145 lines
6.5 KiB
TypeScript
145 lines
6.5 KiB
TypeScript
/** Base branch picker of the local changes view's `branch` scope: the automatic fork point, then remote-tracking and local branches. */
|
|
|
|
import { useState, type ReactNode } from 'react'
|
|
import clsx from 'clsx'
|
|
import {
|
|
IconBranchOutlineRegular, IconCheckOutlineRegular, IconChevronDownOutlineRegular, IconSearchOutlineRegular,
|
|
IconWarningTriangleOutlineRegular, Input, Menu, MenuItemButton, Tooltip,
|
|
} from '@deepseek-ai/dsh-client-ui-primitives'
|
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
|
|
import type { ForgeBaseBranch, ForgeBaseBranches } from '../types.ts'
|
|
import { branchSearchStatus, useBranchSearch } from './branch-search.tsx'
|
|
import type { NS } from './locales.ts'
|
|
import { searchFieldKeyDown } from './menu-search.ts'
|
|
import css from './BaseMenu.module.css'
|
|
|
|
/** Props of the base branch picker. */
|
|
export interface BaseMenuProps extends PropsLocale<typeof NS> {
|
|
/** Chosen branch, or null for the automatic fork point. */
|
|
readonly chosen: ForgeBaseBranch | null
|
|
/** Name the trigger shows: the chosen branch, the automatic fork point, or the automatic choice's own name. */
|
|
readonly label: string
|
|
/** Whether the chosen branch no longer exists. */
|
|
readonly missing: boolean
|
|
/** Whether the owning tab is visible; a hidden tab keeps the menu closed. */
|
|
readonly visible: boolean
|
|
/** Read the branches whose names contain `query`; `signal` aborts the read. */
|
|
readonly list: (query: string, signal: AbortSignal) => Promise<RemoteResult<ForgeBaseBranches>>
|
|
/** Compare with a branch, or with the automatic fork point for null. */
|
|
readonly choose: (base: ForgeBaseBranch | null) => void
|
|
}
|
|
|
|
/** One selectable row: a branch, or the automatic fork point. */
|
|
interface BaseOption {
|
|
readonly key: string
|
|
readonly name: string
|
|
readonly base: ForgeBaseBranch | null
|
|
readonly tag?: string
|
|
}
|
|
|
|
/**
|
|
* Render the trigger and, while open, the searchable menu. Opening and each
|
|
* search read the branches again; rows already shown follow the search at once
|
|
* until the new listing arrives.
|
|
* @param props - the choice, the trigger label, the listing read, the choose action, and copy.
|
|
* @returns the trigger with its portalled menu.
|
|
*/
|
|
export function BaseMenu({ chosen, label, missing, visible, list, choose, t }: BaseMenuProps): ReactNode {
|
|
const [open, setOpen] = useState(false)
|
|
const shown = visible && open
|
|
const { query, setQuery, listing, retry, reset, field } = useBranchSearch(shown, list)
|
|
const close = (): void => {
|
|
setOpen(false)
|
|
reset()
|
|
}
|
|
const pick = (base: ForgeBaseBranch | null): void => {
|
|
close()
|
|
if ((base?.ref ?? null) !== (chosen?.ref ?? null)) choose(base)
|
|
}
|
|
|
|
const value = listing?.ok === true ? listing.value : null
|
|
const needle = query.trim().toLowerCase()
|
|
const matches = (name: string): boolean => name.toLowerCase().includes(needle)
|
|
const automatic = value?.automatic ?? null
|
|
const groups: { readonly id: string; readonly label: string; readonly options: readonly BaseOption[] }[] = [
|
|
{
|
|
id: 'automatic',
|
|
label: t('diff.base.automatic'),
|
|
options: automatic === null || !matches(automatic.name) ? [] : [{
|
|
key: 'automatic', name: automatic.name, base: null, tag: t(automatic.worktree ? 'diff.base.worktree' : 'diff.base.automatic'),
|
|
}],
|
|
},
|
|
{
|
|
id: 'remote',
|
|
label: t('diff.base.remote'),
|
|
// The automatic fork point of a code host's default branch is the same comparison as choosing that branch.
|
|
options: (value?.remote ?? [])
|
|
.filter(branch => matches(branch.name) && (automatic === null || automatic.worktree || branch.name !== automatic.name))
|
|
.map(branch => ({ key: branch.ref, name: branch.name, base: branch })),
|
|
},
|
|
{
|
|
id: 'local',
|
|
label: t('diff.base.local'),
|
|
options: (value?.local ?? []).filter(branch => matches(branch.name))
|
|
.map(branch => ({ key: branch.ref, name: branch.name, base: branch })),
|
|
},
|
|
].filter(group => group.options.length > 0)
|
|
const first = groups[0]?.options[0]
|
|
|
|
const body: ReactNode = branchSearchStatus({ listing, empty: groups.length === 0, retry, className: css.status, t })
|
|
?? groups.map(group => (
|
|
<div key={group.id} role="group" aria-label={group.label}>
|
|
{/* The automatic row's tag names it, so its group shows no heading. */}
|
|
{group.id !== 'automatic' && <div className={css.label} role="presentation">{group.label}</div>}
|
|
{group.options.map((option) => {
|
|
const selected = (option.base?.ref ?? null) === (chosen?.ref ?? null)
|
|
return (
|
|
<MenuItemButton key={option.key} icon={<IconBranchOutlineRegular size={14} />} current={selected}
|
|
onSelect={() => { pick(option.base) }}>
|
|
<span className={css.option}>
|
|
<span className={css.name}>{option.name}</span>
|
|
{option.tag !== undefined && <span className={css.tag}>{option.tag}</span>}
|
|
{selected && <IconCheckOutlineRegular size={14} className={css.check} />}
|
|
</span>
|
|
</MenuItemButton>
|
|
)
|
|
})}
|
|
</div>
|
|
))
|
|
|
|
return (
|
|
<Menu
|
|
open={shown}
|
|
portal
|
|
dense
|
|
align="start"
|
|
className={css.anchor}
|
|
listClassName={css.menu}
|
|
onClose={close}
|
|
anchor={(
|
|
<Tooltip label={t('diff.base.aria', { base: label })} side="bottom" portal delayMs={500}>
|
|
<button type="button" className={clsx(css.trigger, missing && css.missing)} aria-haspopup="menu" aria-expanded={shown}
|
|
aria-label={t('diff.base.aria', { base: label })} data-forge-base={chosen?.ref ?? ''}
|
|
onClick={() => { if (shown) close(); else setOpen(true) }}>
|
|
{missing && <IconWarningTriangleOutlineRegular size={12} className={css.warning} />}
|
|
<span className={css.triggerName}>{label}</span>
|
|
<IconChevronDownOutlineRegular size={12} />
|
|
</button>
|
|
</Tooltip>
|
|
)}
|
|
>
|
|
<div className={css.root} data-forge-base-menu="">
|
|
<div className={css.search}>
|
|
<Input ref={field} className={clsx(css.searchInput)} icon={<IconSearchOutlineRegular size={14} />} value={query}
|
|
aria-label={t('diff.base.search')} placeholder={t('diff.base.search')}
|
|
onChange={(event) => { setQuery(event.target.value) }}
|
|
onKeyDown={(event) => { searchFieldKeyDown(event, first === undefined ? undefined : () => { pick(first.base) }) }} />
|
|
</div>
|
|
<div className={css.rows}>{body}</div>
|
|
<div className={css.note}>{t('diff.base.note')}</div>
|
|
</div>
|
|
</Menu>
|
|
)
|
|
}
|