Skip to content

Commit

Permalink
Merge branch 'jt/clone-not-quite-empty'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Feb 9, 2022
2 parents bb754fe + dccea60 commit d991df4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 6 additions & 6 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,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;
Expand Down Expand Up @@ -1185,7 +1185,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));

/*
Expand All @@ -1194,8 +1197,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
Expand Down Expand Up @@ -1241,7 +1242,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;
Expand Down Expand Up @@ -1272,7 +1272,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"));
}
Expand Down
15 changes: 15 additions & 0 deletions t/t5700-protocol-v1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ test_expect_success 'push with file:// using protocol v1' '
grep "push< version 1" log
'

test_expect_success 'cloning branchless tagless but not refless remote' '
rm -rf server client &&
git -c init.defaultbranch=main init server &&
echo foo >server/foo.txt &&
git -C server add foo.txt &&
git -C server commit -m "message" &&
git -C server update-ref refs/notbranch/alsonottag HEAD &&
git -C server checkout --detach &&
git -C server branch -D main &&
git -C server symbolic-ref HEAD refs/heads/nonexistentbranch &&
git -c protocol.version=1 clone "file://$(pwd)/server" client
'

# Test protocol v1 with 'ssh://' transport
#
test_expect_success 'setup ssh wrapper' '
Expand Down

0 comments on commit d991df4

Please sign in to comment.