Skip to content

Commit 390c5b0

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c6429fb commit 390c5b0

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

t/t7300-clean.sh

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,12 @@ test_expect_success 'nested (empty) git should be kept' '
517517
git init empty_repo &&
518518
mkdir to_clean &&
519519
>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 &&
520523
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 &&
522526
test_path_is_missing to_clean
523527
'
524528

@@ -559,10 +563,10 @@ test_expect_success 'giving path in nested git work tree will NOT remove it' '
559563
mkdir -p bar/baz &&
560564
test_commit msg bar/baz/hello.world
561565
) &&
566+
find repo | sort >expect &&
562567
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
566570
'
567571

568572
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' '
573577
git init &&
574578
test_commit msg hello.world
575579
) &&
580+
find repo | sort >expect &&
576581
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 &&
580584
test_path_is_dir untracked/
581585
'
582586

@@ -588,9 +592,10 @@ test_expect_success 'giving path to nested .git/ will NOT remove contents' '
588592
git init &&
589593
test_commit msg hello.world
590594
) &&
595+
find repo | sort >expect &&
591596
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 &&
594599
test_path_is_dir untracked/
595600
'
596601

0 commit comments

Comments
 (0)