Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: <git@vger.kernel.org>,  Patrick Steinhardt <ps@pks.im>,
	 Adam Dinwoodie <adam@dinwoodie.org>
Subject: Re: [PATCH v3] setup: fix hash algorithm detection
Date: Thu, 19 Nov 2026 08:26:22 -0800	[thread overview]
Message-ID: <xmqqse0wzt1t.fsf@gitster.g> (raw)
In-Reply-To: <20261119010612.687733-1-sandals@crustytoothpaste.net> (brian m. carlson's message of "Thu, 19 Nov 2026 01:06:12 +0000")

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> 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?

> +	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.

> +	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.

> +		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?

  parent reply	other threads:[~2026-11-19 16:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 16:50 Default object format for new repositories in Git v3 Adam Dinwoodie
2026-11-06 20:46 ` brian m. carlson
2026-11-08  1:16 ` [PATCH] setup: default hash algo to GIT_HASH_DEFAULT brian m. carlson
2026-11-08  4:42   ` Junio C Hamano
2026-11-08 14:38     ` brian m. carlson
2026-11-08 18:22   ` Junio C Hamano
2026-11-09  2:21     ` Junio C Hamano
2026-11-09  9:54       ` Patrick Steinhardt
2026-11-13 22:17   ` [PATCH v2] setup: fix hash algorithm detection brian m. carlson
2026-11-14  0:16     ` Junio C Hamano
2026-11-16  6:22     ` Patrick Steinhardt
2026-11-19  1:06   ` [PATCH v3] " brian m. carlson
2026-11-19  9:52     ` Patrick Steinhardt
2026-11-19 16:26     ` Junio C Hamano [this message]
2026-11-19 16:38     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqse0wzt1t.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=adam@dinwoodie.org \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox