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.
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/HEAD: refs/remotes/origin/master" \
80 >> $testroot/stdout.expected
81 echo "refs/remotes/origin/master: $commit_id" \
82 >> $testroot/stdout.expected
84 cmp -s $testroot/stdout $testroot/stdout.expected
86 if [ "$ret" != "0" ]; then
87 diff -u $testroot/stdout.expected $testroot/stdout
88 test_done "$testroot" "$ret"
92 cat > $testroot/got.conf.expected <<EOF
96 repository "$testroot/repo"
100 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
102 if [ "$ret" != "0" ]; then
103 diff -u $testroot/got.conf.expected \
104 $testroot/repo-clone/got.conf
105 test_done "$testroot" "$ret"
109 cat > $testroot/config.expected <<EOF
111 repositoryformatversion = 0
116 url = ssh://127.0.0.1$testroot/repo
117 fetch = +refs/heads/master:refs/remotes/origin/master
119 cmp -s $testroot/repo-clone/config $testroot/config.expected
121 if [ "$ret" != "0" ]; then
122 diff -u $testroot/config.expected \
123 $testroot/repo-clone/config
125 test_done "$testroot" "$ret"
129 local testroot=`test_init clone_list`
130 local testurl=ssh://127.0.0.1/$testroot
131 local commit_id=`git_show_head $testroot/repo`
133 got branch -r $testroot/repo -c $commit_id foo
134 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
135 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
137 got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
139 if [ "$ret" != "0" ]; then
140 echo "got clone command failed unexpectedly" >&2
141 test_done "$testroot" "$ret"
145 echo "Connecting to 127.0.0.1" > $testroot/stdout.expected
146 got ref -l -r $testroot/repo >> $testroot/stdout.expected
148 cmp -s $testroot/stdout $testroot/stdout.expected
150 if [ "$ret" != "0" ]; then
151 diff -u $testroot/stdout.expected $testroot/stdout
153 test_done "$testroot" "$ret"
156 test_clone_branch() {
157 local testroot=`test_init clone_branch`
158 local testurl=ssh://127.0.0.1/$testroot
159 local commit_id=`git_show_head $testroot/repo`
161 got branch -r $testroot/repo -c $commit_id foo
162 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
163 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
164 local tag_id=`got ref -r $testroot/repo -l \
165 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
167 got clone -q -b foo $testurl/repo $testroot/repo-clone
169 if [ "$ret" != "0" ]; then
170 echo "got clone command failed unexpectedly" >&2
171 test_done "$testroot" "$ret"
175 got ref -l -r $testroot/repo-clone > $testroot/stdout
177 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
178 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
179 # refs/heads/master is missing because it wasn't passed via -b
180 echo "refs/remotes/origin/foo: $commit_id" >> $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
188 test_done "$testroot" "$ret"
192 cat > $testroot/got.conf.expected <<EOF
196 repository "$testroot/repo"
200 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
202 if [ "$ret" != "0" ]; then
203 diff -u $testroot/got.conf.expected \
204 $testroot/repo-clone/got.conf
205 test_done "$testroot" "$ret"
209 cat > $testroot/config.expected <<EOF
211 repositoryformatversion = 0
216 url = ssh://127.0.0.1$testroot/repo
217 fetch = +refs/heads/foo:refs/remotes/origin/foo
219 cmp -s $testroot/repo-clone/config $testroot/config.expected
221 if [ "$ret" != "0" ]; then
222 diff -u $testroot/config.expected \
223 $testroot/repo-clone/config
225 test_done "$testroot" "$ret"
229 local testroot=`test_init clone_all`
230 local testurl=ssh://127.0.0.1/$testroot
231 local commit_id=`git_show_head $testroot/repo`
233 got branch -r $testroot/repo -c $commit_id foo
234 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
235 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
236 local tag_id=`got ref -r $testroot/repo -l \
237 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
239 got clone -q -a $testurl/repo $testroot/repo-clone
241 if [ "$ret" != "0" ]; then
242 echo "got clone command failed unexpectedly" >&2
243 test_done "$testroot" "$ret"
247 got ref -l -r $testroot/repo-clone > $testroot/stdout
249 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
250 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
251 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
252 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
253 >> $testroot/stdout.expected
254 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
255 echo "refs/remotes/origin/master: $commit_id" \
256 >> $testroot/stdout.expected
257 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
258 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
260 cmp -s $testroot/stdout $testroot/stdout.expected
262 if [ "$ret" != "0" ]; then
263 diff -u $testroot/stdout.expected $testroot/stdout
264 test_done "$testroot" "$ret"
268 cat > $testroot/got.conf.expected <<EOF
272 repository "$testroot/repo"
276 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
278 if [ "$ret" != "0" ]; then
279 diff -u $testroot/got.conf.expected \
280 $testroot/repo-clone/got.conf
281 test_done "$testroot" "$ret"
285 cat > $testroot/config.expected <<EOF
287 repositoryformatversion = 0
292 url = ssh://127.0.0.1$testroot/repo
293 fetch = +refs/heads/*:refs/remotes/origin/*
295 cmp -s $testroot/repo-clone/config $testroot/config.expected
297 if [ "$ret" != "0" ]; then
298 diff -u $testroot/config.expected \
299 $testroot/repo-clone/config
301 test_done "$testroot" "$ret"
304 test_clone_mirror() {
305 local testroot=`test_init clone_mirror`
306 local testurl=ssh://127.0.0.1/$testroot
307 local commit_id=`git_show_head $testroot/repo`
309 got branch -r $testroot/repo -c $commit_id foo
310 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
311 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
312 local tag_id=`got ref -r $testroot/repo -l \
313 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
315 got clone -q -m $testurl/repo $testroot/repo-clone
317 if [ "$ret" != "0" ]; then
318 echo "got clone command failed unexpectedly" >&2
319 test_done "$testroot" "$ret"
323 got ref -l -r $testroot/repo-clone > $testroot/stdout
325 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
326 # refs/heads/foo is missing because we're not fetching all branches
327 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
328 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
329 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
331 cmp -s $testroot/stdout $testroot/stdout.expected
333 if [ "$ret" != "0" ]; then
334 diff -u $testroot/stdout.expected $testroot/stdout
335 test_done "$testroot" "$ret"
339 cat > $testroot/got.conf.expected <<EOF
343 repository "$testroot/repo"
345 mirror-references yes
348 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
350 if [ "$ret" != "0" ]; then
351 diff -u $testroot/got.conf.expected \
352 $testroot/repo-clone/got.conf
353 test_done "$testroot" "$ret"
357 cat > $testroot/config.expected <<EOF
359 repositoryformatversion = 0
364 url = ssh://127.0.0.1$testroot/repo
365 fetch = +refs/*:refs/*
368 cmp -s $testroot/repo-clone/config $testroot/config.expected
370 if [ "$ret" != "0" ]; then
371 diff -u $testroot/config.expected \
372 $testroot/repo-clone/config
374 test_done "$testroot" "$ret"
377 test_clone_mirror_all() {
378 local testroot=`test_init clone_mirror_all`
379 local testurl=ssh://127.0.0.1/$testroot
380 local commit_id=`git_show_head $testroot/repo`
382 got branch -r $testroot/repo -c $commit_id foo
383 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
384 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
385 local tag_id=`got ref -r $testroot/repo -l \
386 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
388 got clone -q -m -a $testurl/repo $testroot/repo-clone
390 if [ "$ret" != "0" ]; then
391 echo "got clone command failed unexpectedly" >&2
392 test_done "$testroot" "$ret"
396 got ref -l -r $testroot/repo-clone > $testroot/stdout
398 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
399 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
400 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
401 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
402 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
404 cmp -s $testroot/stdout $testroot/stdout.expected
406 if [ "$ret" != "0" ]; then
407 diff -u $testroot/stdout.expected $testroot/stdout
408 test_done "$testroot" "$ret"
412 cat > $testroot/got.conf.expected <<EOF
416 repository "$testroot/repo"
418 mirror-references yes
421 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
423 if [ "$ret" != "0" ]; then
424 diff -u $testroot/got.conf.expected \
425 $testroot/repo-clone/got.conf
426 test_done "$testroot" "$ret"
430 cat > $testroot/config.expected <<EOF
432 repositoryformatversion = 0
437 url = ssh://127.0.0.1$testroot/repo
438 fetch = +refs/*:refs/*
441 cmp -s $testroot/repo-clone/config $testroot/config.expected
443 if [ "$ret" != "0" ]; then
444 diff -u $testroot/config.expected \
445 $testroot/repo-clone/config
447 test_done "$testroot" "$ret"
450 test_clone_reference() {
451 local testroot=`test_init clone_reference`
452 local testurl=ssh://127.0.0.1/$testroot
453 local commit_id=`git_show_head $testroot/repo`
455 got branch -r $testroot/repo -c $commit_id foo
456 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
457 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
458 local tag_id=`got ref -r $testroot/repo -l \
459 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
461 got clone -q -R hoo $testurl/repo $testroot/repo-clone
463 if [ "$ret" != "0" ]; then
464 echo "got clone command failed unexpectedly" >&2
465 test_done "$testroot" "$ret"
469 got ref -l -r $testroot/repo-clone > $testroot/stdout
471 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
472 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
473 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
474 >> $testroot/stdout.expected
475 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
476 >> $testroot/stdout.expected
477 echo "refs/remotes/origin/master: $commit_id" \
478 >> $testroot/stdout.expected
479 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
481 cmp -s $testroot/stdout $testroot/stdout.expected
483 if [ "$ret" != "0" ]; then
484 diff -u $testroot/stdout.expected $testroot/stdout
485 test_done "$testroot" "$ret"
489 cat > $testroot/got.conf.expected <<EOF
493 repository "$testroot/repo"
497 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
499 if [ "$ret" != "0" ]; then
500 diff -u $testroot/got.conf.expected \
501 $testroot/repo-clone/got.conf
502 test_done "$testroot" "$ret"
506 cat > $testroot/config.expected <<EOF
508 repositoryformatversion = 0
513 url = ssh://127.0.0.1$testroot/repo
514 fetch = +refs/heads/master:refs/remotes/origin/master
516 cmp -s $testroot/repo-clone/config $testroot/config.expected
518 if [ "$ret" != "0" ]; then
519 diff -u $testroot/config.expected \
520 $testroot/repo-clone/config
522 test_done "$testroot" "$ret"
525 test_clone_branch_and_reference() {
526 local testroot=`test_init clone_reference`
527 local testurl=ssh://127.0.0.1/$testroot
528 local commit_id=`git_show_head $testroot/repo`
530 got branch -r $testroot/repo -c $commit_id foo
531 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
532 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
533 local tag_id=`got ref -r $testroot/repo -l \
534 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
536 got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
538 if [ "$ret" != "0" ]; then
539 echo "got clone command failed unexpectedly" >&2
540 test_done "$testroot" "$ret"
544 got ref -l -r $testroot/repo-clone > $testroot/stdout
546 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
547 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
548 echo "refs/remotes/origin/foo: $commit_id" \
549 >> $testroot/stdout.expected
550 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
551 >> $testroot/stdout.expected
552 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
554 cmp -s $testroot/stdout $testroot/stdout.expected
556 if [ "$ret" != "0" ]; then
557 diff -u $testroot/stdout.expected $testroot/stdout
558 test_done "$testroot" "$ret"
562 cat > $testroot/got.conf.expected <<EOF
566 repository "$testroot/repo"
570 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
572 if [ "$ret" != "0" ]; then
573 diff -u $testroot/got.conf.expected \
574 $testroot/repo-clone/got.conf
575 test_done "$testroot" "$ret"
579 cat > $testroot/config.expected <<EOF
581 repositoryformatversion = 0
586 url = ssh://127.0.0.1$testroot/repo
587 fetch = +refs/heads/foo:refs/remotes/origin/foo
589 cmp -s $testroot/repo-clone/config $testroot/config.expected
591 if [ "$ret" != "0" ]; then
592 diff -u $testroot/config.expected \
593 $testroot/repo-clone/config
595 test_done "$testroot" "$ret"
598 test_clone_reference_mirror() {
599 local testroot=`test_init clone_reference_mirror`
600 local testurl=ssh://127.0.0.1/$testroot
601 local commit_id=`git_show_head $testroot/repo`
603 got branch -r $testroot/repo -c $commit_id foo
604 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
605 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
606 local tag_id=`got ref -r $testroot/repo -l \
607 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
609 got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
611 if [ "$ret" != "0" ]; then
612 echo "got clone command failed unexpectedly" >&2
613 test_done "$testroot" "$ret"
617 got ref -l -r $testroot/repo-clone > $testroot/stdout
619 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
620 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
621 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
622 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
624 cmp -s $testroot/stdout $testroot/stdout.expected
626 if [ "$ret" != "0" ]; then
627 diff -u $testroot/stdout.expected $testroot/stdout
628 test_done "$testroot" "$ret"
632 cat > $testroot/got.conf.expected <<EOF
636 repository "$testroot/repo"
638 mirror-references yes
641 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
643 if [ "$ret" != "0" ]; then
644 diff -u $testroot/got.conf.expected \
645 $testroot/repo-clone/got.conf
646 test_done "$testroot" "$ret"
650 cat > $testroot/config.expected <<EOF
652 repositoryformatversion = 0
657 url = ssh://127.0.0.1$testroot/repo
658 fetch = +refs/*:refs/*
661 cmp -s $testroot/repo-clone/config $testroot/config.expected
663 if [ "$ret" != "0" ]; then
664 diff -u $testroot/config.expected \
665 $testroot/repo-clone/config
667 test_done "$testroot" "$ret"
671 run_test test_clone_basic
672 run_test test_clone_list
673 run_test test_clone_branch
674 run_test test_clone_all
675 run_test test_clone_mirror
676 run_test test_clone_mirror_all
677 run_test test_clone_reference
678 run_test test_clone_branch_and_reference
679 run_test test_clone_reference_mirror