What's wrong
In GitIntegration/Builders/GitWorktreeAddBuilder.cs, when no mode method and no commit-ish are set, AddMode.Plain emits only git worktree add --end-of-options <path> (L190-L206). Given that command, git does one of three things:
- It creates a new branch named after the last path segment. Running
git worktree add --end-of-options ../wt1 printed Preparing worktree (new branch 'wt1').
- If a branch with that name already exists and isn't checked out elsewhere, it checks that branch out.
- With the host setting
worktree.guessRemote=true, it can instead base the new branch on a matching remote branch.
The class remarks (L72-L77) justify leaving out --guess-remote with "--guess-remote extends that to the case where no branch is named at all, which this builder always names." That is not true in the Plain/no-commit-ish case.
Failure scenario
A caller who wants "a worktree at ../feature-x" calls repo.AddWorktree(path).ExecuteAsync(). Depending on the folder name and host config, they get:
- an unrequested branch
feature-x left in the repository, or
- someone else's existing
feature-x branch checked out in the new worktree, which means later commits land on the wrong branch.
The library otherwise pins host config to make results deterministic, but here the result depends on worktree.guessRemote.
Suggested fix
- When neither a mode nor a commit-ish is set, either emit
--detach (a worktree at HEAD with no branch side effects), or throw InvalidOperationException asking the caller to choose Branch/NewBranch/Detach/a commit-ish.
- Correct the
--guess-remote remark to match.
- Add a builder test for the argument list in the bare
AddWorktree(path) case, and an integration test asserting that no new branch appears.
What's wrong
In
GitIntegration/Builders/GitWorktreeAddBuilder.cs, when no mode method and no commit-ish are set,AddMode.Plainemits onlygit worktree add --end-of-options <path>(L190-L206). Given that command, git does one of three things:git worktree add --end-of-options ../wt1printedPreparing worktree (new branch 'wt1').worktree.guessRemote=true, it can instead base the new branch on a matching remote branch.The class remarks (L72-L77) justify leaving out
--guess-remotewith "--guess-remoteextends that to the case where no branch is named at all, which this builder always names." That is not true in the Plain/no-commit-ish case.Failure scenario
A caller who wants "a worktree at
../feature-x" callsrepo.AddWorktree(path).ExecuteAsync(). Depending on the folder name and host config, they get:feature-xleft in the repository, orfeature-xbranch checked out in the new worktree, which means later commits land on the wrong branch.The library otherwise pins host config to make results deterministic, but here the result depends on
worktree.guessRemote.Suggested fix
--detach(a worktree at HEAD with no branch side effects), or throwInvalidOperationExceptionasking the caller to chooseBranch/NewBranch/Detach/a commit-ish.--guess-remoteremark to match.AddWorktree(path)case, and an integration test asserting that no new branch appears.