Skip to content

Commit 9d93988

Browse files
committed
Merge branch 'cc/trailers-corner-case-fix' into maint
The "interpret-trailers" helper mistook a multi-paragraph title of a commit log message with a colon in it as the end of the trailer block. * cc/trailers-corner-case-fix: trailer: support multiline title trailer: retitle a test and correct an in-comment message trailer: ignore first line of message
2 parents 311e5ce + 5c99995 commit 9d93988

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

t/t7513-interpret-trailers.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,39 @@ test_expect_success 'with config option on the command line' '
9393
Acked-by: Johan
9494
Reviewed-by: Peff
9595
EOF
96-
echo "Acked-by: Johan" |
96+
{ echo; echo "Acked-by: Johan"; } |
9797
git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
9898
--trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
9999
test_cmp expected actual
100100
'
101101

102+
test_expect_success 'with only a title in the message' '
103+
cat >expected <<-\EOF &&
104+
area: change
105+
106+
Reviewed-by: Peff
107+
Acked-by: Johan
108+
EOF
109+
echo "area: change" |
110+
git interpret-trailers --trailer "Reviewed-by: Peff" \
111+
--trailer "Acked-by: Johan" >actual &&
112+
test_cmp expected actual
113+
'
114+
115+
test_expect_success 'with multiline title in the message' '
116+
cat >expected <<-\EOF &&
117+
place of
118+
code: change
119+
120+
Reviewed-by: Peff
121+
Acked-by: Johan
122+
EOF
123+
printf "%s\n" "place of" "code: change" |
124+
git interpret-trailers --trailer "Reviewed-by: Peff" \
125+
--trailer "Acked-by: Johan" >actual &&
126+
test_cmp expected actual
127+
'
128+
102129
test_expect_success 'with config setup' '
103130
git config trailer.ack.key "Acked-by: " &&
104131
cat >expected <<-\EOF &&

trailer.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,22 @@ static int find_patch_start(struct strbuf **lines, int count)
735735
*/
736736
static int find_trailer_start(struct strbuf **lines, int count)
737737
{
738-
int start, only_spaces = 1;
738+
int start, end_of_title, only_spaces = 1;
739+
740+
/* The first paragraph is the title and cannot be trailers */
741+
for (start = 0; start < count; start++) {
742+
if (lines[start]->buf[0] == comment_line_char)
743+
continue;
744+
if (contains_only_spaces(lines[start]->buf))
745+
break;
746+
}
747+
end_of_title = start;
739748

740749
/*
741750
* Get the start of the trailers by looking starting from the end
742751
* for a line with only spaces before lines with one separator.
743752
*/
744-
for (start = count - 1; start >= 0; start--) {
753+
for (start = count - 1; start >= end_of_title; start--) {
745754
if (lines[start]->buf[0] == comment_line_char)
746755
continue;
747756
if (contains_only_spaces(lines[start]->buf)) {

0 commit comments

Comments
 (0)