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/87r1i4qf4h.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Oct 1, 2021 at 11:16 UTC
dd45a5624608d353b706cb54ebdf60ef154dbbe5
1 file changed
+61
t/t1006-cat-file.sh
+61
@@ -402,6 +402,67 @@ do
402
done
403
done
404
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
+
466
test_expect_success "Type of broken object is correct" '
467
echo $bogus_short_type >expect &&
468
git cat-file -t --allow-unknown-type $bogus_short_sha1 >actual &&