3 # Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
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.
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.
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
26 if [ "$ret" != "0" ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
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"
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"
44 cmp -s $testroot/log-repo $testroot/log-repo-clone
46 if [ "$ret" != "0" ]; then
47 echo "log -p output of cloned repository differs" >&2
48 test_done "$testroot" "$ret"
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"
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
64 if [ "$ret" != "0" ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 test_done "$testroot" "$ret"
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"
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
84 if [ "$ret" != "0" ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
87 test_done "$testroot" "$ret"
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 -c $commit_id refs/hoo/boo/zoo
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
101 if [ "$ret" != "0" ]; then
102 echo "got clone command failed unexpectedly" >&2
103 test_done "$testroot" "$ret"
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
112 if [ "$ret" != "0" ]; then
113 diff -u $testroot/stdout.expected $testroot/stdout
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 -c $commit_id refs/hoo/boo/zoo
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
131 if [ "$ret" != "0" ]; then
132 echo "got clone command failed unexpectedly" >&2
133 test_done "$testroot" "$ret"
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
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
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 -c $commit_id refs/hoo/boo/zoo
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
167 if [ "$ret" != "0" ]; then
168 echo "got clone command failed unexpectedly" >&2
169 test_done "$testroot" "$ret"
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
186 if [ "$ret" != "0" ]; then
187 diff -u $testroot/stdout.expected $testroot/stdout
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 -c $commit_id refs/hoo/boo/zoo
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
205 if [ "$ret" != "0" ]; then
206 echo "got clone command failed unexpectedly" >&2
207 test_done "$testroot" "$ret"
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
221 if [ "$ret" != "0" ]; then
222 diff -u $testroot/stdout.expected $testroot/stdout
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 -c $commit_id refs/hoo/boo/zoo
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
240 if [ "$ret" != "0" ]; then
241 echo "got clone command failed unexpectedly" >&2
242 test_done "$testroot" "$ret"
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
256 if [ "$ret" != "0" ]; then
257 diff -u $testroot/stdout.expected $testroot/stdout
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 -c $commit_id refs/hoo/boo/zoo
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
275 if [ "$ret" != "0" ]; then
276 echo "got clone command failed unexpectedly" >&2
277 test_done "$testroot" "$ret"
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
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/stdout.expected $testroot/stdout
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 -c $commit_id refs/hoo/boo/zoo
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
312 if [ "$ret" != "0" ]; then
313 echo "got clone command failed unexpectedly" >&2
314 test_done "$testroot" "$ret"
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
330 if [ "$ret" != "0" ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
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 -c $commit_id refs/hoo/boo/zoo
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
349 if [ "$ret" != "0" ]; then
350 echo "got clone command failed unexpectedly" >&2
351 test_done "$testroot" "$ret"
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
364 if [ "$ret" != "0" ]; then
365 diff -u $testroot/stdout.expected $testroot/stdout
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