t0001: exercise initialization with ref formats more thoroughly

While our object format tests for git-init(1) exercise tests with all known formats in t0001, the tests for the ref format don't. This leads to some missing test coverage for interesting cases, like whether or not a non-default ref storage format causes us to bump the repository format version. We also don't test for the precedence of the `--ref-format=` and the `GIT_DEFAULT_REF_FORMAT=` environment variable. Extend the test suite to cover more scenarios related to the ref format. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 16, 2024 at 10:56 UTC 05d20915bc2658371989a47ff1214e2eb6506de4
1 file changed +35 -13
t/t0001-init.sh
+35 -13
@@ -558,15 +558,6 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
558 grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
559 '
560
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 -
561 test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
562 test_when_finished "rm -rf refformat" &&
563 cat >expect <<-EOF &&
@@ -576,15 +567,46 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
567 test_cmp expect err
568 '
569
579 -test_expect_success 'init with --ref-format=files' '
570 +backends="files reftable"
571 +for format in $backends
572 +do
573 + test_expect_success DEFAULT_REPO_FORMAT "init with GIT_DEFAULT_REF_FORMAT=$format" '
574 + test_when_finished "rm -rf refformat" &&
575 + GIT_DEFAULT_REF_FORMAT=$format git init refformat &&
576 +
577 + if test $format = files
578 + then
579 + test_must_fail git -C refformat config extensions.refstorage &&
580 + echo 0 >expect
581 + else
582 + git -C refformat config extensions.refstorage &&
583 + echo 1 >expect
584 + fi &&
585 + git -C refformat config core.repositoryformatversion >actual &&
586 + test_cmp expect actual &&
587 +
588 + echo $format >expect &&
589 + git -C refformat rev-parse --show-ref-format >actual &&
590 + test_cmp expect actual
591 + '
592 +
593 + test_expect_success "init with --ref-format=$format" '
594 + test_when_finished "rm -rf refformat" &&
595 + git init --ref-format=$format refformat &&
596 + echo $format >expect &&
597 + git -C refformat rev-parse --show-ref-format >actual &&
598 + test_cmp expect actual
599 + '
600 +done
601 +
602 +test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" '
603 test_when_finished "rm -rf refformat" &&
581 - git init --ref-format=files refformat &&
582 - echo files >expect &&
604 + GIT_DEFAULT_REF_FORMAT=files git init --ref-format=reftable refformat &&
605 + echo reftable >expect &&
606 git -C refformat rev-parse --show-ref-format >actual &&
607 test_cmp expect actual
608 '
609
587 -backends="files reftable"
610 for from_format in $backends
611 do
612 test_expect_success "re-init with same format ($from_format)" '