Skip to content

Commit 643f918

Browse files
peffgitster
authored andcommitted
clone: always set transport options
A clone will always create a transport struct, whether we are cloning locally or using an actual protocol. In the local case, we only use the transport to get the list of refs, and then transfer the objects out-of-band. However, there are many options that we do not bother setting up in the local case. For the most part, these are noops, because they only affect the object-fetching stage (e.g., the --depth option). However, some options do have a visible impact. For example, giving the path to upload-pack via "-u" does not currently work for a local clone, even though we need upload-pack to get the ref list. We can just drop the conditional entirely and set these options for both local and non-local clones. Rather than keep track of which options impact the object versus the ref fetching stage, we can simply let the noops be noops (and the cost of setting the options in the first place is not high). The one exception is that we also check that the transport provides both a "get_refs_list" and a "fetch" method. We will now be checking the former for both cases (which is good, since a transport that cannot fetch refs would not work for a local clone), and we tweak the conditional to check for a "fetch" only when we are non-local. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2856cbf commit 643f918

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

builtin/clone.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -885,27 +885,25 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
885885
remote = remote_get(option_origin);
886886
transport = transport_get(remote, remote->url[0]);
887887

888-
if (!is_local) {
889-
if (!transport->get_refs_list || !transport->fetch)
890-
die(_("Don't know how to clone %s"), transport->url);
888+
if (!transport->get_refs_list || (!is_local && !transport->fetch))
889+
die(_("Don't know how to clone %s"), transport->url);
891890

892-
transport_set_option(transport, TRANS_OPT_KEEP, "yes");
891+
transport_set_option(transport, TRANS_OPT_KEEP, "yes");
893892

894-
if (option_depth)
895-
transport_set_option(transport, TRANS_OPT_DEPTH,
896-
option_depth);
897-
if (option_single_branch)
898-
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
893+
if (option_depth)
894+
transport_set_option(transport, TRANS_OPT_DEPTH,
895+
option_depth);
896+
if (option_single_branch)
897+
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
899898

900-
transport_set_verbosity(transport, option_verbosity, option_progress);
899+
transport_set_verbosity(transport, option_verbosity, option_progress);
901900

902-
if (option_upload_pack)
903-
transport_set_option(transport, TRANS_OPT_UPLOADPACK,
904-
option_upload_pack);
901+
if (option_upload_pack)
902+
transport_set_option(transport, TRANS_OPT_UPLOADPACK,
903+
option_upload_pack);
905904

906-
if (transport->smart_options && !option_depth)
907-
transport->smart_options->check_self_contained_and_connected = 1;
908-
}
905+
if (transport->smart_options && !option_depth)
906+
transport->smart_options->check_self_contained_and_connected = 1;
909907

910908
refs = transport_get_remote_refs(transport);
911909

t/t5701-clone-local.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,8 @@ test_expect_success 'cloning a local path with --no-local does not hardlink' '
134134
! repo_is_hardlinked force-nonlocal
135135
'
136136

137+
test_expect_success 'cloning locally respects "-u" for fetching refs' '
138+
test_must_fail git clone --bare -u false a should_not_work.git
139+
'
140+
137141
test_done

0 commit comments

Comments
 (0)