From f41c71262dc20c4f52b2565a6ae6565cf9d4ab73 Mon Sep 17 00:00:00 2001 From: Sam Clements Date: Wed, 27 Apr 2022 11:10:47 +0100 Subject: [PATCH] Skip the current branch when cleaning up merged branches --- git_river/repository.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/git_river/repository.py b/git_river/repository.py index af9922e..95520bb 100644 --- a/git_river/repository.py +++ b/git_river/repository.py @@ -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."""