]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7700-repack.sh
The third batch
[thirdparty/git.git] / t / t7700-repack.sh
CommitLineData
9245ddd5
BC
1#!/bin/sh
2
3test_description='git repack works correctly'
4
5. ./test-lib.sh
1d89d88d
TB
6. "${TEST_DIRECTORY}/lib-bitmap.sh"
7. "${TEST_DIRECTORY}/lib-midx.sh"
47ca93d0 8. "${TEST_DIRECTORY}/lib-terminal.sh"
9245ddd5 9
ae475afc 10commit_and_pack () {
09279086 11 test_commit "$@" 1>&2 &&
3699d69d 12 incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
73320e49
TB
13 # Remove any loose object(s) created by test_commit, since they have
14 # already been packed. Leaving these around can create subtly different
15 # packs with `pack-objects`'s `--unpacked` option.
16 git prune-packed 1>&2 &&
3699d69d 17 echo pack-${incrpackid}.pack
ed7e5fc3
NTND
18}
19
ae475afc
DL
20test_no_missing_in_packs () {
21 myidx=$(ls -1 .git/objects/pack/*.idx) &&
22 test_path_is_file "$myidx" &&
23 git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
3699d69d 24 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
ae475afc
DL
25 git verify-pack -v $myidx >dest.raw &&
26 cut -d" " -f1 dest.raw | sort >dest &&
27 comm -23 orig dest >missing &&
28 test_must_be_empty missing
29}
30
3699d69d 31# we expect $packid and $oid to be defined
cfe5eda0
DL
32test_has_duplicate_object () {
33 want_duplicate_object="$1"
34 found_duplicate_object=false
35 for p in .git/objects/pack/*.idx
36 do
37 idx=$(basename $p)
3699d69d 38 test "pack-$packid.idx" = "$idx" && continue
cfe5eda0 39 git verify-pack -v $p >packlist || return $?
3699d69d 40 if grep "^$oid" packlist
cfe5eda0
DL
41 then
42 found_duplicate_object=true
43 echo "DUPLICATE OBJECT FOUND"
44 break
45 fi
46 done &&
47 test "$want_duplicate_object" = "$found_duplicate_object"
48}
49
dd718365 50test_expect_success 'objects in packs marked .keep are not repacked' '
7a1c8c23
DL
51 echo content1 >file1 &&
52 echo content2 >file2 &&
9245ddd5 53 git add . &&
713c79e8 54 test_tick &&
9245ddd5
BC
55 git commit -m initial_commit &&
56 # Create two packs
57 # The first pack will contain all of the objects except one
d9b31db2
DL
58 git rev-list --objects --all >objs &&
59 grep -v file2 objs | git pack-objects pack &&
9245ddd5 60 # The second pack will contain the excluded object
d9b31db2 61 packid=$(grep file2 objs | git pack-objects pack) &&
3699d69d 62 >pack-$packid.keep &&
d9b31db2
DL
63 git verify-pack -v pack-$packid.idx >packlist &&
64 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
9245ddd5 65 mv pack-* .git/objects/pack/ &&
2d0174e3 66 git repack -A -d -l &&
9245ddd5 67 git prune-packed &&
cfe5eda0 68 test_has_duplicate_object false
9245ddd5
BC
69'
70
3198b89f 71test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
3699d69d 72 # build on $oid, $packid, and .keep state from previous
4b58b6f7 73 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 git repack -Adbl &&
cfe5eda0 74 test_has_duplicate_object true
ee34a2be
JK
75'
76
3198b89f 77test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
3699d69d 78 # build on $oid, $packid, and .keep state from previous
4b58b6f7
TB
79 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
80 git -c repack.writebitmaps=true repack -Adl &&
cfe5eda0 81 test_has_duplicate_object true
ee34a2be
JK
82'
83
daae0625 84test_expect_success 'loose objects in alternate ODB are not repacked' '
3c3df429 85 mkdir alt_objects &&
7a1c8c23
DL
86 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
87 echo content3 >file3 &&
3699d69d 88 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
3c3df429 89 git add file3 &&
713c79e8 90 test_tick &&
3c3df429
BC
91 git commit -m commit_file3 &&
92 git repack -a -d -l &&
93 git prune-packed &&
cfe5eda0 94 test_has_duplicate_object false
3c3df429
BC
95'
96
199337d6
GC
97test_expect_success SYMLINKS '--local keeps packs when alternate is objectdir ' '
98 test_when_finished "rm -rf repo" &&
99 git init repo &&
100 test_commit -C repo A &&
101 (
102 cd repo &&
103 git repack -a &&
104 ls .git/objects/pack/*.pack >../expect &&
105 ln -s objects .git/alt_objects &&
106 echo "$(pwd)/.git/alt_objects" >.git/objects/info/alternates &&
107 git repack -a -d -l &&
108 ls .git/objects/pack/*.pack >../actual
109 ) &&
110 test_cmp expect actual
111'
112
d85cd187
PS
113test_expect_success '--local disables writing bitmaps when connected to alternate ODB' '
114 test_when_finished "rm -rf shared member" &&
115
116 git init shared &&
117 git clone --shared shared member &&
118 (
119 cd member &&
120 test_commit "object" &&
121 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adl --write-bitmap-index 2>err &&
122 cat >expect <<-EOF &&
123 warning: disabling bitmap writing, as some objects are not being packed
124 EOF
125 test_cmp expect err &&
126 test_path_is_missing .git/objects/pack-*.bitmap
127 )
128'
129
3289b9de 130test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
2dec68cf 131 mkdir alt_objects/pack &&
3289b9de
BC
132 mv .git/objects/pack/* alt_objects/pack &&
133 git repack -a &&
ae475afc 134 test_no_missing_in_packs
3289b9de
BC
135'
136
1ef2d5a6 137test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
a83c8852 138 rm -f .git/objects/pack/* &&
7a1c8c23 139 echo new_content >>file1 &&
a83c8852 140 git add file1 &&
713c79e8 141 test_tick &&
a83c8852
BC
142 git commit -m more_content &&
143 git repack &&
144 git repack -a -d &&
ae475afc 145 test_no_missing_in_packs
a83c8852
BC
146'
147
171110a4 148test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
92cd8722
BC
149 # swap the .keep so the commit object is in the pack with .keep
150 for p in alt_objects/pack/*.pack
151 do
2dec68cf 152 base_name=$(basename $p .pack) &&
17a4ae92 153 if test_path_is_file alt_objects/pack/$base_name.keep
92cd8722
BC
154 then
155 rm alt_objects/pack/$base_name.keep
156 else
157 touch alt_objects/pack/$base_name.keep
0c51d6b4 158 fi || return 1
2dec68cf 159 done &&
92cd8722 160 git repack -a -d &&
ae475afc 161 test_no_missing_in_packs
92cd8722
BC
162'
163
79bc4c71 164test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
92cd8722
BC
165 rm -f alt_objects/pack/*.keep &&
166 mv .git/objects/pack/* alt_objects/pack/ &&
3699d69d 167 coid=$(git rev-parse HEAD^{commit}) &&
92cd8722 168 git reset --hard HEAD^ &&
713c79e8
JH
169 test_tick &&
170 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
92cd8722
BC
171 # The pack-objects call on the next line is equivalent to
172 # git repack -A -d without the call to prune-packed
173 git pack-objects --honor-pack-keep --non-empty --all --reflog \
174 --unpack-unreachable </dev/null pack &&
175 rm -f .git/objects/pack/* &&
176 mv pack-* .git/objects/pack/ &&
d9b31db2
DL
177 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
178 ! grep "^$coid " packlist &&
7a1c8c23 179 echo >.git/objects/info/alternates &&
3699d69d 180 test_must_fail git show $coid
92cd8722
BC
181'
182
094085e3 183test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
7a1c8c23 184 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
3699d69d 185 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
869a3d34
BC
186 rm -f .git/objects/pack/* &&
187 mv pack-* .git/objects/pack/ &&
188 # The pack-objects call on the next line is equivalent to
189 # git repack -A -d without the call to prune-packed
190 git pack-objects --honor-pack-keep --non-empty --all --reflog \
191 --unpack-unreachable </dev/null pack &&
192 rm -f .git/objects/pack/* &&
193 mv pack-* .git/objects/pack/ &&
d9b31db2
DL
194 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
195 ! grep "^$coid " &&
7a1c8c23 196 echo >.git/objects/info/alternates &&
3699d69d 197 test_must_fail git show $coid
869a3d34
BC
198'
199
7f3140cd 200test_expect_success 'objects made unreachable by grafts only are kept' '
1ec64827
BS
201 test_tick &&
202 git commit --allow-empty -m "commit 4" &&
203 H0=$(git rev-parse HEAD) &&
204 H1=$(git rev-parse HEAD^) &&
205 H2=$(git rev-parse HEAD^^) &&
7a1c8c23 206 echo "$H0 $H2" >.git/info/grafts &&
713c79e8 207 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
1ec64827
BS
208 git repack -a -d &&
209 git cat-file -t $H1
e9e33ab0 210'
1ec64827 211
ed7e5fc3
NTND
212test_expect_success 'repack --keep-pack' '
213 test_create_repo keep-pack &&
214 (
215 cd keep-pack &&
0af06727 216 # avoid producing different packs due to delta/base choices
73320e49 217 git config pack.window 0 &&
ed7e5fc3
NTND
218 P1=$(commit_and_pack 1) &&
219 P2=$(commit_and_pack 2) &&
220 P3=$(commit_and_pack 3) &&
221 P4=$(commit_and_pack 4) &&
222 ls .git/objects/pack/*.pack >old-counts &&
223 test_line_count = 4 old-counts &&
224 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
225 ls .git/objects/pack/*.pack >new-counts &&
226 grep -q $P1 new-counts &&
227 grep -q $P4 new-counts &&
228 test_line_count = 3 new-counts &&
73320e49
TB
229 git fsck &&
230
231 P5=$(commit_and_pack --no-tag 5) &&
232 git reset --hard HEAD^ &&
233 git reflog expire --all --expire=all &&
234 rm -f ".git/objects/pack/${P5%.pack}.idx" &&
235 rm -f ".git/objects/info/commit-graph" &&
236 for from in $(find .git/objects/pack -type f -name "${P5%.pack}.*")
237 do
238 to="$(dirname "$from")/.tmp-1234-$(basename "$from")" &&
239 mv "$from" "$to" || return 1
240 done &&
241
0af06727
DS
242 # A .idx file without a .pack should not stop us from
243 # repacking what we can.
244 touch .git/objects/pack/pack-does-not-exist.idx &&
245
73320e49
TB
246 git repack --cruft -d --keep-pack $P1 --keep-pack $P4 &&
247
248 ls .git/objects/pack/*.pack >newer-counts &&
249 test_cmp new-counts newer-counts &&
ed7e5fc3
NTND
250 git fsck
251 )
252'
253
0af06727
DS
254test_expect_success 'repacking fails when missing .pack actually means missing objects' '
255 test_create_repo idx-without-pack &&
256 (
257 cd idx-without-pack &&
258
259 # Avoid producing different packs due to delta/base choices
260 git config pack.window 0 &&
261 P1=$(commit_and_pack 1) &&
262 P2=$(commit_and_pack 2) &&
263 P3=$(commit_and_pack 3) &&
264 P4=$(commit_and_pack 4) &&
265 ls .git/objects/pack/*.pack >old-counts &&
266 test_line_count = 4 old-counts &&
267
268 # Remove one .pack file
269 rm .git/objects/pack/$P2 &&
270
271 ls .git/objects/pack/*.pack >before-pack-dir &&
272
273 test_must_fail git fsck &&
b1df3b38 274 test_must_fail env GIT_COMMIT_GRAPH_PARANOIA=true git repack --cruft -d 2>err &&
0af06727
DS
275 grep "bad object" err &&
276
277 # Before failing, the repack did not modify the
278 # pack directory.
279 ls .git/objects/pack/*.pack >after-pack-dir &&
280 test_cmp before-pack-dir after-pack-dir
281 )
282'
283
36eba032
EW
284test_expect_success 'bitmaps are created by default in bare repos' '
285 git clone --bare .git bare.git &&
4b58b6f7
TB
286 rm -f bare.git/objects/pack/*.bitmap &&
287 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
288 git -C bare.git repack -ad &&
36eba032
EW
289 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
290 test_path_is_file "$bitmap"
291'
292
293test_expect_success 'incremental repack does not complain' '
294 git -C bare.git repack -q 2>repack.err &&
295 test_must_be_empty repack.err
296'
9245ddd5 297
36eba032 298test_expect_success 'bitmaps can be disabled on bare repos' '
4b58b6f7
TB
299 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
300 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
09279086 301 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
36eba032
EW
302 test -z "$bitmap"
303'
304
73284822
EW
305test_expect_success 'no bitmaps created if .keep files present' '
306 pack=$(ls bare.git/objects/pack/*.pack) &&
307 test_path_is_file "$pack" &&
308 keep=${pack%.pack}.keep &&
cc2649ae 309 test_when_finished "rm -f \"\$keep\"" &&
73284822 310 >"$keep" &&
4b58b6f7
TB
311 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
312 git -C bare.git repack -ad 2>stderr &&
7ff024e7 313 test_must_be_empty stderr &&
73284822
EW
314 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
315 test_must_be_empty actual
316'
317
25575015
JK
318test_expect_success 'auto-bitmaps do not complain if unavailable' '
319 test_config -C bare.git pack.packSizeLimit 1M &&
320 blob=$(test-tool genrandom big $((1024*1024)) |
321 git -C bare.git hash-object -w --stdin) &&
322 git -C bare.git update-ref refs/tags/big $blob &&
4b58b6f7
TB
323 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
324 git -C bare.git repack -ad 2>stderr &&
25575015
JK
325 test_must_be_empty stderr &&
326 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
327 test_must_be_empty actual
328'
329
48a9b67b
CC
330test_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
344test_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
350test_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
379prepare_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
404test_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
433test_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
71c5aec1
CC
465test_expect_success '--filter-to stores filtered out objects' '
466 git -C bare.git repack -a -d &&
467 test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack &&
468
469 git init --bare filtered.git &&
470 git -C bare.git -c repack.writebitmaps=false repack -a -d \
471 --filter=blob:none \
472 --filter-to=../filtered.git/objects/pack/pack &&
473 test_stdout_line_count = 1 ls bare.git/objects/pack/pack-*.pack &&
474 test_stdout_line_count = 1 ls filtered.git/objects/pack/pack-*.pack &&
475
476 commit_pack=$(test-tool -C bare.git find-pack -c 1 HEAD) &&
477 blob_pack=$(test-tool -C bare.git find-pack -c 0 HEAD:file1) &&
478 blob_hash=$(git -C bare.git rev-parse HEAD:file1) &&
479 test -n "$blob_hash" &&
480 blob_pack=$(test-tool -C filtered.git find-pack -c 1 $blob_hash) &&
481
482 echo $(pwd)/filtered.git/objects >bare.git/objects/info/alternates &&
483 blob_pack=$(test-tool -C bare.git find-pack -c 1 HEAD:file1) &&
484 blob_content=$(git -C bare.git show $blob_hash) &&
485 test "$blob_content" = "content1"
486'
487
488test_expect_success '--filter works with --max-pack-size' '
489 rm -rf filtered.git &&
490 git init --bare filtered.git &&
491 git init max-pack-size &&
492 (
493 cd max-pack-size &&
494 test_commit base &&
495 # two blobs which exceed the maximum pack size
496 test-tool genrandom foo 1048576 >foo &&
497 git hash-object -w foo &&
498 test-tool genrandom bar 1048576 >bar &&
499 git hash-object -w bar &&
500 git add foo bar &&
501 git commit -m "adding foo and bar"
502 ) &&
503 git clone --no-local --bare max-pack-size max-pack-size.git &&
504 (
505 cd max-pack-size.git &&
506 git -c repack.writebitmaps=false repack -a -d --filter=blob:none \
507 --max-pack-size=1M \
508 --filter-to=../filtered.git/objects/pack/pack &&
509 echo $(cd .. && pwd)/filtered.git/objects >objects/info/alternates &&
510
511 # Check that the 3 blobs are in different packfiles in filtered.git
512 test_stdout_line_count = 3 ls ../filtered.git/objects/pack/pack-*.pack &&
513 test_stdout_line_count = 1 ls objects/pack/pack-*.pack &&
514 foo_pack=$(test-tool find-pack -c 1 HEAD:foo) &&
515 bar_pack=$(test-tool find-pack -c 1 HEAD:bar) &&
516 base_pack=$(test-tool find-pack -c 1 HEAD:base.t) &&
517 test "$foo_pack" != "$bar_pack" &&
518 test "$foo_pack" != "$base_pack" &&
519 test "$bar_pack" != "$base_pack" &&
520 for pack in "$foo_pack" "$bar_pack" "$base_pack"
521 do
522 case "$foo_pack" in */filtered.git/objects/pack/*) true ;; *) return 1 ;; esac
523 done
524 )
525'
526
1d89d88d
TB
527objdir=.git/objects
528midx=$objdir/pack/multi-pack-index
529
530test_expect_success 'setup for --write-midx tests' '
531 git init midx &&
532 (
533 cd midx &&
534 git config core.multiPackIndex true &&
535
536 test_commit base
537 )
538'
539
540test_expect_success '--write-midx unchanged' '
541 (
542 cd midx &&
543 GIT_TEST_MULTI_PACK_INDEX=0 git repack &&
544 test_path_is_missing $midx &&
545 test_path_is_missing $midx-*.bitmap &&
546
547 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
548
549 test_path_is_file $midx &&
550 test_path_is_missing $midx-*.bitmap &&
551 test_midx_consistent $objdir
552 )
553'
554
555test_expect_success '--write-midx with a new pack' '
556 (
557 cd midx &&
558 test_commit loose &&
559
560 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
561
562 test_path_is_file $midx &&
563 test_path_is_missing $midx-*.bitmap &&
564 test_midx_consistent $objdir
565 )
566'
567
568test_expect_success '--write-midx with -b' '
569 (
570 cd midx &&
571 GIT_TEST_MULTI_PACK_INDEX=0 git repack -mb &&
572
573 test_path_is_file $midx &&
574 test_path_is_file $midx-*.bitmap &&
575 test_midx_consistent $objdir
576 )
577'
578
579test_expect_success '--write-midx with -d' '
580 (
581 cd midx &&
582 test_commit repack &&
583
584 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ad --write-midx &&
585
586 test_path_is_file $midx &&
587 test_path_is_missing $midx-*.bitmap &&
588 test_midx_consistent $objdir
589 )
590'
591
592test_expect_success 'cleans up MIDX when appropriate' '
593 (
594 cd midx &&
595
596 test_commit repack-2 &&
597 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
598
599 checksum=$(midx_checksum $objdir) &&
600 test_path_is_file $midx &&
601 test_path_is_file $midx-$checksum.bitmap &&
1d89d88d
TB
602
603 test_commit repack-3 &&
604 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
605
606 test_path_is_file $midx &&
607 test_path_is_missing $midx-$checksum.bitmap &&
1d89d88d 608 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
1d89d88d
TB
609
610 test_commit repack-4 &&
611 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb &&
612
613 find $objdir/pack -type f -name "multi-pack-index*" >files &&
614 test_must_be_empty files
615 )
616'
617
324efc90
TB
618test_expect_success '--write-midx with preferred bitmap tips' '
619 git init midx-preferred-tips &&
620 test_when_finished "rm -fr midx-preferred-tips" &&
621 (
622 cd midx-preferred-tips &&
623
624 test_commit_bulk --message="%s" 103 &&
625
626 git log --format="%H" >commits.raw &&
627 sort <commits.raw >commits &&
628
629 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
630 git update-ref --stdin <refs &&
631
b494b1ce 632 GIT_TEST_MULTI_PACK_INDEX=0 \
324efc90
TB
633 git repack --write-midx --write-bitmap-index &&
634 test_path_is_file $midx &&
635 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
636
637 test-tool bitmap list-commits | sort >bitmaps &&
638 comm -13 bitmaps commits >before &&
639 test_line_count = 1 before &&
640
641 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
324efc90
TB
642 rm -fr $midx &&
643
644 # instead of constructing the snapshot ourselves (c.f., the test
645 # "write a bitmap with --refs-snapshot (preferred tips)" in
646 # t5326), mark the missing commit as preferred by adding it to
647 # the pack.preferBitmapTips configuration.
648 git for-each-ref --format="%(refname:rstrip=1)" \
649 --points-at="$(cat before)" >missing &&
650 git config pack.preferBitmapTips "$(cat missing)" &&
651 git repack --write-midx --write-bitmap-index &&
652
653 test-tool bitmap list-commits | sort >bitmaps &&
654 comm -13 bitmaps commits >after &&
655
656 ! test_cmp before after
657 )
658'
659
f1486203
DS
660# The first argument is expected to be a filename
661# and that file should contain the name of a .idx
662# file. Send the list of objects in that .idx file
663# into stdout.
664get_sorted_objects_from_pack () {
665 git show-index <$(cat "$1") >raw &&
666 cut -d" " -f2 raw
667}
668
e4d0c11c 669test_expect_success '--write-midx -b packs non-kept objects' '
f1486203
DS
670 git init repo &&
671 test_when_finished "rm -fr repo" &&
672 (
673 cd repo &&
674
675 # Create a kept pack-file
676 test_commit base &&
677 git repack -ad &&
678 find $objdir/pack -name "*.idx" >before &&
679 test_line_count = 1 before &&
680 before_name=$(cat before) &&
681 >${before_name%.idx}.keep &&
682
683 # Create a non-kept pack-file
684 test_commit other &&
685 git repack &&
686
687 # Create loose objects
688 test_commit loose &&
689
690 # Repack everything
691 git repack --write-midx -a -b -d &&
692
693 # There should be two pack-files now, the
694 # old, kept pack and the new, non-kept pack.
695 find $objdir/pack -name "*.idx" | sort >after &&
696 test_line_count = 2 after &&
697 find $objdir/pack -name "*.keep" >kept &&
698 kept_name=$(cat kept) &&
699 echo ${kept_name%.keep}.idx >kept-idx &&
700 test_cmp before kept-idx &&
701
702 # Get object list from the kept pack.
703 get_sorted_objects_from_pack before >old.objects &&
704
705 # Get object list from the one non-kept pack-file
706 comm -13 before after >new-pack &&
707 test_line_count = 1 new-pack &&
708 get_sorted_objects_from_pack new-pack >new.objects &&
709
710 # None of the objects in the new pack should
711 # exist within the kept pack.
712 comm -12 old.objects new.objects >shared.objects &&
713 test_must_be_empty shared.objects
714 )
e4d0c11c
DS
715'
716
55d902cd 717test_expect_success '--write-midx removes stale pack-based bitmaps' '
3a3b98be
JC
718 rm -fr repo &&
719 git init repo &&
720 test_when_finished "rm -fr repo" &&
721 (
55d902cd
TB
722 cd repo &&
723 test_commit base &&
724 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ab &&
725
726 pack_bitmap=$(ls $objdir/pack/pack-*.bitmap) &&
727 test_path_is_file "$pack_bitmap" &&
728
729 test_commit tip &&
730 GIT_TEST_MULTI_PACK_INDEX=0 git repack -bm &&
731
732 test_path_is_file $midx &&
733 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
734 test_path_is_missing $pack_bitmap
3a3b98be 735 )
55d902cd
TB
736'
737
197443e8
TB
738test_expect_success '--write-midx with --pack-kept-objects' '
739 git init repo &&
740 test_when_finished "rm -fr repo" &&
741 (
742 cd repo &&
743
744 test_commit one &&
745 test_commit two &&
746
747 one="$(echo "one" | git pack-objects --revs $objdir/pack/pack)" &&
748 two="$(echo "one..two" | git pack-objects --revs $objdir/pack/pack)" &&
749
750 keep="$objdir/pack/pack-$one.keep" &&
751 touch "$keep" &&
752
b494b1ce 753 GIT_TEST_MULTI_PACK_INDEX=0 \
197443e8
TB
754 git repack --write-midx --write-bitmap-index --geometric=2 -d \
755 --pack-kept-objects &&
756
757 test_path_is_file $keep &&
758 test_path_is_file $midx &&
759 test_path_is_file $midx-$(midx_checksum $objdir).bitmap
760 )
761'
762
47ca93d0
DS
763test_expect_success TTY '--quiet disables progress' '
764 test_terminal env GIT_PROGRESS_DELAY=0 \
765 git -C midx repack -ad --quiet --write-midx 2>stderr &&
766 test_must_be_empty stderr
767'
768
9cf10d87 769test_expect_success 'clean up .tmp-* packs on error' '
9b3fadfd 770 test_must_fail ok=sigpipe git \
9cf10d87
JK
771 -c repack.cruftwindow=bogus \
772 repack -ad --cruft &&
773 find $objdir/pack -name '.tmp-*' >tmpfiles &&
774 test_must_be_empty tmpfiles
775'
776
19343071
JK
777test_expect_success 'repack -ad cleans up old .tmp-* packs' '
778 git rev-parse HEAD >input &&
779 git pack-objects $objdir/pack/.tmp-1234 <input &&
780 git repack -ad &&
781 find $objdir/pack -name '.tmp-*' >tmpfiles &&
782 test_must_be_empty tmpfiles
783'
784
64a6151d
PS
785test_expect_success 'setup for update-server-info' '
786 git init update-server-info &&
787 test_commit -C update-server-info message
788'
789
790test_server_info_present () {
791 test_path_is_file update-server-info/.git/objects/info/packs &&
792 test_path_is_file update-server-info/.git/info/refs
793}
794
795test_server_info_missing () {
796 test_path_is_missing update-server-info/.git/objects/info/packs &&
797 test_path_is_missing update-server-info/.git/info/refs
798}
799
800test_server_info_cleanup () {
801 rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs &&
802 test_server_info_missing
803}
804
805test_expect_success 'updates server info by default' '
806 test_server_info_cleanup &&
807 git -C update-server-info repack &&
808 test_server_info_present
809'
810
811test_expect_success '-n skips updating server info' '
812 test_server_info_cleanup &&
813 git -C update-server-info repack -n &&
814 test_server_info_missing
815'
816
a2565c48
PS
817test_expect_success 'repack.updateServerInfo=true updates server info' '
818 test_server_info_cleanup &&
819 git -C update-server-info -c repack.updateServerInfo=true repack &&
820 test_server_info_present
821'
822
823test_expect_success 'repack.updateServerInfo=false skips updating server info' '
824 test_server_info_cleanup &&
825 git -C update-server-info -c repack.updateServerInfo=false repack &&
826 test_server_info_missing
827'
828
829test_expect_success '-n overrides repack.updateServerInfo=true' '
830 test_server_info_cleanup &&
831 git -C update-server-info -c repack.updateServerInfo=true repack -n &&
832 test_server_info_missing
833'
834
36eba032 835test_done