Skip to content

Commit c407b2c

Browse files
committed
t7519: rewrite sparse index test
The sparse index is tested with the FS Monitor hook and extension since f8fe49e (fsmonitor: integrate with sparse index, 2021-07-14). This test was very fragile because it shared an index across sparse and non-sparse behavior. Since that expansion and contraction could cause the index to lose its FS Monitor bitmap and token, behavior is fragile to changes in 'git sparse-checkout set'. Rewrite the test to use two clones of the original repo: full and sparse. This allows us to also keep the test files (actual, expect, trace2.txt) out of the repos we are testing with 'git status'. Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
1 parent 80b8d6c commit c407b2c

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

t/t7519-status-fsmonitor.sh

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -389,43 +389,47 @@ test_expect_success 'status succeeds after staging/unstaging' '
389389
# If "!" is supplied, then we verify that we do not call ensure_full_index
390390
# during a call to 'git status'. Otherwise, we verify that we _do_ call it.
391391
check_sparse_index_behavior () {
392-
git status --porcelain=v2 >expect &&
393-
git sparse-checkout init --cone --sparse-index &&
394-
git sparse-checkout set dir1 dir2 &&
392+
git -C full status --porcelain=v2 >expect &&
395393
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
396-
git status --porcelain=v2 >actual &&
394+
git -C sparse status --porcelain=v2 >actual &&
397395
test_region $1 index ensure_full_index trace2.txt &&
398396
test_region fsm_hook query trace2.txt &&
399397
test_cmp expect actual &&
400-
rm trace2.txt &&
401-
git sparse-checkout disable
398+
rm trace2.txt
402399
}
403400

404401
test_expect_success 'status succeeds with sparse index' '
405-
git reset --hard &&
402+
git clone . full &&
403+
git clone --sparse . sparse &&
404+
git -C sparse sparse-checkout init --cone --sparse-index &&
405+
git -C sparse sparse-checkout set dir1 dir2 &&
406406
407-
test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
408-
check_sparse_index_behavior ! &&
409-
410-
write_script .git/hooks/fsmonitor-test<<-\EOF &&
407+
write_script .git/hooks/fsmonitor-test <<-\EOF &&
411408
printf "last_update_token\0"
412409
EOF
413-
git config core.fsmonitor .git/hooks/fsmonitor-test &&
410+
git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test &&
411+
git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test &&
414412
check_sparse_index_behavior ! &&
415413
416-
write_script .git/hooks/fsmonitor-test<<-\EOF &&
414+
write_script .git/hooks/fsmonitor-test <<-\EOF &&
417415
printf "last_update_token\0"
418416
printf "dir1/modified\0"
419417
EOF
420418
check_sparse_index_behavior ! &&
421419
422-
cp -r dir1 dir1a &&
423-
git add dir1a &&
424-
git commit -m "add dir1a" &&
420+
git -C sparse sparse-checkout add dir1a &&
421+
422+
for repo in full sparse
423+
do
424+
cp -r $repo/dir1 $repo/dir1a &&
425+
git -C $repo add dir1a &&
426+
git -C $repo commit -m "add dir1a" || return 1
427+
done &&
428+
git -C sparse sparse-checkout set dir1 dir2 &&
425429
426430
# This one modifies outside the sparse-checkout definition
427431
# and hence we expect to expand the sparse-index.
428-
write_script .git/hooks/fsmonitor-test<<-\EOF &&
432+
write_script .git/hooks/fsmonitor-test <<-\EOF &&
429433
printf "last_update_token\0"
430434
printf "dir1a/modified\0"
431435
EOF

0 commit comments

Comments
 (0)