1
0
mirror of https://github.com/git/git synced 2024-07-05 00:58:49 +00:00

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>
This commit is contained in:
Junio C Hamano 2009-11-06 23:06:06 -08:00
parent c1e01b0c51
commit e5138436dd
2 changed files with 10 additions and 1 deletions

View File

@ -530,7 +530,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
; /* do nothing */
if (prefixcmp(sb.buf + i, sob.buf)) {
if (!ends_rfc2822_footer(&sb))
if (!i || !ends_rfc2822_footer(&sb))
strbuf_addch(&sb, '\n');
strbuf_addbuf(&sb, &sob);
}

View File

@ -258,4 +258,13 @@ test_expect_success 'Hand committing of a redundant merge removes dups' '
'
test_expect_success 'A single-liner subject with a token plus colon is not a footer' '
git reset --hard &&
git commit -s -m "hello: kitty" --allow-empty &&
git cat-file commit HEAD | sed -e "1,/^$/d" >actual &&
test $(wc -l <actual) = 3
'
test_done