@matheusbsbs / matheus-bagliano / commits / e5138436dd
Fork 0

builtin-commit.c: fix logic to omit empty line before existing footers

"commit -s" used to add an empty line before adding S-o-b line only when the last line of the existing log message is not another S-o-b line, but c1e01b0 (commit: More generous accepting of RFC-2822 footer lines., 2009-10-28) introduced logic to omit this empty line when the message ends with a run of "footer" lines, to cover S-o-b's friends, e.g. Acked-by. However, the logic was overzealous and missed one corner case. A message that consists of a single line that begins with Token + colon, it can be mistaken as a S-o-b's friend. We do want an empty line in such a case. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Nov 6, 2009 at 23:06 UTC e5138436ddd4b5f75c1e910f6b844e4fcf91343d
2 files changed +10 -1
builtin-commit.c
+1 -1
@@ -530,7 +530,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
530 for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
531 ; /* do nothing */
532 if (prefixcmp(sb.buf + i, sob.buf)) {
533 - if (!ends_rfc2822_footer(&sb))
533 + if (!i || !ends_rfc2822_footer(&sb))
534 strbuf_addch(&sb, '\n');
535 strbuf_addbuf(&sb, &sob);
536 }
t/t7502-commit.sh
+9
@@ -258,4 +258,13 @@ test_expect_success 'Hand committing of a redundant merge removes dups' '
258
259 '
260
261 +test_expect_success 'A single-liner subject with a token plus colon is not a footer' '
262 +
263 + git reset --hard &&
264 + git commit -s -m "hello: kitty" --allow-empty &&
265 + git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
266 + test $(wc -l <actual) = 3
267 +
268 +'
269 +
270 test_done