Skip to content

Commit 4e1b06d

Browse files
dschogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7735612 commit 4e1b06d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int find_commit_subject(const char *commit_buffer, const char **subject)
398398
while (*p && (*p != '\n' || p[1] != '\n'))
399399
p++;
400400
if (*p) {
401-
p += 2;
401+
p = skip_blank_lines(p + 2);
402402
for (eol = p; *eol && *eol != '\n'; eol++)
403403
; /* do nothing */
404404
} else

t/t8008-blame-formats.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,21 @@ test_expect_success 'blame --line-porcelain output' '
8787
test_cmp expect actual
8888
'
8989

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 <[email protected]> 123456789 +0000" \
100+
"committer C <[email protected]> 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+
90107
test_done

0 commit comments

Comments
 (0)