@@ -69,7 +69,7 @@ test_expect_success 'object with bad sha1' '
69
69
git update-ref refs/heads/bogus $cmt &&
70
70
test_when_finished "git update-ref -d refs/heads/bogus" &&
71
71
72
- test_might_fail git fsck 2>out &&
72
+ test_must_fail git fsck 2>out &&
73
73
cat out &&
74
74
grep "$sha.*corrupt" out
75
75
'
@@ -101,7 +101,7 @@ test_expect_success 'email with embedded > is not okay' '
101
101
test_when_finished "remove_object $new" &&
102
102
git update-ref refs/heads/bogus "$new" &&
103
103
test_when_finished "git update-ref -d refs/heads/bogus" &&
104
- git fsck 2>out &&
104
+ test_must_fail git fsck 2>out &&
105
105
cat out &&
106
106
grep "error in commit $new" out
107
107
'
@@ -113,7 +113,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
113
113
test_when_finished "remove_object $new" &&
114
114
git update-ref refs/heads/bogus "$new" &&
115
115
test_when_finished "git update-ref -d refs/heads/bogus" &&
116
- git fsck 2>out &&
116
+ test_must_fail git fsck 2>out &&
117
117
cat out &&
118
118
grep "error in commit $new.* - bad name" out
119
119
'
@@ -125,7 +125,7 @@ test_expect_success 'missing email is reported nicely' '
125
125
test_when_finished "remove_object $new" &&
126
126
git update-ref refs/heads/bogus "$new" &&
127
127
test_when_finished "git update-ref -d refs/heads/bogus" &&
128
- git fsck 2>out &&
128
+ test_must_fail git fsck 2>out &&
129
129
cat out &&
130
130
grep "error in commit $new.* - missing email" out
131
131
'
@@ -137,7 +137,7 @@ test_expect_success '> in name is reported' '
137
137
test_when_finished "remove_object $new" &&
138
138
git update-ref refs/heads/bogus "$new" &&
139
139
test_when_finished "git update-ref -d refs/heads/bogus" &&
140
- git fsck 2>out &&
140
+ test_must_fail git fsck 2>out &&
141
141
cat out &&
142
142
grep "error in commit $new" out
143
143
'
@@ -151,11 +151,31 @@ test_expect_success 'integer overflow in timestamps is reported' '
151
151
test_when_finished "remove_object $new" &&
152
152
git update-ref refs/heads/bogus "$new" &&
153
153
test_when_finished "git update-ref -d refs/heads/bogus" &&
154
- git fsck 2>out &&
154
+ test_must_fail git fsck 2>out &&
155
155
cat out &&
156
156
grep "error in commit $new.*integer overflow" out
157
157
'
158
158
159
+ test_expect_success ' malformatted tree object' '
160
+ test_when_finished "git update-ref -d refs/tags/wrong" &&
161
+ test_when_finished "remove_object \$T" &&
162
+ T=$(
163
+ GIT_INDEX_FILE=test-index &&
164
+ export GIT_INDEX_FILE &&
165
+ rm -f test-index &&
166
+ >x &&
167
+ git add x &&
168
+ T=$(git write-tree) &&
169
+ (
170
+ git cat-file tree $T &&
171
+ git cat-file tree $T
172
+ ) |
173
+ git hash-object -w -t tree --stdin
174
+ ) &&
175
+ test_must_fail git fsck 2>out &&
176
+ grep "error in tree .*contains duplicate file entries" out
177
+ '
178
+
159
179
test_expect_success ' tag pointing to nonexistent' '
160
180
cat >invalid-tag <<-\EOF &&
161
181
object ffffffffffffffffffffffffffffffffffffffff
@@ -282,4 +302,60 @@ test_expect_success 'fsck notices ".git" in trees' '
282
302
)
283
303
'
284
304
305
+ # create a static test repo which is broken by omitting
306
+ # one particular object ($1, which is looked up via rev-parse
307
+ # in the new repository).
308
+ create_repo_missing () {
309
+ rm -rf missing &&
310
+ git init missing &&
311
+ (
312
+ cd missing &&
313
+ git commit -m one --allow-empty &&
314
+ mkdir subdir &&
315
+ echo content > subdir/file &&
316
+ git add subdir/file &&
317
+ git commit -m two &&
318
+ unrelated=$( echo unrelated | git hash-object --stdin -w) &&
319
+ git tag -m foo tag $unrelated &&
320
+ sha1=$( git rev-parse --verify " $1 " ) &&
321
+ path=$( echo $sha1 | sed ' s|..|&/|' ) &&
322
+ rm .git/objects/$path
323
+ )
324
+ }
325
+
326
+ test_expect_success ' fsck notices missing blob' '
327
+ create_repo_missing HEAD:subdir/file &&
328
+ test_must_fail git -C missing fsck
329
+ '
330
+
331
+ test_expect_success ' fsck notices missing subtree' '
332
+ create_repo_missing HEAD:subdir &&
333
+ test_must_fail git -C missing fsck
334
+ '
335
+
336
+ test_expect_success ' fsck notices missing root tree' '
337
+ create_repo_missing HEAD^{tree} &&
338
+ test_must_fail git -C missing fsck
339
+ '
340
+
341
+ test_expect_success ' fsck notices missing parent' '
342
+ create_repo_missing HEAD^ &&
343
+ test_must_fail git -C missing fsck
344
+ '
345
+
346
+ test_expect_success ' fsck notices missing tagged object' '
347
+ create_repo_missing tag^{blob} &&
348
+ test_must_fail git -C missing fsck
349
+ '
350
+
351
+ test_expect_success ' fsck notices ref pointing to missing commit' '
352
+ create_repo_missing HEAD &&
353
+ test_must_fail git -C missing fsck
354
+ '
355
+
356
+ test_expect_success ' fsck notices ref pointing to missing tag' '
357
+ create_repo_missing tag &&
358
+ test_must_fail git -C missing fsck
359
+ '
360
+
285
361
test_done
0 commit comments