Skip to content

fix: return Option from cwd_removed_hint, drop trailing periods - #1446

Merged
max-sixty merged 8 commits into
mainfrom
1168
Mar 11, 2026
Merged

max-sixty merged 8 commits into
mainfrom
1168

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Follow-up to #1238. Two small refinements to the CWD-removed hint system:

  • cwd_removed_hint() now returns Option<String> instead of String — when no repository can be found, there's no actionable hint to give, so None is more accurate than a plain string. The caller in main.rs uses info_message for the no-hint case instead of hint_message.
  • Dropped trailing period from the wt list fallback hint to match the wt switch ^ hint (consistency).

Ref #1168

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

max-sixty and others added 8 commits February 28, 2026 21:17
When a worktree is removed and the user's CWD becomes invalid, the hint
now checks whether `wt switch ^` would actually work (default branch has
an existing worktree) before suggesting it. Three-tier fallback:

1. Default branch worktree exists → suggest `wt switch ^`
2. Repo found but no default branch worktree → suggest `wt list`
3. No repo found at all → plain "Current directory was removed."

Closes #1168

Thanks to @davidbeesley for reporting.

Co-Authored-By: Claude <[email protected]>
The test was calling `cwd_removed_hint()` which depends on the host
repo having a default branch worktree. In CI's checkout this isn't
guaranteed. Use `hint_for_repo()` with a purpose-built test repo instead.

Co-Authored-By: Claude <[email protected]>
Same root cause as the unit test fix: without explicit PWD, CI's
checkout doesn't have a default branch worktree, so recovery falls
through to the `wt list` hint instead of `wt switch ^`.

Also updates stale doc comment on try_repo_at.

Co-Authored-By: Claude <[email protected]>
On Windows, `current_dir()` succeeds even after directory deletion
(the process handle keeps it alive), so `Repository::current()` works
and the hint correctly suggests `wt switch ^`. The "no recovery"
scenario only occurs on Unix where the CWD becomes truly inaccessible.

Co-Authored-By: Claude <[email protected]>
The "no recovery" case isn't a hint (no actionable command to suggest),
so use info_message instead of hint_message. Also drop trailing periods
from hint text to match existing conventions.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	src/git/recover.rs
#	src/main.rs
#	tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_fallback_to_list.snap
#	tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_no_recovery.snap
Merge conflict resolution missed the new quiet parameter added on main.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	src/git/recover.rs
#	tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_fallback_to_list.snap
#	tests/snapshots/integration__integration_tests__merge__merge_cwd_removed_hint_no_recovery.snap
@max-sixty
max-sixty merged commit f8dd9e9 into main Mar 11, 2026
23 checks passed
@max-sixty
max-sixty deleted the 1168 branch March 11, 2026 18:55
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