Skip to content

Commit f23e7fe

Browse files
committed
Correctly append tags on patches without commit details
Only a commit summary (a.k.a. patch subject) is necessary in Git: we don't need details. The regex we were using to search for postscripts however assumed that there would be _something_ before the postscript, resulting in a newline. This wasn't the case. Correct this assumption by instead using 're.MULTILINE' and matching on '^' and '$' for newlines instead of '\n'. Signed-off-by: Stephen Finucane <[email protected]> Closes: #516 Cc: [email protected] (cherry picked from commit 05da32f)
1 parent 9d71ee7 commit f23e7fe

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

patchwork/tests/views/test_utils.py

+23
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,29 @@ def test_multiple_tags(self):
6666
mbox = utils.patch_to_mbox(self.patch)
6767
self.assertIn('Acked-by: 1\nAcked-by: 2\n', mbox)
6868

69+
def test_bug_516(self):
70+
"""Test that tags are appended if a patch description is unset."""
71+
patch = create_patch(
72+
content=(
73+
'---\n'
74+
' manual/string.texi | 2 +-\n'
75+
' 1 file changed, 1 insertion(+), 1 deletion(-)'
76+
),
77+
)
78+
create_patch_comment(patch=patch, content='Acked-by: 2\n')
79+
80+
mbox = utils.patch_to_mbox(patch)
81+
# the epilog comes after the tags
82+
self.assertIn(
83+
(
84+
'Acked-by: 2\n'
85+
'---\n'
86+
' manual/string.texi | 2 +-\n'
87+
' 1 file changed, 1 insertion(+), 1 deletion(-)\n'
88+
),
89+
mbox,
90+
)
91+
6992
def _test_header_passthrough(self, header):
7093
patch = create_patch(headers=header + '\n')
7194
mbox = utils.patch_to_mbox(patch)

patchwork/views/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _submission_to_mbox(submission):
4848
"""
4949
is_patch = isinstance(submission, Patch)
5050

51-
postscript_re = re.compile('\n-{2,3} ?\n')
51+
postscript_re = re.compile('^-{2,3} ?$', re.MULTILINE)
5252
body = ''
5353

5454
if submission.content:
@@ -71,7 +71,7 @@ def _submission_to_mbox(submission):
7171
body += comment.patch_responses
7272

7373
if postscript:
74-
body += '---\n' + postscript + '\n'
74+
body += '---' + postscript + '\n'
7575

7676
if is_patch and submission.diff:
7777
body += '\n' + submission.diff

0 commit comments

Comments
 (0)