Repository navigation
fix: validate candidate repos during CWD recovery - #1193
Merged
Merged
Conversation
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]>
worktrunk-bot
approved these changes
Feb 25, 2026
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]>
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.
Summary
~/git/repo-a,~/git/repo-b), CWD recovery now finds the correct one instead of returning the first it encountersfind_repo_near(returns first match) withfind_validated_repo_near(validates each candidate against git's worktree list)$PWDdeeper than the worktree rootThanks to @davidbeesley for reporting in #1168
Ref #1168
Test plan
test_recover_from_path_multi_repo_siblings— two sibling repos, recovery finds the correct onetest_recover_from_path_nested_worktree— worktree nested under repo directorytest_recover_from_path_deep_pwd—$PWDdeeper than worktree root