diff options
Diffstat (limited to 't/t0001-init.sh')
-rwxr-xr-x | t/t0001-init.sh | 145 |
1 files changed, 132 insertions, 13 deletions
diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 49e9bf77c6..0178aa62a4 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -500,6 +500,7 @@ test_expect_success 're-init from a linked worktree' ' ' test_expect_success 'init honors GIT_DEFAULT_HASH' ' + test_when_finished "rm -rf sha1 sha256" && GIT_DEFAULT_HASH=sha1 git init sha1 && git -C sha1 rev-parse --show-object-format >actual && echo sha1 >expected && @@ -511,6 +512,7 @@ test_expect_success 'init honors GIT_DEFAULT_HASH' ' ' test_expect_success 'init honors --object-format' ' + test_when_finished "rm -rf explicit-sha1 explicit-sha256" && git init --object-format=sha1 explicit-sha1 && git -C explicit-sha1 rev-parse --show-object-format >actual && echo sha1 >expected && @@ -521,7 +523,58 @@ test_expect_success 'init honors --object-format' ' test_cmp expected actual ' +test_expect_success 'init honors init.defaultObjectFormat' ' + test_when_finished "rm -rf sha1 sha256" && + + test_config_global init.defaultObjectFormat sha1 && + ( + sane_unset GIT_DEFAULT_HASH && + git init sha1 && + git -C sha1 rev-parse --show-object-format >actual && + echo sha1 >expected && + test_cmp expected actual + ) && + + test_config_global init.defaultObjectFormat sha256 && + ( + sane_unset GIT_DEFAULT_HASH && + git init sha256 && + git -C sha256 rev-parse --show-object-format >actual && + echo sha256 >expected && + test_cmp expected actual + ) +' + +test_expect_success 'init warns about invalid init.defaultObjectFormat' ' + test_when_finished "rm -rf repo" && + test_config_global init.defaultObjectFormat garbage && + + echo "warning: unknown hash algorithm ${SQ}garbage${SQ}" >expect && + git init repo 2>err && + test_cmp expect err && + + git -C repo rev-parse --show-object-format >actual && + echo $GIT_DEFAULT_HASH >expected && + test_cmp expected actual +' + +test_expect_success '--object-format overrides GIT_DEFAULT_HASH' ' + test_when_finished "rm -rf repo" && + GIT_DEFAULT_HASH=sha1 git init --object-format=sha256 repo && + git -C repo rev-parse --show-object-format >actual && + echo sha256 >expected +' + +test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' ' + test_when_finished "rm -rf repo" && + test_config_global init.defaultObjectFormat sha1 && + GIT_DEFAULT_HASH=sha256 git init repo && + git -C repo rev-parse --show-object-format >actual && + echo sha256 >expected +' + test_expect_success 'extensions.objectFormat is not allowed with repo version 0' ' + test_when_finished "rm -rf explicit-v0" && git init --object-format=sha256 explicit-v0 && git -C explicit-v0 config core.repositoryformatversion 0 && 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 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 +620,90 @@ test_expect_success 'init with GIT_DEFAULT_REF_FORMAT=garbage' ' test_cmp expect err ' -test_expect_success 'init with --ref-format=files' ' +test_expect_success 'init warns about invalid init.defaultRefFormat' ' + test_when_finished "rm -rf repo" && + test_config_global init.defaultRefFormat garbage && + + echo "warning: unknown ref storage format ${SQ}garbage${SQ}" >expect && + git init repo 2>err && + test_cmp expect err && + + git -C repo rev-parse --show-ref-format >actual && + echo $GIT_DEFAULT_REF_FORMAT >expected && + test_cmp expected actual +' + +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 + ' + + test_expect_success "init with init.defaultRefFormat=$format" ' + test_when_finished "rm -rf refformat" && + test_config_global init.defaultRefFormat $format && + ( + sane_unset GIT_DEFAULT_REF_FORMAT && + git init refformat + ) && + + echo $format >expect && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' + + test_expect_success "--ref-format=$format overrides GIT_DEFAULT_REF_FORMAT" ' + test_when_finished "rm -rf refformat" && + GIT_DEFAULT_REF_FORMAT=garbage 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 +' + +test_expect_success "GIT_DEFAULT_REF_FORMAT= overrides init.defaultRefFormat" ' + test_when_finished "rm -rf refformat" && + test_config_global init.defaultRefFormat files && + + GIT_DEFAULT_REF_FORMAT=reftable git init 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)" ' |