t1092: refactor 'sparse-index contents' test

Before expanding this test with more involved cases, first extract the repeated logic into a new test_sparse_checkout_set helper. This helper checks that 'git sparse-checkout set ...' succeeds and then verifies that certain directories have sparse directory entries in the sparse index. It also verifies that the in-cone directories are _not_ sparse directory entries in the sparse index. 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 baa73e2b75645a088268266a408f502457663876
1 file changed +35 -18
t/t1092-sparse-checkout-compatibility.sh
+35 -18
@@ -205,36 +205,53 @@ test_sparse_unstaged () {
205 done
206 }
207
208 -test_expect_success 'sparse-index contents' '
209 - init_repos &&
210 -
208 +# Usage: test_sprase_checkout_set "<c1> ... <cN>" "<s1> ... <sM>"
209 +# Verifies that "git sparse-checkout set <c1> ... <cN>" succeeds and
210 +# leaves the sparse index in a state where <s1> ... <sM> are sparse
211 +# directories (and <c1> ... <cN> are not).
212 +test_sparse_checkout_set () {
213 + CONE_DIRS=$1 &&
214 + SPARSE_DIRS=$2 &&
215 + git -C sparse-index sparse-checkout set $CONE_DIRS &&
216 git -C sparse-index ls-files --sparse --stage >cache &&
212 - for dir in folder1 folder2 x
217 +
218 + # Check that the directories outside of the sparse-checkout cone
219 + # have sparse directory entries.
220 + for dir in $SPARSE_DIRS
221 do
222 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
223 grep "040000 $TREE 0 $dir/" cache \
224 || return 1
225 done &&
226
219 - git -C sparse-index sparse-checkout set folder1 &&
220 -
221 - git -C sparse-index ls-files --sparse --stage >cache &&
222 - for dir in deep folder2 x
227 + # Check that the directories in the sparse-checkout cone
228 + # are not sparse directory entries.
229 + for dir in $CONE_DIRS
230 do
231 TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
225 - grep "040000 $TREE 0 $dir/" cache \
232 + ! grep "040000 $TREE 0 $dir/" cache \
233 || return 1
227 - done &&
234 + done
235 +}
236
229 - git -C sparse-index sparse-checkout set deep/deeper1 &&
237 +test_expect_success 'sparse-index contents' '
238 + init_repos &&
239
231 - git -C sparse-index ls-files --sparse --stage >cache &&
232 - for dir in deep/deeper2 folder1 folder2 x
233 - do
234 - TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
235 - grep "040000 $TREE 0 $dir/" cache \
236 - || return 1
237 - done &&
240 + # Remove deep, add three other directories.
241 + test_sparse_checkout_set \
242 + "folder1 folder2 x" \
243 + "before deep" &&
244 +
245 + # Remove folder1, add deep
246 + test_sparse_checkout_set \
247 + "deep folder2 x" \
248 + "before folder1" &&
249 +
250 + # Replace deep with deep/deeper2 (dropping deep/deeper1)
251 + # Add folder1
252 + test_sparse_checkout_set \
253 + "deep/deeper2 folder1 folder2 x" \
254 + "before deep/deeper1" &&
255
256 # Disabling the sparse-index replaces tree entries with full ones
257 git -C sparse-index sparse-checkout init --no-sparse-index &&