Skip to content

Delete a merged branch together with its remote branch - #70

Merged
rocketraman merged 1 commit into
masterfrom
claude/branch-deletion-merged-d74c98
Oct 20, 2026
Merged

rocketraman merged 1 commit into
masterfrom
claude/branch-deletion-merged-d74c98

Conversation

@rocketraman

Copy link
Copy Markdown
Owner

Cleaning up after a merged PR took one delete in the local branch list and another in the remote list. This does both in one step, from the branch list and from a worktree.

What changed

Branch list. A merged local branch shows Delete both when its upstream:

  • still exists on the remote,
  • has no commits the local branch lacks (so it's merged too), and
  • isn't a shared integration branch (main, develop, …).

Like the existing deletes of merged branches, there's no confirmation.

Worktree card. When the remote branch can go too, "Remove + branch" reads Remove + branch + origin. The confirm dialog has a ticked Also delete "origin/…" on origin box, and the button reads "Remove all" or "Remove both" depending on it. The box is in the dialog rather than a separate button because this is the part that reaches the server.

Worktree sub-row (table). "Remove + branch" is gone from the hover actions, which are now Diff, Log and Terminal. Deleting a branch should happen from the card, where you can see the branch, not from actions that appear when the pointer passes over the row.

Table layout. The name column takes 30% of the table width, between 262dp and 560dp, instead of a fixed 262dp. Long claude/… worktree branch names now fit on a wide window. The sub-rows' badge column now lines up with the repo row's; it was 16dp to the left before.

For reviewers

  • Both remote deletes are leased (--force-with-lease=refs/heads/<b>:<last-fetched sha>). If someone pushed to the branch since the last fetch, the remote refuses instead of discarding their commits. The shared helper is BranchOps.deleteUpstreamLeased.
  • Order: "Delete both" deletes the remote branch first. If the remote refuses, the local branch is still there to retry from. On the worktree path the folder and local branch go regardless, and the toast says the remote branch was kept. It's still in the remote list.
  • Scan cost: Worktree.deletableUpstream is computed on the scan path, but only for merged worktrees: one extra for-each-ref each.
  • New dialog type: Popup.ConfirmWithOption is a new popup (one checkbox), so the 15 existing Popup.Confirm call sites are unchanged.

Testing

  • 6 new tests in BranchOpsTest and WorktreeOpsTest:
    • both branches deleted;
    • lease refusal keeps the remote branch;
    • upstream offered or withheld;
    • worktree removal with and without a concurrent push.
  • All 207 tests pass, checked in the result XML. detekt is clean.
  • Checked visually in an isolated kwin session against a scratch repo:
    • column widths and badge alignment;
    • the card label;
    • the dialog's wrapping checkbox and its button label switch.
  • Not exercised in the app: the branch list's "Delete both" itself (unit tests only).

Cleaning up after a merged PR took a delete in the local list and
another in the remote list. A merged local branch whose upstream still
exists, holds nothing the branch lacks and isn't a shared integration
branch now offers "Delete both".

The worktree card's "Remove + branch" gets the same reach. When the
remote branch can go too, it reads "Remove + branch + origin", and the
dialog has a ticked "Also delete origin/..." box to keep it instead.
The action is gone from the table's worktree sub-row: deleting a branch
is a call to make with the card open, not from a hover lane.

Both remote deletes are leased on the tip last fetched, so a branch
someone pushed to since is refused rather than deleted. The remote goes
first, leaving the local branch to retry from if the remote refuses.

The table's name column now takes 30% of the table width (262-560dp)
instead of a fixed 262dp, so long claude/... worktree branch names fit
on a wide window. The sub-row's badges also line up with the repo row's
now; they sat 16dp to the left before.

Signed-off-by: Raman Gupta <rocketraman@gmail.com>
@rocketraman
rocketraman merged commit cbd976f into master Oct 20, 2026
2 checks passed
@rocketraman
rocketraman deleted the claude/branch-deletion-merged-d74c98 branch October 20, 2026 23:14
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