clean: integrate with sparse index
Remove full index requirement for `git clean` and test to ensure the index is not expanded in `git clean`. Add to existing test for `git clean` to verify cleanup of untracked files in sparse directories is consistent between sparse index and non-sparse index checkouts. Signed-off-by: Victoria Dye <vdye@github.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Victoria Dye committed
Jan 11, 2022 at 18:05 UTC
1e9e10e04891a13e5ccd52b36cfadc55dfaa5066
2 files changed
+24
builtin/clean.c
+3
@@ -983,6 +983,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
983
dir.flags |= DIR_KEEP_UNTRACKED_CONTENTS;
984
}
985
986
+ prepare_repo_settings(the_repository);
987
+ the_repository->settings.command_requires_full_index = 0;
988
+
989
if (read_cache() < 0)
990
die(_("index file corrupt"));
991
t/t1092-sparse-checkout-compatibility.sh
+21
@@ -764,23 +764,42 @@ test_expect_success 'clean' '
764
test_all_match git commit -m "ignore bogus files" &&
765
766
run_on_sparse mkdir folder1 &&
767
+ run_on_all mkdir -p deep/untracked-deep &&
768
run_on_all touch folder1/bogus &&
769
+ run_on_all touch folder1/untracked &&
770
+ run_on_all touch deep/untracked-deep/bogus &&
771
+ run_on_all touch deep/untracked-deep/untracked &&
772
773
test_all_match git status --porcelain=v2 &&
774
test_all_match git clean -f &&
775
test_all_match git status --porcelain=v2 &&
776
test_sparse_match ls &&
777
test_sparse_match ls folder1 &&
778
+ run_on_all test_path_exists folder1/bogus &&
779
+ run_on_all test_path_is_missing folder1/untracked &&
780
+ run_on_all test_path_exists deep/untracked-deep/bogus &&
781
+ run_on_all test_path_exists deep/untracked-deep/untracked &&
782
+
783
+ test_all_match git clean -fd &&
784
+ test_all_match git status --porcelain=v2 &&
785
+ test_sparse_match ls &&
786
+ test_sparse_match ls folder1 &&
787
+ run_on_all test_path_exists folder1/bogus &&
788
+ run_on_all test_path_exists deep/untracked-deep/bogus &&
789
+ run_on_all test_path_is_missing deep/untracked-deep/untracked &&
790
791
test_all_match git clean -xf &&
792
test_all_match git status --porcelain=v2 &&
793
test_sparse_match ls &&
794
test_sparse_match ls folder1 &&
795
+ run_on_all test_path_is_missing folder1/bogus &&
796
+ run_on_all test_path_exists deep/untracked-deep/bogus &&
797
798
test_all_match git clean -xdf &&
799
test_all_match git status --porcelain=v2 &&
800
test_sparse_match ls &&
801
test_sparse_match ls folder1 &&
802
+ run_on_all test_path_is_missing deep/untracked-deep/bogus &&
803
804
test_sparse_match test_path_is_dir folder1
805
'
@@ -920,6 +939,8 @@ test_expect_success 'sparse-index is not expanded' '
939
# Wildcard identifies only full sparse directories, no index expansion
940
ensure_not_expanded reset deepest -- folder\* &&
941
942
+ ensure_not_expanded clean -fd &&
943
+
944
ensure_not_expanded checkout -f update-deep &&
945
test_config -C sparse-index pull.twohead ort &&
946
(