Skip to content

Commit baa73e2

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e54793a commit baa73e2

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,36 +205,53 @@ test_sparse_unstaged () {
205205
done
206206
}
207207

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 &&
211216
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
213221
do
214222
TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
215223
grep "040000 $TREE 0 $dir/" cache \
216224
|| return 1
217225
done &&
218226

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
223230
do
224231
TREE=$(git -C sparse-index rev-parse HEAD:$dir) &&
225-
grep "040000 $TREE 0 $dir/" cache \
232+
! grep "040000 $TREE 0 $dir/" cache \
226233
|| return 1
227-
done &&
234+
done
235+
}
228236

229-
git -C sparse-index sparse-checkout set deep/deeper1 &&
237+
test_expect_success 'sparse-index contents' '
238+
init_repos &&
230239
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" &&
238255
239256
# Disabling the sparse-index replaces tree entries with full ones
240257
git -C sparse-index sparse-checkout init --no-sparse-index &&

0 commit comments

Comments
 (0)