From 596a9262072976f98a19fcd50dc8ead5fd50e1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Fri, 20 May 2022 10:39:48 +0200 Subject: [PATCH 1/3] Add support for git clones made with the `--mirror` option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of a git repository mirror, all branches are kept in sync all the time. Trying to push out a particular refspec errors out with: Failed to push to origin ☹ fatal: --mirror can't be combined with refspecs This change adds support for mirrors. Tested with: https://github.com/python/cpython/pull/92981 --- cherry_picker/cherry_picker.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index b637c92..46be2b1 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 += [f"{head_branch}:{head_branch}"] try: self.run_cmd(cmd) set_state(WORKFLOW_STATES.PUSHED_TO_REMOTE) @@ -571,6 +573,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"]) From 02a9c1079ea438dbecd9ca666d20b8724b277ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Mon, 23 May 2022 12:52:18 +0200 Subject: [PATCH 2/3] Just append a single value Co-authored-by: Ezio Melotti --- cherry_picker/cherry_picker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 46be2b1..298a98e 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -323,7 +323,7 @@ def push_to_remote(self, base_branch, head_branch, commit_message=""): cmd.append("--force-with-lease") cmd.append(self.pr_remote) if not self.is_mirror(): - cmd += [f"{head_branch}:{head_branch}"] + cmd.append(f"{head_branch}:{head_branch}") try: self.run_cmd(cmd) set_state(WORKFLOW_STATES.PUSHED_TO_REMOTE) From c20a55e2e4545d15ed6873701a3960f40fe297ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Fri, 1 Jul 2022 18:31:15 +0200 Subject: [PATCH 3/3] Don't automatically delete the current backport branch after pushing on mirrors --- cherry_picker/cherry_picker.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index 298a98e..f24547f 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -438,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""" @@ -517,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)