]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sparse-checkout: enable reapply to take --[no-]{cone,sparse-index}
authorElijah Newren <newren@gmail.com>
Tue, 14 Dec 2021 04:09:09 +0000 (04:09 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Dec 2021 19:48:22 +0000 (11:48 -0800)
Folks may want to switch to or from cone mode, or to or from a
sparse-index without changing their sparsity paths.  Allow them to do so
using the reapply command.

Reviewed-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Victoria Dye <vdye@github.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/sparse-checkout.c

index 16daae84975465a6c32d6775b705577ab477859e..0dae44c57595d4dd8887bdc0c2b2ba9f115cfd94 100644 (file)
@@ -759,13 +759,22 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
 }
 
 static char const * const builtin_sparse_checkout_reapply_usage[] = {
-       N_("git sparse-checkout reapply"),
+       N_("git sparse-checkout reapply [--[no-]cone] [--[no-]sparse-index] "),
        NULL
 };
 
+static struct sparse_checkout_reapply_opts {
+       int cone_mode;
+       int sparse_index;
+} reapply_opts;
+
 static int sparse_checkout_reapply(int argc, const char **argv)
 {
        static struct option builtin_sparse_checkout_reapply_options[] = {
+               OPT_BOOL(0, "cone", &reapply_opts.cone_mode,
+                        N_("initialize the sparse-checkout in cone mode")),
+               OPT_BOOL(0, "sparse-index", &reapply_opts.sparse_index,
+                        N_("toggle the use of a sparse index")),
                OPT_END(),
        };
 
@@ -777,6 +786,13 @@ static int sparse_checkout_reapply(int argc, const char **argv)
                             builtin_sparse_checkout_reapply_usage, 0);
 
        repo_read_index(the_repository);
+
+       reapply_opts.cone_mode = -1;
+       reapply_opts.sparse_index = -1;
+
+       if (update_modes(&reapply_opts.cone_mode, &reapply_opts.sparse_index))
+               return 1;
+
        return update_working_directory(NULL);
 }