feat: detect squash/rebase-merged PRs for branch cleanup#402
Merged
atoomic merged 1 commit intosukria:mainfrom Feb 23, 2026
Merged
Conversation
git branch --merged only detects fast-forward merges where commits are direct ancestors of the target branch. Squash-merged and rebase-merged PRs (the most common merge strategies) have different commit SHAs, so their local branches accumulate forever — 90+ stale branches in practice. New get_github_merged_branches() queries gh pr list --state merged to batch-detect branches whose PRs are confirmed merged on GitHub. The cleanup_merged_branches() method now accepts both git-detected (safe -d) and GitHub-detected (force -D) merged branches, with proper dedup. The sync report combines both sources and removes cleaned branches from the unmerged section. 18 new tests, 6230 total pass.
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.
Summary
git branch --mergedonly detects fast-forward merges. Squash-merged and rebase-merged PRs (the most common strategies) produce different commit SHAs, so their local branches are never cleaned up — 90+ stale branches accumulated.get_github_merged_branches()queriesgh pr list --state mergedto batch-detect branches whose PRs are confirmed merged on GitHub.cleanup_merged_branches()now handles both git-detected (safe-d) and GitHub-detected (force-D) merges.Changes
git_sync.py: Addedget_github_merged_branches()method, extendedcleanup_merged_branches()with two-phase cleanup (safe + force), updatedbuild_sync_report()to integrate both sourcestest_git_sync.py: 18 new tests covering GitHub detection, force-delete safety, deduplication, error handling, and report integrationSafety
git branch -d(safe delete, refuses if not merged)git branch -D(force delete), only for branches confirmed merged by GitHub APIghCLI is unavailable, falls back to git-only detectionTest plan
TestGetGithubMergedBranchestests pass (error handling, filtering, dedup)TestCleanupWithGithubMergedtests pass (force-delete, skip logic, safety)get_github_merged_branches()call🤖 Generated by Kōan (autonomous session)