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 <christian.couder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Aug 30, 2015 at 21:14 UTC 5c99995df8ee3b02224f0e2e86a3d1e4bb2f7348
2 files changed +25 -4
t/t7513-interpret-trailers.sh
+14
@@ -112,6 +112,20 @@ test_expect_success 'with only a title in the message' '
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 +
129 test_expect_success 'with config setup' '
130 git config trailer.ack.key "Acked-by: " &&
131 cat >expected <<-\EOF &&
trailer.c
+11 -4
@@ -743,15 +743,22 @@ static int find_patch_start(struct strbuf **lines, int count)
743 */
744 static int find_trailer_start(struct strbuf **lines, int count)
745 {
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;
756
757 /*
758 * Get the start of the trailers by looking starting from the end
759 * 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.
760 */
754 - for (start = count - 1; start >= 1; start--) {
761 + for (start = count - 1; start >= end_of_title; start--) {
762 if (lines[start]->buf[0] == comment_line_char)
763 continue;
764 if (contains_only_spaces(lines[start]->buf)) {