From 1093ad084f352b76cab21718f68030190962ca97 Mon Sep 17 00:00:00 2001 From: Mariatta Wijaya Date: Thu, 4 May 2017 21:23:33 -0700 Subject: [PATCH] Add --no-push option When supplied, changes won't be pushed to remote. Use --continue or --abort afterwards. Document --no-push option Modify --abort behavior, ensuring that only branch created by cherry-picker.py gets deleted. --- cherry_picker/cherry_picker.py | 34 +++++++++++++++++++++++++++------- cherry_picker/readme.rst | 12 ++++++++++-- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/cherry_picker/cherry_picker.py b/cherry_picker/cherry_picker.py index f18f1a2..f5e6e51 100755 --- a/cherry_picker/cherry_picker.py +++ b/cherry_picker/cherry_picker.py @@ -10,11 +10,12 @@ class CherryPicker: def __init__(self, pr_remote, commit_sha1, branches, - *, dry_run=False): + *, dry_run=False, push=True): self.pr_remote = pr_remote self.commit_sha1 = commit_sha1 self.branches = branches self.dry_run = dry_run + self.push = push @property def upstream(self): @@ -192,8 +193,21 @@ def backport(self): click.echo(self.get_exit_message(maint_branch)) sys.exit(-1) else: - self.push_to_remote(maint_branch, cherry_pick_branch) - self.cleanup_branch(cherry_pick_branch) + if self.push: + self.push_to_remote(maint_branch, cherry_pick_branch) + self.cleanup_branch(cherry_pick_branch) + else: + click.echo(\ +f""" +Finished cherry-pick {self.commit_sha1} into {cherry_pick_branch} \U0001F600 +--no-push option used. +... Stopping here. +To continue and push the changes: + $ python -m cherry_picker --continue + +To abort the cherry-pick and cleanup: + $ python -m cherry_picker --abort +""") def abort_cherry_pick(self): """ @@ -204,7 +218,8 @@ def abort_cherry_pick(self): self.run_cmd(cmd) except subprocess.CalledProcessError as cpe: click.echo(cpe.output) - else: + # only delete backport branch created by cherry_picker.py + if get_current_branch().startswith('backport-'): self.cleanup_branch(get_current_branch()) def continue_cherry_pick(self): @@ -245,12 +260,15 @@ def continue_cherry_pick(self): help="Abort current cherry-pick and clean up branch") @click.option('--continue', 'abort', flag_value=False, default=None, help="Continue cherry-pick, push, and clean up branch") -@click.option('--status', 'status', flag_value = True, default=None, +@click.option('--status', 'status', flag_value=True, default=None, help="Get the status of cherry-pick") +@click.option('--push/--no-push', 'push', is_flag=True, default=True, + help="Changes won't be pushed to remote") @click.argument('commit_sha1', 'The commit sha1 to be cherry-picked', nargs=1, default = "") @click.argument('branches', 'The branches to backport to', nargs=-1) -def cherry_pick_cli(dry_run, pr_remote, abort, status, commit_sha1, branches): +def cherry_pick_cli(dry_run, pr_remote, abort, status, push, + commit_sha1, branches): click.echo("\U0001F40D \U0001F352 \u26CF") current_dir = os.path.dirname(os.path.abspath(__file__)) @@ -262,7 +280,9 @@ def cherry_pick_cli(dry_run, pr_remote, abort, status, commit_sha1, branches): if dry_run: click.echo("Dry run requested, listing expected command sequence") - cherry_picker = CherryPicker(pr_remote, commit_sha1, branches, dry_run=dry_run) + cherry_picker = CherryPicker(pr_remote, commit_sha1, branches, + dry_run=dry_run, + push=push) if abort is not None: if abort: diff --git a/cherry_picker/readme.rst b/cherry_picker/readme.rst index d23ea2a..88aa8e9 100644 --- a/cherry_picker/readme.rst +++ b/cherry_picker/readme.rst @@ -1,6 +1,6 @@ Usage:: - python -m cherry_picker [--push REMOTE] [--dry-run] [--status] [--abort/--continue] + python -m cherry_picker [--push REMOTE] [--dry-run] [--status] [--abort/--continue] [--no-push] Alternate Usage (from an existing cpython directory):: @@ -88,7 +88,7 @@ Additional options:: -- abort Abort current cherry-pick and clean up branch -- continue Continue cherry-pick, push, and clean up branch - + -- no-push Changes won't be pushed to remote Demo ---- @@ -183,6 +183,14 @@ Cancels the current cherry-pick and cleans up the cherry-pick branch. Continues the current cherry-pick, commits, pushes the current branch to origin, opens the PR page, and cleans up the branch. +`--no-push` option +------------------ + +Changes won't be pushed to remote. This allows you to test and make additional +changes. Once you're satisfied with local changes, use `--continue` to complete +the backport, or `--abort` to cancel and clean up the branch. + + Creating Pull Requests ======================