@@ -500,6 +500,7 @@ test_expect_success 're-init from a linked worktree' '
500
500
'
501
501
502
502
test_expect_success ' init honors GIT_DEFAULT_HASH' '
503
+ test_when_finished "rm -rf sha1 sha256" &&
503
504
GIT_DEFAULT_HASH=sha1 git init sha1 &&
504
505
git -C sha1 rev-parse --show-object-format >actual &&
505
506
echo sha1 >expected &&
@@ -511,6 +512,7 @@ test_expect_success 'init honors GIT_DEFAULT_HASH' '
511
512
'
512
513
513
514
test_expect_success ' init honors --object-format' '
515
+ test_when_finished "rm -rf explicit-sha1 explicit-sha256" &&
514
516
git init --object-format=sha1 explicit-sha1 &&
515
517
git -C explicit-sha1 rev-parse --show-object-format >actual &&
516
518
echo sha1 >expected &&
@@ -521,7 +523,58 @@ test_expect_success 'init honors --object-format' '
521
523
test_cmp expected actual
522
524
'
523
525
526
+ test_expect_success ' init honors init.defaultObjectFormat' '
527
+ test_when_finished "rm -rf sha1 sha256" &&
528
+
529
+ test_config_global init.defaultObjectFormat sha1 &&
530
+ (
531
+ sane_unset GIT_DEFAULT_HASH &&
532
+ git init sha1 &&
533
+ git -C sha1 rev-parse --show-object-format >actual &&
534
+ echo sha1 >expected &&
535
+ test_cmp expected actual
536
+ ) &&
537
+
538
+ test_config_global init.defaultObjectFormat sha256 &&
539
+ (
540
+ sane_unset GIT_DEFAULT_HASH &&
541
+ git init sha256 &&
542
+ git -C sha256 rev-parse --show-object-format >actual &&
543
+ echo sha256 >expected &&
544
+ test_cmp expected actual
545
+ )
546
+ '
547
+
548
+ test_expect_success ' init warns about invalid init.defaultObjectFormat' '
549
+ test_when_finished "rm -rf repo" &&
550
+ test_config_global init.defaultObjectFormat garbage &&
551
+
552
+ echo "warning: unknown hash algorithm ${SQ}garbage${SQ}" >expect &&
553
+ git init repo 2>err &&
554
+ test_cmp expect err &&
555
+
556
+ git -C repo rev-parse --show-object-format >actual &&
557
+ echo $GIT_DEFAULT_HASH >expected &&
558
+ test_cmp expected actual
559
+ '
560
+
561
+ test_expect_success ' --object-format overrides GIT_DEFAULT_HASH' '
562
+ test_when_finished "rm -rf repo" &&
563
+ GIT_DEFAULT_HASH=sha1 git init --object-format=sha256 repo &&
564
+ git -C repo rev-parse --show-object-format >actual &&
565
+ echo sha256 >expected
566
+ '
567
+
568
+ test_expect_success ' GIT_DEFAULT_HASH overrides init.defaultObjectFormat' '
569
+ test_when_finished "rm -rf repo" &&
570
+ test_config_global init.defaultObjectFormat sha1 &&
571
+ GIT_DEFAULT_HASH=sha256 git init repo &&
572
+ git -C repo rev-parse --show-object-format >actual &&
573
+ echo sha256 >expected
574
+ '
575
+
524
576
test_expect_success ' extensions.objectFormat is not allowed with repo version 0' '
577
+ test_when_finished "rm -rf explicit-v0" &&
525
578
git init --object-format=sha256 explicit-v0 &&
526
579
git -C explicit-v0 config core.repositoryformatversion 0 &&
527
580
test_must_fail git -C explicit-v0 rev-parse --show-object-format
@@ -558,15 +611,6 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
558
611
grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
559
612
'
560
613
561
- test_expect_success DEFAULT_REPO_FORMAT ' init with GIT_DEFAULT_REF_FORMAT=files' '
562
- test_when_finished "rm -rf refformat" &&
563
- GIT_DEFAULT_REF_FORMAT=files git init refformat &&
564
- echo 0 >expect &&
565
- git -C refformat config core.repositoryformatversion >actual &&
566
- test_cmp expect actual &&
567
- test_must_fail git -C refformat config extensions.refstorage
568
- '
569
-
570
614
test_expect_success ' init with GIT_DEFAULT_REF_FORMAT=garbage' '
571
615
test_when_finished "rm -rf refformat" &&
572
616
cat >expect <<-EOF &&
@@ -576,15 +620,90 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
576
620
test_cmp expect err
577
621
'
578
622
579
- test_expect_success ' init with --ref-format=files' '
623
+ test_expect_success ' init warns about invalid init.defaultRefFormat' '
624
+ test_when_finished "rm -rf repo" &&
625
+ test_config_global init.defaultRefFormat garbage &&
626
+
627
+ echo "warning: unknown ref storage format ${SQ}garbage${SQ}" >expect &&
628
+ git init repo 2>err &&
629
+ test_cmp expect err &&
630
+
631
+ git -C repo rev-parse --show-ref-format >actual &&
632
+ echo $GIT_DEFAULT_REF_FORMAT >expected &&
633
+ test_cmp expected actual
634
+ '
635
+
636
+ backends=" files reftable"
637
+ for format in $backends
638
+ do
639
+ test_expect_success DEFAULT_REPO_FORMAT " init with GIT_DEFAULT_REF_FORMAT=$format " '
640
+ test_when_finished "rm -rf refformat" &&
641
+ GIT_DEFAULT_REF_FORMAT=$format git init refformat &&
642
+
643
+ if test $format = files
644
+ then
645
+ test_must_fail git -C refformat config extensions.refstorage &&
646
+ echo 0 >expect
647
+ else
648
+ git -C refformat config extensions.refstorage &&
649
+ echo 1 >expect
650
+ fi &&
651
+ git -C refformat config core.repositoryformatversion >actual &&
652
+ test_cmp expect actual &&
653
+
654
+ echo $format >expect &&
655
+ git -C refformat rev-parse --show-ref-format >actual &&
656
+ test_cmp expect actual
657
+ '
658
+
659
+ test_expect_success " init with --ref-format=$format " '
660
+ test_when_finished "rm -rf refformat" &&
661
+ git init --ref-format=$format refformat &&
662
+ echo $format >expect &&
663
+ git -C refformat rev-parse --show-ref-format >actual &&
664
+ test_cmp expect actual
665
+ '
666
+
667
+ test_expect_success " init with init.defaultRefFormat=$format " '
668
+ test_when_finished "rm -rf refformat" &&
669
+ test_config_global init.defaultRefFormat $format &&
670
+ (
671
+ sane_unset GIT_DEFAULT_REF_FORMAT &&
672
+ git init refformat
673
+ ) &&
674
+
675
+ echo $format >expect &&
676
+ git -C refformat rev-parse --show-ref-format >actual &&
677
+ test_cmp expect actual
678
+ '
679
+
680
+ test_expect_success " --ref-format=$format overrides GIT_DEFAULT_REF_FORMAT" '
681
+ test_when_finished "rm -rf refformat" &&
682
+ GIT_DEFAULT_REF_FORMAT=garbage git init --ref-format=$format refformat &&
683
+ echo $format >expect &&
684
+ git -C refformat rev-parse --show-ref-format >actual &&
685
+ test_cmp expect actual
686
+ '
687
+ done
688
+
689
+ test_expect_success " --ref-format= overrides GIT_DEFAULT_REF_FORMAT" '
580
690
test_when_finished "rm -rf refformat" &&
581
- git init --ref-format=files refformat &&
582
- echo files >expect &&
691
+ GIT_DEFAULT_REF_FORMAT=files git init --ref-format=reftable refformat &&
692
+ echo reftable >expect &&
693
+ git -C refformat rev-parse --show-ref-format >actual &&
694
+ test_cmp expect actual
695
+ '
696
+
697
+ test_expect_success " GIT_DEFAULT_REF_FORMAT= overrides init.defaultRefFormat" '
698
+ test_when_finished "rm -rf refformat" &&
699
+ test_config_global init.defaultRefFormat files &&
700
+
701
+ GIT_DEFAULT_REF_FORMAT=reftable git init refformat &&
702
+ echo reftable >expect &&
583
703
git -C refformat rev-parse --show-ref-format >actual &&
584
704
test_cmp expect actual
585
705
'
586
706
587
- backends=" files reftable"
588
707
for from_format in $backends
589
708
do
590
709
test_expect_success " re-init with same format ($from_format )" '
0 commit comments