diff --git a/builtin/clone.c b/builtin/clone.c index d60d1b60bc..5cbebbf7c2 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -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"); diff --git a/t/t5621-clone-revision.sh b/t/t5621-clone-revision.sh index db3b8cff55..54789423f8 100755 --- a/t/t5621-clone-revision.sh +++ b/t/t5621-clone-revision.sh @@ -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) &&