]>
Commit | Line | Data |
---|---|---|
9245ddd5 BC |
1 | #!/bin/sh |
2 | ||
3 | test_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 | 10 | commit_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 |
20 | test_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 |
32 | test_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 | 50 | test_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 | 71 | test_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 | 77 | test_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 | 84 | test_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 |
97 | test_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 |
113 | test_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 | 130 | test_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 | 137 | test_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 | 148 | test_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 | 164 | test_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 | 183 | test_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 | 200 | test_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 |
212 | test_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 |
254 | test_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 && | |
274 | test_must_fail git repack --cruft -d 2>err && | |
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 |
284 | test_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 | ||
293 | test_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 | 298 | test_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 |
305 | test_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 |
318 | test_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 | ||
1d89d88d TB |
330 | objdir=.git/objects |
331 | midx=$objdir/pack/multi-pack-index | |
332 | ||
333 | test_expect_success 'setup for --write-midx tests' ' | |
334 | git init midx && | |
335 | ( | |
336 | cd midx && | |
337 | git config core.multiPackIndex true && | |
338 | ||
339 | test_commit base | |
340 | ) | |
341 | ' | |
342 | ||
343 | test_expect_success '--write-midx unchanged' ' | |
344 | ( | |
345 | cd midx && | |
346 | GIT_TEST_MULTI_PACK_INDEX=0 git repack && | |
347 | test_path_is_missing $midx && | |
348 | test_path_is_missing $midx-*.bitmap && | |
349 | ||
350 | GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx && | |
351 | ||
352 | test_path_is_file $midx && | |
353 | test_path_is_missing $midx-*.bitmap && | |
354 | test_midx_consistent $objdir | |
355 | ) | |
356 | ' | |
357 | ||
358 | test_expect_success '--write-midx with a new pack' ' | |
359 | ( | |
360 | cd midx && | |
361 | test_commit loose && | |
362 | ||
363 | GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx && | |
364 | ||
365 | test_path_is_file $midx && | |
366 | test_path_is_missing $midx-*.bitmap && | |
367 | test_midx_consistent $objdir | |
368 | ) | |
369 | ' | |
370 | ||
371 | test_expect_success '--write-midx with -b' ' | |
372 | ( | |
373 | cd midx && | |
374 | GIT_TEST_MULTI_PACK_INDEX=0 git repack -mb && | |
375 | ||
376 | test_path_is_file $midx && | |
377 | test_path_is_file $midx-*.bitmap && | |
378 | test_midx_consistent $objdir | |
379 | ) | |
380 | ' | |
381 | ||
382 | test_expect_success '--write-midx with -d' ' | |
383 | ( | |
384 | cd midx && | |
385 | test_commit repack && | |
386 | ||
387 | GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ad --write-midx && | |
388 | ||
389 | test_path_is_file $midx && | |
390 | test_path_is_missing $midx-*.bitmap && | |
391 | test_midx_consistent $objdir | |
392 | ) | |
393 | ' | |
394 | ||
395 | test_expect_success 'cleans up MIDX when appropriate' ' | |
396 | ( | |
397 | cd midx && | |
398 | ||
399 | test_commit repack-2 && | |
400 | GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx && | |
401 | ||
402 | checksum=$(midx_checksum $objdir) && | |
403 | test_path_is_file $midx && | |
404 | test_path_is_file $midx-$checksum.bitmap && | |
1d89d88d TB |
405 | |
406 | test_commit repack-3 && | |
407 | GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx && | |
408 | ||
409 | test_path_is_file $midx && | |
410 | test_path_is_missing $midx-$checksum.bitmap && | |
1d89d88d | 411 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && |
1d89d88d TB |
412 | |
413 | test_commit repack-4 && | |
414 | GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb && | |
415 | ||
416 | find $objdir/pack -type f -name "multi-pack-index*" >files && | |
417 | test_must_be_empty files | |
418 | ) | |
419 | ' | |
420 | ||
324efc90 TB |
421 | test_expect_success '--write-midx with preferred bitmap tips' ' |
422 | git init midx-preferred-tips && | |
423 | test_when_finished "rm -fr midx-preferred-tips" && | |
424 | ( | |
425 | cd midx-preferred-tips && | |
426 | ||
427 | test_commit_bulk --message="%s" 103 && | |
428 | ||
429 | git log --format="%H" >commits.raw && | |
430 | sort <commits.raw >commits && | |
431 | ||
432 | git log --format="create refs/tags/%s/%s %H" HEAD >refs && | |
433 | git update-ref --stdin <refs && | |
434 | ||
435 | git repack --write-midx --write-bitmap-index && | |
436 | test_path_is_file $midx && | |
437 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
438 | ||
439 | test-tool bitmap list-commits | sort >bitmaps && | |
440 | comm -13 bitmaps commits >before && | |
441 | test_line_count = 1 before && | |
442 | ||
443 | rm -fr $midx-$(midx_checksum $objdir).bitmap && | |
324efc90 TB |
444 | rm -fr $midx && |
445 | ||
446 | # instead of constructing the snapshot ourselves (c.f., the test | |
447 | # "write a bitmap with --refs-snapshot (preferred tips)" in | |
448 | # t5326), mark the missing commit as preferred by adding it to | |
449 | # the pack.preferBitmapTips configuration. | |
450 | git for-each-ref --format="%(refname:rstrip=1)" \ | |
451 | --points-at="$(cat before)" >missing && | |
452 | git config pack.preferBitmapTips "$(cat missing)" && | |
453 | git repack --write-midx --write-bitmap-index && | |
454 | ||
455 | test-tool bitmap list-commits | sort >bitmaps && | |
456 | comm -13 bitmaps commits >after && | |
457 | ||
458 | ! test_cmp before after | |
459 | ) | |
460 | ' | |
461 | ||
f1486203 DS |
462 | # The first argument is expected to be a filename |
463 | # and that file should contain the name of a .idx | |
464 | # file. Send the list of objects in that .idx file | |
465 | # into stdout. | |
466 | get_sorted_objects_from_pack () { | |
467 | git show-index <$(cat "$1") >raw && | |
468 | cut -d" " -f2 raw | |
469 | } | |
470 | ||
e4d0c11c | 471 | test_expect_success '--write-midx -b packs non-kept objects' ' |
f1486203 DS |
472 | git init repo && |
473 | test_when_finished "rm -fr repo" && | |
474 | ( | |
475 | cd repo && | |
476 | ||
477 | # Create a kept pack-file | |
478 | test_commit base && | |
479 | git repack -ad && | |
480 | find $objdir/pack -name "*.idx" >before && | |
481 | test_line_count = 1 before && | |
482 | before_name=$(cat before) && | |
483 | >${before_name%.idx}.keep && | |
484 | ||
485 | # Create a non-kept pack-file | |
486 | test_commit other && | |
487 | git repack && | |
488 | ||
489 | # Create loose objects | |
490 | test_commit loose && | |
491 | ||
492 | # Repack everything | |
493 | git repack --write-midx -a -b -d && | |
494 | ||
495 | # There should be two pack-files now, the | |
496 | # old, kept pack and the new, non-kept pack. | |
497 | find $objdir/pack -name "*.idx" | sort >after && | |
498 | test_line_count = 2 after && | |
499 | find $objdir/pack -name "*.keep" >kept && | |
500 | kept_name=$(cat kept) && | |
501 | echo ${kept_name%.keep}.idx >kept-idx && | |
502 | test_cmp before kept-idx && | |
503 | ||
504 | # Get object list from the kept pack. | |
505 | get_sorted_objects_from_pack before >old.objects && | |
506 | ||
507 | # Get object list from the one non-kept pack-file | |
508 | comm -13 before after >new-pack && | |
509 | test_line_count = 1 new-pack && | |
510 | get_sorted_objects_from_pack new-pack >new.objects && | |
511 | ||
512 | # None of the objects in the new pack should | |
513 | # exist within the kept pack. | |
514 | comm -12 old.objects new.objects >shared.objects && | |
515 | test_must_be_empty shared.objects | |
516 | ) | |
e4d0c11c DS |
517 | ' |
518 | ||
55d902cd | 519 | test_expect_success '--write-midx removes stale pack-based bitmaps' ' |
3a3b98be JC |
520 | rm -fr repo && |
521 | git init repo && | |
522 | test_when_finished "rm -fr repo" && | |
523 | ( | |
55d902cd TB |
524 | cd repo && |
525 | test_commit base && | |
526 | GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ab && | |
527 | ||
528 | pack_bitmap=$(ls $objdir/pack/pack-*.bitmap) && | |
529 | test_path_is_file "$pack_bitmap" && | |
530 | ||
531 | test_commit tip && | |
532 | GIT_TEST_MULTI_PACK_INDEX=0 git repack -bm && | |
533 | ||
534 | test_path_is_file $midx && | |
535 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
536 | test_path_is_missing $pack_bitmap | |
3a3b98be | 537 | ) |
55d902cd TB |
538 | ' |
539 | ||
197443e8 TB |
540 | test_expect_success '--write-midx with --pack-kept-objects' ' |
541 | git init repo && | |
542 | test_when_finished "rm -fr repo" && | |
543 | ( | |
544 | cd repo && | |
545 | ||
546 | test_commit one && | |
547 | test_commit two && | |
548 | ||
549 | one="$(echo "one" | git pack-objects --revs $objdir/pack/pack)" && | |
550 | two="$(echo "one..two" | git pack-objects --revs $objdir/pack/pack)" && | |
551 | ||
552 | keep="$objdir/pack/pack-$one.keep" && | |
553 | touch "$keep" && | |
554 | ||
555 | git repack --write-midx --write-bitmap-index --geometric=2 -d \ | |
556 | --pack-kept-objects && | |
557 | ||
558 | test_path_is_file $keep && | |
559 | test_path_is_file $midx && | |
560 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap | |
561 | ) | |
562 | ' | |
563 | ||
47ca93d0 DS |
564 | test_expect_success TTY '--quiet disables progress' ' |
565 | test_terminal env GIT_PROGRESS_DELAY=0 \ | |
566 | git -C midx repack -ad --quiet --write-midx 2>stderr && | |
567 | test_must_be_empty stderr | |
568 | ' | |
569 | ||
9cf10d87 | 570 | test_expect_success 'clean up .tmp-* packs on error' ' |
9b3fadfd | 571 | test_must_fail ok=sigpipe git \ |
9cf10d87 JK |
572 | -c repack.cruftwindow=bogus \ |
573 | repack -ad --cruft && | |
574 | find $objdir/pack -name '.tmp-*' >tmpfiles && | |
575 | test_must_be_empty tmpfiles | |
576 | ' | |
577 | ||
19343071 JK |
578 | test_expect_success 'repack -ad cleans up old .tmp-* packs' ' |
579 | git rev-parse HEAD >input && | |
580 | git pack-objects $objdir/pack/.tmp-1234 <input && | |
581 | git repack -ad && | |
582 | find $objdir/pack -name '.tmp-*' >tmpfiles && | |
583 | test_must_be_empty tmpfiles | |
584 | ' | |
585 | ||
64a6151d PS |
586 | test_expect_success 'setup for update-server-info' ' |
587 | git init update-server-info && | |
588 | test_commit -C update-server-info message | |
589 | ' | |
590 | ||
591 | test_server_info_present () { | |
592 | test_path_is_file update-server-info/.git/objects/info/packs && | |
593 | test_path_is_file update-server-info/.git/info/refs | |
594 | } | |
595 | ||
596 | test_server_info_missing () { | |
597 | test_path_is_missing update-server-info/.git/objects/info/packs && | |
598 | test_path_is_missing update-server-info/.git/info/refs | |
599 | } | |
600 | ||
601 | test_server_info_cleanup () { | |
602 | rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs && | |
603 | test_server_info_missing | |
604 | } | |
605 | ||
606 | test_expect_success 'updates server info by default' ' | |
607 | test_server_info_cleanup && | |
608 | git -C update-server-info repack && | |
609 | test_server_info_present | |
610 | ' | |
611 | ||
612 | test_expect_success '-n skips updating server info' ' | |
613 | test_server_info_cleanup && | |
614 | git -C update-server-info repack -n && | |
615 | test_server_info_missing | |
616 | ' | |
617 | ||
a2565c48 PS |
618 | test_expect_success 'repack.updateServerInfo=true updates server info' ' |
619 | test_server_info_cleanup && | |
620 | git -C update-server-info -c repack.updateServerInfo=true repack && | |
621 | test_server_info_present | |
622 | ' | |
623 | ||
624 | test_expect_success 'repack.updateServerInfo=false skips updating server info' ' | |
625 | test_server_info_cleanup && | |
626 | git -C update-server-info -c repack.updateServerInfo=false repack && | |
627 | test_server_info_missing | |
628 | ' | |
629 | ||
630 | test_expect_success '-n overrides repack.updateServerInfo=true' ' | |
631 | test_server_info_cleanup && | |
632 | git -C update-server-info -c repack.updateServerInfo=true repack -n && | |
633 | test_server_info_missing | |
634 | ' | |
635 | ||
91badeba TB |
636 | test_expect_success '--expire-to stores pruned objects (now)' ' |
637 | git init expire-to-now && | |
638 | ( | |
639 | cd expire-to-now && | |
640 | ||
641 | git branch -M main && | |
642 | ||
643 | test_commit base && | |
644 | ||
645 | git checkout -b cruft && | |
646 | test_commit --no-tag cruft && | |
647 | ||
648 | git rev-list --objects --no-object-names main..cruft >moved.raw && | |
649 | sort moved.raw >moved.want && | |
650 | ||
651 | git rev-list --all --objects --no-object-names >expect.raw && | |
652 | sort expect.raw >expect && | |
653 | ||
654 | git checkout main && | |
655 | git branch -D cruft && | |
656 | git reflog expire --all --expire=all && | |
657 | ||
658 | git init --bare expired.git && | |
659 | git repack -d \ | |
660 | --cruft --cruft-expiration="now" \ | |
661 | --expire-to="expired.git/objects/pack/pack" && | |
662 | ||
663 | expired="$(ls expired.git/objects/pack/pack-*.idx)" && | |
664 | test_path_is_file "${expired%.idx}.mtimes" && | |
665 | ||
666 | # Since the `--cruft-expiration` is "now", the effective | |
667 | # behavior is to move _all_ unreachable objects out to | |
668 | # the location in `--expire-to`. | |
669 | git show-index <$expired >expired.raw && | |
670 | cut -d" " -f2 expired.raw | sort >expired.objects && | |
671 | git rev-list --all --objects --no-object-names \ | |
672 | >remaining.objects && | |
673 | ||
674 | # ...in other words, the combined contents of this | |
675 | # repository and expired.git should be the same as the | |
676 | # set of objects we started with. | |
677 | cat expired.objects remaining.objects | sort >actual && | |
678 | test_cmp expect actual && | |
679 | ||
680 | # The "moved" objects (i.e., those in expired.git) | |
681 | # should be the same as the cruft objects which were | |
682 | # expired in the previous step. | |
683 | test_cmp moved.want expired.objects | |
684 | ) | |
685 | ' | |
686 | ||
687 | test_expect_success '--expire-to stores pruned objects (5.minutes.ago)' ' | |
688 | git init expire-to-5.minutes.ago && | |
689 | ( | |
690 | cd expire-to-5.minutes.ago && | |
691 | ||
692 | git branch -M main && | |
693 | ||
694 | test_commit base && | |
695 | ||
696 | # Create two classes of unreachable objects, one which | |
697 | # is older than 5 minutes (stale), and another which is | |
698 | # newer (recent). | |
699 | for kind in stale recent | |
700 | do | |
701 | git checkout -b $kind main && | |
702 | test_commit --no-tag $kind || return 1 | |
703 | done && | |
704 | ||
705 | git rev-list --objects --no-object-names main..stale >in && | |
706 | stale="$(git pack-objects $objdir/pack/pack <in)" && | |
707 | mtime="$(test-tool chmtime --get =-600 $objdir/pack/pack-$stale.pack)" && | |
708 | ||
709 | # expect holds the set of objects we expect to find in | |
710 | # this repository after repacking | |
711 | git rev-list --objects --no-object-names recent >expect.raw && | |
712 | sort expect.raw >expect && | |
713 | ||
714 | # moved.want holds the set of objects we expect to find | |
715 | # in expired.git | |
716 | git rev-list --objects --no-object-names main..stale >out && | |
717 | sort out >moved.want && | |
718 | ||
719 | git checkout main && | |
720 | git branch -D stale recent && | |
721 | git reflog expire --all --expire=all && | |
722 | git prune-packed && | |
723 | ||
724 | git init --bare expired.git && | |
725 | git repack -d \ | |
726 | --cruft --cruft-expiration=5.minutes.ago \ | |
727 | --expire-to="expired.git/objects/pack/pack" && | |
728 | ||
729 | # Some of the remaining objects in this repository are | |
730 | # unreachable, so use `cat-file --batch-all-objects` | |
731 | # instead of `rev-list` to get their names | |
732 | git cat-file --batch-all-objects --batch-check="%(objectname)" \ | |
733 | >remaining.objects && | |
734 | sort remaining.objects >actual && | |
735 | test_cmp expect actual && | |
736 | ||
737 | ( | |
738 | cd expired.git && | |
739 | ||
740 | expired="$(ls objects/pack/pack-*.mtimes)" && | |
741 | test-tool pack-mtimes $(basename $expired) >out && | |
742 | cut -d" " -f1 out | sort >../moved.got && | |
743 | ||
744 | # Ensure that there are as many objects with the | |
745 | # expected mtime as were moved to expired.git. | |
746 | # | |
747 | # In other words, ensure that the recorded | |
748 | # mtimes of any moved objects was written | |
749 | # correctly. | |
750 | grep " $mtime$" out >matching && | |
751 | test_line_count = $(wc -l <../moved.want) matching | |
752 | ) && | |
753 | test_cmp moved.want moved.got | |
754 | ) | |
755 | ' | |
756 | ||
36eba032 | 757 | test_done |