Skip to content

fix(remove): don't point at a detached worktree removed in the same run - #4313

Merged
max-sixty merged 1 commit into
mainfrom
nightly/clean-36388757635
Sep 28, 2026
Merged

max-sixty merged 1 commit into
mainfrom
nightly/clean-36388757635

Conversation

@worktrunk-bot

@worktrunk-bot worktrunk-bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

#3791 made a branch-only wt remove name the detached worktree still sitting at the branch's path, with a hint to run wt remove <that path>. When the user does that in the same command, wt remove feature ../repo.feature, the worktree removal runs first. The branch-only line then still reports the now-deleted directory and suggests removing it:

✓ Removed worktree @ ~/repo.both-detached (detached HEAD, no branch to delete)
○ No worktree found for branch both-detached; a detached worktree is @ ~/repo.both-detached
↳ To remove the detached worktree, run wt remove ~/repo.both-detached
✓ Removed branch both-detached (same commit as main, _)

--format=json carries the same stale detached_worktree path. The annotation is computed per target inside validate_remove_targets, before the other targets are known. This PR clears it after the loop when another plan in the same run (others or current) removes that path. The check runs after the loop because the path argument can come before or after the branch. A path target that failed validation isn't removed, so its hint stays.

test_remove_branch_and_its_detached_worktree_together fails on main with the output above and passes with the fix. All 142 remove:: integration tests, including the new one, pass locally.

`wt remove <branch> <its-detached-path>` removed the detached worktree and
then told the user to remove that same directory, because the branch-only
plan's annotation was computed before the other targets were known. Clear it
when another plan in the run removes that path.

Co-Authored-By: Claude <[email protected]>
@worktrunk-bot worktrunk-bot added the nightly-cleanup Issues found by nightly code quality sweep label Sep 28, 2026
@max-sixty
max-sixty merged commit d059416 into main Sep 28, 2026
37 of 47 checks passed
@max-sixty
max-sixty deleted the nightly/clean-36388757635 branch September 28, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants