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