Repository navigation
Conversation
…eted When a linked worktree is removed (via `wt remove` or `wt merge` from another terminal) while a shell is still in that directory, all `wt` commands fail with a cryptic git error. This adds recovery logic that finds the parent repository from `$PWD` (which shells preserve after deletion). - `wt switch`, `wt list`, and the interactive picker auto-recover - All other commands show a hint: "Try: wt switch ^" - Pre-switch hooks are skipped when recovering (source worktree is gone) Closes #1109 Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI is still running so holding off on approval, but the design looks solid overall. Two issues worth addressing:
-
find_repo_nearaborts entirely if any directory entry can't be stat'd — see inline comment. -
RecoveredRepo.deleted_pathis unused — no caller reads it. Either remove the field or add a TODO explaining the intended use. Per project conventions: don't keep dead code without explanation.
Minor observation (non-blocking): try_repo_at requires a .git directory, so recovery won't work for bare repos (which have no .git subdirectory). The fallback hint in main.rs covers this gracefully, but a brief code comment on try_repo_at noting the limitation would help future readers.
On Windows, std::env::current_dir() can succeed even after the directory is deleted because the process handle keeps it alive. Check path existence in addition to current_dir() success. Also adds unit tests for recover.rs helper functions to improve coverage. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The Windows current_dir() handling and unit tests look good. Two notes:
-
The two issues from the previous review (the
?infind_repo_nearthat aborts on unreadable entries, and the unuseddeleted_pathfield) still apply to the updated code. -
The recovery-from-deleted-CWD pattern is now copy-pasted in three places (
handle_switch,handle_select,main.rslist handler). Consider extracting a helper:
fn current_or_recover() -> anyhow::Result<(Repository, bool)> {
match Repository::current() {
Ok(repo) => Ok((repo, false)),
Err(err) => match recover_from_deleted_cwd() {
Some(recovered) => {
eprintln!("{}", info_message("Current worktree was removed, recovering..."));
Ok((recovered.repo, true))
}
None => Err(err),
},
}
}Each call site would add its own .context() if needed. This also removes the only external use of RecoveredRepo, which would let you drop the deleted_path field (or keep it internal).
Holding off on approval — CI (test linux/macos/windows, coverage) is still running.
worktrunk-bot
left a comment
There was a problem hiding this comment.
Recovery won't work on Windows with native shells (CMD, PowerShell) — $PWD is a Unix shell convention and std::env::var_os("PWD") returns None there. But on Windows, current_dir() succeeds with the (now-deleted) path, so you already have deleted_path — you just discard it. See inline suggestion.
On Windows, deleted directories remain accessible to processes that hold handles (like CWD), making current_dir(), exists(), and read_dir() all return success. Instead of unreliable OS-level detection, set an explicit flag in OutputState when the removal handler knows it removed the CWD's worktree. The error handler checks this flag first, falling back to current_dir() failure detection for external removals. Co-Authored-By: Claude <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The explicit cwd_removed flag approach (0588af8) addresses the Windows detection reliability issue cleanly. No new issues beyond those already noted in previous reviews. Will approve once CI is green.
|
@worktrunk-bot could you make this change if it still applies?
also fix ci |
… pattern - Replace copy-pasted recovery-from-deleted-CWD pattern in handle_switch, handle_select, and main.rs list handler with a single current_or_recover() function in the recover module - Fix find_repo_near aborting entirely when a directory entry can't be stat'd (e.g., broken symlink) — now skips unreadable entries gracefully - Remove unused deleted_path field from RecoveredRepo (struct is now private) - Make recover_from_deleted_cwd private (current_or_recover is the public API) - Add bare repo limitation note on try_repo_at - Add tests for broken symlink handling and current_or_recover happy path Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Addressed the review feedback:
The refactoring also reduces the amount of uncovered code in the patch (call sites are now one-liners instead of 12-line blocks), which should help with the |
Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI is failing on cargo fmt. Two formatting issues from the latest commit:
handle_switch.rs:178-179— rustfmt wants thecurrent_or_recover()call on one linemain.rs:9-11— rustfmt wants the multi-line import on a single line
Additionally, RecoveredRepo is now a single-field struct wrapping Repository with no additional data or methods. It could be replaced with Repository directly in recover_from_deleted_cwd, removing the struct entirely. Non-blocking — the code works fine either way.
|
great, do the consolation |
worktrunk-bot
left a comment
There was a problem hiding this comment.
Latest commit is just cargo fmt (7 lines). All previous suggestions have been addressed. No new issues. Will approve once CI finishes.
|
Extract `recover_from_path` from `recover_from_deleted_cwd` so the core recovery logic (ancestor walk, repo discovery, worktree verification) can be tested directly. This covers the previously-untestable recovery path without needing to actually delete the CWD. Also removes the single-field `RecoveredRepo` wrapper in favor of returning `Repository` directly. Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI clippy is failing — one needless borrow. See inline suggestion.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Switch from unwrap_or_else closures to unwrap_or for the CWD/source_root fallback values. The fallback is a cheap PathBuf::clone() that's fine to evaluate eagerly, and this eliminates unreachable closure bodies from the coverage diff. Co-Authored-By: Claude Opus 4.6 <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI lint is failing — cargo fmt wants the multi-line repo.current_worktree().root().unwrap_or(fallback_path) chain on a single line in both handle_switch.rs and select/mod.rs. See inline suggestions.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Addressed both items:
|
- Add test_find_repo_near_finds_repo_at_dir_itself (covers find_repo_near early-return when dir itself is a repo) - Add test_cwd_removed_flag (covers mark_cwd_removed/was_cwd_removed) - Remove if-guard in test_current_or_recover_returns_repo_when_cwd_exists (tests always run inside a git repo in CI) - Simplify assertion messages to avoid uncovered failure-string lines Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
wt switch,wt list, and the interactive picker now auto-recover by finding the parent repository from$PWDCurrent directory was removed. Try: wt switch ^WorktrunkError::AlreadyDisplayedempty Display implThanks to @davidbeesley for reporting in #1109
Closes #1109
Test plan
merge_post_merge_command_failure(hint now appears after CWD removal)wt switch ^recovers