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