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