Skip to content

Commit 9456b48

Browse files
authored
cherry_picker: add a flag if backport commit msg should be prefixed (GH-193)
Keep the existing functionality that by default the backport commit message will be prefixed with [X.Y]. Part one for fixing python/miss-islington#38
1 parent 70e4522 commit 9456b48

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cherry_picker/cherry_picker.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ class CherryPickException(Exception):
2525
class CherryPicker:
2626

2727
def __init__(self, pr_remote, commit_sha1, branches,
28-
*, dry_run=False, push=True):
28+
*, dry_run=False, push=True,
29+
prefix_commit=True
30+
):
2931
self.pr_remote = pr_remote
3032
self.commit_sha1 = commit_sha1
3133
self.branches = branches
3234
self.dry_run = dry_run
3335
self.push = push
36+
self.prefix_commit = prefix_commit
3437

3538
@property
3639
def upstream(self):
@@ -142,9 +145,11 @@ def get_exit_message(self, branch):
142145

143146
def amend_commit_message(self, cherry_pick_branch):
144147
""" prefix the commit message with (X.Y) """
145-
base_branch = get_base_branch(cherry_pick_branch)
146148

147-
updated_commit_message = f"[{base_branch}] {self.get_commit_message(self.commit_sha1)}{os.linesep}(cherry picked from commit {self.commit_sha1})"
149+
commit_prefix = ""
150+
if self.prefix_commit:
151+
commit_prefix = f"[{get_base_branch(cherry_pick_branch)}] "
152+
updated_commit_message = f"{commit_prefix}{self.get_commit_message(self.commit_sha1)}{os.linesep}(cherry picked from commit {self.commit_sha1})"
148153
updated_commit_message = updated_commit_message.replace('#', 'GH-')
149154
if self.dry_run:
150155
click.echo(f" dry-run: git commit --amend -m '{updated_commit_message}'")

0 commit comments

Comments
 (0)