extend test coverage for latest pack corruption resilience improvements
Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Pitre committed
Oct 29, 2008 at 19:02 UTC
538cf6b6e5f663eea9b777ef12ae58eb0c919480
1 file changed
+89
-7
t/t5303-pack-corruption-resilience.sh
+89
-7
@@ -41,11 +41,17 @@ create_new_pack() {
41
git verify-pack -v ${pack}.pack
42
}
43
44
+do_repack() {
45
+ pack=`printf "$blob_1\n$blob_2\n$blob_3\n" |
46
+ git pack-objects $@ .git/objects/pack/pack` &&
47
+ pack=".git/objects/pack/pack-${pack}"
48
+}
49
+
50
do_corrupt_object() {
51
ofs=`git show-index < ${pack}.idx | grep $1 | cut -f1 -d" "` &&
52
ofs=$(($ofs + $2)) &&
53
chmod +w ${pack}.pack &&
48
- dd if=/dev/zero of=${pack}.pack count=1 bs=1 conv=notrunc seek=$ofs &&
54
+ dd of=${pack}.pack count=1 bs=1 conv=notrunc seek=$ofs &&
55
test_must_fail git verify-pack ${pack}.pack
56
}
57
@@ -60,7 +66,7 @@ test_expect_success \
66
67
test_expect_success \
68
'create corruption in header of first object' \
63
- 'do_corrupt_object $blob_1 0 &&
69
+ 'do_corrupt_object $blob_1 0 < /dev/zero &&
70
test_must_fail git cat-file blob $blob_1 > /dev/null &&
71
test_must_fail git cat-file blob $blob_2 > /dev/null &&
72
test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -119,7 +125,7 @@ test_expect_success \
125
'create corruption in header of first delta' \
126
'create_new_pack &&
127
git prune-packed &&
122
- do_corrupt_object $blob_2 0 &&
128
+ do_corrupt_object $blob_2 0 < /dev/zero &&
129
git cat-file blob $blob_1 > /dev/null &&
130
test_must_fail git cat-file blob $blob_2 > /dev/null &&
131
test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -133,6 +139,15 @@ test_expect_success \
139
git cat-file blob $blob_2 > /dev/null &&
140
git cat-file blob $blob_3 > /dev/null'
141
142
+test_expect_success \
143
+ '... and then a repack "clears" the corruption' \
144
+ 'do_repack &&
145
+ git prune-packed &&
146
+ git verify-pack ${pack}.pack &&
147
+ git cat-file blob $blob_1 > /dev/null &&
148
+ git cat-file blob $blob_2 > /dev/null &&
149
+ git cat-file blob $blob_3 > /dev/null'
150
+
151
test_expect_success \
152
'create corruption in data of first delta' \
153
'create_new_pack &&
@@ -152,11 +167,20 @@ test_expect_success \
167
git cat-file blob $blob_2 > /dev/null &&
168
git cat-file blob $blob_3 > /dev/null'
169
170
+test_expect_success \
171
+ '... and then a repack "clears" the corruption' \
172
+ 'do_repack &&
173
+ git prune-packed &&
174
+ git verify-pack ${pack}.pack &&
175
+ git cat-file blob $blob_1 > /dev/null &&
176
+ git cat-file blob $blob_2 > /dev/null &&
177
+ git cat-file blob $blob_3 > /dev/null'
178
+
179
test_expect_success \
180
'corruption in delta base reference of first delta (OBJ_REF_DELTA)' \
181
'create_new_pack &&
182
git prune-packed &&
159
- do_corrupt_object $blob_2 2 &&
183
+ do_corrupt_object $blob_2 2 < /dev/zero &&
184
git cat-file blob $blob_1 > /dev/null &&
185
test_must_fail git cat-file blob $blob_2 > /dev/null &&
186
test_must_fail git cat-file blob $blob_3 > /dev/null'
@@ -171,17 +195,75 @@ test_expect_success \
195
git cat-file blob $blob_3 > /dev/null'
196
197
test_expect_success \
174
- 'corruption in delta base reference of first delta (OBJ_OFS_DELTA)' \
198
+ '... and then a repack "clears" the corruption' \
199
+ 'do_repack &&
200
+ git prune-packed &&
201
+ git verify-pack ${pack}.pack &&
202
+ git cat-file blob $blob_1 > /dev/null &&
203
+ git cat-file blob $blob_2 > /dev/null &&
204
+ git cat-file blob $blob_3 > /dev/null'
205
+
206
+test_expect_success \
207
+ 'corruption #0 in delta base reference of first delta (OBJ_OFS_DELTA)' \
208
'create_new_pack --delta-base-offset &&
209
git prune-packed &&
177
- do_corrupt_object $blob_2 2 &&
210
+ do_corrupt_object $blob_2 2 < /dev/zero &&
211
git cat-file blob $blob_1 > /dev/null &&
212
test_must_fail git cat-file blob $blob_2 > /dev/null &&
213
test_must_fail git cat-file blob $blob_3 > /dev/null'
214
215
test_expect_success \
183
- '... and a redundant pack allows for full recovery too' \
216
+ '... but having a loose copy allows for full recovery' \
217
'mv ${pack}.idx tmp &&
218
+ git hash-object -t blob -w file_2 &&
219
+ mv tmp ${pack}.idx &&
220
+ git cat-file blob $blob_1 > /dev/null &&
221
+ git cat-file blob $blob_2 > /dev/null &&
222
+ git cat-file blob $blob_3 > /dev/null'
223
+
224
+test_expect_success \
225
+ '... and then a repack "clears" the corruption' \
226
+ 'do_repack --delta-base-offset &&
227
+ git prune-packed &&
228
+ git verify-pack ${pack}.pack &&
229
+ git cat-file blob $blob_1 > /dev/null &&
230
+ git cat-file blob $blob_2 > /dev/null &&
231
+ git cat-file blob $blob_3 > /dev/null'
232
+
233
+test_expect_success \
234
+ 'corruption #1 in delta base reference of first delta (OBJ_OFS_DELTA)' \
235
+ 'create_new_pack --delta-base-offset &&
236
+ git prune-packed &&
237
+ printf "\x01" | do_corrupt_object $blob_2 2 &&
238
+ git cat-file blob $blob_1 > /dev/null &&
239
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
240
+ test_must_fail git cat-file blob $blob_3 > /dev/null'
241
+
242
+test_expect_success \
243
+ '... but having a loose copy allows for full recovery' \
244
+ 'mv ${pack}.idx tmp &&
245
+ git hash-object -t blob -w file_2 &&
246
+ mv tmp ${pack}.idx &&
247
+ git cat-file blob $blob_1 > /dev/null &&
248
+ git cat-file blob $blob_2 > /dev/null &&
249
+ git cat-file blob $blob_3 > /dev/null'
250
+
251
+test_expect_success \
252
+ '... and then a repack "clears" the corruption' \
253
+ 'do_repack --delta-base-offset &&
254
+ git prune-packed &&
255
+ git verify-pack ${pack}.pack &&
256
+ git cat-file blob $blob_1 > /dev/null &&
257
+ git cat-file blob $blob_2 > /dev/null &&
258
+ git cat-file blob $blob_3 > /dev/null'
259
+
260
+test_expect_success \
261
+ '... and a redundant pack allows for full recovery too' \
262
+ 'do_corrupt_object $blob_2 2 < /dev/zero &&
263
+ git cat-file blob $blob_1 > /dev/null &&
264
+ test_must_fail git cat-file blob $blob_2 > /dev/null &&
265
+ test_must_fail git cat-file blob $blob_3 > /dev/null &&
266
+ mv ${pack}.idx tmp &&
267
git hash-object -t blob -w file_1 &&
268
git hash-object -t blob -w file_2 &&
269
printf "$blob_1\n$blob_2\n" | git pack-objects .git/objects/pack/pack &&