Merge branch 'af/clone-revision-v0-segfault-fix' into jch

'git clone --revision' talking to a server that does not support
protocol v2 (falling back to protocol v0) segfaulted, which has
been corrected.

* af/clone-revision-v0-segfault-fix:
  builtin/clone: fix segfault when using --revision with protocol v0
jch
Junio C Hamano 2026-07-24 14:40:41 -07:00
commit 0e593abde0
2 changed files with 9 additions and 1 deletions

View File

@ -557,7 +557,7 @@ static void update_remote_refs(const struct ref *refs,
write_followtags(refs, msg);
}

if (remote_head_points_at && !option_bare) {
if (remote_head_points_at && remote_head_points_at->peer_ref && !option_bare) {
struct strbuf head_ref = STRBUF_INIT;
strbuf_addstr(&head_ref, branch_top);
strbuf_addstr(&head_ref, "HEAD");

View File

@ -90,6 +90,14 @@ test_expect_success 'clone with --revision and --bare' '
test_must_fail git -C dst config remote.origin.fetch
'

test_expect_success 'clone with --revision and protocol v0' '
test_when_finished "rm -rf dst" &&
git -c protocol.version=0 clone --no-local --revision=refs/heads/main . dst &&
git rev-parse refs/heads/main >expect &&
git -C dst rev-parse HEAD >actual &&
test_cmp expect actual
'

test_expect_success 'clone with --revision being a short raw commit hash' '
test_when_finished "rm -rf dst" &&
oid=$(git rev-parse --short refs/heads/feature) &&