t7700: update to work with MIDX bitmap test knob
[git/debian.git] / t / t7700-repack.sh
blob98eda3bfeb56c4cd685ed352ee0fe2a885061c31
1 #!/bin/sh
3 test_description='git repack works correctly'
5 . ./test-lib.sh
7 commit_and_pack () {
8 test_commit "$@" 1>&2 &&
9 incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
10 echo pack-${incrpackid}.pack
13 test_no_missing_in_packs () {
14 myidx=$(ls -1 .git/objects/pack/*.idx) &&
15 test_path_is_file "$myidx" &&
16 git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
17 sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
18 git verify-pack -v $myidx >dest.raw &&
19 cut -d" " -f1 dest.raw | sort >dest &&
20 comm -23 orig dest >missing &&
21 test_must_be_empty missing
24 # we expect $packid and $oid to be defined
25 test_has_duplicate_object () {
26 want_duplicate_object="$1"
27 found_duplicate_object=false
28 for p in .git/objects/pack/*.idx
30 idx=$(basename $p)
31 test "pack-$packid.idx" = "$idx" && continue
32 git verify-pack -v $p >packlist || return $?
33 if grep "^$oid" packlist
34 then
35 found_duplicate_object=true
36 echo "DUPLICATE OBJECT FOUND"
37 break
39 done &&
40 test "$want_duplicate_object" = "$found_duplicate_object"
43 test_expect_success 'objects in packs marked .keep are not repacked' '
44 echo content1 >file1 &&
45 echo content2 >file2 &&
46 git add . &&
47 test_tick &&
48 git commit -m initial_commit &&
49 # Create two packs
50 # The first pack will contain all of the objects except one
51 git rev-list --objects --all >objs &&
52 grep -v file2 objs | git pack-objects pack &&
53 # The second pack will contain the excluded object
54 packid=$(grep file2 objs | git pack-objects pack) &&
55 >pack-$packid.keep &&
56 git verify-pack -v pack-$packid.idx >packlist &&
57 oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
58 mv pack-* .git/objects/pack/ &&
59 git repack -A -d -l &&
60 git prune-packed &&
61 test_has_duplicate_object false
64 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
65 # build on $oid, $packid, and .keep state from previous
66 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 git repack -Adbl &&
67 test_has_duplicate_object true
70 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
71 # build on $oid, $packid, and .keep state from previous
72 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
73 git -c repack.writebitmaps=true repack -Adl &&
74 test_has_duplicate_object true
77 test_expect_success 'loose objects in alternate ODB are not repacked' '
78 mkdir alt_objects &&
79 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
80 echo content3 >file3 &&
81 oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
82 git add file3 &&
83 test_tick &&
84 git commit -m commit_file3 &&
85 git repack -a -d -l &&
86 git prune-packed &&
87 test_has_duplicate_object false
90 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
91 mkdir alt_objects/pack &&
92 mv .git/objects/pack/* alt_objects/pack &&
93 git repack -a &&
94 test_no_missing_in_packs
97 test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
98 rm -f .git/objects/pack/* &&
99 echo new_content >>file1 &&
100 git add file1 &&
101 test_tick &&
102 git commit -m more_content &&
103 git repack &&
104 git repack -a -d &&
105 test_no_missing_in_packs
108 test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
109 # swap the .keep so the commit object is in the pack with .keep
110 for p in alt_objects/pack/*.pack
112 base_name=$(basename $p .pack) &&
113 if test_path_is_file alt_objects/pack/$base_name.keep
114 then
115 rm alt_objects/pack/$base_name.keep
116 else
117 touch alt_objects/pack/$base_name.keep
119 done &&
120 git repack -a -d &&
121 test_no_missing_in_packs
124 test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
125 rm -f alt_objects/pack/*.keep &&
126 mv .git/objects/pack/* alt_objects/pack/ &&
127 coid=$(git rev-parse HEAD^{commit}) &&
128 git reset --hard HEAD^ &&
129 test_tick &&
130 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
131 # The pack-objects call on the next line is equivalent to
132 # git repack -A -d without the call to prune-packed
133 git pack-objects --honor-pack-keep --non-empty --all --reflog \
134 --unpack-unreachable </dev/null pack &&
135 rm -f .git/objects/pack/* &&
136 mv pack-* .git/objects/pack/ &&
137 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
138 ! grep "^$coid " packlist &&
139 echo >.git/objects/info/alternates &&
140 test_must_fail git show $coid
143 test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
144 echo $(pwd)/alt_objects >.git/objects/info/alternates &&
145 echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
146 rm -f .git/objects/pack/* &&
147 mv pack-* .git/objects/pack/ &&
148 # The pack-objects call on the next line is equivalent to
149 # git repack -A -d without the call to prune-packed
150 git pack-objects --honor-pack-keep --non-empty --all --reflog \
151 --unpack-unreachable </dev/null pack &&
152 rm -f .git/objects/pack/* &&
153 mv pack-* .git/objects/pack/ &&
154 git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
155 ! grep "^$coid " &&
156 echo >.git/objects/info/alternates &&
157 test_must_fail git show $coid
160 test_expect_success 'objects made unreachable by grafts only are kept' '
161 test_tick &&
162 git commit --allow-empty -m "commit 4" &&
163 H0=$(git rev-parse HEAD) &&
164 H1=$(git rev-parse HEAD^) &&
165 H2=$(git rev-parse HEAD^^) &&
166 echo "$H0 $H2" >.git/info/grafts &&
167 git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
168 git repack -a -d &&
169 git cat-file -t $H1
172 test_expect_success 'repack --keep-pack' '
173 test_create_repo keep-pack &&
175 cd keep-pack &&
176 P1=$(commit_and_pack 1) &&
177 P2=$(commit_and_pack 2) &&
178 P3=$(commit_and_pack 3) &&
179 P4=$(commit_and_pack 4) &&
180 ls .git/objects/pack/*.pack >old-counts &&
181 test_line_count = 4 old-counts &&
182 git repack -a -d --keep-pack $P1 --keep-pack $P4 &&
183 ls .git/objects/pack/*.pack >new-counts &&
184 grep -q $P1 new-counts &&
185 grep -q $P4 new-counts &&
186 test_line_count = 3 new-counts &&
187 git fsck
191 test_expect_success 'bitmaps are created by default in bare repos' '
192 git clone --bare .git bare.git &&
193 rm -f bare.git/objects/pack/*.bitmap &&
194 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
195 git -C bare.git repack -ad &&
196 bitmap=$(ls bare.git/objects/pack/*.bitmap) &&
197 test_path_is_file "$bitmap"
200 test_expect_success 'incremental repack does not complain' '
201 git -C bare.git repack -q 2>repack.err &&
202 test_must_be_empty repack.err
205 test_expect_success 'bitmaps can be disabled on bare repos' '
206 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
207 git -c repack.writeBitmaps=false -C bare.git repack -ad &&
208 bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
209 test -z "$bitmap"
212 test_expect_success 'no bitmaps created if .keep files present' '
213 pack=$(ls bare.git/objects/pack/*.pack) &&
214 test_path_is_file "$pack" &&
215 keep=${pack%.pack}.keep &&
216 test_when_finished "rm -f \"\$keep\"" &&
217 >"$keep" &&
218 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
219 git -C bare.git repack -ad 2>stderr &&
220 test_must_be_empty stderr &&
221 find bare.git/objects/pack/ -type f -name "*.bitmap" >actual &&
222 test_must_be_empty actual
225 test_expect_success 'auto-bitmaps do not complain if unavailable' '
226 test_config -C bare.git pack.packSizeLimit 1M &&
227 blob=$(test-tool genrandom big $((1024*1024)) |
228 git -C bare.git hash-object -w --stdin) &&
229 git -C bare.git update-ref refs/tags/big $blob &&
230 GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 \
231 git -C bare.git repack -ad 2>stderr &&
232 test_must_be_empty stderr &&
233 find bare.git/objects/pack -type f -name "*.bitmap" >actual &&
234 test_must_be_empty actual
237 test_done