Skip to main content

Module rule_branch_worktree

Module rule_branch_worktree 

Source
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§

BranchWorktreeDecision
What: The outcome of looking at the argument list only. An enum is a closed set of named alternatives; NeedsRemoteGuess carries 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. &str is 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”; String is 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: Only branch, checkout and switch can create a branch outside git 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. bool is true or false. Why: That is when git switch <name> and git checkout <name> create a local branch. A remote’s HEAD pointer 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-ref over 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.