Fix wt add failing when local branch exists without remote#12
Merged
Conversation
When a local branch ref exists in the bare repo but has no remote tracking branch (e.g., worktree removed outside wt, or branch created directly with git branch), wt add would fail with "fatal: a branch named '<branch>' already exists" because it fell through to WorktreeAddNew which uses -b to create a new branch. Add HasLocalBranch check using git rev-parse --verify refs/heads/<branch> so the resolution order is: remote branch → local branch → new branch. Both existing branch paths use WorktreeAdd (no -b flag).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wt add <branch>failed withfatal: a branch named '<branch>' already existswhen a local branch ref existed in the bare repo but had no remote tracking branch (e.g., worktree removed outsidewt, or branch created directly withgit branch)HasLocalBranchmethod usinggit rev-parse --verify refs/heads/<branch>to theGitinterface andRunnerWorktreeAddinstead ofWorktreeAddNew -bTest plan
make devpasses (fmt, vet, tests, build)HasLocalBranchaddedgit branch test-orphan), verifywt add test-orphansucceeds