Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2023 Omar Polo <op@openbsd.org>
4 #
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.
8 #
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 test_load_bundle() {
20 local testroot=`test_init test_load_bundle`
22 # generate a bundle with all the history of the repository
23 git -C "$testroot/repo" bundle create -q "$testroot/bundle" master
25 # then load it in an empty repository
26 (cd "$testroot/" && gotadmin init -b master repo2) >/dev/null
27 (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") \
28 >/dev/null
29 if [ $? -ne 0 ]; then
30 echo "failed to load the bundle" >&2
31 test_done "$testroot" 1
32 return 1
33 fi
35 (cd "$testroot/repo" && got log -p >$testroot/repo.log)
36 (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
37 if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
38 diff -u $testroot/repo.log $testroot/repo2.log
39 test_done "$testroot" 1
40 return 1
41 fi
43 base=$(git_show_head "$testroot/repo")
45 echo "modified alpha in master" >$testroot/repo/alpha
46 git_commit "$testroot/repo" -m "edit alpha in master"
48 git -C "$testroot/repo" bundle create -q \
49 "$testroot/bundle" "$base..master"
51 (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") >/dev/null
52 if [ $? -ne 0 ]; then
53 echo "failed to load incremental bundle" >&2
54 test_done "$testroot" 1
55 return 1
56 fi
58 (cd "$testroot/repo" && got log -p >$testroot/repo.log)
59 (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
60 if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
61 diff -u $testroot/repo.log $testroot/repo2.log
62 test_done "$testroot" 1
63 return 1
64 fi
66 test_done "$testroot" 0
67 }
69 test_load_branch_from_bundle() {
70 local testroot=`test_init test_load_branch_from_bundle`
72 echo "modified alpha in master" >$testroot/repo/alpha
73 git_commit "$testroot/repo" -m "edit alpha in master"
75 master_commit="$(git_show_head "$testroot/repo")"
77 git -C "$testroot/repo" checkout -q -b newbranch
79 for i in `seq 1`; do
80 echo "alpha edit #$i" > $testroot/repo/alpha
81 git_commit "$testroot/repo" -m "edit alpha"
82 done
84 newbranch_commit="$(git_show_head "$testroot/repo")"
86 (cd "$testroot/repo" && gotadmin dump -q >$testroot/bundle)
88 (cd "$testroot/" && gotadmin init -b newbranch repo2) >/dev/null
90 # check that the reference in the bundle are what we expect
91 (cd "$testroot/repo2" && gotadmin load -l "$testroot/bundle") \
92 >$testroot/stdout
94 cat <<EOF >$testroot/stdout.expected
95 HEAD: $newbranch_commit
96 refs/heads/master: $master_commit
97 refs/heads/newbranch: $newbranch_commit
98 EOF
99 if ! cmp -s "$testroot/stdout" "$testroot/stdout.expected"; then
100 diff -u "$testroot/stdout" "$testroot/stdout.expected"
101 test_done "$testroot" 1
102 return 1
103 fi
105 (cd "$testroot/repo2" && gotadmin load -q refs/heads/newbranch \
106 <$testroot/bundle)
107 if [ $? -ne 0 ]; then
108 echo "gotadmin load failed unexpectedly" >&2
109 test_done "$testroot" 1
110 return 1
111 fi
113 # now that the bundle is loaded, delete the branch master on
114 # the repo to have the same got log output.
115 (cd "$testroot/repo" && got branch -d master) >/dev/null
117 (cd "$testroot/repo" && got log -p >$testroot/repo.log)
118 (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
119 if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
120 diff -u $testroot/repo.log $testroot/repo2.log
121 test_done "$testroot" 1
122 return 1
123 fi
125 test_done "$testroot" 0
128 test_parseargs "$@"
129 run_test test_load_bundle
130 run_test test_load_branch_from_bundle