221
( cd C && git fsck )
222
'
223
224
+test_expect_success 'setup repo with garbage in objects/*' '
225
+ git init S &&
226
+ (
227
+ cd S &&
228
+ test_commit A &&
229
+
230
+ cd .git/objects &&
231
+ >.some-hidden-file &&
232
+ >some-file &&
233
+ mkdir .some-hidden-dir &&
234
+ >.some-hidden-dir/some-file &&
235
+ >.some-hidden-dir/.some-dot-file &&
236
+ mkdir some-dir &&
237
+ >some-dir/some-file &&
238
+ >some-dir/.some-dot-file
239
+ )
240
+'
241
+
242
+test_expect_success 'clone a repo with garbage in objects/*' '
243
+ for option in --local --no-hardlinks --shared --dissociate
244
+ do
245
+ git clone $option S S$option || return 1 &&
246
+ git -C S$option fsck || return 1
247
+ done &&
248
+ find S-* -name "*some*" | sort >actual &&
249
+ cat >expected <<-EOF &&
250
+ S--dissociate/.git/objects/.some-hidden-file
251
+ S--dissociate/.git/objects/some-dir
252
+ S--dissociate/.git/objects/some-dir/.some-dot-file
253
+ S--dissociate/.git/objects/some-dir/some-file
254
+ S--dissociate/.git/objects/some-file
255
+ S--local/.git/objects/.some-hidden-file
256
+ S--local/.git/objects/some-dir
257
+ S--local/.git/objects/some-dir/.some-dot-file
258
+ S--local/.git/objects/some-dir/some-file
259
+ S--local/.git/objects/some-file
260
+ S--no-hardlinks/.git/objects/.some-hidden-file
261
+ S--no-hardlinks/.git/objects/some-dir
262
+ S--no-hardlinks/.git/objects/some-dir/.some-dot-file
263
+ S--no-hardlinks/.git/objects/some-dir/some-file
264
+ S--no-hardlinks/.git/objects/some-file
265
+ EOF
266
+ test_cmp expected actual
267
+'
268
+
269
+test_expect_success SYMLINKS 'setup repo with manually symlinked dirs and unknown files at objects/' '
270
+ git init T &&
271
+ (
272
+ cd T &&
273
+ git config gc.auto 0 &&
274
+ test_commit A &&
275
+ git gc &&
276
+ test_commit B &&
277
+
278
+ cd .git/objects &&
279
+ mv pack packs &&
280
+ ln -s packs pack &&
281
+ find ?? -type d >loose-dirs &&
282
+ last_loose=$(tail -n 1 loose-dirs) &&
283
+ rm -f loose-dirs &&
284
+ mv $last_loose a-loose-dir &&
285
+ ln -s a-loose-dir $last_loose &&
286
+ find . -type f | sort >../../../T.objects-files.raw &&
287
+ echo unknown_content >unknown_file
288
+ ) &&
289
+ git -C T fsck &&
290
+ git -C T rev-list --all --objects >T.objects
291
+'
292
+
293
+
294
+test_expect_success SYMLINKS 'clone repo with symlinked dirs and unknown files at objects/' '
295
+ for option in --local --no-hardlinks --shared --dissociate
296
+ do
297
+ git clone $option T T$option || return 1 &&
298
+ git -C T$option fsck || return 1 &&
299
+ git -C T$option rev-list --all --objects >T$option.objects &&
300
+ test_cmp T.objects T$option.objects &&
301
+ (
302
+ cd T$option/.git/objects &&
303
+ find . -type f | sort >../../../T$option.objects-files.raw
304
+ )
305
+ done &&
306
+
307
+ for raw in $(ls T*.raw)
308
+ do
309
+ sed -e "s!/../!/Y/!; s![0-9a-f]\{38,\}!Z!" -e "/commit-graph/d" \
310
+ -e "/multi-pack-index/d" <$raw >$raw.de-sha || return 1
311
+ done &&
312
+
313
+ cat >expected-files <<-EOF &&
314
+ ./Y/Z
315
+ ./Y/Z
316
+ ./a-loose-dir/Z
317
+ ./Y/Z
318
+ ./info/packs
319
+ ./pack/pack-Z.idx
320
+ ./pack/pack-Z.pack
321
+ ./packs/pack-Z.idx
322
+ ./packs/pack-Z.pack
323
+ ./unknown_file
324
+ EOF
325
+
326
+ for option in --local --dissociate --no-hardlinks
327
+ do
328
+ test_cmp expected-files T$option.objects-files.raw.de-sha || return 1
329
+ done &&
330
+
331
+ echo ./info/alternates >expected-files &&
332
+ test_cmp expected-files T--shared.objects-files.raw
333
+'
334
+
335
test_done