Skip to content

Commit 97dd512

Browse files
peffgitster
authored andcommitted
rev-list: detect broken root trees
When the traversal machinery sees a commit without a root tree, it assumes that the tree was part of a BOUNDARY commit, and quietly ignores the tree. But it could also be caused by a commit whose root tree is broken or missing. Instead, let's die() when we see a NULL root tree. We can differentiate it from the BOUNDARY case by seeing if the commit was actually parsed. This covers that case, plus future-proofs us against any others where we might try to show an unparsed commit. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ee4dfee commit 97dd512

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

list-objects.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ static void do_traverse(struct traversal_context *ctx)
374374
struct tree *tree = get_commit_tree(commit);
375375
tree->object.flags |= NOT_USER_GIVEN;
376376
add_pending_tree(ctx->revs, tree);
377+
} else if (commit->object.parsed) {
378+
die(_("unable to load root tree for commit %s"),
379+
oid_to_hex(&commit->object.oid));
377380
}
378381
ctx->show_commit(commit, ctx->show_data);
379382

t/t6102-rev-list-unexpected-objects.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ test_expect_success 'traverse unexpected non-tree root (lone)' '
6767
test_must_fail git rev-list --objects $broken_commit
6868
'
6969

70-
test_expect_failure 'traverse unexpected non-tree root (seen)' '
71-
test_must_fail git rev-list --objects $blob $broken_commit
70+
test_expect_success 'traverse unexpected non-tree root (seen)' '
71+
test_must_fail git rev-list --objects $blob $broken_commit \
72+
>output 2>&1 &&
73+
test_i18ngrep "not a tree" output
7274
'
7375

7476
test_expect_success 'setup unexpected non-commit tag' '

0 commit comments

Comments
 (0)