Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: return Option from cwd_removed_hint, drop trailing periods (#1446)
Maximilian Roosf8dd9e9d834b
diff --git a/src/git/recover.rs b/src/git/recover.rsindex b2e364d30..a89ebce86 100644--- a/src/git/recover.rs+++ b/src/git/recover.rs@@ -38,13 +38,14 @@ pub fn current_or_recover() -> anyhow::Result<(Repository, bool)> {/// Determine the hint to show when the user's CWD has been removed.////// Tries to find the parent repository and checks if `wt switch ^` would work-/// (i.e., the default branch has an existing worktree). Falls back to-/// progressively less specific hints when recovery or resolution fails.-pub fn cwd_removed_hint() -> String {- let Some(repo) = Repository::current().ok().or_else(recover_from_deleted_cwd) else {- return "Current directory was removed.".to_string();- };- hint_for_repo(&repo)+/// (i.e., the default branch has an existing worktree). Falls back to suggesting+/// `wt list` when the default branch isn't resolvable. Returns `None` when no+/// repository can be found (no actionable hint to give).+pub fn cwd_removed_hint() -> Option<String> {+ let repo = Repository::current()+ .ok()+ .or_else(recover_from_deleted_cwd)?;+ Some(hint_for_repo(&repo))}fn hint_for_repo(repo: &Repository) -> String {@@ -58,7 +59,7 @@ fn hint_for_repo(repo: &Repository) -> String {return cformat!("Current directory was removed. Try: <underline>wt switch ^</>");}- cformat!("Current directory was removed. Run <underline>wt list</> to see worktrees.")+ cformat!("Current directory was removed. Run <underline>wt list</> to see worktrees")}/// Attempt to recover a repository when the current directory has been deleted.@@ -525,6 +526,6 @@ mod tests {.unwrap();let repo = Repository::at(tmp.path()).unwrap();let hint = hint_for_repo(&repo);- insta::assert_snapshot!(hint.ansi_strip(), @"Current directory was removed. Run wt list to see worktrees.");+ insta::assert_snapshot!(hint.ansi_strip(), @"Current directory was removed. Run wt list to see worktrees");}}diff --git a/src/main.rs b/src/main.rsindex 396d42488..cb3258f2b 100644--- a/src/main.rs+++ b/src/main.rs@@ -1017,7 +1017,11 @@ fn main() {// for cases not covered by the flag (e.g., external worktree removal).let cwd_gone = output::was_cwd_removed() || std::env::current_dir().is_err();if cwd_gone {- eprintln!("{}", hint_message(cwd_removed_hint()));+ if let Some(hint) = cwd_removed_hint() {+ eprintln!("{}", hint_message(hint));+ } else {+ eprintln!("{}", info_message("Current directory was removed"));+ }}// Preserve exit code from child processes (especially for signals like SIGINT)diff --git a/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_fallback_to_list.snap b/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_fallback_to_list.snapindex 4a814c2d3..5b95fbbf8 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_fallback_to_list.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_fallback_to_list.snap@@ -55,4 +55,4 @@ exit_code: 1[36m◎[39m [36mRunning post-merge project hook @ [1m_REPO_[22m[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1[0m[31m✗[39m [31mCommand failed: exit status: 1[39m-[2m↳[22m [2mCurrent directory was removed. Run [4mwt list[24m to see worktrees.[22m+[2m↳[22m [2mCurrent directory was removed. Run [4mwt list[24m to see worktrees[22mdiff --git a/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_no_recovery.snap b/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_no_recovery.snapindex 9af90342b..1d4577db5 100644--- a/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_no_recovery.snap+++ b/tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_no_recovery.snap@@ -55,4 +55,4 @@ exit_code: 1[36m◎[39m [36mRunning post-merge project hook @ [1m_REPO_[22m[39m[107m [0m [2m[0m[2m[34mexit[0m[2m 1[0m[31m✗[39m [31mCommand failed: exit status: 1[39m-[2m↳[22m [2mCurrent directory was removed.[22m+[2m○[22m Current directory was removed