Skip to content

feat(ui): confirm deletion of unmerged branches - #14

Merged
AgileIndustrialComplex merged 4 commits into
essafrom
claude/unmerged-branch-delete-confirm-0c9f13
Jul 19, 2026
Merged

AgileIndustrialComplex merged 4 commits into
essafrom
claude/unmerged-branch-delete-confirm-0c9f13

Conversation

@AgileIndustrialComplex

Copy link
Copy Markdown
Owner

Intent

Add a second confirmation step before deleting a branch that has unmerged changes, per a user-provided spec. wt's existing mark-then-D-then-Enter TUI delete flow uses git branch -d (non-force), which silently refuses branches not fully merged - so those branches previously had no path to deletion at all. Design: gitdata.Collect now runs 'git branch --format=%(refname:short) --merged' (format must precede --merged for this git version, discovered via manual testing) and sets a new Item.Unmerged flag per branch. If any branch in the confirmed marked set is unmerged, the picker advances to a new modeConfirmForceDelete screen instead of deleting immediately; it lists only the unmerged branches and requires the user to type an exact confirmation phrase and press Enter before proceeding (Esc/Ctrl-C cancels the whole batch, including any merged branches marked alongside it, without touching Git state). Once confirmed, action.DeleteWorktrees deletes the whole batch in one pass: git branch -d for merged branches (unchanged from before), git branch -D (force) only for the Unmerged ones. Detached-HEAD worktree entries are excluded from the unmerged check since they have no associated branch. The confirmation phrase was originally specified by the user as the literal sentence 'Yes, I want to remove the branch that has changes that have been unmerged.' but the user later asked to simplify it, so it was changed to just 'delete' (single word, still case-sensitive typed confirmation) - this was a deliberate, explicit simplification request, not an oversight, so the shorter phrase is intentional. Separately, the user asked about being able to delete/mark branches with no worktree; investigation showed that capability was already fixed in a prior commit (5836c3a, already on the default branch 'essa') by removing a HasWorktree() restriction from toggleMarked in internal/ui/ui.go - no code change was needed for that, only rebuilding/reinstalling the local wt binary from current source, so there is no corresponding diff for it on this branch. New/updated tests cover: merge-status detection in gitdata (unit tests with a fakeRunner keyed by full git invocation, since two different 'git branch' subcommands are now issued), the new confirm-phrase UI mode (wrong phrase, exact phrase, backspace editing, Esc/Ctrl-C cancel preserving marks, mixed merged+unmerged batches), the force-delete flag selection in action.DeleteWorktrees, and a real end-to-end integration test via teatest that drives mark -> D -> Enter -> typed phrase -> Enter against a real git repo and confirms git branch -D actually removes an unmerged branch. SPEC.md and README.md were updated to document the new screen and, later, the simplified phrase.

What Changed

  • Detect unmerged local branches during collection while preserving support for empty repositories with an unborn HEAD.
  • Add a second confirmation screen for mixed or unmerged deletion batches, requiring the exact phrase delete; Esc or Ctrl-C cancels the entire batch without losing marks.
  • Force-delete only confirmed unmerged branches with git branch -D, retain git branch -d for merged branches, and update tests and documentation for the new flow.

Risk Assessment

✅ Low: The change is well-bounded, the previously identified unborn-repository regression is fixed, and the required Esc/Ctrl-C cancellation coverage is now present without introducing new material risks.

Testing

All focused and repository-wide tests passed. A real terminal session demonstrated the second unmerged-change warning, case-sensitive delete prompt, force deletion, and resulting Git state. Because this is a terminal TUI rather than a graphical/browser UI, reviewer-visible evidence was captured as a rendered terminal transcript instead of a screenshot.

Evidence: Rendered terminal session showing the warning, exact confirmation phrase, and deletion
Select branch or worktree (j/k, / to filter, c to mark, ? for help)
> ● main                         [worktree]           /private/var/folders/6y/60sv_t9162q36tw66s1fnynm0000gn/T/no-mistakes-evidence/01KXXHT4T9TNVKQ4T8KP3K6GT4/demo-repo (current)
  ○ wip                          (no worktree)
  ● main                         [worktree] (current)
> ○ wip                          (no worktree)
  [ ] ● main                         [worktree] (current)
> [x] ○ wip                          (no worktree)
1 marked — [D] delete
Delete 1 branch(es) (and their worktrees, if any)?
  wip  (no worktree)
[Enter] confirm  [Esc] cancel
The following branch(es) have unmerged changes and will be permanently lost:
  wip
Type "delete" and press Enter to proceed, or Esc to cancel:
>
> d
> de
> del
> dele
> delet
> delete
Deleted branch wip (was 611d9c0).
wt: deleted 1 branch(es)
Evidence: Post-deletion Git state showing wip absent and main retained
Git state after exact confirmation:
main c74945a
Lookup of deleted unmerged branch wip (empty means absent):
Unmerged commit remains in reflog/object database for audit:
611d9c0 unmerged work

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed (2) ✅
  • ⚠️ internal/gitdata/gitdata.go:105 - The new unconditional git branch --merged query fails in a valid repository with an unborn HEAD (for example, immediately after git init, Git reports that HEAD is not a valid object). Previously Collect could finish in that state, but it now returns the command error and the picker cannot start. Skip the merged query when branches is empty (or explicitly handle the unborn-HEAD error) so adding merge-status detection does not break empty repositories.

🔧 Fix: Handle branch collection in unborn repositories
1 warning still open:

  • ⚠️ internal/ui/ui_test.go:437 - The acceptance criterion says the new UI tests cover “Esc/Ctrl-C cancel preserving marks,” but this test exercises only Esc; there is no force-confirmation test sending tea.KeyCtrlC. Please add Ctrl-C to this test (for example, table-drive both keys) so the required cancellation behavior is explicitly covered.

🔧 Fix: Cover Ctrl-C force-delete cancellation
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • go test ./internal/gitdata ./internal/ui ./internal/action
  • go test . -run 'TestIntegrationDelete(UnmergedBranchRequiresForcePhrase|MarkedBranchWithoutWorktree)$' -v
  • go test ./...
  • Built cmd/wt, created a real divergent Git repository, drove j → c → D → Enter → delete → Enter through the actual TUI in a PTY, and verified the unmerged wip branch was removed while main remained
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

AgileIndustrialComplex and others added 4 commits July 19, 2026 18:11
Replace the full sentence confirmation with a single word ("delete") per
user request - still requires deliberate typed input before force-deleting
an unmerged branch, just less verbose.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@AgileIndustrialComplex
AgileIndustrialComplex force-pushed the claude/unmerged-branch-delete-confirm-0c9f13 branch from cf95537 to 5bfd01b Compare July 19, 2026 16:12
@AgileIndustrialComplex
AgileIndustrialComplex merged commit 4d323fa into essa Jul 19, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant