]> git.ipfire.org Git - thirdparty/git.git/commitdiff
read-tree: expand sparse checkout test coverage
authorVictoria Dye <vdye@github.com>
Tue, 1 Mar 2022 20:24:27 +0000 (20:24 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Mar 2022 20:36:01 +0000 (12:36 -0800)
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>
t/perf/p2000-sparse-operations.sh
t/t1092-sparse-checkout-compatibility.sh

index 2a7106b9495ce1190dec2ff1a42bd0cb77ff3f9b..382716cfca909e82c0bc5bf04e3bb3726dc2f9f1 100755 (executable)
@@ -117,6 +117,7 @@ test_perf_on_all git diff
 test_perf_on_all git diff --cached
 test_perf_on_all git blame $SPARSE_CONE/a
 test_perf_on_all git blame $SPARSE_CONE/f3/a
+test_perf_on_all git read-tree -mu HEAD
 test_perf_on_all git checkout-index -f --all
 test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
 
index b1dcaa0e64213491f1d08a03b2747d4a31833e1b..9bb5aeb979c3ec38c874a550a15799bcab7e7a82 100755 (executable)
@@ -819,6 +819,93 @@ test_expect_success 'update-index --cacheinfo' '
        test_cmp expect sparse-checkout-out
 '
 
+for MERGE_TREES in "base HEAD update-folder2" \
+                  "update-folder1 update-folder2" \
+                  "update-folder2"
+do
+       test_expect_success "'read-tree -mu $MERGE_TREES' with files outside sparse definition" '
+               init_repos &&
+
+               # Although the index matches, without --no-sparse-checkout, outside-of-
+               # definition files will not exist on disk for sparse checkouts
+               test_all_match git read-tree -mu $MERGE_TREES &&
+               test_all_match git status --porcelain=v2 &&
+               test_path_is_missing sparse-checkout/folder2 &&
+               test_path_is_missing sparse-index/folder2 &&
+
+               test_all_match git read-tree --reset -u HEAD &&
+               test_all_match git status --porcelain=v2 &&
+
+               test_all_match git read-tree -mu --no-sparse-checkout $MERGE_TREES &&
+               test_all_match git status --porcelain=v2 &&
+               test_cmp sparse-checkout/folder2/a sparse-index/folder2/a &&
+               test_cmp sparse-checkout/folder2/a full-checkout/folder2/a
+
+       '
+done
+
+test_expect_success 'read-tree --merge with edit/edit conflicts in sparse directories' '
+       init_repos &&
+
+       # Merge of multiple changes to same directory (but not same files) should
+       # succeed
+       test_all_match git read-tree -mu base rename-base update-folder1 &&
+       test_all_match git status --porcelain=v2 &&
+
+       test_all_match git reset --hard &&
+
+       test_all_match git read-tree -mu rename-base update-folder2 &&
+       test_all_match git status --porcelain=v2 &&
+
+       test_all_match git reset --hard &&
+
+       test_all_match test_must_fail git read-tree -mu base update-folder1 rename-out-to-in &&
+       test_all_match test_must_fail git read-tree -mu rename-out-to-in update-folder1
+'
+
+test_expect_success 'read-tree --prefix' '
+       init_repos &&
+
+       # If files differing between the index and target <commit-ish> exist
+       # inside the prefix, `read-tree --prefix` should fail
+       test_all_match test_must_fail git read-tree --prefix=deep/ deepest &&
+       test_all_match test_must_fail git read-tree --prefix=folder1/ update-folder1 &&
+
+       # If no differing index entries exist matching the prefix,
+       # `read-tree --prefix` updates the index successfully
+       test_all_match git rm -rf deep/deeper1/deepest/ &&
+       test_all_match git read-tree --prefix=deep/deeper1/deepest -u deepest &&
+       test_all_match git status --porcelain=v2 &&
+
+       test_all_match git rm -rf --sparse folder1/ &&
+       test_all_match git read-tree --prefix=folder1/ -u update-folder1 &&
+       test_all_match git status --porcelain=v2 &&
+
+       test_all_match git rm -rf --sparse folder2/0 &&
+       test_all_match git read-tree --prefix=folder2/0/ -u rename-out-to-out &&
+       test_all_match git status --porcelain=v2
+'
+
+test_expect_success 'read-tree --merge with directory-file conflicts' '
+       init_repos &&
+
+       test_all_match git checkout -b test-branch rename-base &&
+
+       # Although the index matches, without --no-sparse-checkout, outside-of-
+       # definition files will not exist on disk for sparse checkouts
+       test_sparse_match git read-tree -mu rename-out-to-out &&
+       test_sparse_match git status --porcelain=v2 &&
+       test_path_is_missing sparse-checkout/folder2 &&
+       test_path_is_missing sparse-index/folder2 &&
+
+       test_sparse_match git read-tree --reset -u HEAD &&
+       test_sparse_match git status --porcelain=v2 &&
+
+       test_sparse_match git read-tree -mu --no-sparse-checkout rename-out-to-out &&
+       test_sparse_match git status --porcelain=v2 &&
+       test_cmp sparse-checkout/folder2/0/1 sparse-index/folder2/0/1
+'
+
 test_expect_success 'merge, cherry-pick, and rebase' '
        init_repos &&