Blame


1 6ae16afd 2022-10-31 stsp #!/bin/sh
2 6ae16afd 2022-10-31 stsp #
3 6ae16afd 2022-10-31 stsp # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 6ae16afd 2022-10-31 stsp #
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.
8 6ae16afd 2022-10-31 stsp #
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.
16 6ae16afd 2022-10-31 stsp
17 6ae16afd 2022-10-31 stsp . ../cmdline/common.sh
18 6ae16afd 2022-10-31 stsp . ./common.sh
19 6ae16afd 2022-10-31 stsp
20 6ae16afd 2022-10-31 stsp test_send_basic() {
21 6ae16afd 2022-10-31 stsp local testroot=`test_init send_basic 1`
22 6ae16afd 2022-10-31 stsp
23 6da1c69c 2023-01-18 stsp ls -R ${GOTD_TEST_REPO}/objects/pack > $testroot/repo-list.before
24 6ae16afd 2022-10-31 stsp
25 6ae16afd 2022-10-31 stsp got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
26 6ae16afd 2022-10-31 stsp ret=$?
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"
30 6ae16afd 2022-10-31 stsp return 1
31 6ae16afd 2022-10-31 stsp fi
32 6ae16afd 2022-10-31 stsp
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
35 5dd8d22b 2023-01-09 stsp ret=$?
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"
39 5dd8d22b 2023-01-09 stsp return 1
40 5dd8d22b 2023-01-09 stsp fi
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
44 6da1c69c 2023-01-18 stsp ret=$?
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"
48 6da1c69c 2023-01-18 stsp return 1
49 6da1c69c 2023-01-18 stsp fi
50 5dd8d22b 2023-01-09 stsp
51 6ae16afd 2022-10-31 stsp got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
52 6ae16afd 2022-10-31 stsp ret=$?
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"
56 6ae16afd 2022-10-31 stsp return 1
57 6ae16afd 2022-10-31 stsp fi
58 6ae16afd 2022-10-31 stsp
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
68 6ae16afd 2022-10-31 stsp
69 6da1c69c 2023-01-18 stsp got send -b main -b newbranch -q -r $testroot/repo-clone -t 1.0
70 6ae16afd 2022-10-31 stsp ret=$?
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"
74 6ae16afd 2022-10-31 stsp return 1
75 6ae16afd 2022-10-31 stsp fi
76 6ae16afd 2022-10-31 stsp
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
79 6ae16afd 2022-10-31 stsp ret=$?
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"
83 6ae16afd 2022-10-31 stsp return 1
84 6ae16afd 2022-10-31 stsp fi
85 6ae16afd 2022-10-31 stsp
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
88 6ae16afd 2022-10-31 stsp alpha
89 6ae16afd 2022-10-31 stsp beta
90 6ae16afd 2022-10-31 stsp epsilon/
91 6ae16afd 2022-10-31 stsp epsilon/zeta
92 6ae16afd 2022-10-31 stsp gamma/
93 6ae16afd 2022-10-31 stsp gamma/delta
94 6ae16afd 2022-10-31 stsp psi/
95 6ae16afd 2022-10-31 stsp psi/new
96 6ae16afd 2022-10-31 stsp EOF
97 6ae16afd 2022-10-31 stsp cmp -s $testroot/stdout.expected $testroot/stdout
98 6ae16afd 2022-10-31 stsp ret=$?
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"
102 6ae16afd 2022-10-31 stsp return 1
103 6ae16afd 2022-10-31 stsp fi
104 6ae16afd 2022-10-31 stsp
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)
108 6da1c69c 2023-01-18 stsp ret=$?
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"
112 6da1c69c 2023-01-18 stsp return 1
113 6da1c69c 2023-01-18 stsp fi
114 6da1c69c 2023-01-18 stsp
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"
125 6ae16afd 2022-10-31 stsp return 1
126 6ae16afd 2022-10-31 stsp fi
127 6ae16afd 2022-10-31 stsp egrep -q '\+pack-[a-f0-9]{40}.pack' $testroot/repo-list.newlines
128 6ae16afd 2022-10-31 stsp ret=$?
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"
133 6ae16afd 2022-10-31 stsp return 1
134 6ae16afd 2022-10-31 stsp fi
135 6ae16afd 2022-10-31 stsp egrep -q '\+pack-[a-f0-9]{40}.idx' $testroot/repo-list.newlines
136 6ae16afd 2022-10-31 stsp ret=$?
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"
140 6ae16afd 2022-10-31 stsp return 1
141 6ae16afd 2022-10-31 stsp fi
142 6ae16afd 2022-10-31 stsp
143 6ae16afd 2022-10-31 stsp test_done "$testroot" "$ret"
144 6ae16afd 2022-10-31 stsp }
145 6ae16afd 2022-10-31 stsp
146 f9550d47 2023-01-18 stsp test_fetch_more_history() {
147 f9550d47 2023-01-18 stsp local testroot=`test_init fetch_more_history 1`
148 f9550d47 2023-01-18 stsp
149 f9550d47 2023-01-18 stsp got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
150 f9550d47 2023-01-18 stsp ret=$?
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"
154 f9550d47 2023-01-18 stsp return 1
155 f9550d47 2023-01-18 stsp fi
156 f9550d47 2023-01-18 stsp
157 f9550d47 2023-01-18 stsp got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
158 f9550d47 2023-01-18 stsp ret=$?
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"
162 f9550d47 2023-01-18 stsp return 1
163 f9550d47 2023-01-18 stsp fi
164 f9550d47 2023-01-18 stsp
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)
171 f9550d47 2023-01-18 stsp done
172 f9550d47 2023-01-18 stsp got send -b main -q -r $testroot/repo-clone
173 f9550d47 2023-01-18 stsp ret=$?
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"
177 f9550d47 2023-01-18 stsp return 1
178 f9550d47 2023-01-18 stsp fi
179 f9550d47 2023-01-18 stsp
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
182 f9550d47 2023-01-18 stsp ret=$?
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"
186 f9550d47 2023-01-18 stsp return 1
187 f9550d47 2023-01-18 stsp fi
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
194 f9550d47 2023-01-18 stsp ret=$?
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"
198 f9550d47 2023-01-18 stsp return 1
199 f9550d47 2023-01-18 stsp fi
200 f9550d47 2023-01-18 stsp
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
209 f9550d47 2023-01-18 stsp ret=$?
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"
213 f9550d47 2023-01-18 stsp return 1
214 f9550d47 2023-01-18 stsp fi
215 f9550d47 2023-01-18 stsp
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
218 f9550d47 2023-01-18 stsp ret=$?
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"
222 f9550d47 2023-01-18 stsp return 1
223 f9550d47 2023-01-18 stsp fi
224 f9550d47 2023-01-18 stsp
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
227 f9550d47 2023-01-18 stsp alpha
228 f9550d47 2023-01-18 stsp beta
229 f9550d47 2023-01-18 stsp gamma/
230 f9550d47 2023-01-18 stsp gamma/delta
231 f9550d47 2023-01-18 stsp psi/
232 f9550d47 2023-01-18 stsp psi/new
233 f9550d47 2023-01-18 stsp EOF
234 f9550d47 2023-01-18 stsp cmp -s $testroot/stdout.expected $testroot/stdout
235 f9550d47 2023-01-18 stsp ret=$?
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"
239 f9550d47 2023-01-18 stsp return 1
240 f9550d47 2023-01-18 stsp fi
241 f9550d47 2023-01-18 stsp
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)
245 f9550d47 2023-01-18 stsp ret=$?
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"
249 f9550d47 2023-01-18 stsp return 1
250 f9550d47 2023-01-18 stsp fi
251 f9550d47 2023-01-18 stsp
252 f9550d47 2023-01-18 stsp test_done "$testroot" "$ret"
253 f9550d47 2023-01-18 stsp }
254 0ff2c315 2023-01-18 stsp
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`
257 0ff2c315 2023-01-18 stsp
258 0ff2c315 2023-01-18 stsp got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
259 0ff2c315 2023-01-18 stsp ret=$?
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"
263 0ff2c315 2023-01-18 stsp return 1
264 0ff2c315 2023-01-18 stsp fi
265 0ff2c315 2023-01-18 stsp local commit_id=`git_show_head $testroot/repo-clone`
266 f9550d47 2023-01-18 stsp
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
269 0ff2c315 2023-01-18 stsp ret=$?
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"
273 0ff2c315 2023-01-18 stsp return 1
274 0ff2c315 2023-01-18 stsp fi
275 f9550d47 2023-01-18 stsp
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
278 0ff2c315 2023-01-18 stsp ret=$?
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"
282 0ff2c315 2023-01-18 stsp return 1
283 0ff2c315 2023-01-18 stsp fi
284 0ff2c315 2023-01-18 stsp
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
287 0ff2c315 2023-01-18 stsp ret=$?
288 0ff2c315 2023-01-18 stsp if [ $ret -ne 0 ]; then
289 0ff2c315 2023-01-18 stsp diff -u $testroot/stdout.expected $testroot/stdout
290 0ff2c315 2023-01-18 stsp fi
291 0ff2c315 2023-01-18 stsp
292 0ff2c315 2023-01-18 stsp test_done "$testroot" "$ret"
293 0ff2c315 2023-01-18 stsp }
294 0ff2c315 2023-01-18 stsp
295 0ff2c315 2023-01-18 stsp
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