make got-read-gotconfig clear its imsgbuf before exit in an error case
[got-portable.git] / regress / cmdline / load.sh
blob469333581fa7db2a210f2fa7b4f5c79af191d4a0
1 #!/bin/sh
3 # Copyright (c) 2023 Omar Polo <op@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 format_arg=
20 if [ "${GOT_TEST_ALGO}" = sha256 ]; then
21 format_arg="-A sha256"
24 test_load_bundle() {
25 local testroot=`test_init test_load_bundle`
27 # generate a bundle with all the history of the repository
28 git -C "$testroot/repo" bundle create -q "$testroot/bundle" master
30 # then load it in an empty repository
31 (cd "$testroot/" && gotadmin init $format_arg -b master repo2) >/dev/null
32 (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") \
33 >/dev/null
34 if [ $? -ne 0 ]; then
35 echo "failed to load the bundle" >&2
36 test_done "$testroot" 1
37 return 1
40 (cd "$testroot/repo" && got log -p >$testroot/repo.log)
41 (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
42 if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
43 diff -u $testroot/repo.log $testroot/repo2.log
44 test_done "$testroot" 1
45 return 1
48 base=$(git_show_head "$testroot/repo")
50 echo "modified alpha in master" >$testroot/repo/alpha
51 git_commit "$testroot/repo" -m "edit alpha in master"
53 # XXX git outputs a "thin pack" when making bundles using an
54 # exclude base and doesn't provide a way to generate "thick"
55 # packs; use gotadmin since we don't support them.
56 #git -C "$testroot/repo" bundle create -q \
57 # "$testroot/bundle" "$base..master"
58 gotadmin dump -q -r "$testroot/repo" -x "$base" master \
59 > "$testroot/bundle"
61 (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") >/dev/null
62 if [ $? -ne 0 ]; then
63 echo "failed to load incremental bundle" >&2
64 test_done "$testroot" 1
65 return 1
68 (cd "$testroot/repo" && got log -p >$testroot/repo.log)
69 (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
70 if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
71 diff -u $testroot/repo.log $testroot/repo2.log
72 test_done "$testroot" 1
73 return 1
76 test_done "$testroot" 0
79 test_load_branch_from_bundle() {
80 local testroot=`test_init test_load_branch_from_bundle`
82 echo "modified alpha in master" >$testroot/repo/alpha
83 git_commit "$testroot/repo" -m "edit alpha in master"
85 master_commit="$(git_show_head "$testroot/repo")"
87 git -C "$testroot/repo" checkout -q -b newbranch
89 for i in `seq 1`; do
90 echo "alpha edit #$i" > $testroot/repo/alpha
91 git_commit "$testroot/repo" -m "edit alpha"
92 done
94 newbranch_commit="$(git_show_head "$testroot/repo")"
96 (cd "$testroot/repo" && gotadmin dump -q >$testroot/bundle)
98 (cd "$testroot/" && gotadmin init $format_arg -b newbranch repo2) >/dev/null
100 # check that the reference in the bundle are what we expect
101 (cd "$testroot/repo2" && gotadmin load -l "$testroot/bundle") \
102 >$testroot/stdout
104 cat <<EOF >$testroot/stdout.expected
105 HEAD: $newbranch_commit
106 refs/heads/master: $master_commit
107 refs/heads/newbranch: $newbranch_commit
109 if ! cmp -s "$testroot/stdout" "$testroot/stdout.expected"; then
110 diff -u "$testroot/stdout" "$testroot/stdout.expected"
111 test_done "$testroot" 1
112 return 1
115 (cd "$testroot/repo2" && gotadmin load -q refs/heads/newbranch \
116 <$testroot/bundle)
117 if [ $? -ne 0 ]; then
118 echo "gotadmin load failed unexpectedly" >&2
119 test_done "$testroot" 1
120 return 1
123 # now that the bundle is loaded, delete the branch master on
124 # the repo to have the same got log output.
125 (cd "$testroot/repo" && got branch -d master) >/dev/null
127 (cd "$testroot/repo" && got log -p >$testroot/repo.log)
128 (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
129 if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
130 diff -u $testroot/repo.log $testroot/repo2.log
131 test_done "$testroot" 1
132 return 1
135 test_done "$testroot" 0
138 test_parseargs "$@"
139 run_test test_load_bundle
140 run_test test_load_branch_from_bundle