327
test_must_be_empty actual
328
'
329
330
+test_expect_success 'repacking with a filter works' '
331
+ git -C bare.git repack -a -d &&
332
+ test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
333
+ git -C bare.git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
334
+ test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack &&
335
+ commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
336
+ blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
337
+ test "$commit_pack" != "$blob_pack" &&
338
+ tree_pack=$(test-tool -C bare.git find-pack -c 1 HEAD^{tree}) &&
339
+ test "$tree_pack" = "$commit_pack" &&
340
+ blob_pack2=$(test-tool -C bare.git find-pack -c 1 HEAD:file2) &&
341
+ test "$blob_pack2" = "$blob_pack"
342
+'
343
+
344
+test_expect_success '--filter fails with --write-bitmap-index' '
345
+ test_must_fail \
346
+ env GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
347
+ git -C bare.git repack -a -d --write-bitmap-index --filter=blob:none
348
+'
349
+
350
+test_expect_success 'repacking with two filters works' '
351
+ git init two-filters &&
352
+ (
353
+ cd two-filters &&
354
+ mkdir subdir &&
355
+ test_commit foo &&
356
+ test_commit subdir_bar subdir/bar &&
357
+ test_commit subdir_baz subdir/baz
358
+ ) &&
359
+ git clone --no-local --bare two-filters two-filters.git &&
360
+ (
361
+ cd two-filters.git &&
362
+ test_stdout_line_count = 1 ls objects/pack/*.pack &&
363
+ git -c repack.writebitmaps=false repack -a -d \
364
+ --filter=blob:none --filter=tree:1 &&
365
+ test_stdout_line_count = 2 ls objects/pack/*.pack &&
366
+ commit_pack=$(test-tool find-pack -c 1 HEAD) &&
367
+ blob_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
368
+ root_tree_pack=$(test-tool find-pack -c 1 HEAD^{tree}) &&
369
+ subdir_tree_hash=$(git ls-tree --object-only HEAD -- subdir) &&
370
+ subdir_tree_pack=$(test-tool find-pack -c 1 "$subdir_tree_hash") &&
371
+
372
+ # Root tree and subdir tree are not in the same packfiles
373
+ test "$commit_pack" != "$blob_pack" &&
374
+ test "$commit_pack" = "$root_tree_pack" &&
375
+ test "$blob_pack" = "$subdir_tree_pack"
376
+ )
377
+'
378
+
379
+prepare_for_keep_packs () {
380
+ git init keep-packs &&
381
+ (
382
+ cd keep-packs &&
383
+ test_commit foo &&
384
+ test_commit bar
385
+ ) &&
386
+ git clone --no-local --bare keep-packs keep-packs.git &&
387
+ (
388
+ cd keep-packs.git &&
389
+
390
+ # Create two packs
391
+ # The first pack will contain all of the objects except one blob
392
+ git rev-list --objects --all >objs &&
393
+ grep -v "bar.t" objs | git pack-objects pack &&
394
+ # The second pack will contain the excluded object and be kept
395
+ packid=$(grep "bar.t" objs | git pack-objects pack) &&
396
+ >pack-$packid.keep &&
397
+
398
+ # Replace the existing pack with the 2 new ones
399
+ rm -f objects/pack/pack* &&
400
+ mv pack-* objects/pack/
401
+ )
402
+}
403
+
404
+test_expect_success '--filter works with .keep packs' '
405
+ prepare_for_keep_packs &&
406
+ (
407
+ cd keep-packs.git &&
408
+
409
+ foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
410
+ bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
411
+ head_pack=$(test-tool find-pack -c 1 HEAD) &&
412
+
413
+ test "$foo_pack" != "$bar_pack" &&
414
+ test "$foo_pack" = "$head_pack" &&
415
+
416
+ git -c repack.writebitmaps=false repack -a -d --filter=blob:none &&
417
+
418
+ foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
419
+ bar_pack_1=$(test-tool find-pack -c 1 HEAD:bar.t) &&
420
+ head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
421
+
422
+ # Object bar is still only in the old .keep pack
423
+ test "$foo_pack_1" != "$foo_pack" &&
424
+ test "$bar_pack_1" = "$bar_pack" &&
425
+ test "$head_pack_1" != "$head_pack" &&
426
+
427
+ test "$foo_pack_1" != "$bar_pack_1" &&
428
+ test "$foo_pack_1" != "$head_pack_1" &&
429
+ test "$bar_pack_1" != "$head_pack_1"
430
+ )
431
+'
432
+
433
+test_expect_success '--filter works with --pack-kept-objects and .keep packs' '
434
+ rm -rf keep-packs keep-packs.git &&
435
+ prepare_for_keep_packs &&
436
+ (
437
+ cd keep-packs.git &&
438
+
439
+ foo_pack=$(test-tool find-pack -c 1 HEAD:foo.t) &&
440
+ bar_pack=$(test-tool find-pack -c 1 HEAD:bar.t) &&
441
+ head_pack=$(test-tool find-pack -c 1 HEAD) &&
442
+
443
+ test "$foo_pack" != "$bar_pack" &&
444
+ test "$foo_pack" = "$head_pack" &&
445
+
446
+ git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
447
+ --pack-kept-objects &&
448
+
449
+ foo_pack_1=$(test-tool find-pack -c 1 HEAD:foo.t) &&
450
+ test-tool find-pack -c 2 HEAD:bar.t >bar_pack_1 &&
451
+ head_pack_1=$(test-tool find-pack -c 1 HEAD) &&
452
+
453
+ test "$foo_pack_1" != "$foo_pack" &&
454
+ test "$foo_pack_1" != "$bar_pack" &&
455
+ test "$head_pack_1" != "$head_pack" &&
456
+
457
+ # Object bar is in both the old .keep pack and the new
458
+ # pack that contained the filtered out objects
459
+ grep "$bar_pack" bar_pack_1 &&
460
+ grep "$foo_pack_1" bar_pack_1 &&
461
+ test "$foo_pack_1" != "$head_pack_1"
462
+ )
463
+'
464
+
465
objdir=.git/objects
466
midx=$objdir/pack/multi-pack-index
467