t / t1450-fsck.shon commit Merge branch 'jn/maint-doc-ignore' (c7f874e)
   1#!/bin/sh
   2
   3test_description='git fsck random collection of tests'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8        git config i18n.commitencoding ISO-8859-1 &&
   9        test_commit A fileA one &&
  10        git config --unset i18n.commitencoding &&
  11        git checkout HEAD^0 &&
  12        test_commit B fileB two &&
  13        git tag -d A B &&
  14        git reflog expire --expire=now --all
  15'
  16
  17test_expect_success 'HEAD is part of refs' '
  18        test 0 = $(git fsck | wc -l)
  19'
  20
  21test_expect_success 'loose objects borrowed from alternate are not missing' '
  22        mkdir another &&
  23        (
  24                cd another &&
  25                git init &&
  26                echo ../../../.git/objects >.git/objects/info/alternates &&
  27                test_commit C fileC one &&
  28                git fsck >out &&
  29                ! grep "missing blob" out
  30        )
  31'
  32
  33test_expect_success 'valid objects appear valid' '
  34        { git fsck 2>out; true; } &&
  35        ! grep error out &&
  36        ! grep fatal out
  37'
  38
  39# Corruption tests follow.  Make sure to remove all traces of the
  40# specific corruption you test afterwards, lest a later test trip over
  41# it.
  42
  43test_expect_success 'object with bad sha1' '
  44        sha=$(echo blob | git hash-object -w --stdin) &&
  45        echo $sha &&
  46        old=$(echo $sha | sed "s+^..+&/+") &&
  47        new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
  48        sha="$(dirname $new)$(basename $new)"
  49        mv .git/objects/$old .git/objects/$new &&
  50        git update-index --add --cacheinfo 100644 $sha foo &&
  51        tree=$(git write-tree) &&
  52        cmt=$(echo bogus | git commit-tree $tree) &&
  53        git update-ref refs/heads/bogus $cmt &&
  54        (git fsck 2>out; true) &&
  55        grep "$sha.*corrupt" out &&
  56        rm -f .git/objects/$new &&
  57        git update-ref -d refs/heads/bogus &&
  58        git read-tree -u --reset HEAD
  59'
  60
  61test_expect_success 'branch pointing to non-commit' '
  62        git rev-parse HEAD^{tree} > .git/refs/heads/invalid &&
  63        git fsck 2>out &&
  64        grep "not a commit" out &&
  65        git update-ref -d refs/heads/invalid
  66'
  67
  68new=nothing
  69test_expect_success 'email without @ is okay' '
  70        git cat-file commit HEAD >basis &&
  71        sed "s/@/AT/" basis >okay &&
  72        new=$(git hash-object -t commit -w --stdin <okay) &&
  73        echo "$new" &&
  74        git update-ref refs/heads/bogus "$new" &&
  75        git fsck 2>out &&
  76        cat out &&
  77        ! grep "error in commit $new" out
  78'
  79git update-ref -d refs/heads/bogus
  80rm -f ".git/objects/$new"
  81
  82new=nothing
  83test_expect_success 'email with embedded > is not okay' '
  84        git cat-file commit HEAD >basis &&
  85        sed "s/@[a-z]/&>/" basis >bad-email &&
  86        new=$(git hash-object -t commit -w --stdin <bad-email) &&
  87        echo "$new" &&
  88        git update-ref refs/heads/bogus "$new" &&
  89        git fsck 2>out &&
  90        cat out &&
  91        grep "error in commit $new" out
  92'
  93git update-ref -d refs/heads/bogus
  94rm -f ".git/objects/$new"
  95
  96cat > invalid-tag <<EOF
  97object ffffffffffffffffffffffffffffffffffffffff
  98type commit
  99tag invalid
 100tagger T A Gger <tagger@example.com> 1234567890 -0000
 101
 102This is an invalid tag.
 103EOF
 104
 105test_expect_success 'tag pointing to nonexistent' '
 106        tag=$(git hash-object -t tag -w --stdin < invalid-tag) &&
 107        echo $tag > .git/refs/tags/invalid &&
 108        test_must_fail git fsck --tags >out &&
 109        cat out &&
 110        grep "broken link" out &&
 111        rm .git/refs/tags/invalid
 112'
 113
 114cat > wrong-tag <<EOF
 115object $(echo blob | git hash-object -w --stdin)
 116type commit
 117tag wrong
 118tagger T A Gger <tagger@example.com> 1234567890 -0000
 119
 120This is an invalid tag.
 121EOF
 122
 123test_expect_success 'tag pointing to something else than its type' '
 124        tag=$(git hash-object -t tag -w --stdin < wrong-tag) &&
 125        echo $tag > .git/refs/tags/wrong &&
 126        test_must_fail git fsck --tags 2>out &&
 127        cat out &&
 128        grep "error in tag.*broken links" out &&
 129        rm .git/refs/tags/wrong
 130'
 131
 132
 133
 134test_done