Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f8d36fc

Browse filesBrowse files
authored
Append Co-authored-by: in the commit message. (GH-212)
1 parent 15a4cd5 commit f8d36fc
Copy full SHA for f8d36fc

File tree

Expand file treeCollapse file tree

2 files changed

+37
-7
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+37
-7
lines changed

‎cherry_picker/cherry_picker/cherry_picker.py

Copy file name to clipboardExpand all lines: cherry_picker/cherry_picker/cherry_picker.py
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ def amend_commit_message(self, cherry_pick_branch):
149149
commit_prefix = ""
150150
if self.prefix_commit:
151151
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})"
152+
updated_commit_message = f"""{commit_prefix}{self.get_commit_message(self.commit_sha1)}
153+
(cherry picked from commit {self.commit_sha1})
154+
155+
Co-authored-by: {get_author_info_from_short_sha(self.commit_sha1)}"""
153156
updated_commit_message = updated_commit_message.replace('#', 'GH-')
154157
if self.dry_run:
155158
click.echo(f" dry-run: git commit --amend -m '{updated_commit_message}'")
@@ -295,7 +298,11 @@ def continue_cherry_pick(self):
295298
short_sha = cherry_pick_branch[cherry_pick_branch.index('-')+1:cherry_pick_branch.index(base)-1]
296299
full_sha = get_full_sha_from_short(short_sha)
297300
commit_message = self.get_commit_message(short_sha)
298-
updated_commit_message = f'[{base}] {commit_message}. \n(cherry picked from commit {full_sha})'
301+
co_author_info = f"Co-authored-by: {get_author_info_from_short_sha(short_sha)}"
302+
updated_commit_message = f"""[{base}] {commit_message}.
303+
(cherry picked from commit {full_sha})
304+
305+
{co_author_info}"""
299306
if self.dry_run:
300307
click.echo(f" dry-run: git commit -am '{updated_commit_message}' --allow-empty")
301308
else:
@@ -389,6 +396,13 @@ def get_full_sha_from_short(short_sha):
389396
return full_sha
390397

391398

399+
def get_author_info_from_short_sha(short_sha):
400+
cmd = f"git log -1 --format='%aN <%ae>' {short_sha}"
401+
output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
402+
author = output.strip().decode('utf-8')
403+
return author
404+
405+
392406
def is_cpython_repo():
393407
cmd = "git log -r 7f777ed95a19224294949e1b4ce56bbffcb1fe9f"
394408
try:

‎cherry_picker/cherry_picker/test.py

Copy file name to clipboardExpand all lines: cherry_picker/cherry_picker/test.py
+21-5Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import pytest
44

55
from .cherry_picker import get_base_branch, get_current_branch, \
6-
get_full_sha_from_short, is_cpython_repo, CherryPicker, \
6+
get_full_sha_from_short, get_author_info_from_short_sha, \
7+
is_cpython_repo, CherryPicker, \
78
normalize_commit_message
89

910

@@ -44,6 +45,13 @@ def test_get_full_sha_from_short(subprocess_check_output):
4445
assert get_full_sha_from_short('22a594a') == '22a594a0047d7706537ff2ac676cdc0f1dcb329c'
4546

4647

48+
@mock.patch('subprocess.check_output')
49+
def test_get_author_info_from_short_sha(subprocess_check_output):
50+
mock_output = b"Armin Rigo <armin.rigo@gmail.com>"
51+
subprocess_check_output.return_value = mock_output
52+
assert get_author_info_from_short_sha('22a594a') == 'Armin Rigo <armin.rigo@gmail.com>'
53+
54+
4755
@mock.patch('os.path.exists')
4856
def test_sorted_branch(os_path_exists):
4957
os_path_exists.return_value = True
@@ -119,18 +127,26 @@ def test_normalize_long_commit_message():
119127
The `Show Source` was broken because of a change made in sphinx 1.5.1
120128
In Sphinx 1.4.9, the sourcename was "index.txt".
121129
In Sphinx 1.5.1+, it is now "index.rst.txt".
122-
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
130+
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
131+
132+
Co-authored-by: Elmar Ritsch <35851+elritsch@users.noreply.github.com>"""
123133
title, body = normalize_commit_message(commit_message)
124134
assert title == "[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)"
125135
assert body == """The `Show Source` was broken because of a change made in sphinx 1.5.1
126136
In Sphinx 1.4.9, the sourcename was "index.txt".
127137
In Sphinx 1.5.1+, it is now "index.rst.txt".
128-
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
138+
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
139+
140+
Co-authored-by: Elmar Ritsch <35851+elritsch@users.noreply.github.com>"""
129141

130142
def test_normalize_short_commit_message():
131143
commit_message = """[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)
132144
133-
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
145+
(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
146+
147+
Co-authored-by: Elmar Ritsch <35851+elritsch@users.noreply.github.com>"""
134148
title, body = normalize_commit_message(commit_message)
135149
assert title == "[3.6] Fix broken `Show Source` links on documentation pages (GH-3113)"
136-
assert body == """(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)"""
150+
assert body == """(cherry picked from commit b9ff498793611d1c6a9b99df464812931a1e2d69)
151+
152+
Co-authored-by: Elmar Ritsch <35851+elritsch@users.noreply.github.com>"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.