Skip to content

Commit cdd00df

Browse files
committed
Merge branch 'cc/trailers-corner-case-fix'
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
2 parents 8f8386e + 5c99995 commit cdd00df

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

t/t7513-interpret-trailers.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ test_expect_success 'with only a title in the message' '
112112
test_cmp expected actual
113113
'
114114

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+
115129
test_expect_success 'with config setup' '
116130
git config trailer.ack.key "Acked-by: " &&
117131
cat >expected <<-\EOF &&

trailer.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -735,15 +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.
743-
* The first line must not be analyzed as the others as it
744-
* should be either the message title or a blank line.
745752
*/
746-
for (start = count - 1; start >= 1; start--) {
753+
for (start = count - 1; start >= end_of_title; start--) {
747754
if (lines[start]->buf[0] == comment_line_char)
748755
continue;
749756
if (contains_only_spaces(lines[start]->buf)) {

0 commit comments

Comments
 (0)