* 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.
94 lines
4.9 KiB
TypeScript
94 lines
4.9 KiB
TypeScript
/** Dialog that names the new branch of a requested worktree, from the New Session option or after a failed attempt. */
|
|
|
|
import { useId, useState, type ReactNode } from 'react'
|
|
import clsx from 'clsx'
|
|
import { Button, Input, Modal } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
|
|
import { branchLabel, branchNameProblem } from '../branch-name.ts'
|
|
import type { NS } from './locales.ts'
|
|
import css from './WorktreeNameDialog.module.css'
|
|
|
|
/**
|
|
* Outcome of a worktree request: accepted; refused for its branch name, which the dialog shows; or failed otherwise,
|
|
* which the request reports itself.
|
|
*/
|
|
export type WorktreeRequestResult = 'accepted' | 'invalid-name' | 'branch-exists' | 'failed'
|
|
|
|
/** Props of the naming dialog. */
|
|
export interface WorktreeNameDialogProps extends PropsLocale<typeof NS> {
|
|
/** `name` names the branch of the open request; `retry` renames it after a failed attempt, then tries again. */
|
|
readonly mode: 'name' | 'retry'
|
|
/** Text the field starts with: the chosen name, or the prefix of generated names. */
|
|
readonly initial: string
|
|
/** Prefix of generated names; a field that holds only the prefix names no branch yet. */
|
|
readonly prefix: string
|
|
/** Base of the request, or null for HEAD. */
|
|
readonly from: string | null
|
|
/** Whether the request already names its branch, which offers a return to generated names. */
|
|
readonly named: boolean
|
|
/**
|
|
* Request the worktree on `name`, or on generated names for null; in `retry` mode the caller also tries again
|
|
* once the request is accepted.
|
|
*/
|
|
readonly submit: (name: string | null) => Promise<WorktreeRequestResult>
|
|
/** Close the dialog without a request. */
|
|
readonly close: () => void
|
|
}
|
|
|
|
/**
|
|
* Render the dialog: one branch name field checked against Git's branch-name rules while it is typed, and checked by
|
|
* the Host when it is confirmed. A refused name keeps the dialog open with the reason under the field; an accepted
|
|
* request closes it.
|
|
* @param props - mode, starting text, prefix, base, the request, and copy.
|
|
* @returns the dialog.
|
|
*/
|
|
export function WorktreeNameDialog({ mode, initial, prefix, from, named, submit, close, t }: WorktreeNameDialogProps): ReactNode {
|
|
const [value, setValue] = useState(initial)
|
|
const [refusal, setRefusal] = useState<{ readonly name: string; readonly text: string } | null>(null)
|
|
const [busy, setBusy] = useState(false)
|
|
const fieldId = useId()
|
|
const messageId = useId()
|
|
// The starting prefix names no branch yet, so it gets the hint rather than a rule it breaks, such as a trailing `/`.
|
|
const blank = value === prefix
|
|
const problem = blank ? null : branchNameProblem(value)
|
|
const error = problem !== null ? t(`branchName.${problem}`) : refusal?.name === value ? refusal.text : null
|
|
const retry = mode === 'retry'
|
|
const send = (name: string | null): void => {
|
|
setBusy(true)
|
|
void submit(name).then((result) => {
|
|
setBusy(false)
|
|
if (result === 'accepted') close()
|
|
else if (name !== null && result === 'branch-exists') setRefusal({ name, text: t('branchName.exists', { name }) })
|
|
else if (name !== null && result === 'invalid-name') setRefusal({ name, text: t('branchName.invalid') })
|
|
})
|
|
}
|
|
const confirmable = !busy && error === null && !blank
|
|
const base = from === null ? null : branchLabel(from)
|
|
const hint = blank && prefix !== '' ? t('nameDialog.prefixOnly') : base === null ? t('nameDialog.hintHead') : t('nameDialog.hint', { branch: base })
|
|
return (
|
|
<Modal open onClose={close} title={t(retry ? 'nameDialog.retryTitle' : 'nameDialog.title')} closeLabel={t('nameDialog.close')}
|
|
footer={<>
|
|
{named && !retry && (
|
|
<Button variant="outline" className={css.auto} disabled={busy} onClick={() => { send(null) }}>{t('nameDialog.auto')}</Button>
|
|
)}
|
|
<Button variant="outline" onClick={close}>{t('nameDialog.cancel')}</Button>
|
|
<Button variant="primary" disabled={!confirmable} onClick={() => { send(value) }}>
|
|
{t(retry ? 'nameDialog.retry' : 'nameDialog.confirm')}
|
|
</Button>
|
|
</>}>
|
|
<div className={css.form} data-forge-worktree-name="">
|
|
<label className={css.label} htmlFor={fieldId}>{t('nameDialog.field')}</label>
|
|
<Input id={fieldId} data-modal-autofocus className={clsx(css.field, error !== null && css.invalid)} value={value}
|
|
spellCheck={false} autoCapitalize="off" autoComplete="off" aria-invalid={error !== null} aria-describedby={messageId}
|
|
onChange={(event) => { setValue(event.target.value) }}
|
|
onKeyDown={(event) => {
|
|
if (event.key !== 'Enter' || event.nativeEvent.isComposing) return
|
|
event.preventDefault()
|
|
if (confirmable) send(value)
|
|
}} />
|
|
<p id={messageId} className={clsx(css.message, error !== null && css.error)} role={error === null ? undefined : 'alert'}>{error ?? hint}</p>
|
|
</div>
|
|
</Modal>
|
|
)
|
|
}
|