]>
Commit | Line | Data |
---|---|---|
9245ddd5 BC |
1 | #!/bin/sh |
2 | ||
3 | test_description='git repack works correctly' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
ed7e5fc3 | 7 | commit_and_pack() { |
09279086 | 8 | test_commit "$@" 1>&2 && |
ed7e5fc3 NTND |
9 | SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && |
10 | echo pack-${SHA1}.pack | |
11 | } | |
12 | ||
dd718365 | 13 | test_expect_success 'objects in packs marked .keep are not repacked' ' |
7a1c8c23 DL |
14 | echo content1 >file1 && |
15 | echo content2 >file2 && | |
9245ddd5 | 16 | git add . && |
713c79e8 | 17 | test_tick && |
9245ddd5 BC |
18 | git commit -m initial_commit && |
19 | # Create two packs | |
20 | # The first pack will contain all of the objects except one | |
21 | git rev-list --objects --all | grep -v file2 | | |
09279086 | 22 | git pack-objects pack && |
9245ddd5 BC |
23 | # The second pack will contain the excluded object |
24 | packsha1=$(git rev-list --objects --all | grep file2 | | |
25 | git pack-objects pack) && | |
a0332337 | 26 | >pack-$packsha1.keep && |
9245ddd5 BC |
27 | objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | |
28 | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && | |
29 | mv pack-* .git/objects/pack/ && | |
2d0174e3 | 30 | git repack -A -d -l && |
9245ddd5 | 31 | git prune-packed && |
d2eee32a DL |
32 | for p in .git/objects/pack/*.idx |
33 | do | |
9245ddd5 BC |
34 | idx=$(basename $p) |
35 | test "pack-$packsha1.idx" = "$idx" && continue | |
d2eee32a DL |
36 | if git verify-pack -v $p | egrep "^$objsha1" |
37 | then | |
9245ddd5 BC |
38 | found_duplicate_object=1 |
39 | echo "DUPLICATE OBJECT FOUND" | |
40 | break | |
41 | fi | |
42 | done && | |
43 | test -z "$found_duplicate_object" | |
44 | ' | |
45 | ||
3198b89f | 46 | test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' |
ee34a2be | 47 | # build on $objsha1, $packsha1, and .keep state from previous |
64d3dc94 | 48 | git repack -Adbl && |
ee34a2be | 49 | test_when_finished "found_duplicate_object=" && |
d2eee32a DL |
50 | for p in .git/objects/pack/*.idx |
51 | do | |
ee34a2be JK |
52 | idx=$(basename $p) |
53 | test "pack-$packsha1.idx" = "$idx" && continue | |
d2eee32a DL |
54 | if git verify-pack -v $p | egrep "^$objsha1" |
55 | then | |
ee34a2be JK |
56 | found_duplicate_object=1 |
57 | echo "DUPLICATE OBJECT FOUND" | |
58 | break | |
59 | fi | |
60 | done && | |
61 | test "$found_duplicate_object" = 1 | |
62 | ' | |
63 | ||
3198b89f JK |
64 | test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' |
65 | # build on $objsha1, $packsha1, and .keep state from previous | |
71d76cb4 | 66 | git -c repack.writebitmaps=true repack -Adl && |
ee34a2be | 67 | test_when_finished "found_duplicate_object=" && |
d2eee32a DL |
68 | for p in .git/objects/pack/*.idx |
69 | do | |
ee34a2be JK |
70 | idx=$(basename $p) |
71 | test "pack-$packsha1.idx" = "$idx" && continue | |
d2eee32a DL |
72 | if git verify-pack -v $p | egrep "^$objsha1" |
73 | then | |
ee34a2be JK |
74 | found_duplicate_object=1 |
75 | echo "DUPLICATE OBJECT FOUND" | |
76 | break | |
77 | fi | |
78 | done && | |
79 | test "$found_duplicate_object" = 1 | |
80 | ' | |
81 | ||
daae0625 | 82 | test_expect_success 'loose objects in alternate ODB are not repacked' ' |
3c3df429 | 83 | mkdir alt_objects && |
7a1c8c23 DL |
84 | echo $(pwd)/alt_objects >.git/objects/info/alternates && |
85 | echo content3 >file3 && | |
3c3df429 BC |
86 | objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && |
87 | git add file3 && | |
713c79e8 | 88 | test_tick && |
3c3df429 BC |
89 | git commit -m commit_file3 && |
90 | git repack -a -d -l && | |
91 | git prune-packed && | |
d2eee32a DL |
92 | for p in .git/objects/pack/*.idx |
93 | do | |
94 | if git verify-pack -v $p | egrep "^$objsha1" | |
95 | then | |
3c3df429 BC |
96 | found_duplicate_object=1 |
97 | echo "DUPLICATE OBJECT FOUND" | |
98 | break | |
99 | fi | |
100 | done && | |
101 | test -z "$found_duplicate_object" | |
102 | ' | |
103 | ||
3289b9de | 104 | test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' ' |
2dec68cf | 105 | mkdir alt_objects/pack && |
3289b9de BC |
106 | mv .git/objects/pack/* alt_objects/pack && |
107 | git repack -a && | |
108 | myidx=$(ls -1 .git/objects/pack/*.idx) && | |
109 | test -f "$myidx" && | |
d2eee32a DL |
110 | for p in alt_objects/pack/*.idx |
111 | do | |
3289b9de | 112 | git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" |
d2eee32a DL |
113 | done | while read sha1 rest |
114 | do | |
115 | if ! ( git verify-pack -v $myidx | grep "^$sha1" ) | |
116 | then | |
3289b9de BC |
117 | echo "Missing object in local pack: $sha1" |
118 | return 1 | |
119 | fi | |
120 | done | |
121 | ' | |
122 | ||
1ef2d5a6 | 123 | test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' ' |
a83c8852 | 124 | rm -f .git/objects/pack/* && |
7a1c8c23 | 125 | echo new_content >>file1 && |
a83c8852 | 126 | git add file1 && |
713c79e8 | 127 | test_tick && |
a83c8852 BC |
128 | git commit -m more_content && |
129 | git repack && | |
130 | git repack -a -d && | |
131 | myidx=$(ls -1 .git/objects/pack/*.idx) && | |
132 | test -f "$myidx" && | |
d2eee32a DL |
133 | for p in alt_objects/pack/*.idx |
134 | do | |
a83c8852 | 135 | git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" |
d2eee32a DL |
136 | done | while read sha1 rest |
137 | do | |
138 | if ! ( git verify-pack -v $myidx | grep "^$sha1" ) | |
139 | then | |
a83c8852 BC |
140 | echo "Missing object in local pack: $sha1" |
141 | return 1 | |
142 | fi | |
143 | done | |
144 | ' | |
145 | ||
171110a4 | 146 | test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' |
92cd8722 BC |
147 | # swap the .keep so the commit object is in the pack with .keep |
148 | for p in alt_objects/pack/*.pack | |
149 | do | |
2dec68cf | 150 | base_name=$(basename $p .pack) && |
92cd8722 BC |
151 | if test -f alt_objects/pack/$base_name.keep |
152 | then | |
153 | rm alt_objects/pack/$base_name.keep | |
154 | else | |
155 | touch alt_objects/pack/$base_name.keep | |
156 | fi | |
2dec68cf | 157 | done && |
92cd8722 BC |
158 | git repack -a -d && |
159 | myidx=$(ls -1 .git/objects/pack/*.idx) && | |
160 | test -f "$myidx" && | |
d2eee32a DL |
161 | for p in alt_objects/pack/*.idx |
162 | do | |
92cd8722 | 163 | git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" |
d2eee32a DL |
164 | done | while read sha1 rest |
165 | do | |
166 | if ! ( git verify-pack -v $myidx | grep "^$sha1" ) | |
167 | then | |
92cd8722 BC |
168 | echo "Missing object in local pack: $sha1" |
169 | return 1 | |
170 | fi | |
171 | done | |
172 | ' | |
173 | ||
79bc4c71 | 174 | test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' |
92cd8722 BC |
175 | rm -f alt_objects/pack/*.keep && |
176 | mv .git/objects/pack/* alt_objects/pack/ && | |
177 | csha1=$(git rev-parse HEAD^{commit}) && | |
178 | git reset --hard HEAD^ && | |
713c79e8 JH |
179 | test_tick && |
180 | git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && | |
92cd8722 BC |
181 | # The pack-objects call on the next line is equivalent to |
182 | # git repack -A -d without the call to prune-packed | |
183 | git pack-objects --honor-pack-keep --non-empty --all --reflog \ | |
184 | --unpack-unreachable </dev/null pack && | |
185 | rm -f .git/objects/pack/* && | |
186 | mv pack-* .git/objects/pack/ && | |
187 | test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | | |
188 | egrep "^$csha1 " | sort | uniq | wc -l) && | |
7a1c8c23 | 189 | echo >.git/objects/info/alternates && |
92cd8722 BC |
190 | test_must_fail git show $csha1 |
191 | ' | |
192 | ||
094085e3 | 193 | test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' |
7a1c8c23 | 194 | echo $(pwd)/alt_objects >.git/objects/info/alternates && |
869a3d34 BC |
195 | echo "$csha1" | git pack-objects --non-empty --all --reflog pack && |
196 | rm -f .git/objects/pack/* && | |
197 | mv pack-* .git/objects/pack/ && | |
198 | # The pack-objects call on the next line is equivalent to | |
199 | # git repack -A -d without the call to prune-packed | |
200 | git pack-objects --honor-pack-keep --non-empty --all --reflog \ | |
201 | --unpack-unreachable </dev/null pack && | |
202 | rm -f .git/objects/pack/* && | |
203 | mv pack-* .git/objects/pack/ && | |
204 | test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | | |
205 | egrep "^$csha1 " | sort | uniq | wc -l) && | |
7a1c8c23 | 206 | echo >.git/objects/info/alternates && |
869a3d34 BC |
207 | test_must_fail git show $csha1 |
208 | ' | |
209 | ||
7f3140cd | 210 | test_expect_success 'objects made unreachable by grafts only are kept' ' |
1ec64827 BS |
211 | test_tick && |
212 | git commit --allow-empty -m "commit 4" && | |
213 | H0=$(git rev-parse HEAD) && | |
214 | H1=$(git rev-parse HEAD^) && | |
215 | H2=$(git rev-parse HEAD^^) && | |
7a1c8c23 | 216 | echo "$H0 $H2" >.git/info/grafts && |
713c79e8 | 217 | git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && |
1ec64827 BS |
218 | git repack -a -d && |
219 | git cat-file -t $H1 | |
e9e33ab0 | 220 | ' |
1ec64827 | 221 | |
ed7e5fc3 NTND |
222 | test_expect_success 'repack --keep-pack' ' |
223 | test_create_repo keep-pack && | |
224 | ( | |
225 | cd keep-pack && | |
226 | P1=$(commit_and_pack 1) && | |
227 | P2=$(commit_and_pack 2) && | |
228 | P3=$(commit_and_pack 3) && | |
229 | P4=$(commit_and_pack 4) && | |
230 | ls .git/objects/pack/*.pack >old-counts && | |
231 | test_line_count = 4 old-counts && | |
232 | git repack -a -d --keep-pack $P1 --keep-pack $P4 && | |
233 | ls .git/objects/pack/*.pack >new-counts && | |
234 | grep -q $P1 new-counts && | |
235 | grep -q $P4 new-counts && | |
236 | test_line_count = 3 new-counts && | |
237 | git fsck | |
238 | ) | |
239 | ' | |
240 | ||
36eba032 EW |
241 | test_expect_success 'bitmaps are created by default in bare repos' ' |
242 | git clone --bare .git bare.git && | |
243 | git -C bare.git repack -ad && | |
244 | bitmap=$(ls bare.git/objects/pack/*.bitmap) && | |
245 | test_path_is_file "$bitmap" | |
246 | ' | |
247 | ||
248 | test_expect_success 'incremental repack does not complain' ' | |
249 | git -C bare.git repack -q 2>repack.err && | |
250 | test_must_be_empty repack.err | |
251 | ' | |
9245ddd5 | 252 | |
36eba032 EW |
253 | test_expect_success 'bitmaps can be disabled on bare repos' ' |
254 | git -c repack.writeBitmaps=false -C bare.git repack -ad && | |
09279086 | 255 | bitmap=$(ls bare.git/objects/pack/*.bitmap || :) && |
36eba032 EW |
256 | test -z "$bitmap" |
257 | ' | |
258 | ||
73284822 EW |
259 | test_expect_success 'no bitmaps created if .keep files present' ' |
260 | pack=$(ls bare.git/objects/pack/*.pack) && | |
261 | test_path_is_file "$pack" && | |
262 | keep=${pack%.pack}.keep && | |
cc2649ae | 263 | test_when_finished "rm -f \"\$keep\"" && |
73284822 | 264 | >"$keep" && |
7ff024e7 JK |
265 | git -C bare.git repack -ad 2>stderr && |
266 | test_must_be_empty stderr && | |
73284822 EW |
267 | find bare.git/objects/pack/ -type f -name "*.bitmap" >actual && |
268 | test_must_be_empty actual | |
269 | ' | |
270 | ||
25575015 JK |
271 | test_expect_success 'auto-bitmaps do not complain if unavailable' ' |
272 | test_config -C bare.git pack.packSizeLimit 1M && | |
273 | blob=$(test-tool genrandom big $((1024*1024)) | | |
274 | git -C bare.git hash-object -w --stdin) && | |
275 | git -C bare.git update-ref refs/tags/big $blob && | |
276 | git -C bare.git repack -ad 2>stderr && | |
277 | test_must_be_empty stderr && | |
278 | find bare.git/objects/pack -type f -name "*.bitmap" >actual && | |
279 | test_must_be_empty actual | |
280 | ' | |
281 | ||
36eba032 | 282 | test_done |