Skip to content

Commit a991fff

Browse files
committed
Merge branch 'ps/ls-remote-out-of-repo-fix' into maint-2.46
A recent update broke "git ls-remote" used outside a repository, which has been corrected. * ps/ls-remote-out-of-repo-fix: builtin/ls-remote: fall back to SHA1 outside of a repo
2 parents 87f8426 + 9e89dcb commit a991fff

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

builtin/ls-remote.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
9191
PARSE_OPT_STOP_AT_NON_OPTION);
9292
dest = argv[0];
9393

94+
/*
95+
* TODO: This is buggy, but required for transport helpers. When a
96+
* transport helper advertises a "refspec", then we'd add that to a
97+
* list of refspecs via `refspec_append()`, which transitively depends
98+
* on `the_hash_algo`. Thus, when the hash algorithm isn't properly set
99+
* up, this would lead to a segfault.
100+
*
101+
* We really should fix this in the transport helper logic such that we
102+
* lazily parse refspec capabilities _after_ we have learned about the
103+
* remote's object format. Otherwise, we may end up misparsing refspecs
104+
* depending on what object hash the remote uses.
105+
*/
106+
if (!the_repository->hash_algo)
107+
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
108+
94109
packet_trace_identity("ls-remote");
95110

96111
if (argc > 1) {

t/t5512-ls-remote.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,4 +402,17 @@ test_expect_success 'v0 clients can handle multiple symrefs' '
402402
test_cmp expect actual
403403
'
404404

405+
test_expect_success 'helper with refspec capability fails gracefully' '
406+
mkdir test-bin &&
407+
write_script test-bin/git-remote-foo <<-EOF &&
408+
echo import
409+
echo refspec ${SQ}*:*${SQ}
410+
EOF
411+
(
412+
PATH="$PWD/test-bin:$PATH" &&
413+
export PATH &&
414+
test_must_fail nongit git ls-remote foo::bar
415+
)
416+
'
417+
405418
test_done

0 commit comments

Comments
 (0)