Skip to content

Commit 228135d

Browse files
avargitster
authored andcommitted
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 2fca19f ("fix multiple issues with t5300", 2010-02-03) a comment was added warning against adding any subsequent tests, but since 4614043 ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80938c3 commit 228135d

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

t/t5300-pack-object.sh

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -468,29 +468,32 @@ test_expect_success 'pack-objects in too-many-packs mode' '
468468
git fsck
469469
'
470470

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+
)
484481
'
485482

486483
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+
)
489489
'
490490

491491
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+
)
494497
'
495498

496499
test_done

0 commit comments

Comments
 (0)