3 test_description
='git fsck random collection of tests'
7 test_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 &&
14 git reflog expire --expire=now --all
17 test_expect_success
'HEAD is part of refs' '
18 test 0 = $(git fsck | wc -l)
21 test_expect_success
'loose objects borrowed from alternate are not missing' '
26 echo ../../../.git/objects >.git/objects/info/alternates &&
27 test_commit C fileC one &&
29 ! grep "missing blob" out
33 test_expect_success
'valid objects appear valid' '
34 { git fsck 2>out; true; } &&
39 # Corruption tests follow. Make sure to remove all traces of the
40 # specific corruption you test afterwards, lest a later test trip over
43 test_expect_success
'object with bad sha1' '
44 sha=$(echo blob | git hash-object -w --stdin) &&
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
61 test_expect_success
'branch pointing to non-commit' '
62 git rev-parse HEAD^{tree} > .git/refs/heads/invalid &&
64 grep "not a commit" out &&
65 git update-ref -d refs/heads/invalid
69 test_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) &&
74 git update-ref refs/heads/bogus "$new" &&
77 ! grep "error in commit $new" out
79 git update-ref
-d refs
/heads
/bogus
80 rm -f ".git/objects/$new"
83 test_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) &&
88 git update-ref refs/heads/bogus "$new" &&
91 grep "error in commit $new" out
93 git update-ref
-d refs
/heads
/bogus
94 rm -f ".git/objects/$new"
96 cat > invalid-tag
<<EOF
97 object ffffffffffffffffffffffffffffffffffffffff
100 tagger T A Gger <tagger@example.com> 1234567890 -0000
102 This is an invalid tag.
105 test_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 &&
110 grep "broken link" out &&
111 rm .git/refs/tags/invalid
114 cat > wrong-tag
<<EOF
115 object $(echo blob | git hash-object -w --stdin)
118 tagger T A Gger <tagger@example.com> 1234567890 -0000
120 This is an invalid tag.
123 test_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 &&
128 grep "error in tag.*broken links" out &&
129 rm .git/refs/tags/wrong