Re: [PATCH v3] setup: fix hash algorithm detection
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 19, 2026, 16:26 UTC
- Message-ID
- <xmqqse0wzt1t.fsf@gitster.g>
- In-Reply-To
- <20261119010612.687733-1-sandals@crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 13 quoted lines
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh > index 9e57a06cea..d89f60bab9 100755 > --- a/t/t0001-init.sh > +++ b/t/t0001-init.sh > @@ -516,6 +516,17 @@ test_expect_success 're-init from a linked worktree' ' > ) > ' > > +test_expect_success 'git init uses default object format' ' > + test_when_finished "rm -rf repo" && > + ( > + sane_unset GIT_DEFAULT_HASH && > + git init repo &&
In this subshell, we discard GIT_DEFAULT_HASH that was set up by t/test-lib.sh (either from the GIT_TEST_DEFAULT_HASH exported by the CI framework or from the GIT_TEST_BUILTIN_HASH to match the running binary). "git init repo" will create a repository using the binary built-in default.
> + echo "$GIT_TEST_BUILTIN_HASH" >expect && > + git -C repo rev-parse --show-object-format >actual &&
And we have to see the same TEST_BUILTIN_HASH as the result.
> + test_cmp expect actual > + ) > +'
Very good.
> +test_expect_success 'init refuses to reinitialize with different hash' ' > + test_when_finished "rm -rf repo" && > + sane_unset GIT_DEFAULT_HASH &&
Here, we permanently discard GIT_DEFAULT_HASH from t/test-lib.sh without saving what it was. Would it cause issues to later tests that we do not see in post context of this patch?
Show 9 quoted lines
> + for algo in sha1 sha256 > + do > + if test "$algo" = sha1 > + then > + other=sha256 > + else > + other=sha1 > + fi && > + git init --object-format="$algo" repo &&
We create in one format and then ...
> + cat >expect <<-EOF && > + fatal: attempt to reinitialize repository with different hash > + EOF > + test_must_fail git init --object-format="$other" repo 2>err &&
... try reinitializing to the other format. Expected is a failure with a message.
> + test_cmp expect err && > + rm -fr repo || return 1 > + done > +'
OK.
> +test_expect_success 're-init does not modify hash from config' ' > + test_when_finished "rm -rf repo" && > + sane_unset GIT_DEFAULT_HASH &&
Here, we discard GIT_DEFAULT_HASH again, correctly assumig that the previous one can be skipped.
Show 9 quoted lines
> + for algo in sha1 sha256 > + do > + if test "$algo" = sha1 > + then > + other=sha256 > + else > + other=sha1 > + fi && > + git init --object-format="$algo" repo &&
Again, we create in one format and then ...
> + test_config_global init.defaultObjectFormat "$other" && > + git init repo && > + echo "$algo" >expect &&
... we do not want the configuration to cause reinitialization to touch the format.
Show 5 quoted lines
> + git -C repo rev-parse --show-object-format >actual && > + test_cmp expect actual && > + rm -fr repo || return 1 > + done > +'
Looks good.
> 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 &&
My earlier question was about this one. A format is explicitly given to this one, so the environment variables would not affect this particular one, but if we have "git init" in later tests that used to rely on the GIT_DEFAULT_HASH setting left by t/test-lib.sh may we get in a trobule?