Blame


1 90afc9f3 2023-07-10 thomas #!/bin/sh
2 90afc9f3 2023-07-10 thomas #
3 90afc9f3 2023-07-10 thomas # Copyright (c) 2023 Omar Polo <op@openbsd.org>
4 90afc9f3 2023-07-10 thomas #
5 90afc9f3 2023-07-10 thomas # Permission to use, copy, modify, and distribute this software for any
6 90afc9f3 2023-07-10 thomas # purpose with or without fee is hereby granted, provided that the above
7 90afc9f3 2023-07-10 thomas # copyright notice and this permission notice appear in all copies.
8 90afc9f3 2023-07-10 thomas #
9 90afc9f3 2023-07-10 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 90afc9f3 2023-07-10 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 90afc9f3 2023-07-10 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 90afc9f3 2023-07-10 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 90afc9f3 2023-07-10 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 90afc9f3 2023-07-10 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 90afc9f3 2023-07-10 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 90afc9f3 2023-07-10 thomas
17 90afc9f3 2023-07-10 thomas . ./common.sh
18 90afc9f3 2023-07-10 thomas
19 90afc9f3 2023-07-10 thomas test_load_bundle() {
20 90afc9f3 2023-07-10 thomas local testroot=`test_init test_load_bundle`
21 90afc9f3 2023-07-10 thomas
22 90afc9f3 2023-07-10 thomas # generate a bundle with all the history of the repository
23 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" bundle create -q "$testroot/bundle" master
24 90afc9f3 2023-07-10 thomas
25 90afc9f3 2023-07-10 thomas # then load it in an empty repository
26 90afc9f3 2023-07-10 thomas (cd "$testroot/" && gotadmin init -b master repo2) >/dev/null
27 cfbfa60c 2023-07-11 thomas (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") \
28 90afc9f3 2023-07-10 thomas >/dev/null
29 90afc9f3 2023-07-10 thomas if [ $? -ne 0 ]; then
30 90afc9f3 2023-07-10 thomas echo "failed to load the bundle" >&2
31 90afc9f3 2023-07-10 thomas test_done "$testroot" 1
32 90afc9f3 2023-07-10 thomas return 1
33 90afc9f3 2023-07-10 thomas fi
34 90afc9f3 2023-07-10 thomas
35 90afc9f3 2023-07-10 thomas (cd "$testroot/repo" && got log -p >$testroot/repo.log)
36 90afc9f3 2023-07-10 thomas (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
37 90afc9f3 2023-07-10 thomas if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
38 90afc9f3 2023-07-10 thomas diff -u $testroot/repo.log $testroot/repo2.log
39 90afc9f3 2023-07-10 thomas test_done "$testroot" 1
40 90afc9f3 2023-07-10 thomas return 1
41 90afc9f3 2023-07-10 thomas fi
42 90afc9f3 2023-07-10 thomas
43 90afc9f3 2023-07-10 thomas base=$(git_show_head "$testroot/repo")
44 90afc9f3 2023-07-10 thomas
45 90afc9f3 2023-07-10 thomas echo "modified alpha in master" >$testroot/repo/alpha
46 90afc9f3 2023-07-10 thomas git_commit "$testroot/repo" -m "edit alpha in master"
47 90afc9f3 2023-07-10 thomas
48 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" bundle create -q \
49 d1e03b8c 2023-10-08 thomas "$testroot/bundle" "$base..master"
50 90afc9f3 2023-07-10 thomas
51 cfbfa60c 2023-07-11 thomas (cd "$testroot/repo2" && gotadmin load < "$testroot/bundle") >/dev/null
52 90afc9f3 2023-07-10 thomas if [ $? -ne 0 ]; then
53 90afc9f3 2023-07-10 thomas echo "failed to load incremental bundle" >&2
54 90afc9f3 2023-07-10 thomas test_done "$testroot" 1
55 90afc9f3 2023-07-10 thomas return 1
56 90afc9f3 2023-07-10 thomas fi
57 90afc9f3 2023-07-10 thomas
58 90afc9f3 2023-07-10 thomas (cd "$testroot/repo" && got log -p >$testroot/repo.log)
59 90afc9f3 2023-07-10 thomas (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
60 90afc9f3 2023-07-10 thomas if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
61 90afc9f3 2023-07-10 thomas diff -u $testroot/repo.log $testroot/repo2.log
62 90afc9f3 2023-07-10 thomas test_done "$testroot" 1
63 90afc9f3 2023-07-10 thomas return 1
64 90afc9f3 2023-07-10 thomas fi
65 90afc9f3 2023-07-10 thomas
66 90afc9f3 2023-07-10 thomas test_done "$testroot" 0
67 90afc9f3 2023-07-10 thomas }
68 90afc9f3 2023-07-10 thomas
69 90afc9f3 2023-07-10 thomas test_load_branch_from_bundle() {
70 90afc9f3 2023-07-10 thomas local testroot=`test_init test_load_branch_from_bundle`
71 90afc9f3 2023-07-10 thomas
72 90afc9f3 2023-07-10 thomas echo "modified alpha in master" >$testroot/repo/alpha
73 90afc9f3 2023-07-10 thomas git_commit "$testroot/repo" -m "edit alpha in master"
74 90afc9f3 2023-07-10 thomas
75 90afc9f3 2023-07-10 thomas master_commit="$(git_show_head "$testroot/repo")"
76 90afc9f3 2023-07-10 thomas
77 d1e03b8c 2023-10-08 thomas git -C "$testroot/repo" checkout -q -b newbranch
78 90afc9f3 2023-07-10 thomas
79 90afc9f3 2023-07-10 thomas for i in `seq 1`; do
80 90afc9f3 2023-07-10 thomas echo "alpha edit #$i" > $testroot/repo/alpha
81 90afc9f3 2023-07-10 thomas git_commit "$testroot/repo" -m "edit alpha"
82 90afc9f3 2023-07-10 thomas done
83 90afc9f3 2023-07-10 thomas
84 90afc9f3 2023-07-10 thomas newbranch_commit="$(git_show_head "$testroot/repo")"
85 90afc9f3 2023-07-10 thomas
86 90afc9f3 2023-07-10 thomas (cd "$testroot/repo" && gotadmin dump -q >$testroot/bundle)
87 90afc9f3 2023-07-10 thomas
88 90afc9f3 2023-07-10 thomas (cd "$testroot/" && gotadmin init -b newbranch repo2) >/dev/null
89 90afc9f3 2023-07-10 thomas
90 90afc9f3 2023-07-10 thomas # check that the reference in the bundle are what we expect
91 90afc9f3 2023-07-10 thomas (cd "$testroot/repo2" && gotadmin load -l "$testroot/bundle") \
92 90afc9f3 2023-07-10 thomas >$testroot/stdout
93 90afc9f3 2023-07-10 thomas
94 90afc9f3 2023-07-10 thomas cat <<EOF >$testroot/stdout.expected
95 90afc9f3 2023-07-10 thomas HEAD: $newbranch_commit
96 90afc9f3 2023-07-10 thomas refs/heads/master: $master_commit
97 90afc9f3 2023-07-10 thomas refs/heads/newbranch: $newbranch_commit
98 90afc9f3 2023-07-10 thomas EOF
99 90afc9f3 2023-07-10 thomas if ! cmp -s "$testroot/stdout" "$testroot/stdout.expected"; then
100 90afc9f3 2023-07-10 thomas diff -u "$testroot/stdout" "$testroot/stdout.expected"
101 90afc9f3 2023-07-10 thomas test_done "$testroot" 1
102 90afc9f3 2023-07-10 thomas return 1
103 90afc9f3 2023-07-10 thomas fi
104 90afc9f3 2023-07-10 thomas
105 cfbfa60c 2023-07-11 thomas (cd "$testroot/repo2" && gotadmin load -q refs/heads/newbranch \
106 90afc9f3 2023-07-10 thomas <$testroot/bundle)
107 90afc9f3 2023-07-10 thomas if [ $? -ne 0 ]; then
108 90afc9f3 2023-07-10 thomas echo "gotadmin load failed unexpectedly" >&2
109 90afc9f3 2023-07-10 thomas test_done "$testroot" 1
110 90afc9f3 2023-07-10 thomas return 1
111 90afc9f3 2023-07-10 thomas fi
112 90afc9f3 2023-07-10 thomas
113 90afc9f3 2023-07-10 thomas # now that the bundle is loaded, delete the branch master on
114 90afc9f3 2023-07-10 thomas # the repo to have the same got log output.
115 90afc9f3 2023-07-10 thomas (cd "$testroot/repo" && got branch -d master) >/dev/null
116 90afc9f3 2023-07-10 thomas
117 90afc9f3 2023-07-10 thomas (cd "$testroot/repo" && got log -p >$testroot/repo.log)
118 90afc9f3 2023-07-10 thomas (cd "$testroot/repo2" && got log -p >$testroot/repo2.log)
119 90afc9f3 2023-07-10 thomas if ! cmp -s $testroot/repo.log $testroot/repo2.log; then
120 90afc9f3 2023-07-10 thomas diff -u $testroot/repo.log $testroot/repo2.log
121 90afc9f3 2023-07-10 thomas test_done "$testroot" 1
122 90afc9f3 2023-07-10 thomas return 1
123 90afc9f3 2023-07-10 thomas fi
124 90afc9f3 2023-07-10 thomas
125 90afc9f3 2023-07-10 thomas test_done "$testroot" 0
126 90afc9f3 2023-07-10 thomas }
127 90afc9f3 2023-07-10 thomas
128 90afc9f3 2023-07-10 thomas test_parseargs "$@"
129 90afc9f3 2023-07-10 thomas run_test test_load_bundle
130 90afc9f3 2023-07-10 thomas run_test test_load_branch_from_bundle