Repository navigation
fix: refuse removing a worktree that contains another, and finish picker removals before exit - #4861
Merged
Merged
Conversation
`wt remove`, `wt remove --force` and `wt step prune` moved the target into trash with any checkout nested inside it, deleting that checkout's uncommitted files at exit 0. An ignored nested checkout is invisible to the dirty gate, and `--force` waives only the target's own changes. Only `wt merge` refused this. Planning now refuses such a target on every removal path. `wt remove` fails with a hint to remove the nested worktree first. `wt step prune` prints `Skipped <branch> (contains worktree @ <path>)` in the preview and the run, and removes the rest. Merge's recheck after hooks reports the same error. The guard is `Repository::worktree_nested_in`. It resolves each registered checkout once per inventory read, keeps the canonical paths sorted beside the inventory in the repository cache, and answers each target with one range lookup, so a prune of N worktrees resolves N paths rather than N per target and gains no registry wait (#3954). A checkout nested during `wt remove`'s approval prompt or `pre-remove` hook still isn't caught; only merge rechecks after them.
Leaving the picker right after alt-x ended the process with the removal thread still running. The row had gone, but the worktree stayed and nothing said so; a removal further along left its checkout in trash. `wt switch` now waits for requested removals once skim releases the terminal, printing `Finishing worktree removal...` if one is still running, and then reports any failure. A slow `pre-remove` hook delays exit by its remaining time.
A failing `post-checkout` hook fails `git switch` after promote has moved ignored files into `.git/wt/staging/promote`. The error named only the failed step, and the next run's first instruction for the only copy was `rm -rf`. The failure now names the staging directory. The next run says what `a/` and `b/` hold, and gives `rm -rf` as the step after recovering them.
worktrunk-bot
approved these changes
Nov 20, 2026
This was referenced Nov 20, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three removal-safety fixes. Together they replace #4458 and #4463, fixing the same failures in far less code.
wt removeandwt step prunedeleted a checkout nested inside the target.wt remove,wt remove --forceandwt step prunemoved the target into trash along with any checkout nested inside it, deleting that checkout's uncommitted files at exit 0. An ignored nested checkout is invisible to the dirty gate, and--forcewaives only the target's own changes. Onlywt mergerefused this (#4360). Planning now refuses such a target on every removal path:wt removefails with a hint to remove the nested worktree first.wt step pruneprintsSkipped <branch> (contains worktree @ <path>)and removes the rest.The guard is
Repository::worktree_nested_in. It canonicalizes each registered checkout once per inventory read and answers each target with one range lookup, so prune adds no per-target path resolution (#3954). A checkout nested duringwt remove's approval prompt orpre-removehook still isn't caught; only merge rechecks after them.Leaving the picker right after alt-x abandoned the removal. The process exited with the removal thread still running: the row was gone but the worktree stayed, and nothing said so. A removal further along left its checkout in trash.
wt switchnow waits for requested removals once skim releases the terminal. It printsFinishing worktree removal...while one is still running, then reports any failure.A failed promote gave
rm -rfas the first step for the only copy of the ignored files. When apost-checkouthook failsgit switchafter promote has staged ignored files in.git/wt/staging/promote, the error now names that directory. The next run says whata/andb/hold, and givesrm -rfonly as the step after recovering them.Supersedes #4458 and #4463.