Blame


1 05118f5a 2021-06-22 stsp #!/bin/sh
2 05118f5a 2021-06-22 stsp #
3 05118f5a 2021-06-22 stsp # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 05118f5a 2021-06-22 stsp #
5 05118f5a 2021-06-22 stsp # Permission to use, copy, modify, and distribute this software for any
6 05118f5a 2021-06-22 stsp # purpose with or without fee is hereby granted, provided that the above
7 05118f5a 2021-06-22 stsp # copyright notice and this permission notice appear in all copies.
8 05118f5a 2021-06-22 stsp #
9 05118f5a 2021-06-22 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 05118f5a 2021-06-22 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 05118f5a 2021-06-22 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 05118f5a 2021-06-22 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 05118f5a 2021-06-22 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 05118f5a 2021-06-22 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 05118f5a 2021-06-22 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 05118f5a 2021-06-22 stsp
17 05118f5a 2021-06-22 stsp . ./common.sh
18 05118f5a 2021-06-22 stsp
19 05118f5a 2021-06-22 stsp # disable automatic packing for these tests
20 05118f5a 2021-06-22 stsp export GOT_TEST_PACK=""
21 05118f5a 2021-06-22 stsp
22 05118f5a 2021-06-22 stsp test_pack_all_loose_objects() {
23 05118f5a 2021-06-22 stsp local testroot=`test_init pack_all_loose_objects`
24 05118f5a 2021-06-22 stsp
25 05118f5a 2021-06-22 stsp # tags should also be packed
26 05118f5a 2021-06-22 stsp got tag -r $testroot/repo -m 1.0 1.0 >/dev/null
27 05118f5a 2021-06-22 stsp
28 05118f5a 2021-06-22 stsp # no pack files should exist yet
29 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
30 05118f5a 2021-06-22 stsp ret="$?"
31 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
32 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
33 05118f5a 2021-06-22 stsp return 1
34 05118f5a 2021-06-22 stsp fi
35 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
36 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
37 05118f5a 2021-06-22 stsp ret="$?"
38 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
39 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
40 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
41 05118f5a 2021-06-22 stsp return 1
42 05118f5a 2021-06-22 stsp fi
43 05118f5a 2021-06-22 stsp
44 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo > $testroot/stdout
45 05118f5a 2021-06-22 stsp ret="$?"
46 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
47 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
48 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
49 05118f5a 2021-06-22 stsp return 1
50 05118f5a 2021-06-22 stsp fi
51 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
52 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
53 05118f5a 2021-06-22 stsp > $testroot/stdout
54 05118f5a 2021-06-22 stsp
55 05118f5a 2021-06-22 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
56 05118f5a 2021-06-22 stsp id0=`basename $d`
57 05118f5a 2021-06-22 stsp ret=0
58 05118f5a 2021-06-22 stsp for e in `ls $d`; do
59 05118f5a 2021-06-22 stsp obj_id=${id0}${e}
60 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
61 05118f5a 2021-06-22 stsp continue
62 05118f5a 2021-06-22 stsp fi
63 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
64 05118f5a 2021-06-22 stsp ret=1
65 05118f5a 2021-06-22 stsp break
66 05118f5a 2021-06-22 stsp done
67 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
68 05118f5a 2021-06-22 stsp break
69 05118f5a 2021-06-22 stsp fi
70 05118f5a 2021-06-22 stsp done
71 05118f5a 2021-06-22 stsp
72 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
73 05118f5a 2021-06-22 stsp }
74 05118f5a 2021-06-22 stsp
75 05118f5a 2021-06-22 stsp test_pack_exclude() {
76 05118f5a 2021-06-22 stsp local testroot=`test_init pack_exclude`
77 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
78 05118f5a 2021-06-22 stsp
79 05118f5a 2021-06-22 stsp # no pack files should exist yet
80 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
81 05118f5a 2021-06-22 stsp ret="$?"
82 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
83 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
84 05118f5a 2021-06-22 stsp return 1
85 05118f5a 2021-06-22 stsp fi
86 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
87 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
88 05118f5a 2021-06-22 stsp ret="$?"
89 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
90 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
91 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
92 05118f5a 2021-06-22 stsp return 1
93 05118f5a 2021-06-22 stsp fi
94 05118f5a 2021-06-22 stsp
95 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
96 05118f5a 2021-06-22 stsp ret="$?"
97 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
98 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
99 05118f5a 2021-06-22 stsp return 1
100 05118f5a 2021-06-22 stsp fi
101 05118f5a 2021-06-22 stsp
102 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
103 05118f5a 2021-06-22 stsp ret="$?"
104 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
105 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
106 05118f5a 2021-06-22 stsp return 1
107 05118f5a 2021-06-22 stsp fi
108 05118f5a 2021-06-22 stsp
109 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
110 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
111 05118f5a 2021-06-22 stsp
112 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo -x master > $testroot/stdout
113 05118f5a 2021-06-22 stsp ret="$?"
114 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
115 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
116 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
117 05118f5a 2021-06-22 stsp return 1
118 05118f5a 2021-06-22 stsp fi
119 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
120 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
121 05118f5a 2021-06-22 stsp > $testroot/stdout
122 05118f5a 2021-06-22 stsp
123 05118f5a 2021-06-22 stsp tree0=`got cat -r $testroot/repo $commit0 | grep ^tree | \
124 05118f5a 2021-06-22 stsp cut -d ' ' -f2`
125 05118f5a 2021-06-22 stsp excluded_ids=`got tree -r $testroot/repo -c $commit0 -R -i | \
126 05118f5a 2021-06-22 stsp cut -d ' ' -f 1`
127 05118f5a 2021-06-22 stsp excluded_ids="$excluded_ids $commit0 $tree0"
128 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
129 05118f5a 2021-06-22 stsp ret=0
130 05118f5a 2021-06-22 stsp if grep -q ^$id $testroot/stdout; then
131 05118f5a 2021-06-22 stsp echo "found excluded object $id in pack file" >&2
132 05118f5a 2021-06-22 stsp ret=1
133 05118f5a 2021-06-22 stsp fi
134 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
135 05118f5a 2021-06-22 stsp break
136 05118f5a 2021-06-22 stsp fi
137 05118f5a 2021-06-22 stsp done
138 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
139 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
140 05118f5a 2021-06-22 stsp return 1
141 05118f5a 2021-06-22 stsp fi
142 05118f5a 2021-06-22 stsp
143 05118f5a 2021-06-22 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
144 05118f5a 2021-06-22 stsp id0=`basename $d`
145 05118f5a 2021-06-22 stsp ret=0
146 05118f5a 2021-06-22 stsp for e in `ls $d`; do
147 05118f5a 2021-06-22 stsp obj_id=${id0}${e}
148 05118f5a 2021-06-22 stsp excluded=0
149 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
150 8775a682 2021-07-03 naddy if [ "$obj_id" = "$id" ]; then
151 05118f5a 2021-06-22 stsp excluded=1
152 05118f5a 2021-06-22 stsp break
153 05118f5a 2021-06-22 stsp fi
154 05118f5a 2021-06-22 stsp done
155 8775a682 2021-07-03 naddy if [ "$excluded" = "1" ]; then
156 05118f5a 2021-06-22 stsp continue
157 05118f5a 2021-06-22 stsp fi
158 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
159 05118f5a 2021-06-22 stsp continue
160 05118f5a 2021-06-22 stsp fi
161 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
162 05118f5a 2021-06-22 stsp ret=1
163 05118f5a 2021-06-22 stsp break
164 05118f5a 2021-06-22 stsp done
165 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
166 05118f5a 2021-06-22 stsp break
167 05118f5a 2021-06-22 stsp fi
168 05118f5a 2021-06-22 stsp done
169 05118f5a 2021-06-22 stsp
170 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
171 05118f5a 2021-06-22 stsp }
172 05118f5a 2021-06-22 stsp
173 05118f5a 2021-06-22 stsp test_pack_include() {
174 05118f5a 2021-06-22 stsp local testroot=`test_init pack_include`
175 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
176 05118f5a 2021-06-22 stsp
177 05118f5a 2021-06-22 stsp # no pack files should exist yet
178 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
179 05118f5a 2021-06-22 stsp ret="$?"
180 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
181 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
182 05118f5a 2021-06-22 stsp return 1
183 05118f5a 2021-06-22 stsp fi
184 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
185 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
186 05118f5a 2021-06-22 stsp ret="$?"
187 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
188 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
189 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
190 05118f5a 2021-06-22 stsp return 1
191 05118f5a 2021-06-22 stsp fi
192 05118f5a 2021-06-22 stsp
193 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
194 05118f5a 2021-06-22 stsp ret="$?"
195 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
196 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
197 05118f5a 2021-06-22 stsp return 1
198 05118f5a 2021-06-22 stsp fi
199 05118f5a 2021-06-22 stsp
200 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
201 05118f5a 2021-06-22 stsp ret="$?"
202 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
203 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
204 05118f5a 2021-06-22 stsp return 1
205 05118f5a 2021-06-22 stsp fi
206 05118f5a 2021-06-22 stsp
207 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
208 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
209 05118f5a 2021-06-22 stsp local commit1=`git_show_branch_head $testroot/repo mybranch`
210 05118f5a 2021-06-22 stsp
211 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo master > $testroot/stdout
212 05118f5a 2021-06-22 stsp ret="$?"
213 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
214 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
215 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
216 05118f5a 2021-06-22 stsp return 1
217 05118f5a 2021-06-22 stsp fi
218 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
219 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
220 05118f5a 2021-06-22 stsp > $testroot/stdout
221 05118f5a 2021-06-22 stsp
222 05118f5a 2021-06-22 stsp tree1=`got cat -r $testroot/repo $commit1 | grep ^tree | \
223 05118f5a 2021-06-22 stsp cut -d ' ' -f2`
224 05118f5a 2021-06-22 stsp alpha1=`got tree -r $testroot/repo -i -c $commit1 | \
225 05118f5a 2021-06-22 stsp grep "[0-9a-f] alpha$" | cut -d' ' -f 1`
226 05118f5a 2021-06-22 stsp excluded_ids="$alpha1 $commit1 $tree1"
227 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
228 05118f5a 2021-06-22 stsp ret=0
229 05118f5a 2021-06-22 stsp if grep -q ^$id $testroot/stdout; then
230 05118f5a 2021-06-22 stsp echo "found excluded object $id in pack file" >&2
231 05118f5a 2021-06-22 stsp ret=1
232 05118f5a 2021-06-22 stsp fi
233 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
234 05118f5a 2021-06-22 stsp break
235 05118f5a 2021-06-22 stsp fi
236 05118f5a 2021-06-22 stsp done
237 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
238 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
239 05118f5a 2021-06-22 stsp return 1
240 05118f5a 2021-06-22 stsp fi
241 05118f5a 2021-06-22 stsp
242 05118f5a 2021-06-22 stsp tree0=`got cat -r $testroot/repo $commit0 | grep ^tree | \
243 05118f5a 2021-06-22 stsp cut -d ' ' -f2`
244 05118f5a 2021-06-22 stsp included_ids=`got tree -r $testroot/repo -c $commit0 -R -i | \
245 05118f5a 2021-06-22 stsp cut -d ' ' -f 1`
246 05118f5a 2021-06-22 stsp included_ids="$included_ids $commit0 $tree0"
247 05118f5a 2021-06-22 stsp for obj_id in $included_ids; do
248 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
249 8775a682 2021-07-03 naddy if [ "$obj_id" = "$id" ]; then
250 05118f5a 2021-06-22 stsp excluded=1
251 05118f5a 2021-06-22 stsp break
252 05118f5a 2021-06-22 stsp fi
253 05118f5a 2021-06-22 stsp done
254 8775a682 2021-07-03 naddy if [ "$excluded" = "1" ]; then
255 05118f5a 2021-06-22 stsp continue
256 05118f5a 2021-06-22 stsp fi
257 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
258 05118f5a 2021-06-22 stsp continue
259 05118f5a 2021-06-22 stsp fi
260 05118f5a 2021-06-22 stsp echo "included object $obj_id was not packed" >&2
261 05118f5a 2021-06-22 stsp ret=1
262 05118f5a 2021-06-22 stsp break
263 05118f5a 2021-06-22 stsp done
264 05118f5a 2021-06-22 stsp
265 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
266 05118f5a 2021-06-22 stsp }
267 05118f5a 2021-06-22 stsp
268 05118f5a 2021-06-22 stsp test_pack_ambiguous_arg() {
269 05118f5a 2021-06-22 stsp local testroot=`test_init pack_ambiguous_arg`
270 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
271 05118f5a 2021-06-22 stsp
272 05118f5a 2021-06-22 stsp # no pack files should exist yet
273 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
274 05118f5a 2021-06-22 stsp ret="$?"
275 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
276 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
277 05118f5a 2021-06-22 stsp return 1
278 05118f5a 2021-06-22 stsp fi
279 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
280 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
281 05118f5a 2021-06-22 stsp ret="$?"
282 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
283 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
284 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
285 05118f5a 2021-06-22 stsp return 1
286 05118f5a 2021-06-22 stsp fi
287 05118f5a 2021-06-22 stsp
288 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
289 05118f5a 2021-06-22 stsp ret="$?"
290 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
291 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
292 05118f5a 2021-06-22 stsp return 1
293 05118f5a 2021-06-22 stsp fi
294 05118f5a 2021-06-22 stsp
295 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
296 05118f5a 2021-06-22 stsp ret="$?"
297 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
298 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
299 05118f5a 2021-06-22 stsp return 1
300 05118f5a 2021-06-22 stsp fi
301 05118f5a 2021-06-22 stsp
302 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
303 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
304 05118f5a 2021-06-22 stsp local commit1=`git_show_branch_head $testroot/repo mybranch`
305 05118f5a 2021-06-22 stsp
306 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo -x master master \
307 05118f5a 2021-06-22 stsp > $testroot/stdout 2> $testroot/stderr
308 05118f5a 2021-06-22 stsp ret="$?"
309 8775a682 2021-07-03 naddy if [ "$ret" = "0" ]; then
310 05118f5a 2021-06-22 stsp echo "gotadmin pack succeeded unexpectedly" >&2
311 05118f5a 2021-06-22 stsp test_done "$testroot" "1"
312 05118f5a 2021-06-22 stsp return 1
313 05118f5a 2021-06-22 stsp fi
314 05118f5a 2021-06-22 stsp
315 05118f5a 2021-06-22 stsp printf "\rpacking 1 reference\n" > $testroot/stdout.expected
316 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
317 05118f5a 2021-06-22 stsp ret="$?"
318 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
319 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
320 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
321 05118f5a 2021-06-22 stsp return 1
322 05118f5a 2021-06-22 stsp fi
323 05118f5a 2021-06-22 stsp
324 05118f5a 2021-06-22 stsp echo "gotadmin: not enough objects to pack" > $testroot/stderr.expected
325 05118f5a 2021-06-22 stsp cmp -s $testroot/stderr.expected $testroot/stderr
326 05118f5a 2021-06-22 stsp ret="$?"
327 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
328 05118f5a 2021-06-22 stsp diff -u $testroot/stderr.expected $testroot/stderr
329 05118f5a 2021-06-22 stsp fi
330 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
331 05118f5a 2021-06-22 stsp }
332 05118f5a 2021-06-22 stsp
333 05118f5a 2021-06-22 stsp test_pack_loose_only() {
334 05118f5a 2021-06-22 stsp local testroot=`test_init pack_loose_only`
335 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
336 05118f5a 2021-06-22 stsp
337 05118f5a 2021-06-22 stsp # no pack files should exist yet
338 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
339 05118f5a 2021-06-22 stsp ret="$?"
340 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
341 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
342 05118f5a 2021-06-22 stsp return 1
343 05118f5a 2021-06-22 stsp fi
344 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
345 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
346 05118f5a 2021-06-22 stsp ret="$?"
347 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
348 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
349 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
350 05118f5a 2021-06-22 stsp return 1
351 05118f5a 2021-06-22 stsp fi
352 05118f5a 2021-06-22 stsp
353 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
354 05118f5a 2021-06-22 stsp ret="$?"
355 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
356 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
357 05118f5a 2021-06-22 stsp return 1
358 05118f5a 2021-06-22 stsp fi
359 05118f5a 2021-06-22 stsp
360 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
361 05118f5a 2021-06-22 stsp ret="$?"
362 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
363 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
364 05118f5a 2021-06-22 stsp return 1
365 05118f5a 2021-06-22 stsp fi
366 05118f5a 2021-06-22 stsp
367 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
368 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
369 05118f5a 2021-06-22 stsp
370 05118f5a 2021-06-22 stsp # pack objects belonging to the 'master' branch; its objects
371 05118f5a 2021-06-22 stsp # should then be excluded while packing 'mybranch' since they
372 05118f5a 2021-06-22 stsp # are already packed
373 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo master > /dev/null
374 05118f5a 2021-06-22 stsp ret="$?"
375 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
376 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
377 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
378 05118f5a 2021-06-22 stsp return 1
379 05118f5a 2021-06-22 stsp fi
380 05118f5a 2021-06-22 stsp
381 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo mybranch > $testroot/stdout
382 05118f5a 2021-06-22 stsp ret="$?"
383 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
384 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
385 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
386 05118f5a 2021-06-22 stsp return 1
387 05118f5a 2021-06-22 stsp fi
388 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
389 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
390 05118f5a 2021-06-22 stsp > $testroot/stdout
391 05118f5a 2021-06-22 stsp
392 05118f5a 2021-06-22 stsp tree0=`got cat -r $testroot/repo $commit0 | grep ^tree | \
393 05118f5a 2021-06-22 stsp cut -d ' ' -f2`
394 05118f5a 2021-06-22 stsp excluded_ids=`got tree -r $testroot/repo -c $commit0 -R -i | \
395 05118f5a 2021-06-22 stsp cut -d ' ' -f 1`
396 05118f5a 2021-06-22 stsp excluded_ids="$excluded_ids $commit0 $tree0"
397 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
398 05118f5a 2021-06-22 stsp ret=0
399 05118f5a 2021-06-22 stsp if grep -q ^$id $testroot/stdout; then
400 05118f5a 2021-06-22 stsp echo "found excluded object $id in pack file" >&2
401 05118f5a 2021-06-22 stsp ret=1
402 05118f5a 2021-06-22 stsp fi
403 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
404 05118f5a 2021-06-22 stsp break
405 05118f5a 2021-06-22 stsp fi
406 05118f5a 2021-06-22 stsp done
407 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
408 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
409 05118f5a 2021-06-22 stsp return 1
410 05118f5a 2021-06-22 stsp fi
411 05118f5a 2021-06-22 stsp
412 05118f5a 2021-06-22 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
413 05118f5a 2021-06-22 stsp id0=`basename $d`
414 05118f5a 2021-06-22 stsp ret=0
415 05118f5a 2021-06-22 stsp for e in `ls $d`; do
416 05118f5a 2021-06-22 stsp obj_id=${id0}${e}
417 05118f5a 2021-06-22 stsp excluded=0
418 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
419 8775a682 2021-07-03 naddy if [ "$obj_id" = "$id" ]; then
420 05118f5a 2021-06-22 stsp excluded=1
421 05118f5a 2021-06-22 stsp break
422 05118f5a 2021-06-22 stsp fi
423 05118f5a 2021-06-22 stsp done
424 8775a682 2021-07-03 naddy if [ "$excluded" = "1" ]; then
425 05118f5a 2021-06-22 stsp continue
426 05118f5a 2021-06-22 stsp fi
427 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
428 05118f5a 2021-06-22 stsp continue
429 05118f5a 2021-06-22 stsp fi
430 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
431 05118f5a 2021-06-22 stsp ret=1
432 05118f5a 2021-06-22 stsp break
433 05118f5a 2021-06-22 stsp done
434 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
435 05118f5a 2021-06-22 stsp break
436 05118f5a 2021-06-22 stsp fi
437 05118f5a 2021-06-22 stsp done
438 05118f5a 2021-06-22 stsp
439 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
440 05118f5a 2021-06-22 stsp }
441 05118f5a 2021-06-22 stsp
442 05118f5a 2021-06-22 stsp test_pack_all_objects() {
443 05118f5a 2021-06-22 stsp local testroot=`test_init pack_all_objects`
444 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
445 05118f5a 2021-06-22 stsp
446 05118f5a 2021-06-22 stsp # no pack files should exist yet
447 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
448 05118f5a 2021-06-22 stsp ret="$?"
449 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
450 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
451 05118f5a 2021-06-22 stsp return 1
452 05118f5a 2021-06-22 stsp fi
453 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
454 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
455 05118f5a 2021-06-22 stsp ret="$?"
456 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
457 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
458 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
459 05118f5a 2021-06-22 stsp return 1
460 05118f5a 2021-06-22 stsp fi
461 05118f5a 2021-06-22 stsp
462 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
463 05118f5a 2021-06-22 stsp ret="$?"
464 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
465 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
466 05118f5a 2021-06-22 stsp return 1
467 05118f5a 2021-06-22 stsp fi
468 05118f5a 2021-06-22 stsp
469 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
470 05118f5a 2021-06-22 stsp ret="$?"
471 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
472 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
473 05118f5a 2021-06-22 stsp return 1
474 05118f5a 2021-06-22 stsp fi
475 05118f5a 2021-06-22 stsp
476 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
477 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
478 05118f5a 2021-06-22 stsp
479 05118f5a 2021-06-22 stsp # pack objects belonging to the 'master' branch
480 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo master > /dev/null
481 05118f5a 2021-06-22 stsp ret="$?"
482 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
483 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
484 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
485 05118f5a 2021-06-22 stsp return 1
486 05118f5a 2021-06-22 stsp fi
487 05118f5a 2021-06-22 stsp
488 05118f5a 2021-06-22 stsp # pack mybranch, including already packed objects on the
489 05118f5a 2021-06-22 stsp # 'master' branch which are reachable from mybranch
490 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo -a mybranch > $testroot/stdout
491 05118f5a 2021-06-22 stsp ret="$?"
492 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
493 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
494 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
495 05118f5a 2021-06-22 stsp return 1
496 05118f5a 2021-06-22 stsp fi
497 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
498 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
499 05118f5a 2021-06-22 stsp > $testroot/stdout
500 05118f5a 2021-06-22 stsp
501 05118f5a 2021-06-22 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
502 05118f5a 2021-06-22 stsp id0=`basename $d`
503 05118f5a 2021-06-22 stsp ret=0
504 05118f5a 2021-06-22 stsp for e in `ls $d`; do
505 05118f5a 2021-06-22 stsp obj_id=${id0}${e}
506 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
507 05118f5a 2021-06-22 stsp continue
508 05118f5a 2021-06-22 stsp fi
509 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
510 05118f5a 2021-06-22 stsp ret=1
511 05118f5a 2021-06-22 stsp break
512 05118f5a 2021-06-22 stsp done
513 8775a682 2021-07-03 naddy if [ "$ret" = "1" ]; then
514 05118f5a 2021-06-22 stsp break
515 05118f5a 2021-06-22 stsp fi
516 05118f5a 2021-06-22 stsp done
517 05118f5a 2021-06-22 stsp
518 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
519 05118f5a 2021-06-22 stsp }
520 05118f5a 2021-06-22 stsp
521 05118f5a 2021-06-22 stsp test_pack_bad_ref() {
522 05118f5a 2021-06-22 stsp local testroot=`test_init pack_bad_ref`
523 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
524 05118f5a 2021-06-22 stsp
525 05118f5a 2021-06-22 stsp # no pack files should exist yet
526 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
527 05118f5a 2021-06-22 stsp ret="$?"
528 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
529 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
530 05118f5a 2021-06-22 stsp return 1
531 05118f5a 2021-06-22 stsp fi
532 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
533 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
534 05118f5a 2021-06-22 stsp ret="$?"
535 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
536 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
537 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
538 05118f5a 2021-06-22 stsp return 1
539 05118f5a 2021-06-22 stsp fi
540 05118f5a 2021-06-22 stsp
541 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
542 05118f5a 2021-06-22 stsp ret="$?"
543 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
544 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
545 05118f5a 2021-06-22 stsp return 1
546 05118f5a 2021-06-22 stsp fi
547 05118f5a 2021-06-22 stsp
548 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
549 05118f5a 2021-06-22 stsp ret="$?"
550 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
551 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
552 05118f5a 2021-06-22 stsp return 1
553 05118f5a 2021-06-22 stsp fi
554 05118f5a 2021-06-22 stsp
555 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo refs/got/worktree/ \
556 05118f5a 2021-06-22 stsp > $testroot/stdout 2> $testroot/stderr
557 05118f5a 2021-06-22 stsp ret="$?"
558 8775a682 2021-07-03 naddy if [ "$ret" = "0" ]; then
559 05118f5a 2021-06-22 stsp echo "gotadmin pack succeeded unexpectedly" >&2
560 05118f5a 2021-06-22 stsp test_done "$testroot" "1"
561 05118f5a 2021-06-22 stsp return 1
562 05118f5a 2021-06-22 stsp fi
563 05118f5a 2021-06-22 stsp
564 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
565 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
566 05118f5a 2021-06-22 stsp ret="$?"
567 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
568 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
569 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
570 05118f5a 2021-06-22 stsp return 1
571 05118f5a 2021-06-22 stsp fi
572 05118f5a 2021-06-22 stsp
573 05118f5a 2021-06-22 stsp echo "gotadmin: not enough objects to pack" > $testroot/stderr.expected
574 05118f5a 2021-06-22 stsp cmp -s $testroot/stderr.expected $testroot/stderr
575 05118f5a 2021-06-22 stsp ret="$?"
576 05118f5a 2021-06-22 stsp if [ "$ret" != "0" ]; then
577 05118f5a 2021-06-22 stsp diff -u $testroot/stderr.expected $testroot/stderr
578 05118f5a 2021-06-22 stsp fi
579 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
580 05118f5a 2021-06-22 stsp }
581 05118f5a 2021-06-22 stsp
582 05118f5a 2021-06-22 stsp test_parseargs "$@"
583 05118f5a 2021-06-22 stsp run_test test_pack_all_loose_objects
584 05118f5a 2021-06-22 stsp run_test test_pack_exclude
585 05118f5a 2021-06-22 stsp run_test test_pack_include
586 05118f5a 2021-06-22 stsp run_test test_pack_ambiguous_arg
587 05118f5a 2021-06-22 stsp run_test test_pack_loose_only
588 05118f5a 2021-06-22 stsp run_test test_pack_all_objects
589 05118f5a 2021-06-22 stsp run_test test_pack_bad_ref