Skip to content

Tolerate stale worktree paths in LinkedWorktrees#97

Merged
dansimau merged 1 commit into
mainfrom
claude/cool-hypatia-xefUU
Jun 5, 2026
Merged

Tolerate stale worktree paths in LinkedWorktrees#97
dansimau merged 1 commit into
mainfrom
claude/cool-hypatia-xefUU

Conversation

@dansimau

@dansimau dansimau commented Jun 5, 2026

Copy link
Copy Markdown
Owner

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:

worktree /private/tmp/1
branch refs/heads/bar
prunable gitdir file points to non-existent location

The failure chain:

  1. yas sync tries to delete a branch (pkg/yascli/sync.go)
  2. DeleteBranch calls LinkedWorktreePathForBranch (pkg/yas/branch.go)
  3. That calls LinkedWorktrees, which compares every worktree against the primary via fsutil.IsSameRealPath (pkg/gitexec/worktrees.go)
  4. IsSameRealPath calls filepath.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, when IsSameRealPath returns an os.IsNotExist error, 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-IsNotExist errors are still propagated.

Testing

  • Added TestLinkedWorktreesTolerateStalePath which creates a worktree, removes its directory to simulate a stale/prunable entry, and verifies LinkedWorktrees / LinkedWorktreePathForBranch no longer error.
  • make lint passes (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

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
dansimau marked this pull request as ready for review June 5, 2026 08:33
@dansimau
dansimau merged commit 7a5bf22 into main Jun 5, 2026
1 check passed
@dansimau
dansimau deleted the claude/cool-hypatia-xefUU branch June 5, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants