feat(vcs): open the existing worktree that already holds a branch - #63
Merged
Merged
Conversation
Reopening a branch through a worktree thread failed with an opaque "git worktree add failed" whenever git refused the add. Handle the two cases the caller cannot fix by hand: - the branch is already checked out in another worktree — hand that worktree (and the threads rooted at it) back instead of failing, and explain clearly when the claim is the main repo checkout. - the derived directory is taken because a worktree kept its directory after its branch was switched — fall back to a sibling `<name>-2`. Prune-and-retry once for a stale worktree whose directory was removed behind git's back. All of this runs on the failure path only, so a successful add stays a single spawn. Resolve GitHub account routes through symlinks: a cwd and the stored project root routinely name one directory via different symlinks (/tmp vs /private/tmp, symlinked home or worktree dirs). On a literal miss, resolve both sides' real paths (cached) before falling back to the ambient account, and sharpen the token-failure warnings. Preserve the previous draft when opening a review chat beside the current one, so a fresh review draft stays attached to its worktree. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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 freeto 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
Reopening a branch through a worktree thread previously failed with an opaque
git worktree add failedwhenever git refused the add. This PR handles the cases the caller cannot fix by hand and resolves GitHub account routes through symlinks.VCS worktree handling (
GitVcsDriverCore.ts)<name>-2.git worktree pruneand retry once.GitHub account resolution (
GitHubAccountResolver.ts)/tmpvs/private/tmp, symlinked home/worktree dirs). On a literal miss, resolve both sides' real paths (cached, TTL) before falling back to the ambient account.Web (
ChatView.tsx)Test plan
GitVcsDriverCore.test.tscases: reuse a worktree that already holds the branch, explain a branch only the requesting checkout holds, create a sibling worktree when the directory is taken, reopen a branch whose worktree directory was deleted.GitHubAccountResolver.test.tscase: resolve a cwd that reaches the workspace root through a symlink.🤖 Generated with Claude Code