t / t1450-fsck.shon commit tests: document cherry-pick behavior in face of conflicts (6a84334)
   1#!/bin/sh
   2
   3test_description='git fsck random collection of tests'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8        test_commit A fileA one &&
   9        git checkout HEAD^0 &&
  10        test_commit B fileB two &&
  11        git tag -d A B &&
  12        git reflog expire --expire=now --all
  13'
  14
  15test_expect_success 'HEAD is part of refs' '
  16        test 0 = $(git fsck | wc -l)
  17'
  18
  19test_expect_success 'loose objects borrowed from alternate are not missing' '
  20        mkdir another &&
  21        (
  22                cd another &&
  23                git init &&
  24                echo ../../../.git/objects >.git/objects/info/alternates &&
  25                test_commit C fileC one &&
  26                git fsck >out &&
  27                ! grep "missing blob" out
  28        )
  29'
  30
  31# Corruption tests follow.  Make sure to remove all traces of the
  32# specific corruption you test afterwards, lest a later test trip over
  33# it.
  34
  35test_expect_success 'object with bad sha1' '
  36        sha=$(echo blob | git hash-object -w --stdin) &&
  37        echo $sha &&
  38        old=$(echo $sha | sed "s+^..+&/+") &&
  39        new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
  40        sha="$(dirname $new)$(basename $new)"
  41        mv .git/objects/$old .git/objects/$new &&
  42        git update-index --add --cacheinfo 100644 $sha foo &&
  43        tree=$(git write-tree) &&
  44        cmt=$(echo bogus | git commit-tree $tree) &&
  45        git update-ref refs/heads/bogus $cmt &&
  46        (git fsck 2>out; true) &&
  47        grep "$sha.*corrupt" out &&
  48        rm -f .git/objects/$new &&
  49        git update-ref -d refs/heads/bogus &&
  50        git read-tree -u --reset HEAD
  51'
  52
  53test_expect_success 'branch pointing to non-commit' '
  54        git rev-parse HEAD^{tree} > .git/refs/heads/invalid &&
  55        git fsck 2>out &&
  56        grep "not a commit" out &&
  57        git update-ref -d refs/heads/invalid
  58'
  59
  60cat > invalid-tag <<EOF
  61object ffffffffffffffffffffffffffffffffffffffff
  62type commit
  63tag invalid
  64tagger T A Gger <tagger@example.com> 1234567890 -0000
  65
  66This is an invalid tag.
  67EOF
  68
  69test_expect_success 'tag pointing to nonexistent' '
  70        tag=$(git hash-object -t tag -w --stdin < invalid-tag) &&
  71        echo $tag > .git/refs/tags/invalid &&
  72        test_must_fail git fsck --tags >out &&
  73        cat out &&
  74        grep "broken link" out &&
  75        rm .git/refs/tags/invalid
  76'
  77
  78cat > wrong-tag <<EOF
  79object $(echo blob | git hash-object -w --stdin)
  80type commit
  81tag wrong
  82tagger T A Gger <tagger@example.com> 1234567890 -0000
  83
  84This is an invalid tag.
  85EOF
  86
  87test_expect_success 'tag pointing to something else than its type' '
  88        tag=$(git hash-object -t tag -w --stdin < wrong-tag) &&
  89        echo $tag > .git/refs/tags/wrong &&
  90        test_must_fail git fsck --tags 2>out &&
  91        cat out &&
  92        grep "error in tag.*broken links" out &&
  93        rm .git/refs/tags/wrong
  94'
  95
  96
  97
  98test_done