Skip to content

Clean up merged remote branches; fast remote branch list - #77

Merged
rocketraman merged 2 commits into
masterfrom
claude/cleanup-merged-remote-branches-276d52
Oct 29, 2026
Merged

rocketraman merged 2 commits into
masterfrom
claude/cleanup-merged-remote-branches-276d52

Conversation

@rocketraman

Copy link
Copy Markdown
Owner

Clean up merged remote branches

Each remote's heading in Remote branches gets Clean up N merged. It deletes every merged branch shown for that remote, including squash-merged ones, and skips integration branches. A confirmation lists the branches first.

  • It's scoped per remote: in a fork, sweeping your own copy and sweeping the project's remote are separate decisions.
  • Each delete is leased on the tip from the last fetch, so a branch someone has pushed to since is skipped, not deleted with their commits.
  • A branch already deleted on the remote counts as deleted, and its stale local copy is dropped.
  • It's one ls-remote plus chunked pushes per remote, not a push per branch.

Remote branch list: loading indicator and speed

On a repo with ~250 remote branches the list took ~22s to appear and showed "No remote branches" until then. It now shows Loading…, and takes ~1.7s cold and ~25ms when you come back to the repo.

  • Cause: the squash-merge check ran git log -p … -- <every file the branch changed>. git matches each pathspec against every commit it walks, which took 5–7s for a single branch of a few thousand files; the same log with no pathspec takes 40ms. Candidate commits now come from a --name-only log with no pathspec, and only those few are diffed. Results matched the old algorithm on all 249 branches of the test repo.
  • The answers are cached by (branch tip, mainline tip).
  • "In mainline's history" is now one for-each-ref --merged, not one process per branch.
  • Six branches are checked at a time.

Testing

  • 4 new BranchOps.deleteRemotes tests: a normal batch, a branch pushed to since the fetch, one already gone on the remote, and one the server refuses.
  • Full suite: 252 tests, 0 failures, from parsed result XML. detekt is clean.
  • Not yet checked by hand in the running app.

Each remote's heading in Remote branches gets "Clean up N merged", which
deletes every merged (or squash-merged) branch shown for that remote,
skipping integration branches. Unlike a single merged delete it asks
first, listing the branches, since it deletes ones the click never named
on a server others share.

BranchOps.deleteRemotes does one ls-remote and a few chunked pushes per
remote. Each delete is leased on the tip last fetched, so a branch pushed
to since is skipped; one already deleted on the remote counts as deleted
and its stale copy is dropped. Popup.Confirm gains an optional details
list to show the names, as the message is capped at three lines.

Signed-off-by: Raman Gupta <rocketraman@gmail.com>
…loading

On a repo with ~250 remote branches the list took ~22s to appear, showing
"No remote branches" meanwhile. It now shows "Loading…", and loads in
~1.7s cold and ~25ms when returning to the repo.

Nearly all the time was the squash-merge check, and within it the
pathspec on `git log -p <base>..<mainline> -- <branch's files>`: git
matches every pathspec against every commit walked, 5-7s for one branch
of a few thousand files. Candidates now come from a pathspec-free
--name-only log (commits touching all of the branch's files) and only
those are diffed. Answers are identical on all 249 branches checked.

Also: results are cached by (branch tip, mainline tip), the ancestry test
is one for-each-ref --merged instead of a process per branch, and
branches are tested six at a time. Reopening the section mid-load no
longer starts a second load, and leaving the repo cancels it.

Signed-off-by: Raman Gupta <rocketraman@gmail.com>
@rocketraman
rocketraman force-pushed the claude/cleanup-merged-remote-branches-276d52 branch from 5503c77 to 412f94c Compare October 29, 2026 18:42
@rocketraman
rocketraman merged commit ff2022e into master Oct 29, 2026
2 checks passed
@rocketraman
rocketraman deleted the claude/cleanup-merged-remote-branches-276d52 branch October 29, 2026 18:42
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