Skip to content

Commit d991df4

Browse files
committed
Merge branch 'jt/clone-not-quite-empty'
Cloning from a repository that does not yet have any branches or tags but has other refs resulted in a "remote transport reported error", which has been corrected. * jt/clone-not-quite-empty: clone: support unusual remote ref configurations
2 parents bb754fe + dccea60 commit d991df4

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

builtin/clone.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
863863
const struct ref *refs, *remote_head;
864864
struct ref *remote_head_points_at = NULL;
865865
const struct ref *our_head_points_at;
866-
struct ref *mapped_refs;
866+
struct ref *mapped_refs = NULL;
867867
const struct ref *ref;
868868
struct strbuf key = STRBUF_INIT;
869869
struct strbuf branch_top = STRBUF_INIT, reflog_msg = STRBUF_INIT;
@@ -1185,7 +1185,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11851185

11861186
refs = transport_get_remote_refs(transport, &transport_ls_refs_options);
11871187

1188-
if (refs) {
1188+
if (refs)
1189+
mapped_refs = wanted_peer_refs(refs, &remote->fetch);
1190+
1191+
if (mapped_refs) {
11891192
int hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));
11901193

11911194
/*
@@ -1194,8 +1197,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11941197
*/
11951198
initialize_repository_version(hash_algo, 1);
11961199
repo_set_hash_algo(the_repository, hash_algo);
1197-
1198-
mapped_refs = wanted_peer_refs(refs, &remote->fetch);
11991200
/*
12001201
* transport_get_remote_refs() may return refs with null sha-1
12011202
* in mapped_refs (see struct transport->get_refs_list
@@ -1241,7 +1242,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12411242
option_branch, remote_name);
12421243

12431244
warning(_("You appear to have cloned an empty repository."));
1244-
mapped_refs = NULL;
12451245
our_head_points_at = NULL;
12461246
remote_head_points_at = NULL;
12471247
remote_head = NULL;
@@ -1272,7 +1272,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12721272

12731273
if (is_local)
12741274
clone_local(path, git_dir);
1275-
else if (refs && complete_refs_before_fetch) {
1275+
else if (mapped_refs && complete_refs_before_fetch) {
12761276
if (transport_fetch_refs(transport, mapped_refs))
12771277
die(_("remote transport reported error"));
12781278
}

t/t5700-protocol-v1.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,21 @@ test_expect_success 'push with file:// using protocol v1' '
149149
grep "push< version 1" log
150150
'
151151

152+
test_expect_success 'cloning branchless tagless but not refless remote' '
153+
rm -rf server client &&
154+
155+
git -c init.defaultbranch=main init server &&
156+
echo foo >server/foo.txt &&
157+
git -C server add foo.txt &&
158+
git -C server commit -m "message" &&
159+
git -C server update-ref refs/notbranch/alsonottag HEAD &&
160+
git -C server checkout --detach &&
161+
git -C server branch -D main &&
162+
git -C server symbolic-ref HEAD refs/heads/nonexistentbranch &&
163+
164+
git -c protocol.version=1 clone "file://$(pwd)/server" client
165+
'
166+
152167
# Test protocol v1 with 'ssh://' transport
153168
#
154169
test_expect_success 'setup ssh wrapper' '

0 commit comments

Comments
 (0)