Skip to content

Commit

Permalink
Allow specifying custom upstream remote name
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackenmen committed Aug 7, 2021
1 parent f02b68c commit 2cfd2f8
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(
commit_sha1,
branches,
*,
upstream_remote=None,
dry_run=False,
push=True,
prefix_commit=True,
Expand Down Expand Up @@ -121,6 +122,7 @@ def __init__(
click.echo("Dry run requested, listing expected command sequence")

self.pr_remote = pr_remote
self.upstream_remote = upstream_remote
self.commit_sha1 = commit_sha1
self.branches = branches
self.dry_run = dry_run
Expand All @@ -136,14 +138,20 @@ def set_paused_state(self):
@property
def upstream(self):
"""Get the remote name to use for upstream branches
Uses "upstream" if it exists, "origin" otherwise
Uses the remote passed to `--upstream-remote`.
If this flag wasn't passed, it uses "upstream" if it exists or "origin" otherwise.
"""
if self.upstream_remote is not None:
return self.upstream_remote
cmd = ["git", "remote", "get-url", "upstream"]
try:
subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
except subprocess.CalledProcessError:
return "origin"
return "upstream"
self.upstream_remote = "origin"
else:
self.upstream_remote = "upstream"
return self.upstream_remote

@property
def sorted_branches(self):
Expand Down Expand Up @@ -541,6 +549,13 @@ class state:
help="git remote to use for PR branches",
default="origin",
)
@click.option(
"--upstream-remote",
"upstream_remote",
metavar="REMOTE",
help="git remote to use for upstream branches",
default=None,
)
@click.option(
"--abort",
"abort",
Expand Down Expand Up @@ -584,7 +599,7 @@ class state:
@click.argument("branches", nargs=-1)
@click.pass_context
def cherry_pick_cli(
ctx, dry_run, pr_remote, abort, status, push, config_path, commit_sha1, branches
ctx, dry_run, pr_remote, upstream_remote, abort, status, push, config_path, commit_sha1, branches
):
"""cherry-pick COMMIT_SHA1 into target BRANCHES."""

Expand All @@ -597,6 +612,7 @@ def cherry_pick_cli(
pr_remote,
commit_sha1,
branches,
upstream_remote=upstream_remote,
dry_run=dry_run,
push=push,
config=config,
Expand Down

0 comments on commit 2cfd2f8

Please sign in to comment.