read-tree: expand sparse checkout test coverage
Add tests focused on how 'git read-tree' behaves in sparse checkouts. Extra emphasis is placed on interactions with files outside the sparse cone, e.g. merges with out-of-cone conflicts. Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Victoria Dye <vdye@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Victoria Dye committed
Mar 1, 2022 at 20:24 UTC
14bf38cfcff0b68468444e85bc09c7d5007be34b
2 files changed
+88
t/perf/p2000-sparse-operations.sh
+1
@@ -117,6 +117,7 @@ test_perf_on_all git diff
117
test_perf_on_all git diff --cached
118
test_perf_on_all git blame $SPARSE_CONE/a
119
test_perf_on_all git blame $SPARSE_CONE/f3/a
120
+test_perf_on_all git read-tree -mu HEAD
121
test_perf_on_all git checkout-index -f --all
122
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
123
t/t1092-sparse-checkout-compatibility.sh
+87
@@ -819,6 +819,93 @@ test_expect_success 'update-index --cacheinfo' '
819
test_cmp expect sparse-checkout-out
820
'
821
822
+for MERGE_TREES in "base HEAD update-folder2" \
823
+ "update-folder1 update-folder2" \
824
+ "update-folder2"
825
+do
826
+ test_expect_success "'read-tree -mu $MERGE_TREES' with files outside sparse definition" '
827
+ init_repos &&
828
+
829
+ # Although the index matches, without --no-sparse-checkout, outside-of-
830
+ # definition files will not exist on disk for sparse checkouts
831
+ test_all_match git read-tree -mu $MERGE_TREES &&
832
+ test_all_match git status --porcelain=v2 &&
833
+ test_path_is_missing sparse-checkout/folder2 &&
834
+ test_path_is_missing sparse-index/folder2 &&
835
+
836
+ test_all_match git read-tree --reset -u HEAD &&
837
+ test_all_match git status --porcelain=v2 &&
838
+
839
+ test_all_match git read-tree -mu --no-sparse-checkout $MERGE_TREES &&
840
+ test_all_match git status --porcelain=v2 &&
841
+ test_cmp sparse-checkout/folder2/a sparse-index/folder2/a &&
842
+ test_cmp sparse-checkout/folder2/a full-checkout/folder2/a
843
+
844
+ '
845
+done
846
+
847
+test_expect_success 'read-tree --merge with edit/edit conflicts in sparse directories' '
848
+ init_repos &&
849
+
850
+ # Merge of multiple changes to same directory (but not same files) should
851
+ # succeed
852
+ test_all_match git read-tree -mu base rename-base update-folder1 &&
853
+ test_all_match git status --porcelain=v2 &&
854
+
855
+ test_all_match git reset --hard &&
856
+
857
+ test_all_match git read-tree -mu rename-base update-folder2 &&
858
+ test_all_match git status --porcelain=v2 &&
859
+
860
+ test_all_match git reset --hard &&
861
+
862
+ test_all_match test_must_fail git read-tree -mu base update-folder1 rename-out-to-in &&
863
+ test_all_match test_must_fail git read-tree -mu rename-out-to-in update-folder1
864
+'
865
+
866
+test_expect_success 'read-tree --prefix' '
867
+ init_repos &&
868
+
869
+ # If files differing between the index and target <commit-ish> exist
870
+ # inside the prefix, `read-tree --prefix` should fail
871
+ test_all_match test_must_fail git read-tree --prefix=deep/ deepest &&
872
+ test_all_match test_must_fail git read-tree --prefix=folder1/ update-folder1 &&
873
+
874
+ # If no differing index entries exist matching the prefix,
875
+ # `read-tree --prefix` updates the index successfully
876
+ test_all_match git rm -rf deep/deeper1/deepest/ &&
877
+ test_all_match git read-tree --prefix=deep/deeper1/deepest -u deepest &&
878
+ test_all_match git status --porcelain=v2 &&
879
+
880
+ test_all_match git rm -rf --sparse folder1/ &&
881
+ test_all_match git read-tree --prefix=folder1/ -u update-folder1 &&
882
+ test_all_match git status --porcelain=v2 &&
883
+
884
+ test_all_match git rm -rf --sparse folder2/0 &&
885
+ test_all_match git read-tree --prefix=folder2/0/ -u rename-out-to-out &&
886
+ test_all_match git status --porcelain=v2
887
+'
888
+
889
+test_expect_success 'read-tree --merge with directory-file conflicts' '
890
+ init_repos &&
891
+
892
+ test_all_match git checkout -b test-branch rename-base &&
893
+
894
+ # Although the index matches, without --no-sparse-checkout, outside-of-
895
+ # definition files will not exist on disk for sparse checkouts
896
+ test_sparse_match git read-tree -mu rename-out-to-out &&
897
+ test_sparse_match git status --porcelain=v2 &&
898
+ test_path_is_missing sparse-checkout/folder2 &&
899
+ test_path_is_missing sparse-index/folder2 &&
900
+
901
+ test_sparse_match git read-tree --reset -u HEAD &&
902
+ test_sparse_match git status --porcelain=v2 &&
903
+
904
+ test_sparse_match git read-tree -mu --no-sparse-checkout rename-out-to-out &&
905
+ test_sparse_match git status --porcelain=v2 &&
906
+ test_cmp sparse-checkout/folder2/0/1 sparse-index/folder2/0/1
907
+'
908
+
909
test_expect_success 'merge, cherry-pick, and rebase' '
910
init_repos &&
911