Blob


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