worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Picker alt-x on a worktree row with a missing directory keeps the stale registration

Open worktrunk-bot opened this issue 1 week ago • 1 comments

When a worktree's directory has been deleted outside wt, pressing alt-x on its picker row leaves the stale registration in place. wt remove on the same branch unregisters it. For two of the three affected cases, the picker's flash message also gives the wrong reason.

Mechanism. For a prunable worktree, prepare_worktree_removal plans RemovalPlan::BranchOnly { prune_entry: Some(path), .. } (repository_ext.rs). Two shapes of that plan remove no branch:

  • the branch is unborn or checked out in a live sibling: deletion_mode: Keep (L332-L343)
  • the branch is unmerged: integration_reason: None (L344-L361)

For both, removal_will_remove_target returns false, so apply takes its last arm and calls keep_unremovable_row (picker/mod.rs L747-L760). That path never runs do_removal, so prune_entry is never unregistered. Its flash always says the branch is unmerged, which is false for the unborn and shared-checkout cases. The arm's comment also assumes the only way to reach it is an unmerged BranchOnly branch row, and doesn't account for a stale worktree row.

Reproduction (expected path, not yet run as a test):

  1. wt switch -c feature, make a commit on feature so it's unmerged, then rm -rf the worktree directory.
  2. wt switch and press alt-x on the feature row.
  3. The row stays and the flash says feature is kept as unmerged. git worktree list still shows the stale entry. wt remove feature would unregister it and keep the branch.

test_do_removal_branch_only_prunes_stale_entry calls do_removal directly, so the dispatch in apply has no test for this case.

Possible fix. When the plan carries a prune_entry, run the removal in the background so the entry is unregistered, and show the row as a branch row, as morph_and_remove_in_background does for a worktree whose branch stays. Pick the keep message from the actual reason: keep mode or unmerged. The open question is the row's presentation after the prune: morph it into a / branch row, or drop it when the branch is shared.

Found by the nightly survey.

worktrunk-bot avatar Nov 22 '26 06:11 worktrunk-bot

#4882 fixes this. alt-x on a stale worktree row now unregisters the entry whenever the branch stays. If no other row shows the branch, the row turns into the / branch row; if the branch is unborn or a live sibling's row already shows it, the row drops. The "branch is unmerged" flash now appears only on branch-only rows, where it's accurate.

I reproduced both flows from the report through apply with regression tests: an unmerged branch, and a branch shared with a live sibling. Both kept the row on the old code and pass with the fix. The automated review pushed a follow-up commit that corrects the message for a failed prune, and CI on that head hasn't finished yet. A maintainer decides on merging.

worktrunk-bot avatar Nov 22 '26 06:11 worktrunk-bot