summaryrefslogtreecommitdiff
path: root/builtin/sparse-checkout.c
diff options
context:
space:
mode:
authorLibravatar Derrick Stolee <dstolee@microsoft.com>2019-11-21 22:04:38 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2019-11-22 16:11:44 +0900
commit72918c1ad91504f56c395cc91c5072651125662a (patch)
tree2b758a07f18725cfd47349a7e09d011b4f788dd1 /builtin/sparse-checkout.c
parentsparse-checkout: add '--stdin' option to set subcommand (diff)
downloadtgif-72918c1ad91504f56c395cc91c5072651125662a.tar.xz
sparse-checkout: create 'disable' subcommand
The instructions for disabling a sparse-checkout to a full working directory are complicated and non-intuitive. Add a subcommand, 'git sparse-checkout disable', to perform those steps for the user. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/sparse-checkout.c')
-rw-r--r--builtin/sparse-checkout.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 82bff0020d..e3a8d3460a 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -8,7 +8,7 @@
#include "strbuf.h"
static char const * const builtin_sparse_checkout_usage[] = {
- N_("git sparse-checkout (init|list|set) <options>"),
+ N_("git sparse-checkout (init|list|set|disable) <options>"),
NULL
};
@@ -207,6 +207,28 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
return result;
}
+static int sparse_checkout_disable(int argc, const char **argv)
+{
+ char *sparse_filename;
+ FILE *fp;
+
+ if (set_config(MODE_ALL_PATTERNS))
+ die(_("failed to change config"));
+
+ sparse_filename = get_sparse_checkout_filename();
+ fp = xfopen(sparse_filename, "w");
+ fprintf(fp, "/*\n");
+ fclose(fp);
+
+ if (update_working_directory())
+ die(_("error while refreshing working directory"));
+
+ unlink(sparse_filename);
+ free(sparse_filename);
+
+ return set_config(MODE_NO_PATTERNS);
+}
+
int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
{
static struct option builtin_sparse_checkout_options[] = {
@@ -231,6 +253,8 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
return sparse_checkout_init(argc, argv);
if (!strcmp(argv[0], "set"))
return sparse_checkout_set(argc, argv, prefix);
+ if (!strcmp(argv[0], "disable"))
+ return sparse_checkout_disable(argc, argv);
}
usage_with_options(builtin_sparse_checkout_usage,