Skip to content

Commit f7a0dba

Browse files
avargitster
authored andcommitted
fsck tests: refactor one test to use a sub-repo
Refactor one of the fsck tests to use a throwaway repository. It's a pervasive pattern in t1450-fsck.sh to spend a lot of effort on the teardown of a tests so we're not leaving corrupt content for the next test. We can instead use the pattern of creating a named sub-repository, then we don't have to worry about cleaning up after ourselves, nobody will care what state the broken "hash-mismatch" repository is after this test runs. See [1] for related discussion on various "modern" test patterns that can be used to avoid verbosity and increase reliability. 1. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 093fffd commit f7a0dba

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

t/t1450-fsck.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,25 @@ remove_object () {
4848
rm "$(sha1_file "$1")"
4949
}
5050

51-
test_expect_success 'object with bad sha1' '
52-
sha=$(echo blob | git hash-object -w --stdin) &&
53-
old=$(test_oid_to_path "$sha") &&
54-
new=$(dirname $old)/$(test_oid ff_2) &&
55-
sha="$(dirname $new)$(basename $new)" &&
56-
mv .git/objects/$old .git/objects/$new &&
57-
test_when_finished "remove_object $sha" &&
58-
git update-index --add --cacheinfo 100644 $sha foo &&
59-
test_when_finished "git read-tree -u --reset HEAD" &&
60-
tree=$(git write-tree) &&
61-
test_when_finished "remove_object $tree" &&
62-
cmt=$(echo bogus | git commit-tree $tree) &&
63-
test_when_finished "remove_object $cmt" &&
64-
git update-ref refs/heads/bogus $cmt &&
65-
test_when_finished "git update-ref -d refs/heads/bogus" &&
51+
test_expect_success 'object with hash mismatch' '
52+
git init --bare hash-mismatch &&
53+
(
54+
cd hash-mismatch &&
6655
67-
test_must_fail git fsck 2>out &&
68-
test_i18ngrep "$sha.*corrupt" out
56+
oid=$(echo blob | git hash-object -w --stdin) &&
57+
old=$(test_oid_to_path "$oid") &&
58+
new=$(dirname $old)/$(test_oid ff_2) &&
59+
oid="$(dirname $new)$(basename $new)" &&
60+
61+
mv objects/$old objects/$new &&
62+
git update-index --add --cacheinfo 100644 $oid foo &&
63+
tree=$(git write-tree) &&
64+
cmt=$(echo bogus | git commit-tree $tree) &&
65+
git update-ref refs/heads/bogus $cmt &&
66+
67+
test_must_fail git fsck 2>out &&
68+
grep "$oid.*corrupt" out
69+
)
6970
'
7071

7172
test_expect_success 'branch pointing to non-commit' '

0 commit comments

Comments
 (0)