Skip to content

Commit 7603482

Browse files
committed
Merge branch 'ps/ls-remote-out-of-repo-fix'
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 ecbed3f + 9e89dcb commit 7603482

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
@@ -90,6 +90,21 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
9090
PARSE_OPT_STOP_AT_NON_OPTION);
9191
dest = argv[0];
9292

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

95110
for (int i = 1; i < argc; i++)

t/t5512-ls-remote.sh

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

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

0 commit comments

Comments
 (0)