Skip to content

Commit

Permalink
Skip the current branch when cleaning up merged branches
Browse files Browse the repository at this point in the history
  • Loading branch information
borntyping committed Apr 27, 2022
1 parent 4093b69 commit f41c712
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions git_river/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,21 @@ def remove_merged_branches(self, target: str, *, dry_run: bool = True) -> None:
"""Remove branches that have been merged into the repo's default branch."""
log = self.bind(logger).bind(target=target, dry_run=dry_run)
merged_branches = self.merged(target)
active_branch = self.repo.active_branch.name
for merged_branch in merged_branches:
if active_branch == merged_branch:
log.debug("Skipping current branch", head=merged_branch)
continue

if merged_branch.startswith("release/"):
log.debug("Skipping release/* branch", head=merged_branch)
continue

if dry_run:
log.info("Would delete branch", head=merged_branch)
continue

log.info("Deleting branch", head=merged_branch)
self.repo.delete_head(merged_branch)
else:
log.info("Deleting branch", head=merged_branch)
self.repo.delete_head(merged_branch)

def merged(self, target: str) -> typing.Set[str]:
"""Return a list of branches merged into a target branch."""
Expand Down

0 comments on commit f41c712

Please sign in to comment.