Skip to content

fix: validate candidate repos during CWD recovery - #1193

Merged
max-sixty merged 1 commit into
mainfrom
missing-dir
Feb 25, 2026
Merged

max-sixty merged 1 commit into
mainfrom
missing-dir

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • When multiple repos are siblings (e.g., ~/git/repo-a, ~/git/repo-b), CWD recovery now finds the correct one instead of returning the first it encounters
  • Replaces find_repo_near (returns first match) with find_validated_repo_near (validates each candidate against git's worktree list)
  • Walks multiple ancestor levels and handles $PWD deeper than the worktree root

Thanks to @davidbeesley for reporting in #1168

Ref #1168

Test plan

  • test_recover_from_path_multi_repo_siblings — two sibling repos, recovery finds the correct one
  • test_recover_from_path_nested_worktree — worktree nested under repo directory
  • test_recover_from_path_deep_pwd — $PWD deeper than worktree root
  • All 555 unit tests pass
  • All 1120 integration tests pass
  • Lints clean

This was written by Claude Code on behalf of @max-sixty

When a worktree directory is deleted while a shell is still in it,
recovery scans nearby directories for the parent repo. Previously,
find_repo_near returned the first repo it found without checking if the
deleted path actually belonged to it — wrong result when multiple repos
are siblings (e.g., ~/git/repo-a and ~/git/repo-b).

Replace find_repo_near with find_validated_repo_near that checks each
candidate against git's worktree list before returning. Walk multiple
ancestor levels instead of only the first. Use starts_with instead of
exact equality in was_worktree_of to handle $PWD deeper than the
worktree root.

Ref #1168

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 77c6aea into main Feb 25, 2026
21 of 22 checks passed
@max-sixty
max-sixty deleted the missing-dir branch February 25, 2026 07:48
max-sixty added a commit that referenced this pull request Feb 25, 2026
## Summary

- Use `is_ok_and` in `was_worktree_of` to eliminate uncoverable error
branch
- Enable debug log level in one test so `log::debug!` format args
execute

Follow-up to #1193.

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude <[email protected]>
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