Skip to content

Commit dd45a56

Browse files
avargitster
authored andcommitted
cat-file tests: test for current --allow-unknown-type behavior
Add more tests for the current --allow-unknown-type behavior. As noted in [1] I don't think much of this makes sense, but let's test for it as-is so we can see if the behavior changes in the future. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e7d220 commit dd45a56

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

t/t1006-cat-file.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,67 @@ do
402402
done
403403
done
404404

405+
test_expect_success '-e is OK with a broken object without --allow-unknown-type' '
406+
git cat-file -e $bogus_short_sha1
407+
'
408+
409+
test_expect_success '-e can not be combined with --allow-unknown-type' '
410+
test_expect_code 128 git cat-file -e --allow-unknown-type $bogus_short_sha1
411+
'
412+
413+
test_expect_success '-p cannot print a broken object even with --allow-unknown-type' '
414+
test_must_fail git cat-file -p $bogus_short_sha1 &&
415+
test_expect_code 128 git cat-file -p --allow-unknown-type $bogus_short_sha1
416+
'
417+
418+
test_expect_success '<type> <hash> does not work with objects of broken types' '
419+
cat >err.expect <<-\EOF &&
420+
fatal: invalid object type "bogus"
421+
EOF
422+
test_must_fail git cat-file $bogus_short_type $bogus_short_sha1 2>err.actual &&
423+
test_cmp err.expect err.actual
424+
'
425+
426+
test_expect_success 'broken types combined with --batch and --batch-check' '
427+
echo $bogus_short_sha1 >bogus-oid &&
428+
429+
cat >err.expect <<-\EOF &&
430+
fatal: invalid object type
431+
EOF
432+
433+
test_must_fail git cat-file --batch <bogus-oid 2>err.actual &&
434+
test_cmp err.expect err.actual &&
435+
436+
test_must_fail git cat-file --batch-check <bogus-oid 2>err.actual &&
437+
test_cmp err.expect err.actual
438+
'
439+
440+
test_expect_success 'the --batch and --batch-check options do not combine with --allow-unknown-type' '
441+
test_expect_code 128 git cat-file --batch --allow-unknown-type <bogus-oid &&
442+
test_expect_code 128 git cat-file --batch-check --allow-unknown-type <bogus-oid
443+
'
444+
445+
test_expect_success 'the --allow-unknown-type option does not consider replacement refs' '
446+
cat >expect <<-EOF &&
447+
$bogus_short_type
448+
EOF
449+
git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
450+
test_cmp expect actual &&
451+
452+
# Create it manually, as "git replace" will die on bogus
453+
# types.
454+
head=$(git rev-parse --verify HEAD) &&
455+
test_when_finished "rm -rf .git/refs/replace" &&
456+
mkdir -p .git/refs/replace &&
457+
echo $head >.git/refs/replace/$bogus_short_sha1 &&
458+
459+
cat >expect <<-EOF &&
460+
commit
461+
EOF
462+
git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&
463+
test_cmp expect actual
464+
'
465+
405466
test_expect_success "Type of broken object is correct" '
406467
echo $bogus_short_type >expect &&
407468
git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&

0 commit comments

Comments
 (0)