Test fsck a bit harder
git-fsck, of all tools, has very few tests. This adds some more: * a corrupted object; * a branch pointing to a non-commit; * a tag pointing to a nonexistent object; * and a tag pointing to an object of a type other than what the tag itself claims. Only the first two are caught. At least the third probably should, too, but currently slips through. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Feb 19, 2009 at 12:13 UTC
02a6552c28eabb524fcd23e8f5bd36e4f5afa63b
1 file changed
+67
t/t1450-fsck.sh
+67
@@ -28,4 +28,71 @@ test_expect_success 'loose objects borrowed from alternate are not missing' '
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
+
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
51
+'
52
+
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
58
+'
59
+
60
+cat > invalid-tag <<EOF
61
+object ffffffffffffffffffffffffffffffffffffffff
62
+type commit
63
+tag invalid
64
+tagger T A Gger <tagger@example.com> 1234567890 -0000
65
+
66
+This is an invalid tag.
67
+EOF
68
+
69
+test_expect_failure 'tag pointing to nonexistent' '
70
+ tag=$(git hash-object -w --stdin < invalid-tag) &&
71
+ echo $tag > .git/refs/tags/invalid &&
72
+ git fsck --tags 2>out &&
73
+ cat out &&
74
+ grep "could not load tagged object" out &&
75
+ rm .git/refs/tags/invalid
76
+'
77
+
78
+cat > wrong-tag <<EOF
79
+object $(echo blob | git hash-object -w --stdin)
80
+type commit
81
+tag wrong
82
+tagger T A Gger <tagger@example.com> 1234567890 -0000
83
+
84
+This is an invalid tag.
85
+EOF
86
+
87
+test_expect_failure 'tag pointing to something else than its type' '
88
+ tag=$(git hash-object -w --stdin < wrong-tag) &&
89
+ echo $tag > .git/refs/tags/wrong &&
90
+ git fsck --tags 2>out &&
91
+ cat out &&
92
+ grep "some sane error message" out &&
93
+ rm .git/refs/tags/wrong
94
+'
95
+
96
+
97
+
98
test_done