Skip to content

Commit 5c99995

Browse files
chriscoolgitster
authored andcommitted
trailer: support multiline title
We currently ignore the first line passed to `git interpret-trailers`, when looking for the beginning of the trailers. Unfortunately this does not work well when a commit is created with a line break in the title, using for example the following command: git commit -m 'place of code: change we made' That's why instead of ignoring only the first line, it is better to ignore the first paragraph. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6262fe9 commit 5c99995

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
@@ -743,15 +743,22 @@ static int find_patch_start(struct strbuf **lines, int count)
743743
*/
744744
static int find_trailer_start(struct strbuf **lines, int count)
745745
{
746-
int start, only_spaces = 1;
746+
int start, end_of_title, only_spaces = 1;
747+
748+
/* The first paragraph is the title and cannot be trailers */
749+
for (start = 0; start < count; start++) {
750+
if (lines[start]->buf[0] == comment_line_char)
751+
continue;
752+
if (contains_only_spaces(lines[start]->buf))
753+
break;
754+
}
755+
end_of_title = start;
747756

748757
/*
749758
* Get the start of the trailers by looking starting from the end
750759
* for a line with only spaces before lines with one separator.
751-
* The first line must not be analyzed as the others as it
752-
* should be either the message title or a blank line.
753760
*/
754-
for (start = count - 1; start >= 1; start--) {
761+
for (start = count - 1; start >= end_of_title; start--) {
755762
if (lines[start]->buf[0] == comment_line_char)
756763
continue;
757764
if (contains_only_spaces(lines[start]->buf)) {

0 commit comments

Comments
 (0)