sequencer: detect author name errors in read_author_script()
[git/debian.git] / t / t7700-repack.sh
blobe489869dd94daf98f900d14d75a3da97f5f7ab34
1 #!/bin/sh
3 test_description='git repack works correctly'
5 . ./test-lib.sh
6 . "${TEST_DIRECTORY}/lib-bitmap.sh"
7 . "${TEST_DIRECTORY}/lib-midx.sh"
8 . "${TEST_DIRECTORY}/lib-terminal.sh"
10 commit_and_pack () {
11 test_commit "$@" 1>&2 &&
12 incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
13 echo pack-${incrpackid}.pack
16 test_no_missing_in_packs () {
17 myidx=$(ls -1 .git/objects/pack/*.idx) &&
18 test_path_is_file "$myidx" &&
19 git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
20 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
21 git verify-pack -v $myidx >dest.raw &&
22 cut -d" " -f1 dest.raw | sort >dest &&
23 comm -23 orig dest >missing &&
24 test_must_be_empty missing
27 # we expect $packid and $oid to be defined
28 test_has_duplicate_object () {
29 want_duplicate_object="$1"
30 found_duplicate_object=false
31 for p in .git/objects/pack/*.idx
33 idx=$(basename $p)
34 test "pack-$packid.idx" = "$idx" && continue
35 git verify-pack -v $p >packlist || return $?
36 if grep "^$oid" packlist
37 then
38 found_duplicate_object=true
39 echo "DUPLICATE OBJECT FOUND"
40 break
42 done &&
43 test "$want_duplicate_object" = "$found_duplicate_object"
46 test_expect_success 'objects in packs marked .keep are not repacked' '
47 echo content1 >file1 &&
48 echo content2 >file2 &&
49 git add . &&
50 test_tick &&
51 git commit -m initial_commit &&
52 # Create two packs
53 # The first pack will contain all of the objects except one
54 git rev-list --objects --all >objs &&
55 grep -v file2 objs | git pack-objects pack &&
56 # The second pack will contain the excluded object
57 packid=$(grep file2 objs | git pack-objects pack) &&
58 >pack-$packid.keep &&
59 git verify-pack -v pack-$packid.idx >packlist &&
60 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
61 mv pack-* .git/objects/pack/ &&
62 git repack -A -d -l &&
63 git prune-packed &&
64 test_has_duplicate_object false
67 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
68 # build on $oid, $packid, and .keep state from previous
69 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 git repack -Adbl &&
70 test_has_duplicate_object true
73 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
74 # build on $oid, $packid, and .keep state from previous
75 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
76 git -c repack.writebitmaps=true repack -Adl &&
77 test_has_duplicate_object true
80 test_expect_success 'loose objects in alternate ODB are not repacked' '
81 mkdir alt_objects &&
82 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
83 echo content3 >file3 &&
84 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
85 git add file3 &&
86 test_tick &&
87 git commit -m commit_file3 &&
88 git repack -a -d -l &&
89 git prune-packed &&
90 test_has_duplicate_object false
93 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
94 mkdir alt_objects/pack &&
95 mv .git/objects/pack/* alt_objects/pack &&
96 git repack -a &&
97 test_no_missing_in_packs
100 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
101 rm -f .git/objects/pack/* &&
102 echo new_content >>file1 &&
103 git add file1 &&
104 test_tick &&
105 git commit -m more_content &&
106 git repack &&
107 git repack -a -d &&
108 test_no_missing_in_packs
111 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
112 # swap the .keep so the commit object is in the pack with .keep
113 for p in alt_objects/pack/*.pack
115 base_name=$(basename $p .pack) &&
116 if test_path_is_file alt_objects/pack/$base_name.keep
117 then
118 rm alt_objects/pack/$base_name.keep
119 else
120 touch alt_objects/pack/$base_name.keep
121 fi || return 1
122 done &&
123 git repack -a -d &&
124 test_no_missing_in_packs
127 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
128 rm -f alt_objects/pack/*.keep &&
129 mv .git/objects/pack/* alt_objects/pack/ &&
130 coid=$(git rev-parse HEAD^{commit}) &&
131 git reset --hard HEAD^ &&
132 test_tick &&
133 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
134 # The pack-objects call on the next line is equivalent to
135 # git repack -A -d without the call to prune-packed
136 git pack-objects --honor-pack-keep --non-empty --all --reflog \
137 --unpack-unreachable </dev/null pack &&
138 rm -f .git/objects/pack/* &&
139 mv pack-* .git/objects/pack/ &&
140 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
141 ! grep "^$coid " packlist &&
142 echo >.git/objects/info/alternates &&
143 test_must_fail git show $coid
146 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
147 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
148 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
149 rm -f .git/objects/pack/* &&
150 mv pack-* .git/objects/pack/ &&
151 # The pack-objects call on the next line is equivalent to
152 # git repack -A -d without the call to prune-packed
153 git pack-objects --honor-pack-keep --non-empty --all --reflog \
154 --unpack-unreachable </dev/null pack &&
155 rm -f .git/objects/pack/* &&
156 mv pack-* .git/objects/pack/ &&
157 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
158 ! grep "^$coid " &&
159 echo >.git/objects/info/alternates &&
160 test_must_fail git show $coid
163 test_expect_success 'objects made unreachable by grafts only are kept' '
164 test_tick &&
165 git commit --allow-empty -m "commit 4" &&
166 H0=$(git rev-parse HEAD) &&
167 H1=$(git rev-parse HEAD^) &&
168 H2=$(git rev-parse HEAD^^) &&
169 echo "$H0 $H2" >.git/info/grafts &&
170 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
171 git repack -a -d &&
172 git cat-file -t $H1
175 test_expect_success 'repack --keep-pack' '
176 test_create_repo keep-pack &&
178 cd keep-pack &&
179 P1=$(commit_and_pack 1) &&
180 P2=$(commit_and_pack 2) &&
181 P3=$(commit_and_pack 3) &&
182 P4=$(commit_and_pack 4) &&
183 ls .git/objects/pack/*.pack >old-counts &&
184 test_line_count = 4 old-counts &&
185 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
186 ls .git/objects/pack/*.pack >new-counts &&
187 grep -q $P1 new-counts &&
188 grep -q $P4 new-counts &&
189 test_line_count = 3 new-counts &&
190 git fsck
194 test_expect_success 'bitmaps are created by default in bare repos' '
195 git clone --bare .git bare.git &&
196 rm -f bare.git/objects/pack/*.bitmap &&
197 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
198 git -C bare.git repack -ad &&
199 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
200 test_path_is_file "$bitmap"
203 test_expect_success 'incremental repack does not complain' '
204 git -C bare.git repack -q 2>repack.err &&
205 test_must_be_empty repack.err
208 test_expect_success 'bitmaps can be disabled on bare repos' '
209 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
210 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
211 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
212 test -z "$bitmap"
215 test_expect_success 'no bitmaps created if .keep files present' '
216 pack=$(ls bare.git/objects/pack/*.pack) &&
217 test_path_is_file "$pack" &&
218 keep=${pack%.pack}.keep &&
219 test_when_finished "rm -f \"\$keep\"" &&
220 >"$keep" &&
221 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
222 git -C bare.git repack -ad 2>stderr &&
223 test_must_be_empty stderr &&
224 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
225 test_must_be_empty actual
228 test_expect_success 'auto-bitmaps do not complain if unavailable' '
229 test_config -C bare.git pack.packSizeLimit 1M &&
230 blob=$(test-tool genrandom big $((1024*1024)) |
231 git -C bare.git hash-object -w --stdin) &&
232 git -C bare.git update-ref refs/tags/big $blob &&
233 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
234 git -C bare.git repack -ad 2>stderr &&
235 test_must_be_empty stderr &&
236 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
237 test_must_be_empty actual
240 objdir=.git/objects
241 midx=$objdir/pack/multi-pack-index
243 test_expect_success 'setup for --write-midx tests' '
244 git init midx &&
246 cd midx &&
247 git config core.multiPackIndex true &&
249 test_commit base
253 test_expect_success '--write-midx unchanged' '
255 cd midx &&
256 GIT_TEST_MULTI_PACK_INDEX=0 git repack &&
257 test_path_is_missing $midx &&
258 test_path_is_missing $midx-*.bitmap &&
260 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
262 test_path_is_file $midx &&
263 test_path_is_missing $midx-*.bitmap &&
264 test_midx_consistent $objdir
268 test_expect_success '--write-midx with a new pack' '
270 cd midx &&
271 test_commit loose &&
273 GIT_TEST_MULTI_PACK_INDEX=0 git repack --write-midx &&
275 test_path_is_file $midx &&
276 test_path_is_missing $midx-*.bitmap &&
277 test_midx_consistent $objdir
281 test_expect_success '--write-midx with -b' '
283 cd midx &&
284 GIT_TEST_MULTI_PACK_INDEX=0 git repack -mb &&
286 test_path_is_file $midx &&
287 test_path_is_file $midx-*.bitmap &&
288 test_midx_consistent $objdir
292 test_expect_success '--write-midx with -d' '
294 cd midx &&
295 test_commit repack &&
297 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Ad --write-midx &&
299 test_path_is_file $midx &&
300 test_path_is_missing $midx-*.bitmap &&
301 test_midx_consistent $objdir
305 test_expect_success 'cleans up MIDX when appropriate' '
307 cd midx &&
309 test_commit repack-2 &&
310 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
312 checksum=$(midx_checksum $objdir) &&
313 test_path_is_file $midx &&
314 test_path_is_file $midx-$checksum.bitmap &&
315 test_path_is_file $midx-$checksum.rev &&
317 test_commit repack-3 &&
318 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb --write-midx &&
320 test_path_is_file $midx &&
321 test_path_is_missing $midx-$checksum.bitmap &&
322 test_path_is_missing $midx-$checksum.rev &&
323 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
324 test_path_is_file $midx-$(midx_checksum $objdir).rev &&
326 test_commit repack-4 &&
327 GIT_TEST_MULTI_PACK_INDEX=0 git repack -Adb &&
329 find $objdir/pack -type f -name "multi-pack-index*" >files &&
330 test_must_be_empty files
334 test_expect_success '--write-midx with preferred bitmap tips' '
335 git init midx-preferred-tips &&
336 test_when_finished "rm -fr midx-preferred-tips" &&
338 cd midx-preferred-tips &&
340 test_commit_bulk --message="%s" 103 &&
342 git log --format="%H" >commits.raw &&
343 sort <commits.raw >commits &&
345 git log --format="create refs/tags/%s/%s %H" HEAD >refs &&
346 git update-ref --stdin <refs &&
348 git repack --write-midx --write-bitmap-index &&
349 test_path_is_file $midx &&
350 test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
352 test-tool bitmap list-commits | sort >bitmaps &&
353 comm -13 bitmaps commits >before &&
354 test_line_count = 1 before &&
356 rm -fr $midx-$(midx_checksum $objdir).bitmap &&
357 rm -fr $midx-$(midx_checksum $objdir).rev &&
358 rm -fr $midx &&
360 # instead of constructing the snapshot ourselves (c.f., the test
361 # "write a bitmap with --refs-snapshot (preferred tips)" in
362 # t5326), mark the missing commit as preferred by adding it to
363 # the pack.preferBitmapTips configuration.
364 git for-each-ref --format="%(refname:rstrip=1)" \
365 --points-at="$(cat before)" >missing &&
366 git config pack.preferBitmapTips "$(cat missing)" &&
367 git repack --write-midx --write-bitmap-index &&
369 test-tool bitmap list-commits | sort >bitmaps &&
370 comm -13 bitmaps commits >after &&
372 ! test_cmp before after
376 test_expect_success '--write-midx -b packs non-kept objects' '
377 GIT_TRACE2_EVENT="$(pwd)/trace.txt" \
378 git repack --write-midx -a -b &&
379 test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
382 test_expect_success TTY '--quiet disables progress' '
383 test_terminal env GIT_PROGRESS_DELAY=0 \
384 git -C midx repack -ad --quiet --write-midx 2>stderr &&
385 test_must_be_empty stderr
388 test_done