Skip to content

Add delete worktree action to branch-folder chooser#24

Merged
seankearon merged 2 commits into
mainfrom
claude/worktree-branch-deletion-c9zg9o
Jul 1, 2026
Merged

Add delete worktree action to branch-folder chooser#24
seankearon merged 2 commits into
mainfrom
claude/worktree-branch-deletion-c9zg9o

Conversation

@seankearon

Copy link
Copy Markdown
Owner

Summary

Adds a Delete worktree & branch action to the branch-folder chooser dialog in branch-only mode. When a linked worktree is located on a branch, users can now delete the worktree, its local branch, and the corresponding remote branch (if it exists) directly from the UI.

Key Changes

  • New deletion workflow: Added DeleteWorktreeDialog confirmation dialog that warns about uncommitted changes, orphaned commits, and remote branch status before proceeding with deletion.

  • Git service enhancements: Extended GitService with new methods:

    • IsLinkedWorktreeAsync() — detects linked worktrees vs. main tree
    • WorktreeRemoveAsync() — removes a worktree (with force option for dirty trees)
    • DeleteLocalBranchAsync() / DeleteRemoteBranchAsync() — branch deletion
    • CountOrphanedCommitsAsync() — counts commits unique to a branch
  • Opener service integration: Added BuildWorktreeDeletionAsync() and DeleteWorktreeAsync() to orchestrate the full deletion flow, gathering deletion metadata and executing the git operations.

  • UI updates:

    • Enhanced ChooserDialog with optional delete button (shown only when a delete label is provided)
    • Modified MainWindow.ChooseOpenTargetAsync() to detect linked worktrees and offer delete action for non-default branches
    • Added DeleteWorktreeDialog with visual warnings for dirty worktrees and orphaned commits
    • Updated ChooserViewModel to support the delete button
  • Safety guards:

    • Delete action only offered for linked worktrees (not the main tree)
    • Default branches (main/master) are protected — no delete option offered
    • Confirmation dialog shows worktree path, branch name, remote status, and data-loss warnings
    • Failed remote deletes don't block local cleanup; partial success is reported
  • Test coverage: Comprehensive end-to-end tests covering:

    • Successful deletion of pushed branches
    • Declining confirmation (nothing deleted)
    • Unpushed branches (local-only deletion)
    • Dirty worktrees (forced removal)
    • Worktrees with no solution files
    • Protected default branches
    • Failed remote deletes with successful local cleanup
    • Multi-folder scenarios (deleting from one clone doesn't affect others)

Implementation Details

  • The delete action is resolved early in the chooser flow so it's available even when there are no solutions to open (folder-only editors or worktrees without .sln files).
  • Deletion runs from the clone's main tree to avoid standing inside the worktree being removed.
  • Remote branch deletion is attempted but doesn't fail the operation if it's already gone — the local cleanup is the critical part.
  • Orphaned commit detection uses git rev-list to identify unpushed, unmerged work that would be lost.

https://claude.ai/code/session_019JuVApu68rjnvBUEY5NCBV

claude added 2 commits July 1, 2026 14:26
When branch-only mode locates a linked worktree, the "Open from branch
folder" dialog now offers a "Delete worktree & branch" button that removes
the linked worktree, deletes the local branch, and deletes the branch on
origin when present. The git steps run from the clone's main tree so the
worktree is dropped cleanly; a dirty worktree is force-removed after a
warning, and a failed remote delete leaves the completed local cleanup in
place and reports it.

A confirmation dialog spells out the worktree path, local branch, and
origin state, with explicit data-loss warnings for uncommitted changes and
for commits that exist only on the branch (unpushed/unmerged work that
`git branch -D` would orphan).

Safety:
- Offered only for a linked worktree (main tree can't be worktree-removed),
  detected via git-dir comparison so it stays correct under symlinked roots.
- Default branches (main/master) are never offered.
- The destructive button is out of the tab order; Cancel/Enter/Esc back out.
- Reachable even when there's nothing to open (folder-only editor or a
  worktree with no solution file).

Covered by GitService, dialog-widget, and end-to-end tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019JuVApu68rjnvBUEY5NCBV
The confirmation dialog now shows a checkbox for each present target — the
worktree, its local branch, and the branch on origin — each ticked by
default. Unticking one skips its deletion, so you can (for example) drop
only the remote branch or remove the worktree while keeping its branches.

Because a checked-out branch can't be deleted, keeping the worktree
disables (and clears) the local-branch checkbox. Delete is disabled when
nothing is selected, and the deletion carries out exactly the ticked
targets, reporting precisely what it removed.

Docs (Features, CHANGELOG, screenshot gallery) updated. Adds UI tests for
the checkbox behaviour and a screenshot test that captures the deletion
dialog and the branch-folder chooser (with its delete button) in both
light and dark themes; the captured PNGs are committed to the gallery.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019JuVApu68rjnvBUEY5NCBV
@seankearon seankearon merged commit add27cb into main Jul 1, 2026
2 checks passed
@seankearon seankearon deleted the claude/worktree-branch-deletion-c9zg9o branch July 1, 2026 15:11
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.

2 participants