]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t0001: exercise initialization with ref formats more thoroughly
authorPatrick Steinhardt <ps@pks.im>
Fri, 16 Aug 2024 08:56:53 +0000 (10:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Aug 2024 16:55:21 +0000 (09:55 -0700)
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>
t/t0001-init.sh

index 49e9bf77c6037541a9bdd8d98d482b3d40f6e070..2093f5c1eeeff0ac41aa848f7feb2d516a932fd0 100755 (executable)
@@ -558,15 +558,6 @@ test_expect_success DEFAULT_REPO_FORMAT 'extensions.refStorage with unknown back
        grep "invalid value for ${SQ}extensions.refstorage${SQ}: ${SQ}garbage${SQ}" err
 '
 
-test_expect_success DEFAULT_REPO_FORMAT 'init with GIT_DEFAULT_REF_FORMAT=files' '
-       test_when_finished "rm -rf refformat" &&
-       GIT_DEFAULT_REF_FORMAT=files git init refformat &&
-       echo 0 >expect &&
-       git -C refformat config core.repositoryformatversion >actual &&
-       test_cmp expect actual &&
-       test_must_fail git -C refformat config extensions.refstorage
-'
-
 test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
        test_when_finished "rm -rf refformat" &&
        cat >expect <<-EOF &&
@@ -576,15 +567,46 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' '
        test_cmp expect err
 '
 
-test_expect_success 'init with --ref-format=files' '
+backends="files reftable"
+for format in $backends
+do
+       test_expect_success DEFAULT_REPO_FORMAT "init with GIT_DEFAULT_REF_FORMAT=$format" '
+               test_when_finished "rm -rf refformat" &&
+               GIT_DEFAULT_REF_FORMAT=$format git init refformat &&
+
+               if test $format = files
+               then
+                       test_must_fail git -C refformat config extensions.refstorage &&
+                       echo 0 >expect
+               else
+                       git -C refformat config extensions.refstorage &&
+                       echo 1 >expect
+               fi &&
+               git -C refformat config core.repositoryformatversion >actual &&
+               test_cmp expect actual &&
+
+               echo $format >expect &&
+               git -C refformat rev-parse --show-ref-format >actual &&
+               test_cmp expect actual
+       '
+
+       test_expect_success "init with --ref-format=$format" '
+               test_when_finished "rm -rf refformat" &&
+               git init --ref-format=$format refformat &&
+               echo $format >expect &&
+               git -C refformat rev-parse --show-ref-format >actual &&
+               test_cmp expect actual
+       '
+done
+
+test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" '
        test_when_finished "rm -rf refformat" &&
-       git init --ref-format=files refformat &&
-       echo files >expect &&
+       GIT_DEFAULT_REF_FORMAT=files git init --ref-format=reftable refformat &&
+       echo reftable >expect &&
        git -C refformat rev-parse --show-ref-format >actual &&
        test_cmp expect actual
 '
 
-backends="files reftable"
 for from_format in $backends
 do
        test_expect_success "re-init with same format ($from_format)" '