commit.c: make find_commit_subject() more robust

Just like the pretty printing machinery, we should simply ignore blank lines at the beginning of the commit messages. This discrepancy was noticed when an early version of the rebase--helper produced commit objects with more than one empty line between the header and the commit message. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 22, 2016 at 22:20 UTC 4e1b06da252a7609f0c6641750e6acbec451e698
2 files changed +18 -1
commit.c
+1 -1
@@ -398,7 +398,7 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
398 while (*p && (*p != '\n' || p[1] != '\n'))
399 p++;
400 if (*p) {
401 - p += 2;
401 + p = skip_blank_lines(p + 2);
402 for (eol = p; *eol && *eol != '\n'; eol++)
403 ; /* do nothing */
404 } else
t/t8008-blame-formats.sh
+17
@@ -87,4 +87,21 @@ test_expect_success 'blame --line-porcelain output' '
87 test_cmp expect actual
88 '
89
90 +test_expect_success '--porcelain detects first non-blank line as subject' '
91 + (
92 + GIT_INDEX_FILE=.git/tmp-index &&
93 + export GIT_INDEX_FILE &&
94 + echo "This is it" >single-file &&
95 + git add single-file &&
96 + tree=$(git write-tree) &&
97 + commit=$(printf "%s\n%s\n%s\n\n\n \noneline\n\nbody\n" \
98 + "tree $tree" \
99 + "author A <a@b.c> 123456789 +0000" \
100 + "committer C <c@d.e> 123456789 +0000" |
101 + git hash-object -w -t commit --stdin) &&
102 + git blame --porcelain $commit -- single-file >output &&
103 + grep "^summary oneline$" output
104 + )
105 +'
106 +
107 test_done