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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Aug 20, 2015 at 23:59 UTC
dc5d553b5582e543f3151e43f9ae0df9831a4cc9
2 files changed
+16
-2
t/t7513-interpret-trailers.sh
+14
-1
@@ -93,12 +93,25 @@ test_expect_success 'with config option on the command line' '
93
Acked-by: Johan
94
Reviewed-by: Peff
95
EOF
96
- echo "Acked-by: Johan" |
96
+ { echo; echo "Acked-by: Johan"; } |
97
git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \
98
--trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual &&
99
test_cmp expected actual
100
'
101
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
+
115
test_expect_success 'with config setup' '
116
git config trailer.ack.key "Acked-by: " &&
117
cat >expected <<-\EOF &&
trailer.c
+2
-1
@@ -748,8 +748,9 @@ static int find_trailer_start(struct strbuf **lines, int count)
748
/*
749
* Get the start of the trailers by looking starting from the end
750
* for a line with only spaces before lines with one separator.
751
+ * The start cannot be the first line.
752
*/
752
- for (start = count - 1; start >= 0; start--) {
753
+ for (start = count - 1; start >= 1; start--) {
754
if (lines[start]->buf[0] == comment_line_char)
755
continue;
756
if (contains_only_spaces(lines[start]->buf)) {