mingw: implement getppid
[git/kusma.git] / t / t1450-fsck.sh
blob759cf12e16bcddc3dab9d6b3ad8abd5590245a94
1 #!/bin/sh
3 test_description='git fsck random collection of tests'
5 . ./test-lib.sh
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 &&
13 git tag -d A B &&
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' '
22 mkdir another &&
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
33 test_expect_success 'valid objects appear valid' '
34 { git fsck 2>out; true; } &&
35 ! grep error out &&
36 ! grep fatal out
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.
43 test_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
61 test_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
68 new=nothing
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) &&
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
79 git update-ref -d refs/heads/bogus
80 rm -f ".git/objects/$new"
82 new=nothing
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) &&
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
93 git update-ref -d refs/heads/bogus
94 rm -f ".git/objects/$new"
96 cat > invalid-tag <<EOF
97 object ffffffffffffffffffffffffffffffffffffffff
98 type commit
99 tag invalid
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 &&
109 cat 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)
116 type commit
117 tag wrong
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 &&
127 cat out &&
128 grep "error in tag.*broken links" out &&
129 rm .git/refs/tags/wrong
134 test_done