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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Apr 9, 2019 at 19:13 UTC
97dd512af7ce4afb4f638ef73b4770921c8ca3aa
2 files changed
+7
-2
list-objects.c
+3
@@ -374,6 +374,9 @@ static void do_traverse(struct traversal_context *ctx)
374
struct tree *tree = get_commit_tree(commit);
375
tree->object.flags |= NOT_USER_GIVEN;
376
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));
380
}
381
ctx->show_commit(commit, ctx->show_data);
382
t/t6102-rev-list-unexpected-objects.sh
+4
-2
@@ -67,8 +67,10 @@ test_expect_success 'traverse unexpected non-tree root (lone)' '
67
test_must_fail git rev-list --objects $broken_commit
68
'
69
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
74
'
75
76
test_expect_success 'setup unexpected non-commit tag' '