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> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Sep 8, 2021 at 01:42 UTC 522d3cec0089228d0b1a5178c396662953cb2dc2
1 file changed +21 -17
t/t7519-status-fsmonitor.sh
+21 -17
@@ -389,43 +389,47 @@ test_expect_success 'status succeeds after staging/unstaging' '
389 # If "!" is supplied, then we verify that we do not call ensure_full_index
390 # during a call to 'git status'. Otherwise, we verify that we _do_ call it.
391 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 &&
393 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 &&
395 test_region $1 index ensure_full_index trace2.txt &&
396 test_region fsm_hook query trace2.txt &&
397 test_cmp expect actual &&
400 - rm trace2.txt &&
401 - git sparse-checkout disable
398 + rm trace2.txt
399 }
400
401 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 &&
406
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 &&
408 printf "last_update_token\0"
409 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 &&
412 check_sparse_index_behavior ! &&
413
416 - write_script .git/hooks/fsmonitor-test<<-\EOF &&
414 + write_script .git/hooks/fsmonitor-test <<-\EOF &&
415 printf "last_update_token\0"
416 printf "dir1/modified\0"
417 EOF
418 check_sparse_index_behavior ! &&
419
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 &&
429
430 # This one modifies outside the sparse-checkout definition
431 # 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 &&
433 printf "last_update_token\0"
434 printf "dir1a/modified\0"
435 EOF