diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-02-10 10:18:29 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-02-10 10:18:29 -0800 |
| commit | 442b7e0018fac61874a8423270e8fee2c0c7e689 (patch) | |
| tree | bd6747143f56f6cb8db35c5bc91d3a1b8558e77c | |
| parent | 9520f7d9985d8879bddd157309928fc0679c8e92 (diff) | |
| parent | 7e88640cd1801b6fe0288f744da7310b4749c0c8 (diff) | |
| download | git-442b7e0018fac61874a8423270e8fee2c0c7e689.tar.gz | |
Merge branch 'ps/setup-reinit-fixes'
"git init" to reinitialize a repository that already exists cannot
change the hash function and ref backends; such a request is
silently ignored now.
* ps/setup-reinit-fixes:
setup: fix reinit of repos with incompatible GIT_DEFAULT_HASH
setup: fix reinit of repos with incompatible GIT_DEFAULT_REF_FORMAT
t0001: remove duplicate test
| -rw-r--r-- | setup.c | 8 | ||||
| -rwxr-xr-x | t/t0001-init.sh | 30 |
2 files changed, 27 insertions, 11 deletions
@@ -2517,7 +2517,9 @@ static void repository_format_configure(struct repository_format *repo_fmt, int env_algo = hash_algo_by_name(env); if (env_algo == GIT_HASH_UNKNOWN) die(_("unknown hash algorithm '%s'"), env); - repo_fmt->hash_algo = env_algo; + if (repo_fmt->version < 0 || + repo_fmt->hash_algo == GIT_HASH_UNKNOWN) + repo_fmt->hash_algo = env_algo; } else if (cfg.hash != GIT_HASH_UNKNOWN) { repo_fmt->hash_algo = cfg.hash; } @@ -2534,7 +2536,9 @@ static void repository_format_configure(struct repository_format *repo_fmt, ref_format = ref_storage_format_by_name(env); if (ref_format == REF_STORAGE_FORMAT_UNKNOWN) die(_("unknown ref storage format '%s'"), env); - repo_fmt->ref_storage_format = ref_format; + if (repo_fmt->version < 0 || + repo_fmt->ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN) + repo_fmt->ref_storage_format = ref_format; } else if (cfg.ref_format != REF_STORAGE_FORMAT_UNKNOWN) { repo_fmt->ref_storage_format = cfg.ref_format; } diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 72a0c2e7d4..c49d9e0d38 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -586,6 +586,18 @@ test_expect_success 'GIT_DEFAULT_HASH overrides init.defaultObjectFormat' ' echo sha256 >expected ' +for hash in sha1 sha256 +do + test_expect_success "reinit repository with GIT_DEFAULT_HASH=$hash does not change format" ' + test_when_finished "rm -rf repo" && + git init repo && + git -C repo rev-parse --show-object-format >expect && + GIT_DEFAULT_HASH=$hash git init repo && + git -C repo rev-parse --show-object-format >actual && + test_cmp expect actual + ' +done + 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 && @@ -697,6 +709,15 @@ do git -C refformat rev-parse --show-ref-format >actual && test_cmp expect actual ' + + test_expect_success "reinit repository with GIT_DEFAULT_REF_FORMAT=$format does not change format" ' + test_when_finished "rm -rf refformat" && + git init refformat && + git -C refformat rev-parse --show-ref-format >expect && + GIT_DEFAULT_REF_FORMAT=$format git init refformat && + git -C refformat rev-parse --show-ref-format >actual && + test_cmp expect actual + ' done test_expect_success "--ref-format= overrides GIT_DEFAULT_REF_FORMAT" ' @@ -861,15 +882,6 @@ test_expect_success 're-init with includeIf.onbranch condition' ' test_cmp expect actual ' -test_expect_success 're-init with includeIf.onbranch condition' ' - test_when_finished "rm -rf repo" && - git init repo && - git -c includeIf.onbranch:nonexistent.path=/does/not/exist init repo && - echo $GIT_DEFAULT_REF_FORMAT >expect && - git -C repo rev-parse --show-ref-format >actual && - test_cmp expect actual -' - test_expect_success 're-init skips non-matching includeIf.onbranch' ' test_when_finished "rm -rf repo config" && cat >config <<-EOF && |
