Skip to content

wt remove <branch> silently strands the worktree when its HEAD is detached #3769

Description

@chachi

wt remove <branch> on a worktree whose HEAD has since been detached deletes the branch, leaves the worktree, and exits 0 reporting success.

Worktrees go detached routinely — Codex creates one per session, and 0.72.0's own release notes say so. Any of those that started life on a branch is now in this state.

Repro

git init -b main repo && cd repo
git commit --allow-empty -m init
wt switch -c feature
git -C ../repo.feature checkout --detach
cd ../repo
wt remove feature --yes --foreground; echo "exit=$?"
git worktree list

Actual

○ No worktree found for branch feature
✓ Removed branch feature (same commit as main, _)
exit=0
/tmp/…/repo          efb554a [main]
/tmp/…/repo.feature  efb554a (detached HEAD)

The branch is gone, the worktree and its registration are still there, and the
command reported success. Nothing in the output says a removal was skipped: the
line reads as information, the line reads as the result, and a script checking
the exit code sees a clean run.

Expected

Either remove the worktree (it is the one wt switch -c feature created, and
wt remove <path> removes it happily), or refuse — but do not delete the branch and
report success while the worktree stays behind. The failing half is silent, so the
caller learns about it the next time something walks git worktree list.

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions