Blame


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