Skip to content

fix: only suggest wt switch ^ when resolvable after CWD removal - #1238

Merged
max-sixty merged 4 commits into
mainfrom
1168
Mar 1, 2026
Merged

max-sixty merged 4 commits into
mainfrom
1168

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • After a worktree is removed, the hint now checks whether wt switch ^ would
    actually work before suggesting it. Three-tier fallback: suggest wt switch ^
    if the default branch worktree exists, suggest wt list if the repo is found
    but ^ isn't resolvable, or show a plain message if no repo is found at all.

Thanks to @davidbeesley for reporting in #1168.

Test plan

  • Unit tests for cwd_removed_hint() and hint_for_repo() (bare repo
    fallback)
  • Integration snapshot tests for all three hint scenarios
  • Existing merge snapshot updated with ANSI formatting on hint command
  • cargo run -- hook pre-merge --yes passes

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

max-sixty and others added 2 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]>
worktrunk-bot
worktrunk-bot previously approved these changes Mar 1, 2026

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: the doc comment on try_repo_at still references "the fallback hint in main.rs" but that logic now lives in cwd_removed_hint() in the same file.

max-sixty and others added 2 commits February 28, 2026 21:25
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]>
@worktrunk-bot
worktrunk-bot dismissed their stale review March 1, 2026 05:37

Windows CI failure in test_merge_cwd_removed_hint_no_recovery

worktrunk-bot pushed a commit that referenced this pull request Mar 1, 2026
1. Add jq `!=` escaping warning to running-in-ci skill. Despite the
   pre-flight template fix in #1152, Claude still generates `!=` in
   ad-hoc jq queries during CI polling — 4 of 6 review sessions in the
   past 24 hours hit this bug. The new guidance tells Claude to use
   `| not` instead of `!=` in all jq expressions.

2. Swap Step 5 dismissal ordering in pr-review. Previously: dismiss
   approval first, then post analysis. If the session times out between
   these, the PR author gets a bare dismissal with no context (happened
   on PR #1238, run 22536752559). Now: post analysis first, dismiss
   second — the safer ordering.

Closes #1239
Closes #1240

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty
max-sixty merged commit 5500097 into main Mar 1, 2026
22 checks passed
@max-sixty
max-sixty deleted the 1168 branch March 1, 2026 07:47
max-sixty added a commit that referenced this pull request Mar 11, 2026
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_

---------

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