]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5319-multi-pack-index.sh
t4216: avoid unnecessary subshell in test_bloom_filters_not_used
[thirdparty/git.git] / t / t5319-multi-pack-index.sh
CommitLineData
a3407730
DS
1#!/bin/sh
2
3test_description='multi-pack-indexes'
4. ./test-lib.sh
5
c4d25228
DS
6objdir=.git/objects
7
4d80560c 8midx_read_expect () {
396f2570 9 NUM_PACKS=$1
d7cacf29 10 NUM_OBJECTS=$2
662148c4
DS
11 NUM_CHUNKS=$3
12 OBJECT_DIR=$4
13 EXTRA_CHUNKS="$5"
3227565c
DS
14 {
15 cat <<-EOF &&
662148c4
DS
16 header: 4d494458 1 $NUM_CHUNKS $NUM_PACKS
17 chunks: pack-names oid-fanout oid-lookup object-offsets$EXTRA_CHUNKS
d7cacf29 18 num_objects: $NUM_OBJECTS
3227565c
DS
19 packs:
20 EOF
21 if test $NUM_PACKS -ge 1
22 then
662148c4 23 ls $OBJECT_DIR/pack/ | grep idx | sort
3227565c 24 fi &&
662148c4 25 printf "object-dir: $OBJECT_DIR\n"
3227565c 26 } >expect &&
662148c4 27 test-tool read-midx $OBJECT_DIR >actual &&
4d80560c
DS
28 test_cmp expect actual
29}
30
3c5e65ca 31test_expect_success 'setup' '
32 test_oid_init &&
33 test_oid_cache <<-EOF
34 idxoff sha1:2999
35 idxoff sha256:3739
36
37 packnameoff sha1:652
38 packnameoff sha256:940
39
40 fanoutoff sha1:1
41 fanoutoff sha256:3
42 EOF
43'
44
a3407730 45test_expect_success 'write midx with no packs' '
fc59e748
DS
46 test_when_finished rm -f pack/multi-pack-index &&
47 git multi-pack-index --object-dir=. write &&
662148c4 48 midx_read_expect 0 0 4 .
a3407730
DS
49'
50
2c381335
DS
51generate_objects () {
52 i=$1
53 iii=$(printf '%03i' $i)
54 {
55 test-tool genrandom "bar" 200 &&
56 test-tool genrandom "baz $iii" 50
57 } >wide_delta_$iii &&
58 {
59 test-tool genrandom "foo"$i 100 &&
60 test-tool genrandom "foo"$(( $i + 1 )) 100 &&
61 test-tool genrandom "foo"$(( $i + 2 )) 100
62 } >deep_delta_$iii &&
63 {
64 echo $iii &&
65 test-tool genrandom "$iii" 8192
66 } >file_$iii &&
67 git update-index --add file_$iii deep_delta_$iii wide_delta_$iii
68}
69
70commit_and_list_objects () {
71 {
72 echo 101 &&
73 test-tool genrandom 100 8192;
74 } >file_101 &&
75 git update-index --add file_101 &&
76 tree=$(git write-tree) &&
77 commit=$(git commit-tree $tree -p HEAD</dev/null) &&
78 {
79 echo $tree &&
80 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
81 } >obj-list &&
82 git reset --hard $commit
83}
84
85test_expect_success 'create objects' '
86 test_commit initial &&
87 for i in $(test_seq 1 5)
88 do
89 generate_objects $i
90 done &&
91 commit_and_list_objects
92'
93
94test_expect_success 'write midx with one v1 pack' '
c4d25228
DS
95 pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&
96 test_when_finished rm $objdir/pack/test-$pack.pack \
97 $objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&
98 git multi-pack-index --object-dir=$objdir write &&
99 midx_read_expect 1 18 4 $objdir
2c381335
DS
100'
101
c4d25228 102midx_git_two_modes () {
b4a14394
JK
103 git -c core.multiPackIndex=false $1 >expect &&
104 git -c core.multiPackIndex=true $1 >actual &&
e9ab2ed7
DS
105 if [ "$2" = "sorted" ]
106 then
b4a14394
JK
107 sort <expect >expect.sorted &&
108 mv expect.sorted expect &&
109 sort <actual >actual.sorted &&
110 mv actual.sorted actual
e9ab2ed7 111 fi &&
c4d25228
DS
112 test_cmp expect actual
113}
114
115compare_results_with_midx () {
116 MSG=$1
117 test_expect_success "check normal git operations: $MSG" '
118 midx_git_two_modes "rev-list --objects --all" &&
e9ab2ed7
DS
119 midx_git_two_modes "log --raw" &&
120 midx_git_two_modes "count-objects --verbose" &&
5670ad98
JK
121 midx_git_two_modes "cat-file --batch-all-objects --batch-check" &&
122 midx_git_two_modes "cat-file --batch-all-objects --batch-check --unordered" sorted
c4d25228
DS
123 '
124}
125
2c381335 126test_expect_success 'write midx with one v2 pack' '
c4d25228
DS
127 git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&
128 git multi-pack-index --object-dir=$objdir write &&
129 midx_read_expect 1 18 4 $objdir
2c381335
DS
130'
131
c4d25228
DS
132compare_results_with_midx "one v2 pack"
133
fc789156
JK
134test_expect_success 'corrupt idx not opened' '
135 idx=$(test-tool read-midx $objdir | grep "\.idx\$") &&
136 mv $objdir/pack/$idx backup-$idx &&
137 test_when_finished "mv backup-\$idx \$objdir/pack/\$idx" &&
138
139 # This is the minimum size for a sha-1 based .idx; this lets
140 # us pass perfunctory tests, but anything that actually opens and reads
141 # the idx file will complain.
142 test_copy_bytes 1064 <backup-$idx >$objdir/pack/$idx &&
143
144 git -c core.multiPackIndex=true rev-list --objects --all 2>err &&
145 test_must_be_empty err
146'
147
2c381335
DS
148test_expect_success 'add more objects' '
149 for i in $(test_seq 6 10)
150 do
151 generate_objects $i
152 done &&
153 commit_and_list_objects
154'
155
156test_expect_success 'write midx with two packs' '
c4d25228
DS
157 git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&
158 git multi-pack-index --object-dir=$objdir write &&
159 midx_read_expect 2 34 4 $objdir
2c381335
DS
160'
161
c4d25228
DS
162compare_results_with_midx "two packs"
163
680cba2c
WB
164test_expect_success 'write progress off for redirected stderr' '
165 git multi-pack-index --object-dir=$objdir write 2>err &&
166 test_line_count = 0 err
167'
168
169test_expect_success 'write force progress on for stderr' '
170 git multi-pack-index --object-dir=$objdir --progress write 2>err &&
171 test_file_not_empty err
172'
173
174test_expect_success 'write with the --no-progress option' '
175 git multi-pack-index --object-dir=$objdir --no-progress write 2>err &&
176 test_line_count = 0 err
177'
178
2c381335
DS
179test_expect_success 'add more packs' '
180 for j in $(test_seq 11 20)
181 do
182 generate_objects $j &&
183 commit_and_list_objects &&
c4d25228 184 git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list
2c381335
DS
185 done
186'
187
c4d25228
DS
188compare_results_with_midx "mixed mode (two packs + extra)"
189
2c381335 190test_expect_success 'write midx with twelve packs' '
c4d25228
DS
191 git multi-pack-index --object-dir=$objdir write &&
192 midx_read_expect 12 74 4 $objdir
662148c4
DS
193'
194
c4d25228
DS
195compare_results_with_midx "twelve packs"
196
56ee7ff1
DS
197test_expect_success 'verify multi-pack-index success' '
198 git multi-pack-index verify --object-dir=$objdir
199'
200
680cba2c
WB
201test_expect_success 'verify progress off for redirected stderr' '
202 git multi-pack-index verify --object-dir=$objdir 2>err &&
203 test_line_count = 0 err
204'
205
206test_expect_success 'verify force progress on for stderr' '
207 git multi-pack-index verify --object-dir=$objdir --progress 2>err &&
208 test_file_not_empty err
209'
210
211test_expect_success 'verify with the --no-progress option' '
212 git multi-pack-index verify --object-dir=$objdir --no-progress 2>err &&
213 test_line_count = 0 err
214'
215
53ad0407
DS
216# usage: corrupt_midx_and_verify <pos> <data> <objdir> <string>
217corrupt_midx_and_verify() {
218 POS=$1 &&
219 DATA="${2:-\0}" &&
220 OBJDIR=$3 &&
221 GREPSTR="$4" &&
66ec0390
DS
222 COMMAND="$5" &&
223 if test -z "$COMMAND"
224 then
225 COMMAND="git multi-pack-index verify --object-dir=$OBJDIR"
226 fi &&
53ad0407
DS
227 FILE=$OBJDIR/pack/multi-pack-index &&
228 chmod a+w $FILE &&
229 test_when_finished mv midx-backup $FILE &&
230 cp $FILE midx-backup &&
231 printf "$DATA" | dd of="$FILE" bs=1 seek="$POS" conv=notrunc &&
66ec0390 232 test_must_fail $COMMAND 2>test_err &&
53ad0407
DS
233 grep -v "^+" test_err >err &&
234 test_i18ngrep "$GREPSTR" err
235}
236
237test_expect_success 'verify bad signature' '
238 corrupt_midx_and_verify 0 "\00" $objdir \
239 "multi-pack-index signature"
240'
241
3c5e65ca 242HASH_LEN=$(test_oid rawsz)
cc6af73c 243NUM_OBJECTS=74
53ad0407
DS
244MIDX_BYTE_VERSION=4
245MIDX_BYTE_OID_VERSION=5
246MIDX_BYTE_CHUNK_COUNT=6
d3f8e211
DS
247MIDX_HEADER_SIZE=12
248MIDX_BYTE_CHUNK_ID=$MIDX_HEADER_SIZE
249MIDX_BYTE_CHUNK_OFFSET=$(($MIDX_HEADER_SIZE + 4))
8e72a3c3
DS
250MIDX_NUM_CHUNKS=5
251MIDX_CHUNK_LOOKUP_WIDTH=12
252MIDX_OFFSET_PACKNAMES=$(($MIDX_HEADER_SIZE + \
253 $MIDX_NUM_CHUNKS * $MIDX_CHUNK_LOOKUP_WIDTH))
254MIDX_BYTE_PACKNAME_ORDER=$(($MIDX_OFFSET_PACKNAMES + 2))
3c5e65ca 255MIDX_OFFSET_OID_FANOUT=$(($MIDX_OFFSET_PACKNAMES + $(test_oid packnameoff)))
2f23d3f3 256MIDX_OID_FANOUT_WIDTH=4
3c5e65ca 257MIDX_BYTE_OID_FANOUT_ORDER=$((MIDX_OFFSET_OID_FANOUT + 250 * $MIDX_OID_FANOUT_WIDTH + $(test_oid fanoutoff)))
55c5648d
DS
258MIDX_OFFSET_OID_LOOKUP=$(($MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
259MIDX_BYTE_OID_LOOKUP=$(($MIDX_OFFSET_OID_LOOKUP + 16 * $HASH_LEN))
cc6af73c
DS
260MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
261MIDX_OFFSET_WIDTH=8
262MIDX_BYTE_PACK_INT_ID=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 2))
263MIDX_BYTE_OFFSET=$(($MIDX_OFFSET_OBJECT_OFFSETS + 16 * $MIDX_OFFSET_WIDTH + 6))
53ad0407
DS
264
265test_expect_success 'verify bad version' '
266 corrupt_midx_and_verify $MIDX_BYTE_VERSION "\00" $objdir \
267 "multi-pack-index version"
268'
269
270test_expect_success 'verify bad OID version' '
271 corrupt_midx_and_verify $MIDX_BYTE_OID_VERSION "\02" $objdir \
272 "hash version"
273'
274
275test_expect_success 'verify truncated chunk count' '
276 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\01" $objdir \
277 "missing required"
278'
279
280test_expect_success 'verify extended chunk count' '
281 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_COUNT "\07" $objdir \
282 "terminating multi-pack-index chunk id appears earlier than expected"
283'
284
d3f8e211
DS
285test_expect_success 'verify missing required chunk' '
286 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_ID "\01" $objdir \
287 "missing required"
288'
289
290test_expect_success 'verify invalid chunk offset' '
291 corrupt_midx_and_verify $MIDX_BYTE_CHUNK_OFFSET "\01" $objdir \
292 "invalid chunk offset (too large)"
293'
294
8e72a3c3
DS
295test_expect_success 'verify packnames out of order' '
296 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "z" $objdir \
297 "pack names out of order"
298'
299
d4bf1d88
DS
300test_expect_success 'verify packnames out of order' '
301 corrupt_midx_and_verify $MIDX_BYTE_PACKNAME_ORDER "a" $objdir \
302 "failed to load pack"
303'
304
2f23d3f3
DS
305test_expect_success 'verify oid fanout out of order' '
306 corrupt_midx_and_verify $MIDX_BYTE_OID_FANOUT_ORDER "\01" $objdir \
307 "oid fanout out of order"
308'
309
55c5648d
DS
310test_expect_success 'verify oid lookup out of order' '
311 corrupt_midx_and_verify $MIDX_BYTE_OID_LOOKUP "\00" $objdir \
312 "oid lookup out of order"
313'
314
cc6af73c
DS
315test_expect_success 'verify incorrect pack-int-id' '
316 corrupt_midx_and_verify $MIDX_BYTE_PACK_INT_ID "\07" $objdir \
317 "bad pack-int-id"
318'
319
320test_expect_success 'verify incorrect offset' '
235d3cdd 321 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
cc6af73c
DS
322 "incorrect object offset"
323'
324
66ec0390 325test_expect_success 'git-fsck incorrect offset' '
235d3cdd 326 corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
66ec0390
DS
327 "incorrect object offset" \
328 "git -c core.multipackindex=true fsck"
329'
330
680cba2c
WB
331test_expect_success 'repack progress off for redirected stderr' '
332 git multi-pack-index --object-dir=$objdir repack 2>err &&
333 test_line_count = 0 err
334'
335
336test_expect_success 'repack force progress on for stderr' '
337 git multi-pack-index --object-dir=$objdir --progress repack 2>err &&
338 test_file_not_empty err
339'
340
341test_expect_success 'repack with the --no-progress option' '
342 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err &&
343 test_line_count = 0 err
344'
345
525e18c0
DS
346test_expect_success 'repack removes multi-pack-index' '
347 test_path_is_file $objdir/pack/multi-pack-index &&
0465a505 348 GIT_TEST_MULTI_PACK_INDEX=0 git repack -adf &&
525e18c0
DS
349 test_path_is_missing $objdir/pack/multi-pack-index
350'
351
352compare_results_with_midx "after repack"
353
e9ab2ed7
DS
354test_expect_success 'multi-pack-index and pack-bitmap' '
355 git -c repack.writeBitmaps=true repack -ad &&
356 git multi-pack-index write &&
357 git rev-list --test-bitmap HEAD
358'
359
29e2016b
DS
360test_expect_success 'multi-pack-index and alternates' '
361 git init --bare alt.git &&
362 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
363 echo content1 >file1 &&
364 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
365 git cat-file blob $altblob &&
366 git rev-list --all
367'
368
369compare_results_with_midx "with alternate (local midx)"
370
371test_expect_success 'multi-pack-index in an alternate' '
6a22d521
DS
372 mv .git/objects/pack/* alt.git/objects/pack &&
373 test_commit add_local_objects &&
374 git repack --local &&
375 git multi-pack-index write &&
376 midx_read_expect 1 3 4 $objdir &&
377 git reset --hard HEAD~1 &&
378 rm -f .git/objects/pack/*
29e2016b
DS
379'
380
381compare_results_with_midx "with alternate (remote midx)"
382
662148c4
DS
383# usage: corrupt_data <file> <pos> [<data>]
384corrupt_data () {
385 file=$1
386 pos=$2
387 data="${3:-\0}"
388 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
389}
390
391# Force 64-bit offsets by manipulating the idx file.
392# This makes the IDX file _incorrect_ so be careful to clean up after!
393test_expect_success 'force some 64-bit offsets with pack-objects' '
394 mkdir objects64 &&
395 mkdir objects64/pack &&
396 for i in $(test_seq 1 11)
397 do
398 generate_objects 11
399 done &&
400 commit_and_list_objects &&
401 pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) &&
402 idx64=objects64/pack/test-64-$pack64.idx &&
403 chmod u+w $idx64 &&
3c5e65ca 404 corrupt_data $idx64 $(test_oid idxoff) "\02" &&
662148c4
DS
405 midx64=$(git multi-pack-index --object-dir=objects64 write) &&
406 midx_read_expect 1 63 5 objects64 " large-offsets"
2c381335
DS
407'
408
56ee7ff1
DS
409test_expect_success 'verify multi-pack-index with 64-bit offsets' '
410 git multi-pack-index verify --object-dir=objects64
411'
412
cc6af73c
DS
413NUM_OBJECTS=63
414MIDX_OFFSET_OID_FANOUT=$((MIDX_OFFSET_PACKNAMES + 54))
415MIDX_OFFSET_OID_LOOKUP=$((MIDX_OFFSET_OID_FANOUT + 256 * $MIDX_OID_FANOUT_WIDTH))
416MIDX_OFFSET_OBJECT_OFFSETS=$(($MIDX_OFFSET_OID_LOOKUP + $NUM_OBJECTS * $HASH_LEN))
417MIDX_OFFSET_LARGE_OFFSETS=$(($MIDX_OFFSET_OBJECT_OFFSETS + $NUM_OBJECTS * $MIDX_OFFSET_WIDTH))
418MIDX_BYTE_LARGE_OFFSET=$(($MIDX_OFFSET_LARGE_OFFSETS + 3))
419
420test_expect_success 'verify incorrect 64-bit offset' '
421 corrupt_midx_and_verify $MIDX_BYTE_LARGE_OFFSET "\07" objects64 \
422 "incorrect object offset"
423'
424
cff97116
DS
425test_expect_success 'setup expire tests' '
426 mkdir dup &&
427 (
428 cd dup &&
429 git init &&
430 test-tool genrandom "data" 4096 >large_file.txt &&
431 git update-index --add large_file.txt &&
432 for i in $(test_seq 1 20)
433 do
434 test_commit $i
435 done &&
436 git branch A HEAD &&
437 git branch B HEAD~8 &&
438 git branch C HEAD~13 &&
439 git branch D HEAD~16 &&
440 git branch E HEAD~18 &&
441 git pack-objects --revs .git/objects/pack/pack-A <<-EOF &&
442 refs/heads/A
443 ^refs/heads/B
444 EOF
445 git pack-objects --revs .git/objects/pack/pack-B <<-EOF &&
446 refs/heads/B
447 ^refs/heads/C
448 EOF
449 git pack-objects --revs .git/objects/pack/pack-C <<-EOF &&
450 refs/heads/C
451 ^refs/heads/D
452 EOF
453 git pack-objects --revs .git/objects/pack/pack-D <<-EOF &&
454 refs/heads/D
455 ^refs/heads/E
456 EOF
457 git pack-objects --revs .git/objects/pack/pack-E <<-EOF &&
458 refs/heads/E
459 EOF
2af890bb
DS
460 git multi-pack-index write &&
461 cp -r .git/objects/pack .git/objects/pack-backup
cff97116
DS
462 )
463'
464
465test_expect_success 'expire does not remove any packs' '
466 (
467 cd dup &&
468 ls .git/objects/pack >expect &&
469 git multi-pack-index expire &&
470 ls .git/objects/pack >actual &&
471 test_cmp expect actual
472 )
473'
474
680cba2c
WB
475test_expect_success 'expire progress off for redirected stderr' '
476 (
477 cd dup &&
478 git multi-pack-index expire 2>err &&
479 test_line_count = 0 err
480 )
481'
482
483test_expect_success 'expire force progress on for stderr' '
484 (
485 cd dup &&
486 git multi-pack-index --progress expire 2>err &&
487 test_file_not_empty err
488 )
489'
490
491test_expect_success 'expire with the --no-progress option' '
492 (
493 cd dup &&
494 git multi-pack-index --no-progress expire 2>err &&
495 test_line_count = 0 err
496 )
497'
498
19575c7c
DS
499test_expect_success 'expire removes unreferenced packs' '
500 (
501 cd dup &&
502 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
503 refs/heads/A
504 ^refs/heads/C
505 EOF
506 git multi-pack-index write &&
507 ls .git/objects/pack | grep -v -e pack-[AB] >expect &&
508 git multi-pack-index expire &&
509 ls .git/objects/pack >actual &&
510 test_cmp expect actual &&
511 ls .git/objects/pack/ | grep idx >expect-idx &&
512 test-tool read-midx .git/objects | grep idx >actual-midx &&
513 test_cmp expect-idx actual-midx &&
514 git multi-pack-index verify &&
515 git fsck
516 )
517'
518
2af890bb
DS
519test_expect_success 'repack with minimum size does not alter existing packs' '
520 (
521 cd dup &&
522 rm -rf .git/objects/pack &&
523 mv .git/objects/pack-backup .git/objects/pack &&
524 touch -m -t 201901010000 .git/objects/pack/pack-D* &&
525 touch -m -t 201901010001 .git/objects/pack/pack-C* &&
526 touch -m -t 201901010002 .git/objects/pack/pack-B* &&
527 touch -m -t 201901010003 .git/objects/pack/pack-A* &&
528 ls .git/objects/pack >expect &&
3612c233 529 MINSIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 1) &&
2af890bb
DS
530 git multi-pack-index repack --batch-size=$MINSIZE &&
531 ls .git/objects/pack >actual &&
532 test_cmp expect actual
533 )
534'
535
ce1e4a10
DS
536test_expect_success 'repack creates a new pack' '
537 (
538 cd dup &&
539 ls .git/objects/pack/*idx >idx-list &&
540 test_line_count = 5 idx-list &&
3612c233 541 THIRD_SMALLEST_SIZE=$(test-tool path-utils file-size .git/objects/pack/*pack | sort -n | head -n 3 | tail -n 1) &&
ce1e4a10
DS
542 BATCH_SIZE=$(($THIRD_SMALLEST_SIZE + 1)) &&
543 git multi-pack-index repack --batch-size=$BATCH_SIZE &&
544 ls .git/objects/pack/*idx >idx-list &&
545 test_line_count = 6 idx-list &&
546 test-tool read-midx .git/objects | grep idx >midx-list &&
547 test_line_count = 6 midx-list
548 )
549'
550
551test_expect_success 'expire removes repacked packs' '
552 (
553 cd dup &&
554 ls -al .git/objects/pack/*pack &&
555 ls -S .git/objects/pack/*pack | head -n 4 >expect &&
556 git multi-pack-index expire &&
557 ls -S .git/objects/pack/*pack >actual &&
558 test_cmp expect actual &&
559 test-tool read-midx .git/objects | grep idx >midx-list &&
560 test_line_count = 4 midx-list
561 )
562'
563
d2743315
DS
564test_expect_success 'expire works when adding new packs' '
565 (
566 cd dup &&
567 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
568 refs/heads/A
569 ^refs/heads/B
570 EOF
571 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
572 refs/heads/B
573 ^refs/heads/C
574 EOF
575 git pack-objects --revs .git/objects/pack/pack-combined <<-EOF &&
576 refs/heads/C
577 ^refs/heads/D
578 EOF
579 git multi-pack-index write &&
580 git pack-objects --revs .git/objects/pack/a-pack <<-EOF &&
581 refs/heads/D
582 ^refs/heads/E
583 EOF
584 git multi-pack-index write &&
585 git pack-objects --revs .git/objects/pack/z-pack <<-EOF &&
586 refs/heads/E
587 EOF
588 git multi-pack-index expire &&
589 ls .git/objects/pack/ | grep idx >expect &&
590 test-tool read-midx .git/objects | grep idx >actual &&
591 test_cmp expect actual &&
592 git multi-pack-index verify
593 )
594'
595
10bfa3f7
DS
596test_expect_success 'expire respects .keep files' '
597 (
598 cd dup &&
599 git pack-objects --revs .git/objects/pack/pack-all <<-EOF &&
600 refs/heads/A
601 EOF
602 git multi-pack-index write &&
603 PACKA=$(ls .git/objects/pack/a-pack*\.pack | sed s/\.pack\$//) &&
604 touch $PACKA.keep &&
605 git multi-pack-index expire &&
606 ls -S .git/objects/pack/a-pack* | grep $PACKA >a-pack-files &&
607 test_line_count = 3 a-pack-files &&
608 test-tool read-midx .git/objects | grep idx >midx-list &&
609 test_line_count = 2 midx-list
610 )
611'
612
b526d8cb
DS
613test_expect_success 'repack --batch-size=0 repacks everything' '
614 (
615 cd dup &&
616 rm .git/objects/pack/*.keep &&
617 ls .git/objects/pack/*idx >idx-list &&
618 test_line_count = 2 idx-list &&
619 git multi-pack-index repack --batch-size=0 &&
620 ls .git/objects/pack/*idx >idx-list &&
621 test_line_count = 3 idx-list &&
622 test-tool read-midx .git/objects | grep idx >midx-list &&
623 test_line_count = 3 midx-list &&
624 git multi-pack-index expire &&
625 ls -al .git/objects/pack/*idx >idx-list &&
626 test_line_count = 1 idx-list &&
627 git multi-pack-index repack --batch-size=0 &&
628 ls -al .git/objects/pack/*idx >new-idx-list &&
629 test_cmp idx-list new-idx-list
630 )
631'
10bfa3f7 632
a3407730 633test_done