Merge branch 'js/gitdir-at-unc-root'
[gitweb.git] / builtin / clone.c
index 62b6a0a352e8f42b83c03b4a3bd4f445ce280e8a..2048b6760aa9f0a426524e5ea1bd7a3a4c4c5536 100644 (file)
@@ -69,6 +69,7 @@ static int max_jobs = -1;
 static struct string_list option_recurse_submodules = STRING_LIST_INIT_NODUP;
 static struct list_objects_filter_options filter_options;
 static struct string_list server_options = STRING_LIST_INIT_NODUP;
+static int option_remote_submodules;
 
 static int recurse_submodules_cb(const struct option *opt,
                                 const char *arg, int unset)
@@ -144,6 +145,8 @@ static struct option builtin_clone_options[] = {
        OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
                        TRANSPORT_FAMILY_IPV6),
        OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
+       OPT_BOOL(0, "remote-submodules", &option_remote_submodules,
+                   N_("any cloned submodules will use their remote-tracking branch")),
        OPT_END()
 };
 
@@ -502,7 +505,7 @@ static enum {
 static const char junk_leave_repo_msg[] =
 N_("Clone succeeded, but checkout failed.\n"
    "You can inspect what was checked out with 'git status'\n"
-   "and retry the checkout with 'git checkout -f HEAD'\n");
+   "and retry with 'git restore --source=HEAD :/'\n");
 
 static void remove_junk(void)
 {
@@ -801,6 +804,11 @@ static int checkout(int submodule_progress)
                if (option_verbosity < 0)
                        argv_array_push(&args, "--quiet");
 
+               if (option_remote_submodules) {
+                       argv_array_push(&args, "--remote");
+                       argv_array_push(&args, "--no-fetch");
+               }
+
                err = run_command_v_opt(args.argv, RUN_GIT_CMD);
                argv_array_clear(&args);
        }
@@ -1152,13 +1160,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                transport->server_options = &server_options;
 
        if (filter_options.choice) {
-               struct strbuf expanded_filter_spec = STRBUF_INIT;
-               expand_list_objects_filter_spec(&filter_options,
-                                               &expanded_filter_spec);
+               const char *spec =
+                       expand_list_objects_filter_spec(&filter_options);
                transport_set_option(transport, TRANS_OPT_LIST_OBJECTS_FILTER,
-                                    expanded_filter_spec.buf);
+                                    spec);
                transport_set_option(transport, TRANS_OPT_FROM_PROMISOR, "1");
-               strbuf_release(&expanded_filter_spec);
        }
 
        if (transport->smart_options && !deepen && !filter_options.choice)
@@ -1230,7 +1236,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                        remote_head_points_at, &branch_top);
 
        if (filter_options.choice)
-               partial_clone_register("origin", &filter_options);
+               partial_clone_register(option_origin, &filter_options);
 
        if (is_local)
                clone_local(path, git_dir);
@@ -1255,7 +1261,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        transport_disconnect(transport);
 
        if (option_dissociate) {
-               close_all_packs(the_repository->objects);
+               close_object_store(the_repository->objects);
                dissociate_from_references();
        }