summaryrefslogtreecommitdiff
path: root/builtin/clone.c
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2022-01-24 18:09:09 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-01-26 19:12:19 (GMT)
commitdccea605b6c30262a6a44bde8d10b0a20c331d87 (patch)
treeb1c222ce5c208fa720fa08c7d28b88adacdb918e /builtin/clone.c
parente9d7761bb94f20acc98824275e317fa82436c25d (diff)
downloadgit-dccea605b6c30262a6a44bde8d10b0a20c331d87.zip
git-dccea605b6c30262a6a44bde8d10b0a20c331d87.tar.gz
git-dccea605b6c30262a6a44bde8d10b0a20c331d87.tar.bz2
clone: support unusual remote ref configurations
When cloning a branchless and tagless but not refless remote using protocol v0 or v1, Git calls transport_fetch_refs() with an empty ref list. This makes the clone fail with the message "remote transport reported error". Git should have refrained from calling transport_fetch_refs(), just like it does in the case that the remote is refless. Therefore, teach Git to do this. In protocol v2, this does not happen because the client passes ref-prefix arguments that filter out non-branches and non-tags in the ref advertisement, making the remote appear empty. Note that this bug concerns logic in builtin/clone.c and only affects cloning, not fetching. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/clone.c')
-rw-r--r--builtin/clone.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index fb377b2..f4dc498 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -862,7 +862,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
const struct ref *refs, *remote_head;
struct ref *remote_head_points_at = NULL;
const struct ref *our_head_points_at;
- struct ref *mapped_refs;
+ struct ref *mapped_refs = NULL;
const struct ref *ref;
struct strbuf key = STRBUF_INIT;
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
@@ -1184,7 +1184,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
refs = transport_get_remote_refs(transport, &transport_ls_refs_options);
- if (refs) {
+ if (refs)
+ mapped_refs = wanted_peer_refs(refs, &remote->fetch);
+
+ if (mapped_refs) {
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
/*
@@ -1193,8 +1196,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
*/
initialize_repository_version(hash_algo, 1);
repo_set_hash_algo(the_repository, hash_algo);
-
- mapped_refs = wanted_peer_refs(refs, &remote->fetch);
/*
* transport_get_remote_refs() may return refs with null sha-1
* in mapped_refs (see struct transport->get_refs_list
@@ -1240,7 +1241,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
option_branch, remote_name);
warning(_("You appear to have cloned an empty repository."));
- mapped_refs = NULL;
our_head_points_at = NULL;
remote_head_points_at = NULL;
remote_head = NULL;
@@ -1271,7 +1271,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (is_local)
clone_local(path, git_dir);
- else if (refs && complete_refs_before_fetch) {
+ else if (mapped_refs && complete_refs_before_fetch) {
if (transport_fetch_refs(transport, mapped_refs))
die(_("remote transport reported error"));
}