Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2020 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 . ./common.sh
19 function test_clone_basic {
20 local testroot=`test_init clone_basic`
21 local testurl=ssh://127.0.0.1/$testroot
22 local commit_id=`git_show_head $testroot/repo`
24 got clone -q $testurl/repo $testroot/repo-clone
25 ret="$?"
26 if [ "$ret" != "0" ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 got log -l0 -p -r $testroot/repo > $testroot/log-repo
33 if [ "$ret" != "0" ]; then
34 echo "got log command failed unexpectedly" >&2
35 test_done "$testroot" "$ret"
36 return 1
37 fi
38 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
39 if [ "$ret" != "0" ]; then
40 echo "got log command failed unexpectedly" >&2
41 test_done "$testroot" "$ret"
42 return 1
43 fi
44 cmp -s $testroot/log-repo $testroot/log-repo-clone
45 ret="$?"
46 if [ "$ret" != "0" ]; then
47 echo "log -p output of cloned repository differs" >&2
48 test_done "$testroot" "$ret"
49 return 1
50 fi
52 got ref -l -r $testroot/repo > $testroot/stdout
53 if [ "$ret" != "0" ]; then
54 echo "got ref command failed unexpectedly" >&2
55 test_done "$testroot" "$ret"
56 return 1
57 fi
59 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
60 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
62 cmp -s $testroot/stdout $testroot/stdout.expected
63 ret="$?"
64 if [ "$ret" != "0" ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 got ref -l -r $testroot/repo-clone > $testroot/stdout
71 if [ "$ret" != "0" ]; then
72 echo "got ref command failed unexpectedly" >&2
73 test_done "$testroot" "$ret"
74 return 1
75 fi
77 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
78 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
79 echo "refs/remotes/origin/master: $commit_id" \
80 >> $testroot/stdout.expected
82 cmp -s $testroot/stdout $testroot/stdout.expected
83 ret="$?"
84 if [ "$ret" != "0" ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
86 fi
87 test_done "$testroot" "$ret"
88 }
90 function test_clone_list {
91 local testroot=`test_init clone_list`
92 local testurl=ssh://127.0.0.1/$testroot
93 local commit_id=`git_show_head $testroot/repo`
95 got branch -r $testroot/repo -c $commit_id foo
96 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
97 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
99 got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
100 ret="$?"
101 if [ "$ret" != "0" ]; then
102 echo "got clone command failed unexpectedly" >&2
103 test_done "$testroot" "$ret"
104 return 1
105 fi
107 echo "Connected to 127.0.0.1" > $testroot/stdout.expected
108 got ref -l -r $testroot/repo >> $testroot/stdout.expected
110 cmp -s $testroot/stdout $testroot/stdout.expected
111 ret="$?"
112 if [ "$ret" != "0" ]; then
113 diff -u $testroot/stdout.expected $testroot/stdout
114 fi
115 test_done "$testroot" "$ret"
118 function test_clone_branch {
119 local testroot=`test_init clone_branch`
120 local testurl=ssh://127.0.0.1/$testroot
121 local commit_id=`git_show_head $testroot/repo`
123 got branch -r $testroot/repo -c $commit_id foo
124 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
125 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
126 local tag_id=`got ref -r $testroot/repo -l \
127 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
129 got clone -q -b foo $testurl/repo $testroot/repo-clone
130 ret="$?"
131 if [ "$ret" != "0" ]; then
132 echo "got clone command failed unexpectedly" >&2
133 test_done "$testroot" "$ret"
134 return 1
135 fi
137 got ref -l -r $testroot/repo-clone > $testroot/stdout
139 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
140 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
141 # refs/heads/master is missing because it wasn't passed via -b
142 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
143 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
144 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
146 cmp -s $testroot/stdout $testroot/stdout.expected
147 ret="$?"
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 fi
151 test_done "$testroot" "$ret"
154 function test_clone_all {
155 local testroot=`test_init clone_all`
156 local testurl=ssh://127.0.0.1/$testroot
157 local commit_id=`git_show_head $testroot/repo`
159 got branch -r $testroot/repo -c $commit_id foo
160 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
161 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
162 local tag_id=`got ref -r $testroot/repo -l \
163 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
165 got clone -q -a $testurl/repo $testroot/repo-clone
166 ret="$?"
167 if [ "$ret" != "0" ]; then
168 echo "got clone command failed unexpectedly" >&2
169 test_done "$testroot" "$ret"
170 return 1
171 fi
173 got ref -l -r $testroot/repo-clone > $testroot/stdout
175 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
176 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
177 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
178 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
179 echo "refs/remotes/origin/master: $commit_id" \
180 >> $testroot/stdout.expected
181 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
182 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
184 cmp -s $testroot/stdout $testroot/stdout.expected
185 ret="$?"
186 if [ "$ret" != "0" ]; then
187 diff -u $testroot/stdout.expected $testroot/stdout
188 fi
189 test_done "$testroot" "$ret"
192 function test_clone_mirror {
193 local testroot=`test_init clone_mirror`
194 local testurl=ssh://127.0.0.1/$testroot
195 local commit_id=`git_show_head $testroot/repo`
197 got branch -r $testroot/repo -c $commit_id foo
198 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
199 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
200 local tag_id=`got ref -r $testroot/repo -l \
201 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
203 got clone -q -m $testurl/repo $testroot/repo-clone
204 ret="$?"
205 if [ "$ret" != "0" ]; then
206 echo "got clone command failed unexpectedly" >&2
207 test_done "$testroot" "$ret"
208 return 1
209 fi
211 got ref -l -r $testroot/repo-clone > $testroot/stdout
213 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
214 # refs/heads/foo is missing because we're not fetching all branches
215 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
216 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
217 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
219 cmp -s $testroot/stdout $testroot/stdout.expected
220 ret="$?"
221 if [ "$ret" != "0" ]; then
222 diff -u $testroot/stdout.expected $testroot/stdout
223 fi
224 test_done "$testroot" "$ret"
227 function test_clone_mirror_all {
228 local testroot=`test_init clone_mirror_all`
229 local testurl=ssh://127.0.0.1/$testroot
230 local commit_id=`git_show_head $testroot/repo`
232 got branch -r $testroot/repo -c $commit_id foo
233 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
234 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
235 local tag_id=`got ref -r $testroot/repo -l \
236 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
238 got clone -q -m -a $testurl/repo $testroot/repo-clone
239 ret="$?"
240 if [ "$ret" != "0" ]; then
241 echo "got clone command failed unexpectedly" >&2
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 got ref -l -r $testroot/repo-clone > $testroot/stdout
248 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
249 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
250 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
251 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
252 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
254 cmp -s $testroot/stdout $testroot/stdout.expected
255 ret="$?"
256 if [ "$ret" != "0" ]; then
257 diff -u $testroot/stdout.expected $testroot/stdout
258 fi
259 test_done "$testroot" "$ret"
262 function test_clone_reference {
263 local testroot=`test_init clone_reference`
264 local testurl=ssh://127.0.0.1/$testroot
265 local commit_id=`git_show_head $testroot/repo`
267 got branch -r $testroot/repo -c $commit_id foo
268 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
269 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
270 local tag_id=`got ref -r $testroot/repo -l \
271 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
273 got clone -q -R hoo $testurl/repo $testroot/repo-clone
274 ret="$?"
275 if [ "$ret" != "0" ]; then
276 echo "got clone command failed unexpectedly" >&2
277 test_done "$testroot" "$ret"
278 return 1
279 fi
281 got ref -l -r $testroot/repo-clone > $testroot/stdout
283 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
284 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
285 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
286 >> $testroot/stdout.expected
287 echo "refs/remotes/origin/master: $commit_id" \
288 >> $testroot/stdout.expected
289 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
291 cmp -s $testroot/stdout $testroot/stdout.expected
292 ret="$?"
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/stdout.expected $testroot/stdout
295 fi
296 test_done "$testroot" "$ret"
299 function test_clone_branch_and_reference {
300 local testroot=`test_init clone_reference`
301 local testurl=ssh://127.0.0.1/$testroot
302 local commit_id=`git_show_head $testroot/repo`
304 got branch -r $testroot/repo -c $commit_id foo
305 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
306 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
307 local tag_id=`got ref -r $testroot/repo -l \
308 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
310 got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
311 ret="$?"
312 if [ "$ret" != "0" ]; then
313 echo "got clone command failed unexpectedly" >&2
314 test_done "$testroot" "$ret"
315 return 1
316 fi
318 got ref -l -r $testroot/repo-clone > $testroot/stdout
320 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
321 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
322 echo "refs/remotes/origin/foo: $commit_id" \
323 >> $testroot/stdout.expected
324 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
325 >> $testroot/stdout.expected
326 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
328 cmp -s $testroot/stdout $testroot/stdout.expected
329 ret="$?"
330 if [ "$ret" != "0" ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 fi
333 test_done "$testroot" "$ret"
336 function test_clone_reference_mirror {
337 local testroot=`test_init clone_reference_mirror`
338 local testurl=ssh://127.0.0.1/$testroot
339 local commit_id=`git_show_head $testroot/repo`
341 got branch -r $testroot/repo -c $commit_id foo
342 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
343 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
344 local tag_id=`got ref -r $testroot/repo -l \
345 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
347 got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
348 ret="$?"
349 if [ "$ret" != "0" ]; then
350 echo "got clone command failed unexpectedly" >&2
351 test_done "$testroot" "$ret"
352 return 1
353 fi
355 got ref -l -r $testroot/repo-clone > $testroot/stdout
357 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
358 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
359 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
360 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
362 cmp -s $testroot/stdout $testroot/stdout.expected
363 ret="$?"
364 if [ "$ret" != "0" ]; then
365 diff -u $testroot/stdout.expected $testroot/stdout
366 fi
367 test_done "$testroot" "$ret"
370 run_test test_clone_basic
371 run_test test_clone_list
372 run_test test_clone_branch
373 run_test test_clone_all
374 run_test test_clone_mirror
375 run_test test_clone_mirror_all
376 run_test test_clone_reference
377 run_test test_clone_branch_and_reference
378 run_test test_clone_reference_mirror