Conversation
A worktree whose directory is gone keeps its branch claim until the administrative entry is pruned, so `git worktree add` refuses the branch forever. `listRefs` drops prunable worktrees, so the branch looks free in the picker and the failure only surfaced as "git worktree add failed". Give `createWorktree` the stale-claim recovery `switchRef` already had, shared as `resolveWorktreeClaimRecovery`: prune and retry when the holder is stale, and otherwise name the live worktree that holds the branch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
Opening an existing branch failed with an opaque error:
The branch was still claimed by a worktree whose directory no longer exists (a
/private/tmpcheckout wiped by tmp cleanup, or any hand-deleted worktree dir):Git keeps that administrative entry — and keeps refusing the branch a second worktree — until it is pruned.
listRefsdeliberately drops prunable worktrees, so the branch shows as a free "Existing branch" in the picker, the dialog takes the create path, andgit worktree addfails. The generalexecuteGitfailure is redacted, so git's actual reason ("already checked out in ...") never reached the user.switchRefalready recovered from exactly this stale claim;createWorktreenever got it.Change
switchRef's recovery into a sharedresolveWorktreeClaimRecovery(operation, cwd, branch): on the failure path it readsgit worktree list --porcelainand either prunes a stale holder so the caller can retry, or reports the live worktree that holds the branch.createWorktreerunsworktree addwithallowNonZeroExitand, on failure, prunes + retries once when a prunable worktree holds the target branch. A live holder now produces an actionable message instead of "git worktree add failed":gitCommandResultFailurehelper, so the error shape is unchanged.git worktree pruneonly drops entries whose working tree is already gone, so it never discards work. Everything runs on the failure path only — a successfulworktree addis still a single git spawn.Tests
Two new tests in
GitVcsDriverCore.test.ts: creating a worktree for a branch a deleted worktree still claims, and naming the live worktree that blocks a second one. Both fail on the old code (verified by stashing the fix). 202 tests acrosssrc/git+src/vcspass; typecheck and lint show no new findings.🤖 Generated with Claude Code