]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/clone: allow remote helpers to detect repo
authorPatrick Steinhardt <ps@pks.im>
Tue, 27 Feb 2024 14:27:44 +0000 (15:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Feb 2024 20:58:57 +0000 (12:58 -0800)
commit199f44cb2ead34486f2588dc32d000d17e30f9cc
treeb2d3e7dcbd047dc7ecb1dc77baf146899a8e8238
parent3c2a3fdc388747b9eaf4a4a4f2035c1c9ddb26d0
builtin/clone: allow remote helpers to detect repo

In 18c9cb7524 (builtin/clone: create the refdb with the correct object
format, 2023-12-12), we have changed git-clone(1) so that it delays
creation of the refdb until after it has learned about the remote's
object format. This change was required for the reftable backend, which
encodes the object format into the tables. So if we pre-initialized the
refdb with the default object format, but the remote uses a different
object format than that, then the resulting tables would have encoded
the wrong object format.

This change unfortunately breaks remote helpers which try to access the
repository that is about to be created. Because the refdb has not yet
been initialized at the point where we spawn the remote helper, we also
don't yet have "HEAD" or "refs/". Consequently, any Git commands ran by
the remote helper which try to access the repository would fail because
it cannot be discovered.

This is essentially a chicken-and-egg problem: we cannot initialize the
refdb because we don't know about the object format. But we cannot learn
about the object format because the remote helper may be unable to
access the partially-initialized repository.

Ideally, we would address this issue via capabilities. But the remote
helper protocol is not structured in a way that guarantees that the
capability announcement happens before the remote helper tries to access
the repository.

Instead, fix this issue by partially initializing the refdb up to the
point where it becomes discoverable by Git commands.

Reported-by: Mike Hommey <mh@glandium.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/clone.c
setup.c
t/t5801/git-remote-testgit