t1092: stress test 'git sparse-checkout set'

The 'sparse-index contents' test checks that the sparse index has the correct set of sparse directories in the index after modifying the cone mode patterns using 'git sparse-checkout set'. Add to the coverage here by adding more complicated scenarios that were not previously tested. In order to check paths that do not exist at HEAD, we need to modify the test_sparse_checkout_set helper slightly: 1. Add the --skip-checks argument to the 'set' command to avoid failures when passing paths that do not exist at HEAD. 2. When looking for the non-existence of sparse directories for the paths in $CONE_DIRS, allow the rev-list command to fail because the path does not exist at HEAD. This allows us to add some interesting test cases. Helped-by: Victoria Dye <vdye@github.com> Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed May 23, 2022 at 13:48 UTC 8846847a142d720f63b5cbf9f0481c7694445ace
1 file changed +17 -2
t/t1092-sparse-checkout-compatibility.sh
+17 -2
@@ -212,7 +212,7 @@ test_sparse_unstaged () {
212 test_sparse_checkout_set () {
213 CONE_DIRS=$1 &&
214 SPARSE_DIRS=$2 &&
215 - git -C sparse-index sparse-checkout set $CONE_DIRS &&
215 + git -C sparse-index sparse-checkout set --skip-checks $CONE_DIRS &&
216 git -C sparse-index ls-files --sparse --stage >cache &&
217
218 # Check that the directories outside of the sparse-checkout cone
@@ -228,7 +228,9 @@ test_sparse_checkout_set () {
228 # are not sparse directory entries.
229 for dir in $CONE_DIRS
230 do
231 - TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
231 + # Allow TREE to not exist because
232 + # $dir does not exist at HEAD.
233 + TREE=$(git -C sparse-index rev-parse HEAD:$dir) ||
234 ! grep "040000 $TREE 0 $dir/" cache \
235 || return 1
236 done
@@ -253,6 +255,19 @@ test_expect_success 'sparse-index contents' '
255 "deep/deeper2 folder1 folder2 x" \
256 "before deep/deeper1" &&
257
258 + # Replace deep/deeper2 with deep/deeper1
259 + # Replace folder1 with folder1/0/0
260 + # Replace folder2 with non-existent folder2/2/3
261 + # Add non-existent "bogus"
262 + test_sparse_checkout_set \
263 + "bogus deep/deeper1 folder1/0/0 folder2/2/3 x" \
264 + "before deep/deeper2 folder2/0" &&
265 +
266 + # Drop down to only files at root
267 + test_sparse_checkout_set \
268 + "" \
269 + "before deep folder1 folder2 x" &&
270 +
271 # Disabling the sparse-index replaces tree entries with full ones
272 git -C sparse-index sparse-checkout init --no-sparse-index &&
273 test_sparse_match git ls-files --stage --sparse