Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-11-22 01:04:51 +0300
committerJunio C Hamano <gitster@pobox.com>2019-11-22 10:11:45 +0300
commitcff4e9138d8df45e3b6199171092ee781cdadaeb (patch)
treea450b219be113a8b0f9e26265b5ae5fc6dbcd7e2 /builtin/sparse-checkout.c
parent416adc8711d16c5231693f19ca483dd3d59bef5d (diff)
sparse-checkout: check for dirty status
The index-merge performed by 'git sparse-checkout' will erase any staged changes, which can lead to data loss. Prevent these attempts by requiring a clean 'git status' output. Helped-by: Szeder Gábor <szeder.dev@gmail.com> 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.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index 5dbfb2a7e0..a542d617a5 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -12,6 +12,7 @@
#include "lockfile.h"
#include "resolve-undo.h"
#include "unpack-trees.h"
+#include "wt-status.h"
static const char *empty_base = "";
@@ -256,6 +257,10 @@ static int sparse_checkout_init(int argc, const char **argv)
OPT_END(),
};
+ repo_read_index(the_repository);
+ require_clean_work_tree(the_repository,
+ N_("initialize sparse-checkout"), NULL, 1, 0);
+
argc = parse_options(argc, argv, NULL,
builtin_sparse_checkout_init_options,
builtin_sparse_checkout_init_usage, 0);
@@ -368,6 +373,10 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
OPT_END(),
};
+ repo_read_index(the_repository);
+ require_clean_work_tree(the_repository,
+ N_("set sparse-checkout patterns"), NULL, 1, 0);
+
memset(&pl, 0, sizeof(pl));
argc = parse_options(argc, argv, prefix,
@@ -427,6 +436,10 @@ static int sparse_checkout_disable(int argc, const char **argv)
struct pattern_list pl;
struct strbuf match_all = STRBUF_INIT;
+ repo_read_index(the_repository);
+ require_clean_work_tree(the_repository,
+ N_("disable sparse-checkout"), NULL, 1, 0);
+
memset(&pl, 0, sizeof(pl));
hashmap_init(&pl.recursive_hashmap, pl_hashmap_cmp, NULL, 0);
hashmap_init(&pl.parent_hashmap, pl_hashmap_cmp, NULL, 0);