Expand description
Pure decision of the branch-worktree-only policy and its one-query remote guess.
What:
Pure decision of the branch-worktree-only policy:
a new branch starts in its own
linked worktree,
not in the current one.
Why:
git branch <name>,
git checkout -b,
git switch -c and Git’s guess of a remote
branch all create a branch in the current worktree.
The policy rejects them and
points at git worktree add -b.
This file decides from the arguments alone,
names
the one repository query the guess needs,
and reads that query’s answer.
It starts
no process.
In TS you’d write (pseudocode):
// decideBranchWorktree(['switch', '-c', 'topic']) => { kind: 'creates', command: 'switch' }Enums§
- Branch
Worktree Decision - What:
The outcome of looking at the argument list only.
An
enumis a closed set of named alternatives;NeedsRemoteGuesscarries the name Git may guess.#[derive(...)]asks the compiler to generate cloning, debug printing and==. Why: Explicit creation is decided here; the guess depends on which branches exist.
Constants§
- BRANCH_
CREATION_ CODE - What:
The finding code of a branch-worktree rejection.
&stris borrowed text baked into the program. Why: Callers identify the finding by this stable code.
Functions§
- branch_
creation_ message - What:
Build the rejection text.
Option<&OsStr>is “a borrowed branch name or nothing”;Stringis the owned result. Why: The text names the command, the guessed branch when there is one, the worktree form to use instead, and the one-invocation bypass. - decide_
branch_ worktree - What:
Decide from the argument list.
&[OsString]borrows the arguments, already free of wrapper controls. Why: Onlybranch,checkoutandswitchcan create a branch outsidegit worktree add. A region Git itself refuses creates nothing. - remote_
guess_ creates_ branch - What:
Read the guess query’s listing:
no local branch of that name,
and exactly one
remote branch of that name.
boolis true or false. Why: That is whengit switch <name>andgit checkout <name>create a local branch. A remote’sHEADpointer is not a branch and is never guessed. - remote_
guess_ query_ arguments - What:
Build the real-Git argument list of the guess query:
the caller’s global
options,
then one
for-each-refover the local branch of that name and the remote branches of that name.Vec<OsString>is the owned result. Why: One listing answers both questions the guess depends on, so the check starts one Git process. The query must inspect the repository the command will run in, so the global options are forwarded unchanged.