3 f2900386 2022-10-31 thomas # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
5 f2900386 2022-10-31 thomas # Permission to use, copy, modify, and distribute this software for any
6 f2900386 2022-10-31 thomas # purpose with or without fee is hereby granted, provided that the above
7 f2900386 2022-10-31 thomas # copyright notice and this permission notice appear in all copies.
9 f2900386 2022-10-31 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 f2900386 2022-10-31 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 f2900386 2022-10-31 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 f2900386 2022-10-31 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 f2900386 2022-10-31 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 f2900386 2022-10-31 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 f2900386 2022-10-31 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 f2900386 2022-10-31 thomas . ../cmdline/common.sh
18 f2900386 2022-10-31 thomas . ./common.sh
20 f2900386 2022-10-31 thomas test_send_basic() {
21 f2900386 2022-10-31 thomas local testroot=`test_init send_basic 1`
23 0445d8ec 2023-01-19 thomas ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.before
25 f2900386 2022-10-31 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
27 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
28 f2900386 2022-10-31 thomas echo "got clone failed unexpectedly" >&2
29 f2900386 2022-10-31 thomas test_done "$testroot" "1"
33 c9aa63fb 2023-01-10 thomas # create a second clone to test an incremental fetch with later
34 c9aa63fb 2023-01-10 thomas got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
36 c9aa63fb 2023-01-10 thomas if [ $ret -ne 0 ]; then
37 c9aa63fb 2023-01-10 thomas echo "got clone failed unexpectedly" >&2
38 c9aa63fb 2023-01-10 thomas test_done "$testroot" "1"
41 0445d8ec 2023-01-19 thomas # same for Git
42 0445d8ec 2023-01-19 thomas git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone3 \
43 0445d8ec 2023-01-19 thomas >$testroot/stdout 2>$testroot/stderr
45 0445d8ec 2023-01-19 thomas if [ $ret -ne 0 ]; then
46 0445d8ec 2023-01-19 thomas echo "git clone failed unexpectedly" >&2
47 0445d8ec 2023-01-19 thomas test_done "$testroot" "1"
51 f2900386 2022-10-31 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
53 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
54 f2900386 2022-10-31 thomas echo "got checkout failed unexpectedly" >&2
55 f2900386 2022-10-31 thomas test_done "$testroot" "1"
59 f2900386 2022-10-31 thomas mkdir $testroot/wt/psi
60 f2900386 2022-10-31 thomas echo "new" > $testroot/wt/psi/new
61 f2900386 2022-10-31 thomas (cd $testroot/wt && got add psi/new > /dev/null)
62 f2900386 2022-10-31 thomas echo "more alpha" >> $testroot/wt/alpha
63 f2900386 2022-10-31 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
64 0445d8ec 2023-01-19 thomas (cd $testroot/wt && got branch newbranch >/dev/null)
65 0445d8ec 2023-01-19 thomas echo "even more alpha" >> $testroot/wt/alpha
66 0445d8ec 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
67 0445d8ec 2023-01-19 thomas got tag -r $testroot/repo-clone -m "tagging 1.0" 1.0 >/dev/null
69 0445d8ec 2023-01-19 thomas got send -b main -b newbranch -q -r $testroot/repo-clone -t 1.0
71 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
72 f2900386 2022-10-31 thomas echo "got send failed unexpectedly" >&2
73 f2900386 2022-10-31 thomas test_done "$testroot" "1"
77 f2900386 2022-10-31 thomas # Verify that the send operation worked fine.
78 c9aa63fb 2023-01-10 thomas got fetch -q -r $testroot/repo-clone2
80 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
81 c9aa63fb 2023-01-10 thomas echo "got fetch failed unexpectedly" >&2
82 f2900386 2022-10-31 thomas test_done "$testroot" "1"
86 f2900386 2022-10-31 thomas got tree -R -r $testroot/repo-clone2 > $testroot/stdout
87 f2900386 2022-10-31 thomas cat > $testroot/stdout.expected <<EOF
91 f2900386 2022-10-31 thomas epsilon/zeta
93 f2900386 2022-10-31 thomas gamma/delta
97 f2900386 2022-10-31 thomas cmp -s $testroot/stdout.expected $testroot/stdout
99 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
100 f2900386 2022-10-31 thomas diff -u $testroot/stdout.expected $testroot/stdout
101 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
105 0445d8ec 2023-01-19 thomas # Verify that git pull works, too
106 0445d8ec 2023-01-19 thomas (cd $testroot/repo-clone3 && git pull -q > $testroot/stdout \
107 0445d8ec 2023-01-19 thomas 2> $testroot/stderr)
109 0445d8ec 2023-01-19 thomas if [ $ret -ne 0 ]; then
110 0445d8ec 2023-01-19 thomas echo "git pull failed unexpectedly" >&2
111 0445d8ec 2023-01-19 thomas test_done "$testroot" "1"
115 f2900386 2022-10-31 thomas # sending to a repository should result in a new pack file
116 0445d8ec 2023-01-19 thomas ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.after
117 f2900386 2022-10-31 thomas diff -u $testroot/repo-list.before $testroot/repo-list.after \
118 f2900386 2022-10-31 thomas > $testroot/repo-list.diff
119 f2900386 2022-10-31 thomas grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
120 f2900386 2022-10-31 thomas nplus=`wc -l < $testroot/repo-list.newlines | tr -d ' '`
121 f2900386 2022-10-31 thomas if [ "$nplus" != "2" ]; then
122 0445d8ec 2023-01-19 thomas echo "$nplus new files created:"
123 0445d8ec 2023-01-19 thomas cat $testroot/repo-list.diff
124 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
127 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.pack' $testroot/repo-list.newlines
129 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
130 f2900386 2022-10-31 thomas echo "new pack file not found in ${GOTD_TEST_REPO}"
131 f2900386 2022-10-31 thomas cat $testroot/repo-list.newlines
132 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
135 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.idx' $testroot/repo-list.newlines
137 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
138 f2900386 2022-10-31 thomas echo "new pack index not found in ${GOTD_TEST_REPO}"
139 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
143 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
146 6110f5ef 2023-01-19 thomas test_fetch_more_history() {
147 6110f5ef 2023-01-19 thomas local testroot=`test_init fetch_more_history 1`
149 6110f5ef 2023-01-19 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
151 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
152 6110f5ef 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
153 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
157 6110f5ef 2023-01-19 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
159 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
160 6110f5ef 2023-01-19 thomas echo "got checkout failed unexpectedly" >&2
161 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
165 6110f5ef 2023-01-19 thomas # Create some more commit history on the main branch.
166 6110f5ef 2023-01-19 thomas # History needs to be deep enough to trick 'git pull' into sending
167 6110f5ef 2023-01-19 thomas # a lot of 'have' lines, which triggered a bug in gotd.
168 6110f5ef 2023-01-19 thomas for i in `jot 50`; do
169 6110f5ef 2023-01-19 thomas echo "more alpha" >> $testroot/wt/alpha
170 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
172 6110f5ef 2023-01-19 thomas got send -b main -q -r $testroot/repo-clone
174 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
175 6110f5ef 2023-01-19 thomas echo "got send failed unexpectedly" >&2
176 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
180 6110f5ef 2023-01-19 thomas # create a second clone to test an incremental fetch with later
181 6110f5ef 2023-01-19 thomas got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
183 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
184 6110f5ef 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
185 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
188 6110f5ef 2023-01-19 thomas # same for Git, which used to fail:
189 6110f5ef 2023-01-19 thomas # fetch-pack: protocol error: bad band #69
190 6110f5ef 2023-01-19 thomas # fatal: protocol error: bad pack header
191 6110f5ef 2023-01-19 thomas # gotsh: unexpected 'have' packet
192 6110f5ef 2023-01-19 thomas git clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone3 \
193 6110f5ef 2023-01-19 thomas >$testroot/stdout 2>$testroot/stderr
195 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
196 6110f5ef 2023-01-19 thomas echo "git clone failed unexpectedly" >&2
197 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
201 6110f5ef 2023-01-19 thomas # Create more commit history on the main branch
202 6110f5ef 2023-01-19 thomas echo "more alpha" >> $testroot/wt/alpha
203 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
204 6110f5ef 2023-01-19 thomas echo "more beta" >> $testroot/wt/beta
205 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'more changes' > /dev/null)
206 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got rm epsilon/zeta > /dev/null)
207 6110f5ef 2023-01-19 thomas (cd $testroot/wt && got commit -m 'rm epsilon/zeta' > /dev/null)
208 6110f5ef 2023-01-19 thomas got send -b main -q -r $testroot/repo-clone
210 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
211 6110f5ef 2023-01-19 thomas echo "got send failed unexpectedly" >&2
212 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
216 6110f5ef 2023-01-19 thomas # Verify that the new changes can be fetched
217 6110f5ef 2023-01-19 thomas got fetch -q -r $testroot/repo-clone2
219 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
220 6110f5ef 2023-01-19 thomas echo "got fetch failed unexpectedly" >&2
221 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
225 6110f5ef 2023-01-19 thomas got tree -R -r $testroot/repo-clone2 > $testroot/stdout
226 6110f5ef 2023-01-19 thomas cat > $testroot/stdout.expected <<EOF
230 6110f5ef 2023-01-19 thomas gamma/delta
234 6110f5ef 2023-01-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
236 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
237 6110f5ef 2023-01-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
238 6110f5ef 2023-01-19 thomas test_done "$testroot" "$ret"
242 6110f5ef 2023-01-19 thomas # Verify that git pull works, too
243 6110f5ef 2023-01-19 thomas (cd $testroot/repo-clone3 && git pull -q > $testroot/stdout \
244 6110f5ef 2023-01-19 thomas 2> $testroot/stderr)
246 6110f5ef 2023-01-19 thomas if [ $ret -ne 0 ]; then
247 6110f5ef 2023-01-19 thomas echo "git pull failed unexpectedly" >&2
248 6110f5ef 2023-01-19 thomas test_done "$testroot" "1"
252 6110f5ef 2023-01-19 thomas test_done "$testroot" "$ret"
255 d98779cd 2023-01-19 thomas test_send_new_empty_branch() {
256 d98779cd 2023-01-19 thomas local testroot=`test_init send_new_empty_branch 1`
258 d98779cd 2023-01-19 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
260 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
261 d98779cd 2023-01-19 thomas echo "got clone failed unexpectedly" >&2
262 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
265 d98779cd 2023-01-19 thomas local commit_id=`git_show_head $testroot/repo-clone`
267 d98779cd 2023-01-19 thomas got branch -r $testroot/repo-clone -c main newbranch2 >/dev/null
268 d98779cd 2023-01-19 thomas got send -b newbranch2 -q -r $testroot/repo-clone
270 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
271 d98779cd 2023-01-19 thomas echo "got send failed unexpectedly" >&2
272 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
276 d98779cd 2023-01-19 thomas # Verify that the send operation worked fine.
277 d98779cd 2023-01-19 thomas got clone -l ${GOTD_TEST_REPO_URL} | grep newbranch2 > $testroot/stdout
279 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
280 d98779cd 2023-01-19 thomas echo "got clone -l failed unexpectedly" >&2
281 d98779cd 2023-01-19 thomas test_done "$testroot" "1"
285 d98779cd 2023-01-19 thomas echo "refs/heads/newbranch2: $commit_id" > $testroot/stdout.expected
286 d98779cd 2023-01-19 thomas cmp -s $testroot/stdout.expected $testroot/stdout
288 d98779cd 2023-01-19 thomas if [ $ret -ne 0 ]; then
289 d98779cd 2023-01-19 thomas diff -u $testroot/stdout.expected $testroot/stdout
292 d98779cd 2023-01-19 thomas test_done "$testroot" "$ret"
296 f2900386 2022-10-31 thomas test_parseargs "$@"
297 f2900386 2022-10-31 thomas run_test test_send_basic
298 6110f5ef 2023-01-19 thomas run_test test_fetch_more_history
299 d98779cd 2023-01-19 thomas run_test test_send_new_empty_branch