Re: [PATCH 2/3] setup: fix reinit of repos with incompatible GIT_DEFAULT_REF_FORMAT
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 30, 2025, 22:40 UTC
- Message-ID
- <xmqqy0ys9b97.fsf@gitster.g>
- In-Reply-To
- <20250130-b4-pks-reinit-default-ref-format-v1-2-d2769ca01207@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 20 quoted lines
> The GIT_DEFAULT_REF_FORMAT environment variable can be set to influence > the default ref format that new repostiories shall be initialized with. > While this is the expected behaviour when creating a new repository, it > is not when reinitializing a repository: we should retain the ref format > currently used by it in that case. > > This doesn't work correctly right now: > > $ git init --ref-format=files repo > Initialized empty Git repository in /tmp/repo/.git/ > $ GIT_DEFAULT_REF_FORMAT=reftable git init repo > fatal: could not open '/tmp/repo/.git/refs/heads' for writing: Is a directory > > Instead of retaining the current ref format, the reinitialization tries > to reinitialize the repository with the different format. This action > fails when git-init(1) tries to write the ".git/refs/heads" stub, which > in the context of the reftable backend is always written as a file so > that we can detect clients which inadvertently try to access the repo > with the wrong ref format. Seems like the protection mechanism works for > this case, as well.
Good finding. A plausible alternative behaviour could be to do the backend migration when this is asked, and we might gain consensus to do so in the (far) future, but I agree that it is a good direction to go in the short term to match the behaviour of the code to the documented expectation.