Tolerate stale worktree paths in LinkedWorktrees#97
Merged
Conversation
When a worktree's directory no longer exists (a stale/prunable entry that git still lists), filepath.EvalSymlinks fails with a not-exist error inside IsSameRealPath, which previously aborted the entire LinkedWorktrees call. This broke unrelated operations like deleting a different branch during sync. Skip such stale entries instead of failing, since a non-existent path can't be the primary worktree and there is nothing to operate on. https://claude.ai/code/session_01VgKTFCZbzEXTvewRjXjMGQ
dansimau
marked this pull request as ready for review
June 5, 2026 08:33
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
yas crashes when the git repo has a stale/prunable worktree entry — a worktree registration whose directory no longer exists on disk. git itself flags these:
The failure chain:
yas synctries to delete a branch (pkg/yascli/sync.go)DeleteBranchcallsLinkedWorktreePathForBranch(pkg/yas/branch.go)LinkedWorktrees, which compares every worktree against the primary viafsutil.IsSameRealPath(pkg/gitexec/worktrees.go)IsSameRealPathcallsfilepath.EvalSymlinks(path), which fails with a not-exist error for the stale path — aborting the whole operation, even though that worktree is unrelated to the branch being deleted.Fix
In
LinkedWorktrees, whenIsSameRealPathreturns anos.IsNotExisterror, skip that worktree entry instead of returning the error. A path that doesn't exist can't be the primary worktree and there's nothing to operate on, so skipping is safe and keeps unrelated operations working. Non-IsNotExisterrors are still propagated.Testing
TestLinkedWorktreesTolerateStalePathwhich creates a worktree, removes its directory to simulate a stale/prunable entry, and verifiesLinkedWorktrees/LinkedWorktreePathForBranchno longer error.make lintpasses (0 issues).Note: the user-facing remediation for an already-broken repo is still
git -C <repo> worktree prune; this change makes yas tolerant so it doesn't break in the first place.https://claude.ai/code/session_01VgKTFCZbzEXTvewRjXjMGQ
Generated by Claude Code