Repository navigation
fix: picker alt-r removal for detached worktrees - #1717
Conversation
Resolve the removal target by path (via list_worktrees) instead of
always using Branch. Detached worktrees have no branch name, so
RemoveTarget::Branch("(detached)") would fail silently. Now any
worktree item resolves to RemoveTarget::Path, with Branch as
fallback for branch-only items.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The find closure has a precedence bug: wt.branch.is_none() matches any detached worktree unconditionally, regardless of selected_output. If a detached worktree appears before the target in list_worktrees(), selecting a branched worktree for removal will incorrectly resolve to the detached worktree instead.
For example: user selects "feature-x" for removal, but the main worktree happens to be detached. find matches the main worktree (because branch.is_none()) before reaching the "feature-x" worktree.
Fix: only fall through to branch.is_none() when selected_output is "(detached)".
The test exercises do_removal (the git removal) but not the resolution logic in invoke where this bug lives. Consider adding a test that exercises the worktree lookup path.
Match by branch first, then fall back to detached worktrees. The previous `||` condition could match a detached worktree even when the user selected a branched item. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
worktrunk-bot
left a comment
There was a problem hiding this comment.
The two-pass resolution approach fixes the precedence bug — branch match now takes priority over detached fallback. Previous feedback addressed.
codecov/patch is failing (75.55% vs 95.47% target): the worktree-path resolution block (lines 134–144) is new untested code. It runs inside skim's event callback, so it's not reachable from do_removal unit tests. Options:
- Extract the resolution logic into a standalone function (e.g.,
resolve_removal_target(&repo, &selected_output) -> RemoveTarget) that can be unit-tested independently. - Accept the gap — this is interactive-only code exercisable only through the TUI picker.
I can push a fix commit to extract and test the resolution logic if you'd like.
Resolve the removal target by path (via
list_worktrees) instead of always usingRemoveTarget::Branch. Detached worktrees have no branch name, soBranch("(detached)")failed silently — the item vanished from the picker but the worktree persisted. Now any worktree item resolves toRemoveTarget::Path, withBranchas fallback for branch-only items.Adds
test_do_removal_removes_detached_worktreeunit test. Verified interactively via tmux-cli.