Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,20 @@ def get_exit_message(self, branch):
$ cherry_picker --abort
"""

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

def get_updated_commit_message(self, cherry_pick_branch):
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)}
return f"""{commit_prefix}{self.get_commit_message(self.commit_sha1)}
(cherry picked from commit {self.commit_sha1})


Co-authored-by: {get_author_info_from_short_sha(self.commit_sha1)}"""

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

updated_commit_message = self.get_updated_commit_message(cherry_pick_branch)
if self.dry_run:
click.echo(f" dry-run: git commit --amend -m '{updated_commit_message}'")
else:
Expand Down Expand Up @@ -493,16 +496,8 @@ def continue_cherry_pick(self):
short_sha = cherry_pick_branch[
cherry_pick_branch.index("-") + 1 : cherry_pick_branch.index(base) - 1
]
full_sha = get_full_sha_from_short(short_sha)
commit_message = self.get_commit_message(short_sha)
co_author_info = (
f"Co-authored-by: {get_author_info_from_short_sha(short_sha)}"
)
updated_commit_message = f"""[{base}] {commit_message}.
(cherry picked from commit {full_sha})


{co_author_info}"""
self.commit_sha1 = get_full_sha_from_short(short_sha)
updated_commit_message = self.get_updated_commit_message(cherry_pick_branch)
if self.dry_run:
click.echo(
f" dry-run: git commit -a -m '{updated_commit_message}' --allow-empty"
Expand Down
11 changes: 7 additions & 4 deletions cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,14 @@ def test_backport_pause_and_continue(
), mock.patch(
"cherry_picker.cherry_picker.get_current_branch",
return_value="backport-xxx-3.8",
), mock.patch(
"cherry_picker.cherry_picker.get_author_info_from_short_sha",
return_value="Author Name <author@name.email>",
), mock.patch.object(
cherry_picker, "get_commit_message", return_value="commit message"
cherry_picker,
"get_updated_commit_message",
return_value="""[3.8] commit message
(cherry picked from commit xxxxxxyyyyyy)


Co-authored-by: Author Name <author@name.email>""",
), mock.patch.object(
cherry_picker, "checkout_branch"
), mock.patch.object(
Expand Down