Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"])

Expand Down