Skip to content

Commit dc5d553

Browse files
chriscoolgitster
authored andcommitted
trailer: ignore first line of message
When looking for the start of the trailers in the message we are passed, we should ignore the first line of the message. The reason is that if we are passed a patch or commit message then the first line should be the patch title. If we are passed only trailers we can expect that they start with an empty line that can be ignored too. This way we can properly process commit messages that have only one line with something that looks like a trailer, for example like "area of code: change we made". Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fdf96a2 commit dc5d553

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

t/t7513-interpret-trailers.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,25 @@ 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 message that contains only a title' '
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+
102115
test_expect_success 'with config setup' '
103116
git config trailer.ack.key "Acked-by: " &&
104117
cat >expected <<-\EOF &&

trailer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,9 @@ static int find_trailer_start(struct strbuf **lines, int count)
748748
/*
749749
* Get the start of the trailers by looking starting from the end
750750
* for a line with only spaces before lines with one separator.
751+
* The start cannot be the first line.
751752
*/
752-
for (start = count - 1; start >= 0; start--) {
753+
for (start = count - 1; start >= 1; start--) {
753754
if (lines[start]->buf[0] == comment_line_char)
754755
continue;
755756
if (contains_only_spaces(lines[start]->buf)) {

0 commit comments

Comments
 (0)