Blame


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