Skip to content

Commit e4ece75

Browse files
authored
Unset backport branch's remote from upstream (#85)
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.
1 parent 3e48d19 commit e4ece75

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cherry_picker/cherry_picker.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def __init__(
109109
chosen_config_path=None,
110110
auto_pr=True,
111111
):
112-
113112
self.chosen_config_path = chosen_config_path
114113
"""The config reference used in the current runtime.
115114
@@ -239,11 +238,11 @@ def checkout_branch(self, branch_name, *, create_branch=False):
239238
try:
240239
self.run_cmd(cmd)
241240
except subprocess.CalledProcessError as err:
242-
click.echo(
243-
f"Error checking out the branch {checked_out_branch!r}."
244-
)
241+
click.echo(f"Error checking out the branch {checked_out_branch!r}.")
245242
click.echo(err.output)
246243
raise BranchCheckoutException(checked_out_branch)
244+
if create_branch:
245+
self.unset_upstream(checked_out_branch)
247246

248247
def get_commit_message(self, commit_sha):
249248
"""
@@ -485,6 +484,13 @@ def cleanup_branch(self, branch):
485484
click.echo(f"branch {branch} has been deleted.")
486485
set_state(WORKFLOW_STATES.REMOVED_BACKPORT_BRANCH)
487486

487+
def unset_upstream(self, branch):
488+
cmd = ["git", "branch", "--unset-upstream", branch]
489+
try:
490+
return self.run_cmd(cmd)
491+
except subprocess.CalledProcessError as cpe:
492+
click.echo(cpe.output)
493+
488494
def backport(self):
489495
if not self.branches:
490496
raise click.UsageError("At least one branch must be specified.")

0 commit comments

Comments
 (0)