3 05118f5a 2021-06-22 stsp # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 05118f5a 2021-06-22 stsp . ./common.sh
19 05118f5a 2021-06-22 stsp # disable automatic packing for these tests
20 05118f5a 2021-06-22 stsp export GOT_TEST_PACK=""
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`
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
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
31 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
32 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
35 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
36 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
38 49c543a6 2022-03-31 naddy if [ $ret -ne 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"
44 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo > $testroot/stdout
46 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
47 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
48 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
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
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`
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
63 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
67 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
72 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
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`
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
82 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
83 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
86 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
87 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
89 49c543a6 2022-03-31 naddy if [ $ret -ne 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"
95 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
97 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
98 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
102 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
104 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
105 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
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)
112 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo -x master > $testroot/stdout
114 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
115 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
116 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
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
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
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
134 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
138 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
139 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
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`
146 05118f5a 2021-06-22 stsp for e in `ls $d`; do
147 05118f5a 2021-06-22 stsp obj_id=${id0}${e}
149 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
150 8775a682 2021-07-03 naddy if [ "$obj_id" = "$id" ]; then
155 8775a682 2021-07-03 naddy if [ "$excluded" = "1" ]; then
158 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
161 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
165 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
170 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
173 29e0594f 2022-04-09 stsp test_pack_exclude_tag() {
174 29e0594f 2022-04-09 stsp local testroot=`test_init pack_exclude_tag`
175 29e0594f 2022-04-09 stsp local commit0=`git_show_head $testroot/repo`
177 29e0594f 2022-04-09 stsp # no pack files should exist yet
178 29e0594f 2022-04-09 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
180 29e0594f 2022-04-09 stsp if [ $ret -ne 0 ]; then
181 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
184 29e0594f 2022-04-09 stsp echo -n > $testroot/stdout.expected
185 29e0594f 2022-04-09 stsp cmp -s $testroot/stdout.expected $testroot/stdout
187 29e0594f 2022-04-09 stsp if [ $ret -ne 0 ]; then
188 29e0594f 2022-04-09 stsp diff -u $testroot/stdout.expected $testroot/stdout
189 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
193 29e0594f 2022-04-09 stsp got tag -r $testroot/repo -m 1.0 -c master 1.0 > /dev/null
195 29e0594f 2022-04-09 stsp if [ $ret -ne 0 ]; then
196 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
200 29e0594f 2022-04-09 stsp got branch -r $testroot/repo mybranch
202 29e0594f 2022-04-09 stsp if [ $ret -ne 0 ]; then
203 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
207 29e0594f 2022-04-09 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
209 29e0594f 2022-04-09 stsp if [ $ret -ne 0 ]; then
210 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
214 29e0594f 2022-04-09 stsp echo a new line >> $testroot/wt/alpha
215 29e0594f 2022-04-09 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
217 29e0594f 2022-04-09 stsp gotadmin pack -r $testroot/repo -x refs/tags/1.0 > $testroot/stdout
219 29e0594f 2022-04-09 stsp if [ $ret -ne 0 ]; then
220 29e0594f 2022-04-09 stsp echo "gotadmin pack failed unexpectedly" >&2
221 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
224 29e0594f 2022-04-09 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
225 29e0594f 2022-04-09 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
226 29e0594f 2022-04-09 stsp > $testroot/stdout
228 29e0594f 2022-04-09 stsp tree0=`got cat -r $testroot/repo $commit0 | grep ^tree | \
229 29e0594f 2022-04-09 stsp cut -d ' ' -f2`
230 29e0594f 2022-04-09 stsp tag0=`got tag -l -r $testroot/repo | grep ^tag | cut -d ' ' -f3`
231 29e0594f 2022-04-09 stsp excluded_ids=`got tree -r $testroot/repo -c $commit0 -R -i | \
232 29e0594f 2022-04-09 stsp cut -d ' ' -f 1`
233 29e0594f 2022-04-09 stsp excluded_ids="$excluded_ids $commit0 $tree0 $tag0"
234 29e0594f 2022-04-09 stsp for id in $excluded_ids; do
236 29e0594f 2022-04-09 stsp if grep -q ^$id $testroot/stdout; then
237 29e0594f 2022-04-09 stsp echo "found excluded object $id in pack file" >&2
240 29e0594f 2022-04-09 stsp if [ $ret -eq 1 ]; then
244 29e0594f 2022-04-09 stsp if [ $ret -eq 1 ]; then
245 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
249 29e0594f 2022-04-09 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
250 29e0594f 2022-04-09 stsp id0=`basename $d`
252 29e0594f 2022-04-09 stsp for e in `ls $d`; do
253 29e0594f 2022-04-09 stsp obj_id=${id0}${e}
255 29e0594f 2022-04-09 stsp for id in $excluded_ids; do
256 29e0594f 2022-04-09 stsp if [ "$obj_id" = "$id" ]; then
261 29e0594f 2022-04-09 stsp if [ "$excluded" = "1" ]; then
264 29e0594f 2022-04-09 stsp if grep -q ^$obj_id $testroot/stdout; then
267 29e0594f 2022-04-09 stsp echo "loose object $obj_id was not packed" >&2
271 29e0594f 2022-04-09 stsp if [ $ret -eq 1 ]; then
276 29e0594f 2022-04-09 stsp test_done "$testroot" "$ret"
279 05118f5a 2021-06-22 stsp test_pack_include() {
280 05118f5a 2021-06-22 stsp local testroot=`test_init pack_include`
281 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
283 05118f5a 2021-06-22 stsp # no pack files should exist yet
284 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
286 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
287 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
290 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
291 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
293 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
294 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
295 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
299 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
301 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
302 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
306 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
308 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
309 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
313 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
314 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
315 05118f5a 2021-06-22 stsp local commit1=`git_show_branch_head $testroot/repo mybranch`
317 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo master > $testroot/stdout
319 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
320 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
321 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
324 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
325 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
326 05118f5a 2021-06-22 stsp > $testroot/stdout
328 05118f5a 2021-06-22 stsp tree1=`got cat -r $testroot/repo $commit1 | grep ^tree | \
329 05118f5a 2021-06-22 stsp cut -d ' ' -f2`
330 05118f5a 2021-06-22 stsp alpha1=`got tree -r $testroot/repo -i -c $commit1 | \
331 05118f5a 2021-06-22 stsp grep "[0-9a-f] alpha$" | cut -d' ' -f 1`
332 05118f5a 2021-06-22 stsp excluded_ids="$alpha1 $commit1 $tree1"
333 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
335 05118f5a 2021-06-22 stsp if grep -q ^$id $testroot/stdout; then
336 05118f5a 2021-06-22 stsp echo "found excluded object $id in pack file" >&2
339 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
343 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
344 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
348 05118f5a 2021-06-22 stsp tree0=`got cat -r $testroot/repo $commit0 | grep ^tree | \
349 05118f5a 2021-06-22 stsp cut -d ' ' -f2`
350 05118f5a 2021-06-22 stsp included_ids=`got tree -r $testroot/repo -c $commit0 -R -i | \
351 05118f5a 2021-06-22 stsp cut -d ' ' -f 1`
352 05118f5a 2021-06-22 stsp included_ids="$included_ids $commit0 $tree0"
353 05118f5a 2021-06-22 stsp for obj_id in $included_ids; do
354 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
355 8775a682 2021-07-03 naddy if [ "$obj_id" = "$id" ]; then
360 8775a682 2021-07-03 naddy if [ "$excluded" = "1" ]; then
363 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
366 05118f5a 2021-06-22 stsp echo "included object $obj_id was not packed" >&2
371 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
374 05118f5a 2021-06-22 stsp test_pack_ambiguous_arg() {
375 05118f5a 2021-06-22 stsp local testroot=`test_init pack_ambiguous_arg`
376 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
378 05118f5a 2021-06-22 stsp # no pack files should exist yet
379 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
381 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
382 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
385 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
386 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
388 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
389 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
390 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
394 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
396 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
397 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
401 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
403 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
404 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
408 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
409 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
410 05118f5a 2021-06-22 stsp local commit1=`git_show_branch_head $testroot/repo mybranch`
412 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo -x master master \
413 b8af7c06 2022-03-15 stsp > /dev/null 2> $testroot/stderr
415 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
416 05118f5a 2021-06-22 stsp echo "gotadmin pack succeeded unexpectedly" >&2
417 05118f5a 2021-06-22 stsp test_done "$testroot" "1"
421 05118f5a 2021-06-22 stsp echo "gotadmin: not enough objects to pack" > $testroot/stderr.expected
422 05118f5a 2021-06-22 stsp cmp -s $testroot/stderr.expected $testroot/stderr
424 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
425 05118f5a 2021-06-22 stsp diff -u $testroot/stderr.expected $testroot/stderr
427 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
430 05118f5a 2021-06-22 stsp test_pack_loose_only() {
431 05118f5a 2021-06-22 stsp local testroot=`test_init pack_loose_only`
432 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
434 05118f5a 2021-06-22 stsp # no pack files should exist yet
435 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
437 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
438 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
441 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
442 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
444 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
445 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
446 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
450 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
452 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
453 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
457 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
459 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
460 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
464 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
465 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
467 05118f5a 2021-06-22 stsp # pack objects belonging to the 'master' branch; its objects
468 05118f5a 2021-06-22 stsp # should then be excluded while packing 'mybranch' since they
469 05118f5a 2021-06-22 stsp # are already packed
470 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo master > /dev/null
472 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
473 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
474 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
478 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo mybranch > $testroot/stdout
480 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
481 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
482 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
485 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
486 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
487 05118f5a 2021-06-22 stsp > $testroot/stdout
489 05118f5a 2021-06-22 stsp tree0=`got cat -r $testroot/repo $commit0 | grep ^tree | \
490 05118f5a 2021-06-22 stsp cut -d ' ' -f2`
491 05118f5a 2021-06-22 stsp excluded_ids=`got tree -r $testroot/repo -c $commit0 -R -i | \
492 05118f5a 2021-06-22 stsp cut -d ' ' -f 1`
493 05118f5a 2021-06-22 stsp excluded_ids="$excluded_ids $commit0 $tree0"
494 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
496 05118f5a 2021-06-22 stsp if grep -q ^$id $testroot/stdout; then
497 05118f5a 2021-06-22 stsp echo "found excluded object $id in pack file" >&2
500 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
504 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
505 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
509 05118f5a 2021-06-22 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
510 05118f5a 2021-06-22 stsp id0=`basename $d`
512 05118f5a 2021-06-22 stsp for e in `ls $d`; do
513 05118f5a 2021-06-22 stsp obj_id=${id0}${e}
515 05118f5a 2021-06-22 stsp for id in $excluded_ids; do
516 8775a682 2021-07-03 naddy if [ "$obj_id" = "$id" ]; then
521 8775a682 2021-07-03 naddy if [ "$excluded" = "1" ]; then
524 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
527 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
531 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
536 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
539 05118f5a 2021-06-22 stsp test_pack_all_objects() {
540 05118f5a 2021-06-22 stsp local testroot=`test_init pack_all_objects`
541 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
543 05118f5a 2021-06-22 stsp # no pack files should exist yet
544 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
546 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
547 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
550 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
551 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
553 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
554 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
555 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
559 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
561 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
562 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
566 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
568 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
569 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
573 05118f5a 2021-06-22 stsp echo a new line >> $testroot/wt/alpha
574 05118f5a 2021-06-22 stsp (cd $testroot/wt && got commit -m "edit alpha" >/dev/null)
576 05118f5a 2021-06-22 stsp # pack objects belonging to the 'master' branch
577 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo master > /dev/null
579 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
580 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
581 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
585 05118f5a 2021-06-22 stsp # pack mybranch, including already packed objects on the
586 05118f5a 2021-06-22 stsp # 'master' branch which are reachable from mybranch
587 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo -a mybranch > $testroot/stdout
589 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
590 05118f5a 2021-06-22 stsp echo "gotadmin pack failed unexpectedly" >&2
591 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
594 05118f5a 2021-06-22 stsp packname=`grep ^Wrote $testroot/stdout | cut -d ' ' -f2`
595 05118f5a 2021-06-22 stsp gotadmin listpack $testroot/repo/.git/objects/pack/pack-$packname \
596 05118f5a 2021-06-22 stsp > $testroot/stdout
598 05118f5a 2021-06-22 stsp for d in $testroot/repo/.git/objects/[0-9a-f][0-9a-f]; do
599 05118f5a 2021-06-22 stsp id0=`basename $d`
601 05118f5a 2021-06-22 stsp for e in `ls $d`; do
602 05118f5a 2021-06-22 stsp obj_id=${id0}${e}
603 05118f5a 2021-06-22 stsp if grep -q ^$obj_id $testroot/stdout; then
606 05118f5a 2021-06-22 stsp echo "loose object $obj_id was not packed" >&2
610 49c543a6 2022-03-31 naddy if [ $ret -eq 1 ]; then
615 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
618 05118f5a 2021-06-22 stsp test_pack_bad_ref() {
619 05118f5a 2021-06-22 stsp local testroot=`test_init pack_bad_ref`
620 05118f5a 2021-06-22 stsp local commit0=`git_show_head $testroot/repo`
622 05118f5a 2021-06-22 stsp # no pack files should exist yet
623 05118f5a 2021-06-22 stsp ls $testroot/repo/.git/objects/pack/ > $testroot/stdout
625 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
626 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
629 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
630 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
632 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
633 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
634 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
638 05118f5a 2021-06-22 stsp got branch -r $testroot/repo mybranch
640 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
641 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
645 05118f5a 2021-06-22 stsp got checkout -b mybranch $testroot/repo $testroot/wt > /dev/null
647 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
648 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
652 05118f5a 2021-06-22 stsp gotadmin pack -r $testroot/repo refs/got/worktree/ \
653 05118f5a 2021-06-22 stsp > $testroot/stdout 2> $testroot/stderr
655 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
656 05118f5a 2021-06-22 stsp echo "gotadmin pack succeeded unexpectedly" >&2
657 05118f5a 2021-06-22 stsp test_done "$testroot" "1"
661 05118f5a 2021-06-22 stsp echo -n > $testroot/stdout.expected
662 05118f5a 2021-06-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
664 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
665 05118f5a 2021-06-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
666 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
670 05118f5a 2021-06-22 stsp echo "gotadmin: not enough objects to pack" > $testroot/stderr.expected
671 05118f5a 2021-06-22 stsp cmp -s $testroot/stderr.expected $testroot/stderr
673 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
674 05118f5a 2021-06-22 stsp diff -u $testroot/stderr.expected $testroot/stderr
676 05118f5a 2021-06-22 stsp test_done "$testroot" "$ret"
679 05118f5a 2021-06-22 stsp test_parseargs "$@"
680 05118f5a 2021-06-22 stsp run_test test_pack_all_loose_objects
681 05118f5a 2021-06-22 stsp run_test test_pack_exclude
682 29e0594f 2022-04-09 stsp run_test test_pack_exclude_tag
683 05118f5a 2021-06-22 stsp run_test test_pack_include
684 05118f5a 2021-06-22 stsp run_test test_pack_ambiguous_arg
685 05118f5a 2021-06-22 stsp run_test test_pack_loose_only
686 05118f5a 2021-06-22 stsp run_test test_pack_all_objects
687 05118f5a 2021-06-22 stsp run_test test_pack_bad_ref