Skip to content

Commit 0f5e1de

Browse files
authored
cherry_picker.py bug fixes (GH-123)
- only allow cherry_pick --continue if the current branch is a backport branch - use `git rev-parse --abbrev-ref HEAD` instead of `git symbolic-ref HEAD | sed 's!refs\/heads\/!!'` when retrieving branch names
1 parent 9b85d2a commit 0f5e1de

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

cherry_picker/cherry_picker.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ def continue_cherry_pick(self):
224224
clean up branch
225225
"""
226226
cherry_pick_branch = get_current_branch()
227-
228-
if cherry_pick_branch != 'master':
227+
if cherry_pick_branch.startswith('backport-'):
229228
# amend the commit message, prefix with [X.Y]
230229
base = get_base_branch(cherry_pick_branch)
231230
short_sha = cherry_pick_branch[cherry_pick_branch.index('-')+1:cherry_pick_branch.index(base)-1]
@@ -246,7 +245,7 @@ def continue_cherry_pick(self):
246245
click.echo(updated_commit_message)
247246

248247
else:
249-
click.echo(u"Currently in `master` branch. Will not continue. \U0001F61B")
248+
click.echo(f"Current branch ({cherry_pick_branch}) is not a backport branch. Will not continue. \U0001F61B")
250249

251250

252251
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@@ -308,7 +307,7 @@ def get_current_branch():
308307
"""
309308
Return the current branch
310309
"""
311-
cmd = "git symbolic-ref HEAD | sed 's!refs\/heads\/!!'"
310+
cmd = "git rev-parse --abbrev-ref HEAD"
312311
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
313312
return output.strip().decode('utf-8')
314313

0 commit comments

Comments
 (0)