list-objects.c: handle unexpected non-tree entries

Apply similar treatment as the previous commit for non-tree entries, too. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 9, 2019 at 19:13 UTC b49e74eac480d167c3af8f1286fe520c3d7ce9e1
2 files changed +8 -2
list-objects.c
+5
@@ -125,6 +125,11 @@ static void process_tree_contents(struct traversal_context *ctx,
125
126 if (S_ISDIR(entry.mode)) {
127 struct tree *t = lookup_tree(ctx->revs->repo, &entry.oid);
128 + if (!t) {
129 + die(_("entry '%s' in tree %s has tree mode, "
130 + "but is not a tree"),
131 + entry.path, oid_to_hex(&tree->object.oid));
132 + }
133 t->object.flags |= NOT_USER_GIVEN;
134 process_tree(ctx, t, base, entry.path);
135 }
t/t6102-rev-list-unexpected-objects.sh
+3 -2
@@ -34,8 +34,9 @@ test_expect_failure 'traverse unexpected non-tree entry (lone)' '
34 test_must_fail git rev-list --objects $broken_tree
35 '
36
37 -test_expect_failure 'traverse unexpected non-tree entry (seen)' '
38 - test_must_fail git rev-list --objects $blob $broken_tree
37 +test_expect_success 'traverse unexpected non-tree entry (seen)' '
38 + test_must_fail git rev-list --objects $blob $broken_tree >output 2>&1 &&
39 + test_i18ngrep "is not a tree" output
40 '
41
42 test_expect_success 'setup unexpected non-commit parent' '