pack-objects tests: don't leave test .git corrupt at end

Change the pack-objects tests to not leave their .git directory corrupt and the end. In 2fca19fbb5 ("fix multiple issues with t5300", 2010-02-03) a comment was added warning against adding any subsequent tests, but since 4614043c8f ("index-pack: use streaming interface for collision test on large blobs", 2012-05-24) the comment has drifted away from the code, mentioning two test, when we actually have three. Instead of having this warning let's just create a new .git directory specifically for these tests. As an aside, it would be interesting to instrument the test suite to run a "git fsck" at the very end (in "test_done"). That would have errored before this change, and may find other issues #leftoverbits. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Oct 30, 2018 at 18:43 UTC 228135d9efee6eb1dfac5d78ac24518f53ab093e
1 file changed +20 -17
t/t5300-pack-object.sh
+20 -17
@@ -468,29 +468,32 @@ test_expect_success 'pack-objects in too-many-packs mode' '
468 git fsck
469 '
470
471 -#
472 -# WARNING!
473 -#
474 -# The following test is destructive. Please keep the next
475 -# two tests at the end of this file.
476 -#
477 -
478 -test_expect_success 'fake a SHA1 hash collision' '
479 - long_a=$(git hash-object a | sed -e "s!^..!&/!") &&
480 - long_b=$(git hash-object b | sed -e "s!^..!&/!") &&
481 - test -f .git/objects/$long_b &&
482 - cp -f .git/objects/$long_a \
483 - .git/objects/$long_b
471 +test_expect_success 'setup: fake a SHA1 hash collision' '
472 + git init corrupt &&
473 + (
474 + cd corrupt &&
475 + long_a=$(git hash-object -w ../a | sed -e "s!^..!&/!") &&
476 + long_b=$(git hash-object -w ../b | sed -e "s!^..!&/!") &&
477 + test -f .git/objects/$long_b &&
478 + cp -f .git/objects/$long_a \
479 + .git/objects/$long_b
480 + )
481 '
482
483 test_expect_success 'make sure index-pack detects the SHA1 collision' '
487 - test_must_fail git index-pack -o bad.idx test-3.pack 2>msg &&
488 - test_i18ngrep "SHA1 COLLISION FOUND" msg
484 + (
485 + cd corrupt &&
486 + test_must_fail git index-pack -o ../bad.idx ../test-3.pack 2>msg &&
487 + test_i18ngrep "SHA1 COLLISION FOUND" msg
488 + )
489 '
490
491 test_expect_success 'make sure index-pack detects the SHA1 collision (large blobs)' '
492 - test_must_fail git -c core.bigfilethreshold=1 index-pack -o bad.idx test-3.pack 2>msg &&
493 - test_i18ngrep "SHA1 COLLISION FOUND" msg
492 + (
493 + cd corrupt &&
494 + test_must_fail git -c core.bigfilethreshold=1 index-pack -o ../bad.idx ../test-3.pack 2>msg &&
495 + test_i18ngrep "SHA1 COLLISION FOUND" msg
496 + )
497 '
498
499 test_done