diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index b637c92..f24547f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -321,7 +321,9 @@ def push_to_remote(self, base_branch, head_branch, commit_message=""): if head_branch.startswith("backport-"): # Overwrite potential stale backport branches with extreme prejudice. cmd.append("--force-with-lease") - cmd += [self.pr_remote, f"{head_branch}:{head_branch}"] + cmd.append(self.pr_remote) + if not self.is_mirror(): + cmd.append(f"{head_branch}:{head_branch}") try: self.run_cmd(cmd) set_state(WORKFLOW_STATES.PUSHED_TO_REMOTE) @@ -436,7 +438,8 @@ def backport(self): self.push_to_remote( maint_branch, cherry_pick_branch, commit_message ) - self.cleanup_branch(cherry_pick_branch) + if not self.is_mirror(): + self.cleanup_branch(cherry_pick_branch) else: click.echo( f""" @@ -515,7 +518,8 @@ def continue_cherry_pick(self): self.push_to_remote(base, cherry_pick_branch) - self.cleanup_branch(cherry_pick_branch) + if not self.is_mirror(): + self.cleanup_branch(cherry_pick_branch) click.echo("\nBackport PR:\n") click.echo(updated_commit_message) @@ -571,6 +575,16 @@ class state: ) return state + def is_mirror(self) -> bool: + """Return True if the current repository was created with --mirror.""" + + cmd = ["git", "config", "--local", "--get", "remote.origin.mirror"] + try: + out = self.run_cmd(cmd) + except subprocess.CalledProcessError: + return False + return out.startswith("true") + CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])