Skip to content

Commit ffdf498

Browse files
committed
Merge branch 'af/clone-revision-v0-segfault-fix'
A segfault when 'git clone --revision' talks to a server that does not support protocol v2 (falling back to protocol v0) has been corrected. * af/clone-revision-v0-segfault-fix: builtin/clone: fix segfault when using --revision with protocol v0
2 parents e2753fe + 1034ad3 commit ffdf498

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static void update_remote_refs(const struct ref *refs,
557557
write_followtags(refs, msg);
558558
}
559559

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

t/t5621-clone-revision.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ test_expect_success 'clone with --revision and --bare' '
9090
test_must_fail git -C dst config remote.origin.fetch
9191
'
9292

93+
test_expect_success 'clone with --revision and protocol v0' '
94+
test_when_finished "rm -rf dst" &&
95+
git -c protocol.version=0 clone --no-local --revision=refs/heads/main . dst &&
96+
git rev-parse refs/heads/main >expect &&
97+
git -C dst rev-parse HEAD >actual &&
98+
test_cmp expect actual
99+
'
100+
93101
test_expect_success 'clone with --revision being a short raw commit hash' '
94102
test_when_finished "rm -rf dst" &&
95103
oid=$(git rev-parse --short refs/heads/feature) &&

0 commit comments

Comments
 (0)