]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t1450-fsck.sh
Merge branch 'maint-2.36' into maint-2.37
[thirdparty/git.git] / t / t1450-fsck.sh
index 5071ac63a5b51b89c973456211ce3aaac3587553..922984b903417a954f3ae423485b63fe99566749 100755 (executable)
@@ -48,24 +48,70 @@ remove_object () {
        rm "$(sha1_file "$1")"
 }
 
-test_expect_success 'object with bad sha1' '
-       sha=$(echo blob | git hash-object -w --stdin) &&
-       old=$(test_oid_to_path "$sha") &&
-       new=$(dirname $old)/$(test_oid ff_2) &&
-       sha="$(dirname $new)$(basename $new)" &&
-       mv .git/objects/$old .git/objects/$new &&
-       test_when_finished "remove_object $sha" &&
-       git update-index --add --cacheinfo 100644 $sha foo &&
-       test_when_finished "git read-tree -u --reset HEAD" &&
-       tree=$(git write-tree) &&
-       test_when_finished "remove_object $tree" &&
-       cmt=$(echo bogus | git commit-tree $tree) &&
-       test_when_finished "remove_object $cmt" &&
-       git update-ref refs/heads/bogus $cmt &&
-       test_when_finished "git update-ref -d refs/heads/bogus" &&
+test_expect_success 'object with hash mismatch' '
+       git init --bare hash-mismatch &&
+       (
+               cd hash-mismatch &&
 
-       test_must_fail git fsck 2>out &&
-       test_i18ngrep "$sha.*corrupt" out
+               oid=$(echo blob | git hash-object -w --stdin) &&
+               oldoid=$oid &&
+               old=$(test_oid_to_path "$oid") &&
+               new=$(dirname $old)/$(test_oid ff_2) &&
+               oid="$(dirname $new)$(basename $new)" &&
+
+               mv objects/$old objects/$new &&
+               git update-index --add --cacheinfo 100644 $oid foo &&
+               tree=$(git write-tree) &&
+               cmt=$(echo bogus | git commit-tree $tree) &&
+               git update-ref refs/heads/bogus $cmt &&
+
+               test_must_fail git fsck 2>out &&
+               grep "$oldoid: hash-path mismatch, found at: .*$new" out
+       )
+'
+
+test_expect_success 'object with hash and type mismatch' '
+       git init --bare hash-type-mismatch &&
+       (
+               cd hash-type-mismatch &&
+
+               oid=$(echo blob | git hash-object -w --stdin -t garbage --literally) &&
+               oldoid=$oid &&
+               old=$(test_oid_to_path "$oid") &&
+               new=$(dirname $old)/$(test_oid ff_2) &&
+               oid="$(dirname $new)$(basename $new)" &&
+
+               mv objects/$old objects/$new &&
+               git update-index --add --cacheinfo 100644 $oid foo &&
+               tree=$(git write-tree) &&
+               cmt=$(echo bogus | git commit-tree $tree) &&
+               git update-ref refs/heads/bogus $cmt &&
+
+
+               test_must_fail git fsck 2>out &&
+               grep "^error: $oldoid: hash-path mismatch, found at: .*$new" out &&
+               grep "^error: $oldoid: object is of unknown type '"'"'garbage'"'"'" out
+       )
+'
+
+test_expect_success 'zlib corrupt loose object output ' '
+       git init --bare corrupt-loose-output &&
+       (
+               cd corrupt-loose-output &&
+               oid=$(git hash-object -w --stdin --literally </dev/null) &&
+               oidf=objects/$(test_oid_to_path "$oid") &&
+               chmod +w $oidf &&
+               echo extra garbage >>$oidf &&
+
+               cat >expect.error <<-EOF &&
+               error: garbage at end of loose object '\''$oid'\''
+               error: unable to unpack contents of ./$oidf
+               error: $oid: object corrupt or missing: ./$oidf
+               EOF
+               test_must_fail git fsck 2>actual &&
+               grep ^error: actual >error &&
+               test_cmp expect.error error
+       )
 '
 
 test_expect_success 'branch pointing to non-commit' '
@@ -318,6 +364,20 @@ test_expect_success 'tree entry with type mismatch' '
        test_i18ngrep ! "dangling blob" out
 '
 
+test_expect_success 'tree entry with bogus mode' '
+       test_when_finished "remove_object \$blob" &&
+       test_when_finished "remove_object \$tree" &&
+       blob=$(echo blob | git hash-object -w --stdin) &&
+       blob_oct=$(echo $blob | hex2oct) &&
+       tree=$(printf "100000 foo\0${blob_oct}" |
+              git hash-object -t tree --stdin -w --literally) &&
+       git fsck 2>err &&
+       cat >expect <<-EOF &&
+       warning in tree $tree: badFilemode: contains bad file modes
+       EOF
+       test_cmp expect err
+'
+
 test_expect_success 'tag pointing to nonexistent' '
        badoid=$(test_oid deadbeef) &&
        cat >invalid-tag <<-EOF &&
@@ -728,10 +788,19 @@ test_expect_success 'fsck finds problems in duplicate loose objects' '
                # no "-d" here, so we end up with duplicates
                git repack &&
                # now corrupt the loose copy
-               file=$(sha1_file "$(git rev-parse HEAD)") &&
+               oid="$(git rev-parse HEAD)" &&
+               file=$(sha1_file "$oid") &&
                rm "$file" &&
                echo broken >"$file" &&
-               test_must_fail git fsck
+               test_must_fail git fsck 2>err &&
+
+               cat >expect <<-EOF &&
+               error: inflate: data stream error (incorrect header check)
+               error: unable to unpack header of $file
+               error: $oid: object corrupt or missing: $file
+               EOF
+               grep "^error: " err >actual &&
+               test_cmp expect actual
        )
 '
 
@@ -865,4 +934,45 @@ test_expect_success 'detect corrupt index file in fsck' '
        test_i18ngrep "bad index file" errors
 '
 
+test_expect_success 'fsck error and recovery on invalid object type' '
+       git init --bare garbage-type &&
+       (
+               cd garbage-type &&
+
+               garbage_blob=$(git hash-object --stdin -w -t garbage --literally </dev/null) &&
+
+               cat >err.expect <<-\EOF &&
+               fatal: invalid object type
+               EOF
+               test_must_fail git fsck >out 2>err &&
+               grep -e "^error" -e "^fatal" err >errors &&
+               test_line_count = 1 errors &&
+               grep "$garbage_blob: object is of unknown type '"'"'garbage'"'"':" err
+       )
+'
+
+test_expect_success 'fsck error on gitattributes with excessive line lengths' '
+       blob=$(printf "pattern %02048d" 1 | git hash-object -w --stdin) &&
+       test_when_finished "remove_object $blob" &&
+       tree=$(printf "100644 blob %s\t%s\n" $blob .gitattributes | git mktree) &&
+       test_when_finished "remove_object $tree" &&
+       cat >expected <<-EOF &&
+       error in blob $blob: gitattributesLineLength: .gitattributes has too long lines to parse
+       EOF
+       test_must_fail git fsck --no-dangling >actual 2>&1 &&
+       test_cmp expected actual
+'
+
+test_expect_success 'fsck error on gitattributes with excessive size' '
+       blob=$(test-tool genzeros $((100 * 1024 * 1024 + 1)) | git hash-object -w --stdin) &&
+       test_when_finished "remove_object $blob" &&
+       tree=$(printf "100644 blob %s\t%s\n" $blob .gitattributes | git mktree) &&
+       test_when_finished "remove_object $tree" &&
+       cat >expected <<-EOF &&
+       error in blob $blob: gitattributesLarge: .gitattributes too large to parse
+       EOF
+       test_must_fail git fsck --no-dangling >actual 2>&1 &&
+       test_cmp expected actual
+'
+
 test_done