]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rev-list: detect broken root trees
authorJeff King <peff@peff.net>
Wed, 10 Apr 2019 02:13:25 +0000 (19:13 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Apr 2019 03:59:39 +0000 (12:59 +0900)
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>
list-objects.c
t/t6102-rev-list-unexpected-objects.sh

index bb7e61ef4bb9d1d48ca7840f87a301eff84f08e0..b5651ddd5bfdd6cda4047f71cc3cb66fc31a793d 100644 (file)
@@ -374,6 +374,9 @@ static void do_traverse(struct traversal_context *ctx)
                        struct tree *tree = get_commit_tree(commit);
                        tree->object.flags |= NOT_USER_GIVEN;
                        add_pending_tree(ctx->revs, tree);
+               } else if (commit->object.parsed) {
+                       die(_("unable to load root tree for commit %s"),
+                             oid_to_hex(&commit->object.oid));
                }
                ctx->show_commit(commit, ctx->show_data);
 
index 28ee1bcb07cfe359133273887bb410929db6493d..28611c978e6c0094a5e452bf8c8c8778da02ae6c 100755 (executable)
@@ -67,8 +67,10 @@ test_expect_success 'traverse unexpected non-tree root (lone)' '
        test_must_fail git rev-list --objects $broken_commit
 '
 
-test_expect_failure 'traverse unexpected non-tree root (seen)' '
-       test_must_fail git rev-list --objects $blob $broken_commit
+test_expect_success 'traverse unexpected non-tree root (seen)' '
+       test_must_fail git rev-list --objects $blob $broken_commit \
+               >output 2>&1 &&
+       test_i18ngrep "not a tree" output
 '
 
 test_expect_success 'setup unexpected non-commit tag' '