t7300: assert exact states of repo

Some of the tests in t7300 verify that git-clean(1) doesn't touch repositories that are embedded into the main repository. This is done by asserting a small set of substructures that are assumed to always exist, like the "refs/", "objects/" or "HEAD". This has the downside that we need to assume a specific repository structure that may be subject to change when new backends for the refdb land. At the same time, we don't thoroughly assert that git-clean(1) really didn't end up cleaning any files in the repository either. Convert the tests to instead assert that all files continue to exist after git-clean(1) by comparing a file listing via find(1) before and after executing clean. This makes our actual assertions stricter while having to care less about the repository's actual on-disk format. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Nov 2, 2023 at 09:47 UTC 390c5b07e2c2a1df515f0d9d9077f3ad2fe11f0b
1 file changed +14 -9
t/t7300-clean.sh
+14 -9
@@ -517,8 +517,12 @@ test_expect_success 'nested (empty) git should be kept' '
517 git init empty_repo &&
518 mkdir to_clean &&
519 >to_clean/should_clean.this &&
520 + # Note that we put the expect file in the .git directory so that it
521 + # does not get cleaned.
522 + find empty_repo | sort >.git/expect &&
523 git clean -f -d &&
521 - test_path_is_file empty_repo/.git/HEAD &&
524 + find empty_repo | sort >actual &&
525 + test_cmp .git/expect actual &&
526 test_path_is_missing to_clean
527 '
528
@@ -559,10 +563,10 @@ test_expect_success 'giving path in nested git work tree will NOT remove it' '
563 mkdir -p bar/baz &&
564 test_commit msg bar/baz/hello.world
565 ) &&
566 + find repo | sort >expect &&
567 git clean -f -d repo/bar/baz &&
563 - test_path_is_file repo/.git/HEAD &&
564 - test_path_is_dir repo/bar/ &&
565 - test_path_is_file repo/bar/baz/hello.world
568 + find repo | sort >actual &&
569 + test_cmp expect actual
570 '
571
572 test_expect_success 'giving path to nested .git will not remove it' '
@@ -573,10 +577,10 @@ test_expect_success 'giving path to nested .git will not remove it' '
577 git init &&
578 test_commit msg hello.world
579 ) &&
580 + find repo | sort >expect &&
581 git clean -f -d repo/.git &&
577 - test_path_is_file repo/.git/HEAD &&
578 - test_path_is_dir repo/.git/refs &&
579 - test_path_is_dir repo/.git/objects &&
582 + find repo | sort >actual &&
583 + test_cmp expect actual &&
584 test_path_is_dir untracked/
585 '
586
@@ -588,9 +592,10 @@ test_expect_success 'giving path to nested .git/ will NOT remove contents' '
592 git init &&
593 test_commit msg hello.world
594 ) &&
595 + find repo | sort >expect &&
596 git clean -f -d repo/.git/ &&
592 - test_path_is_dir repo/.git &&
593 - test_path_is_file repo/.git/HEAD &&
597 + find repo | sort >actual &&
598 + test_cmp expect actual &&
599 test_path_is_dir untracked/
600 '
601