Skip to content

Commit

Permalink
cherry_picker: add a flag if backport commit msg should be prefixed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mariatta committed Oct 19, 2017
1 parent 092f289 commit 81b94d8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cherry_picker/cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ class CherryPickException(Exception):
class CherryPicker:

def __init__(self, pr_remote, commit_sha1, branches,
*, dry_run=False, push=True):
*, dry_run=False, push=True,
prefix_commit=True
):
self.pr_remote = pr_remote
self.commit_sha1 = commit_sha1
self.branches = branches
self.dry_run = dry_run
self.push = push
self.prefix_commit = prefix_commit

@property
def upstream(self):
Expand Down Expand Up @@ -142,9 +145,11 @@ def get_exit_message(self, branch):

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

updated_commit_message = f"[{base_branch}] {self.get_commit_message(self.commit_sha1)}{os.linesep}(cherry picked from commit {self.commit_sha1})"
commit_prefix = ""
if self.prefix_commit:
commit_prefix = f"[{get_base_branch(cherry_pick_branch)}] "
updated_commit_message = f"{commit_prefix}{self.get_commit_message(self.commit_sha1)}{os.linesep}(cherry picked from commit {self.commit_sha1})"
updated_commit_message = updated_commit_message.replace('#', 'GH-')
if self.dry_run:
click.echo(f" dry-run: git commit --amend -m '{updated_commit_message}'")
Expand Down

0 comments on commit 81b94d8

Please sign in to comment.