Skip to content

Commit 77bc430

Browse files
committed
Merge branch 'jk/shortlog-tolerate-broken-commit' into maint
"git shortlog" used to choke and die when there is a malformed commit (e.g. missing authors); it now simply ignore such a commit and keeps going. * jk/shortlog-tolerate-broken-commit: shortlog: ignore commits with missing authors
2 parents b28325d + cd4f09e commit 77bc430

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

builtin/shortlog.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
127127
author = buffer + 7;
128128
buffer = eol;
129129
}
130-
if (!author)
131-
die(_("Missing author: %s"),
130+
if (!author) {
131+
warning(_("Missing author: %s"),
132132
sha1_to_hex(commit->object.sha1));
133+
return;
134+
}
133135
if (log->user_format) {
134136
struct pretty_print_context ctx = {0};
135137
ctx.fmt = CMIT_FMT_USERFORMAT;

t/t4201-shortlog.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,20 @@ test_expect_success 'shortlog encoding' '
172172
git shortlog HEAD~2.. > out &&
173173
test_cmp expect out'
174174

175+
test_expect_success 'shortlog ignores commits with missing authors' '
176+
git commit --allow-empty -m normal &&
177+
git commit --allow-empty -m soon-to-be-broken &&
178+
git cat-file commit HEAD >commit.tmp &&
179+
sed "/^author/d" commit.tmp >broken.tmp &&
180+
commit=$(git hash-object -w -t commit --stdin <broken.tmp) &&
181+
git update-ref HEAD $commit &&
182+
cat >expect <<-\EOF &&
183+
A U Thor (1):
184+
normal
185+
186+
EOF
187+
git shortlog HEAD~2.. >actual &&
188+
test_cmp expect actual
189+
'
190+
175191
test_done

0 commit comments

Comments
 (0)