sparse-checkout: provide a new reapply subcommand
If commands like merge or rebase materialize files as part of their work, or a previous sparse-checkout command failed to update individual files due to dirty changes, users may want a command to simply 'reapply' the sparsity rules. Provide one. Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Mar 27, 2020 at 00:49 UTC
5644ca28cded68972c74614fc06d6e0e1db1a7de
3 files changed
+60
-1
Documentation/git-sparse-checkout.txt
+10
@@ -70,6 +70,16 @@ C-style quoted strings.
70
`core.sparseCheckoutCone` is enabled, the given patterns are interpreted
71
as directory names as in the 'set' subcommand.
72
73
+'reapply::
74
+ Reapply the sparsity pattern rules to paths in the working tree.
75
+ Commands like merge or rebase can materialize paths to do their
76
+ work (e.g. in order to show you a conflict), and other
77
+ sparse-checkout commands might fail to sparsify an individual file
78
+ (e.g. because it has unstaged changes or conflicts). In such
79
+ cases, it can make sense to run `git sparse-checkout reapply` later
80
+ after cleaning up affected paths (e.g. resolving conflicts, undoing
81
+ or committing changes, etc.).
82
+
83
'disable'::
84
Disable the `core.sparseCheckout` config setting, and restore the
85
working directory to include all files. Leaves the sparse-checkout
builtin/sparse-checkout.c
+9
-1
@@ -18,7 +18,7 @@
18
static const char *empty_base = "";
19
20
static char const * const builtin_sparse_checkout_usage[] = {
21
- N_("git sparse-checkout (init|list|set|add|disable) <options>"),
21
+ N_("git sparse-checkout (init|list|set|add|reapply|disable) <options>"),
22
NULL
23
};
24
@@ -554,6 +554,12 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix,
554
return modify_pattern_list(argc, argv, m);
555
}
556
557
+static int sparse_checkout_reapply(int argc, const char **argv)
558
+{
559
+ repo_read_index(the_repository);
560
+ return update_working_directory(NULL);
561
+}
562
+
563
static int sparse_checkout_disable(int argc, const char **argv)
564
{
565
struct pattern_list pl;
@@ -603,6 +609,8 @@ int cmd_sparse_checkout(int argc, const char **argv, const char *prefix)
609
return sparse_checkout_set(argc, argv, prefix, REPLACE);
610
if (!strcmp(argv[0], "add"))
611
return sparse_checkout_set(argc, argv, prefix, ADD);
612
+ if (!strcmp(argv[0], "reapply"))
613
+ return sparse_checkout_reapply(argc, argv);
614
if (!strcmp(argv[0], "disable"))
615
return sparse_checkout_disable(argc, argv);
616
}
t/t1091-sparse-checkout-builtin.sh
+41
@@ -370,6 +370,47 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with unmerged stat
370
git -C unmerged sparse-checkout disable
371
'
372
373
+test_expect_success 'sparse-checkout reapply' '
374
+ git clone repo tweak &&
375
+
376
+ echo dirty >tweak/deep/deeper2/a &&
377
+
378
+ cat >input <<-EOF &&
379
+ 0 0000000000000000000000000000000000000000 folder1/a
380
+ 100644 $(git -C tweak rev-parse HEAD:folder1/a) 1 folder1/a
381
+ EOF
382
+ git -C tweak update-index --index-info <input &&
383
+
384
+ git -C tweak sparse-checkout init --cone 2>err &&
385
+ test_i18ngrep "warning.*The following paths are not up to date" err &&
386
+ test_i18ngrep "warning.*The following paths are unmerged" err &&
387
+
388
+ git -C tweak sparse-checkout set folder2 deep/deeper1 2>err &&
389
+ test_i18ngrep "warning.*The following paths are not up to date" err &&
390
+ test_i18ngrep "warning.*The following paths are unmerged" err &&
391
+
392
+ git -C tweak sparse-checkout reapply 2>err &&
393
+ test_i18ngrep "warning.*The following paths are not up to date" err &&
394
+ test_path_is_file tweak/deep/deeper2/a &&
395
+ test_i18ngrep "warning.*The following paths are unmerged" err &&
396
+ test_path_is_file tweak/folder1/a &&
397
+
398
+ git -C tweak checkout HEAD deep/deeper2/a &&
399
+ git -C tweak sparse-checkout reapply 2>err &&
400
+ test_i18ngrep ! "warning.*The following paths are not up to date" err &&
401
+ test_path_is_missing tweak/deep/deeper2/a &&
402
+ test_i18ngrep "warning.*The following paths are unmerged" err &&
403
+ test_path_is_file tweak/folder1/a &&
404
+
405
+ git -C tweak add folder1/a &&
406
+ git -C tweak sparse-checkout reapply 2>err &&
407
+ test_must_be_empty err &&
408
+ test_path_is_missing tweak/deep/deeper2/a &&
409
+ test_path_is_missing tweak/folder1/a &&
410
+
411
+ git -C tweak sparse-checkout disable
412
+'
413
+
414
test_expect_success 'cone mode: set with core.ignoreCase=true' '
415
rm repo/.git/info/sparse-checkout &&
416
git -C repo sparse-checkout init --cone &&