Imported Upstream version 2.28.0
[platform/upstream/git.git] / t / t5300-pack-object.sh
index 6c620cd..746cdb6 100755 (executable)
@@ -12,7 +12,8 @@ TRASH=$(pwd)
 
 test_expect_success \
     'setup' \
-    'rm -f .git/index* &&
+    'test_oid_init &&
+     rm -f .git/index* &&
      perl -e "print \"a\" x 4096;" > a &&
      perl -e "print \"b\" x 4096;" > b &&
      perl -e "print \"c\" x 4096;" > c &&
@@ -412,18 +413,18 @@ test_expect_success 'set up pack for non-repo tests' '
 '
 
 test_expect_success 'index-pack --stdin complains of non-repo' '
-       nongit test_must_fail git index-pack --stdin <foo.pack &&
+       nongit test_must_fail git index-pack --object-format=$(test_oid algo) --stdin <foo.pack &&
        test_path_is_missing non-repo/.git
 '
 
 test_expect_success 'index-pack <pack> works in non-repo' '
-       nongit git index-pack ../foo.pack &&
+       nongit git index-pack --object-format=$(test_oid algo) ../foo.pack &&
        test_path_is_file foo.idx
 '
 
 test_expect_success 'index-pack --strict <pack> works in non-repo' '
        rm -f foo.idx &&
-       nongit git index-pack --strict ../foo.pack &&
+       nongit git index-pack --strict --object-format=$(test_oid algo) ../foo.pack &&
        test_path_is_file foo.idx
 '
 
@@ -468,29 +469,32 @@ test_expect_success 'pack-objects in too-many-packs mode' '
        git fsck
 '
 
-#
-# WARNING!
-#
-# The following test is destructive.  Please keep the next
-# two tests at the end of this file.
-#
-
-test_expect_success \
-    'fake a SHA1 hash collision' \
-    'long_a=$(git hash-object a | sed -e "s!^..!&/!") &&
-     long_b=$(git hash-object b | sed -e "s!^..!&/!") &&
-     test -f   .git/objects/$long_b &&
-     cp -f     .git/objects/$long_a \
-               .git/objects/$long_b'
+test_expect_success 'setup: fake a SHA1 hash collision' '
+       git init corrupt &&
+       (
+               cd corrupt &&
+               long_a=$(git hash-object -w ../a | sed -e "s!^..!&/!") &&
+               long_b=$(git hash-object -w ../b | sed -e "s!^..!&/!") &&
+               test -f .git/objects/$long_b &&
+               cp -f   .git/objects/$long_a \
+                       .git/objects/$long_b
+       )
+'
 
-test_expect_success \
-    'make sure index-pack detects the SHA1 collision' \
-    'test_must_fail git index-pack -o bad.idx test-3.pack 2>msg &&
-     test_i18ngrep "SHA1 COLLISION FOUND" msg'
+test_expect_success 'make sure index-pack detects the SHA1 collision' '
+       (
+               cd corrupt &&
+               test_must_fail git index-pack -o ../bad.idx ../test-3.pack 2>msg &&
+               test_i18ngrep "SHA1 COLLISION FOUND" msg
+       )
+'
 
-test_expect_success \
-    'make sure index-pack detects the SHA1 collision (large blobs)' \
-    'test_must_fail git -c core.bigfilethreshold=1 index-pack -o bad.idx test-3.pack 2>msg &&
-     test_i18ngrep "SHA1 COLLISION FOUND" msg'
+test_expect_success 'make sure index-pack detects the SHA1 collision (large blobs)' '
+       (
+               cd corrupt &&
+               test_must_fail git -c core.bigfilethreshold=1 index-pack -o ../bad.idx ../test-3.pack 2>msg &&
+               test_i18ngrep "SHA1 COLLISION FOUND" msg
+       )
+'
 
 test_done