]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/clone.c
Merge branch 'jk/clone-allow-bare-and-o-together'
[thirdparty/git.git] / builtin / clone.c
index f5f902cce194ee01b889a1cb57fd03fd19ebebf1..ed8d44bb6ab72857508824958f6857ca4b0cff64 100644 (file)
@@ -34,6 +34,7 @@
 #include "list-objects-filter-options.h"
 #include "hook.h"
 #include "bundle.h"
+#include "bundle-uri.h"
 
 /*
  * Overall FIXMEs:
@@ -72,11 +73,12 @@ static struct string_list option_optional_reference = STRING_LIST_INIT_NODUP;
 static int option_dissociate;
 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 list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT;
 static int option_filter_submodules = -1;    /* unspecified */
 static int config_filter_submodules = -1;    /* unspecified */
 static struct string_list server_options = STRING_LIST_INIT_NODUP;
 static int option_remote_submodules;
+static const char *bundle_uri;
 
 static int recurse_submodules_cb(const struct option *opt,
                                 const char *arg, int unset)
@@ -160,6 +162,8 @@ static struct option builtin_clone_options[] = {
                    N_("any cloned submodules will use their remote-tracking branch")),
        OPT_BOOL(0, "sparse", &option_sparse_checkout,
                    N_("initialize sparse-checkout file to include only files at root")),
+       OPT_STRING(0, "bundle-uri", &bundle_uri,
+                  N_("uri"), N_("a URI for downloading bundles before fetching from origin remote")),
        OPT_END()
 };
 
@@ -494,6 +498,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
                        /* if --branch=tag, pull the requested tag explicitly */
                        get_fetch_map(remote_head, tag_refspec, &tail, 0);
                }
+               free_refs(remote_head);
        } else {
                int i;
                for (i = 0; i < refspec->nr; i++)
@@ -929,6 +934,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
                option_no_checkout = 1;
        }
 
+       if (bundle_uri && deepen)
+               die(_("--bundle-uri is incompatible with --depth, --shallow-since, and --shallow-exclude"));
+
        repo_name = argv[0];
 
        path = get_repo_path(repo_name, &is_bundle);
@@ -1228,6 +1236,18 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
        if (transport->smart_options && !deepen && !filter_options.choice)
                transport->smart_options->check_self_contained_and_connected = 1;
 
+       /*
+        * Before fetching from the remote, download and install bundle
+        * data from the --bundle-uri option.
+        */
+       if (bundle_uri) {
+               /* At this point, we need the_repository to match the cloned repo. */
+               if (repo_init(the_repository, git_dir, work_tree))
+                       warning(_("failed to initialize the repo, skipping bundle URI"));
+               else if (fetch_bundle_uri(the_repository, bundle_uri))
+                       warning(_("failed to fetch objects from bundle URI '%s'"),
+                               bundle_uri);
+       }
 
        strvec_push(&transport_ls_refs_options.ref_prefixes, "HEAD");
        refspec_ref_prefixes(&remote->fetch,