git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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?

Previous: Patrick SteinhardtNext: Junio C Hamano
Message 14 of 17 in “Default object format for new repositories in Git v3”
  1. Adam DinwoodieNov 6, 2026
  2. brian m. carlsonNov 6, 2026
  3. setup: default hash algo to GIT_HASH_DEFAULTbrian m. carlson, Nov 8, 2026
  4. Junio C HamanoNov 8, 2026
  5. brian m. carlsonNov 8, 2026
  6. Junio C HamanoNov 8, 2026
  7. Junio C HamanoNov 9, 2026
  8. Patrick SteinhardtNov 9, 2026
  9. setup: fix hash algorithm detectionbrian m. carlson, Nov 13, 2026
  10. Junio C HamanoNov 14, 2026
  11. Patrick SteinhardtNov 16, 2026
  12. setup: fix hash algorithm detectionbrian m. carlson, Nov 19, 2026
  13. Patrick SteinhardtNov 19, 2026
  14. Junio C HamanoNov 19, 2026
  15. Junio C HamanoNov 19, 2026
  16. brian m. carlsonNov 19, 2026
  17. Junio C HamanoNov 19, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.