Skip to content

Commit

Permalink
Unset backport branch's remote from upstream (#85)
Browse files Browse the repository at this point in the history
This way the user can easily commit and push further changes to the backport,
if needed, without having to remember to append their fork's remote name to
`git push`.

The branch sets the upstream as the remote during `git checkout -b`. This isn't
a useful default as we push the resulting backport to the user's fork anyway
and it is never intended to either merge further upstream changes nor to push
to upstream directly.
  • Loading branch information
ambv authored Aug 15, 2023
1 parent 3e48d19 commit e4ece75
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def __init__(
chosen_config_path=None,
auto_pr=True,
):

self.chosen_config_path = chosen_config_path
"""The config reference used in the current runtime.
Expand Down Expand Up @@ -239,11 +238,11 @@ def checkout_branch(self, branch_name, *, create_branch=False):
try:
self.run_cmd(cmd)
except subprocess.CalledProcessError as err:
click.echo(
f"Error checking out the branch {checked_out_branch!r}."
)
click.echo(f"Error checking out the branch {checked_out_branch!r}.")
click.echo(err.output)
raise BranchCheckoutException(checked_out_branch)
if create_branch:
self.unset_upstream(checked_out_branch)

def get_commit_message(self, commit_sha):
"""
Expand Down Expand Up @@ -485,6 +484,13 @@ def cleanup_branch(self, branch):
click.echo(f"branch {branch} has been deleted.")
set_state(WORKFLOW_STATES.REMOVED_BACKPORT_BRANCH)

def unset_upstream(self, branch):
cmd = ["git", "branch", "--unset-upstream", branch]
try:
return self.run_cmd(cmd)
except subprocess.CalledProcessError as cpe:
click.echo(cpe.output)

def backport(self):
if not self.branches:
raise click.UsageError("At least one branch must be specified.")
Expand Down

0 comments on commit e4ece75

Please sign in to comment.