feat(log-tui): D on the worktrees view removes worktree + branch (#838)#843
Merged
feat(log-tui): D on the worktrees view removes worktree + branch (#838)#843
Conversation
Two delete actions in the worktrees view, with W keeping its existing semantics so muscle memory carries: - W (existing): remove worktree only. Leaves the branch in place for the user to re-attach later or delete separately. - D (new): remove worktree AND delete the branch it was tracking. Chains git worktree remove → git branch -d, with both pre-flight guards inherited from the underlying helpers (refuses current/dirty worktrees; uses safe -d so unmerged branches don't lose work). Per-view scoping in inkInput intercepts D on the worktrees surface before the global workflow-by-key dispatcher would otherwise route it to delete-branch (which would target whatever was last cursored on the branches view rather than acting on the worktree under the cursor here). D from elsewhere keeps doing what it always did. The chained helper handles partial failures with named-step messages so the user knows exactly which step broke if anything does. Detached worktrees and worktrees whose tracked branch isn't in the local ref list both skip the branch step cleanly with a "removed worktree (no branch to delete)" success. Closes #838. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #838.
Summary
Two delete actions in the worktrees view, with
Wkeeping its existing semantics so muscle memory carries:W(existing)D(new)git worktree remove→git branch -d.Both pre-flight guards inherit from the underlying helpers:
removeWorktreerefuses the current worktree and dirty worktrees.deleteBranchrefuses the current branch and uses safe-d(so unmerged branches don't silently lose work).Why per-view scoping for
DThe global workflow-by-key dispatcher already routes
Dtodelete-branchfrom anywhere in the TUI. Without per-view interception, pressingDon a worktree would silently target whatever was last cursored on the branches view rather than acting on the worktree under the cursor. TheinkInputper-view scope (isWorktreeActionTarget(state) && context.worktreeListCount) catchesDon the worktrees surface and routes it to the newremove-worktree-and-branchworkflow before the global fallback sees it. From any other surface,Dkeeps doing what it always did.Failure modes
Removed worktree X, but branch delete failed: <git error>. Manual recovery: re-create the worktree if needed, then handle the branch separately.(no branch to delete)success message.Test plan
npm run lintnpm run test:jest(1154 tests pass — added 5 new helper tests covering the happy path + partial-failure + 3 skip-the-branch-step paths, plus 4 input dispatch tests covering the per-view interception)npm run buildnpm run test:cligit worktree add ../foo feat/foo,coco ui,g w, cursor the new worktree, pressD, confirmy, verify both the worktree directory and thefeat/foobranch are goneFollow-up (not in this PR)
The cross-surface case from the original issue (pressing
Don a branch in the branches view that has an attached worktree fails) isn't fully closed. With the worktrees view as the canonical place to do worktree-lifecycle ops, the branches view'sDcould grow a clearer error pointing the user at "pressg wthenD". Left for a separate small PR if the new flow doesn't make the cross-surface confusion fade naturally.🤖 Generated with Claude Code