git am: Display some help text when patch is empty
[git/barrbrain.git] / t / t1450-fsck.sh
blob22a80c8268b368963d58fd26fffde5cc8d084ee6
1 #!/bin/sh
3 test_description='git fsck random collection of tests'
5 . ./test-lib.sh
7 test_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
15 test_expect_success 'HEAD is part of refs' '
16 test 0 = $(git fsck | wc -l)
19 test_expect_success 'loose objects borrowed from alternate are not missing' '
20 mkdir another &&
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
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.
35 test_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
53 test_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
60 new=nothing
61 test_expect_success 'email without @ is okay' '
62 git cat-file commit HEAD >basis &&
63 sed "s/@/AT/" basis >okay &&
64 new=$(git hash-object -t commit -w --stdin <okay) &&
65 echo "$new" &&
66 git update-ref refs/heads/bogus "$new" &&
67 git fsck 2>out &&
68 cat out &&
69 ! grep "error in commit $new" out
71 git update-ref -d refs/heads/bogus
72 rm -f ".git/objects/$new"
74 new=nothing
75 test_expect_success 'email with embedded > is not okay' '
76 git cat-file commit HEAD >basis &&
77 sed "s/@[a-z]/&>/" basis >bad-email &&
78 new=$(git hash-object -t commit -w --stdin <bad-email) &&
79 echo "$new" &&
80 git update-ref refs/heads/bogus "$new" &&
81 git fsck 2>out &&
82 cat out &&
83 grep "error in commit $new" out
85 git update-ref -d refs/heads/bogus
86 rm -f ".git/objects/$new"
88 cat > invalid-tag <<EOF
89 object ffffffffffffffffffffffffffffffffffffffff
90 type commit
91 tag invalid
92 tagger T A Gger <tagger@example.com> 1234567890 -0000
94 This is an invalid tag.
95 EOF
97 test_expect_success 'tag pointing to nonexistent' '
98 tag=$(git hash-object -t tag -w --stdin < invalid-tag) &&
99 echo $tag > .git/refs/tags/invalid &&
100 test_must_fail git fsck --tags >out &&
101 cat out &&
102 grep "broken link" out &&
103 rm .git/refs/tags/invalid
106 cat > wrong-tag <<EOF
107 object $(echo blob | git hash-object -w --stdin)
108 type commit
109 tag wrong
110 tagger T A Gger <tagger@example.com> 1234567890 -0000
112 This is an invalid tag.
115 test_expect_success 'tag pointing to something else than its type' '
116 tag=$(git hash-object -t tag -w --stdin < wrong-tag) &&
117 echo $tag > .git/refs/tags/wrong &&
118 test_must_fail git fsck --tags 2>out &&
119 cat out &&
120 grep "error in tag.*broken links" out &&
121 rm .git/refs/tags/wrong
126 test_done