Skip to content

Add --no-push option #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2017
Merged
Show file tree
Hide file tree
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
34 changes: 27 additions & 7 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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__))
Expand All @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions cherry_picker/readme.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Usage::

python -m cherry_picker [--push REMOTE] [--dry-run] [--status] [--abort/--continue] <commit_sha1> <branches>
python -m cherry_picker [--push REMOTE] [--dry-run] [--status] [--abort/--continue] [--no-push] <commit_sha1> <branches>

Alternate Usage (from an existing cpython directory)::

Expand Down Expand Up @@ -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
----
Expand Down Expand Up @@ -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
======================

Expand Down