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>
This commit is contained in:
Derrick Stolee
2019-11-21 22:04:38 +00:00
committed by Junio C Hamano
parent 7bffca95ea
commit 72918c1ad9
3 changed files with 52 additions and 16 deletions

View File

@ -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,