]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/ls-remote: fall back to SHA1 outside of a repo
authorPatrick Steinhardt <ps@pks.im>
Fri, 2 Aug 2024 04:44:11 +0000 (06:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Aug 2024 15:24:05 +0000 (08:24 -0700)
commit9e89dcb66a70902fef966083998a75272d47d998
tree0c8db03a82ab07c4c642348d84783b9096594ab6
parent39bf06adf96da25b87c9aa7d35a32ef3683eb4a4
builtin/ls-remote: fall back to SHA1 outside of a repo

In c8aed5e8da (repository: stop setting SHA1 as the default object hash,
2024-05-07), we have stopped setting the default hash algorithm for
`the_repository`. Consequently, code that relies on `the_hash_algo` will
now crash when it hasn't explicitly been initialized, which may be the
case when running outside of a Git repository.

It was reported that git-ls-remote(1) may crash in such a way when using
a remote helper that advertises refspecs. This is because the refspec
announced by the helper will get parsed during capability negotiation.
At that point we haven't yet figured out what object format the remote
uses though, so when run outside of a repository then we will fail.

The course of action is somewhat dubious in the first place. Ideally, we
should only parse object IDs once we have asked the remote helper for
the object format. And if the helper didn't announce the "object-format"
capability, then we should always assume SHA256. But instead, we used to
take either SHA1 if there was no repository, or we used the hash of the
local repository, which is wrong.

Arguably though, crashing hard may not be in the best interest of our
users, either. So while the old behaviour was buggy, let's restore it
for now as a short-term fix. We should eventually revisit, potentially
by deferring the point in time when we parse the refspec until after we
have figured out the remote's object hash.

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/ls-remote.c
t/t5512-ls-remote.sh