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 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 -ne 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 ret=$?
34 if [ $ret -ne 0 ]; then
35 echo "got log command failed unexpectedly" >&2
36 test_done "$testroot" "$ret"
37 return 1
38 fi
39 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
40 ret=$?
41 if [ $ret -ne 0 ]; then
42 echo "got log command failed unexpectedly" >&2
43 test_done "$testroot" "$ret"
44 return 1
45 fi
46 cmp -s $testroot/log-repo $testroot/log-repo-clone
47 ret=$?
48 if [ $ret -ne 0 ]; then
49 echo "log -p output of cloned repository differs" >&2
50 test_done "$testroot" "$ret"
51 return 1
52 fi
54 got ref -l -r $testroot/repo > $testroot/stdout
55 ret=$?
56 if [ $ret -ne 0 ]; then
57 echo "got ref command failed unexpectedly" >&2
58 test_done "$testroot" "$ret"
59 return 1
60 fi
62 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
63 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
65 cmp -s $testroot/stdout $testroot/stdout.expected
66 ret=$?
67 if [ $ret -ne 0 ]; then
68 diff -u $testroot/stdout.expected $testroot/stdout
69 test_done "$testroot" "$ret"
70 return 1
71 fi
73 got ref -l -r $testroot/repo-clone > $testroot/stdout
74 ret=$?
75 if [ $ret -ne 0 ]; then
76 echo "got ref command failed unexpectedly" >&2
77 test_done "$testroot" "$ret"
78 return 1
79 fi
81 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
82 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
83 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
84 >> $testroot/stdout.expected
85 echo "refs/remotes/origin/master: $commit_id" \
86 >> $testroot/stdout.expected
88 cmp -s $testroot/stdout $testroot/stdout.expected
89 ret=$?
90 if [ $ret -ne 0 ]; then
91 diff -u $testroot/stdout.expected $testroot/stdout
92 test_done "$testroot" "$ret"
93 return 1
94 fi
96 cat > $testroot/got.conf.expected <<EOF
97 remote "origin" {
98 server 127.0.0.1
99 protocol ssh
100 repository "$testroot/repo"
101 branch { "master" }
103 EOF
104 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/got.conf.expected \
108 $testroot/repo-clone/got.conf
109 test_done "$testroot" "$ret"
110 return 1
111 fi
113 cat > $testroot/config.expected <<EOF
114 [core]
115 repositoryformatversion = 0
116 filemode = true
117 bare = true
119 [remote "origin"]
120 url = ssh://127.0.0.1$testroot/repo
121 fetch = refs/heads/master:refs/remotes/origin/master
122 fetch = refs/tags/*:refs/tags/*
123 EOF
124 cmp -s $testroot/repo-clone/config $testroot/config.expected
125 ret=$?
126 if [ $ret -ne 0 ]; then
127 diff -u $testroot/config.expected \
128 $testroot/repo-clone/config
129 fi
130 test_done "$testroot" "$ret"
133 test_clone_list() {
134 local testroot=`test_init clone_list`
135 local testurl=ssh://127.0.0.1/$testroot
136 local commit_id=`git_show_head $testroot/repo`
138 got branch -r $testroot/repo -c $commit_id foo
139 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
140 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
142 got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
143 ret=$?
144 if [ $ret -ne 0 ]; then
145 echo "got clone command failed unexpectedly" >&2
146 test_done "$testroot" "$ret"
147 return 1
148 fi
150 echo "Connecting to 127.0.0.1" > $testroot/stdout.expected
151 got ref -l -r $testroot/repo >> $testroot/stdout.expected
153 cmp -s $testroot/stdout $testroot/stdout.expected
154 ret=$?
155 if [ $ret -ne 0 ]; then
156 diff -u $testroot/stdout.expected $testroot/stdout
157 fi
158 test_done "$testroot" "$ret"
161 test_clone_branch() {
162 local testroot=`test_init clone_branch`
163 local testurl=ssh://127.0.0.1/$testroot
164 local commit_id=`git_show_head $testroot/repo`
166 got branch -r $testroot/repo -c $commit_id foo
167 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
168 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
169 local tag_id=`got ref -r $testroot/repo -l \
170 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
172 got clone -q -b foo $testurl/repo $testroot/repo-clone
173 ret=$?
174 if [ $ret -ne 0 ]; then
175 echo "got clone command failed unexpectedly" >&2
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 got ref -l -r $testroot/repo-clone > $testroot/stdout
182 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
183 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
184 # refs/heads/master is missing because it wasn't passed via -b
185 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
186 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
187 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
189 cmp -s $testroot/stdout $testroot/stdout.expected
190 ret=$?
191 if [ $ret -ne 0 ]; then
192 diff -u $testroot/stdout.expected $testroot/stdout
193 test_done "$testroot" "$ret"
194 return 1
195 fi
197 cat > $testroot/got.conf.expected <<EOF
198 remote "origin" {
199 server 127.0.0.1
200 protocol ssh
201 repository "$testroot/repo"
202 branch { "foo" }
204 EOF
205 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
206 ret=$?
207 if [ $ret -ne 0 ]; then
208 diff -u $testroot/got.conf.expected \
209 $testroot/repo-clone/got.conf
210 test_done "$testroot" "$ret"
211 return 1
212 fi
214 cat > $testroot/config.expected <<EOF
215 [core]
216 repositoryformatversion = 0
217 filemode = true
218 bare = true
220 [remote "origin"]
221 url = ssh://127.0.0.1$testroot/repo
222 fetch = refs/heads/foo:refs/remotes/origin/foo
223 fetch = refs/tags/*:refs/tags/*
224 EOF
225 cmp -s $testroot/repo-clone/config $testroot/config.expected
226 ret=$?
227 if [ $ret -ne 0 ]; then
228 diff -u $testroot/config.expected \
229 $testroot/repo-clone/config
230 fi
231 test_done "$testroot" "$ret"
234 test_clone_all() {
235 local testroot=`test_init clone_all`
236 local testurl=ssh://127.0.0.1/$testroot
237 local commit_id=`git_show_head $testroot/repo`
239 got branch -r $testroot/repo -c $commit_id foo
240 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
241 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
242 local tag_id=`got ref -r $testroot/repo -l \
243 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
245 got clone -q -a $testurl/repo $testroot/repo-clone
246 ret=$?
247 if [ $ret -ne 0 ]; then
248 echo "got clone command failed unexpectedly" >&2
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 got ref -l -r $testroot/repo-clone > $testroot/stdout
255 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
256 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
257 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
258 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
259 >> $testroot/stdout.expected
260 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
261 echo "refs/remotes/origin/master: $commit_id" \
262 >> $testroot/stdout.expected
263 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
264 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
266 cmp -s $testroot/stdout $testroot/stdout.expected
267 ret=$?
268 if [ $ret -ne 0 ]; then
269 diff -u $testroot/stdout.expected $testroot/stdout
270 test_done "$testroot" "$ret"
271 return 1
272 fi
274 cat > $testroot/got.conf.expected <<EOF
275 remote "origin" {
276 server 127.0.0.1
277 protocol ssh
278 repository "$testroot/repo"
279 fetch_all_branches yes
281 EOF
282 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
283 ret=$?
284 if [ $ret -ne 0 ]; then
285 diff -u $testroot/got.conf.expected \
286 $testroot/repo-clone/got.conf
287 test_done "$testroot" "$ret"
288 return 1
289 fi
291 cat > $testroot/config.expected <<EOF
292 [core]
293 repositoryformatversion = 0
294 filemode = true
295 bare = true
297 [remote "origin"]
298 url = ssh://127.0.0.1$testroot/repo
299 fetch = refs/heads/*:refs/remotes/origin/*
300 fetch = refs/tags/*:refs/tags/*
301 EOF
302 cmp -s $testroot/repo-clone/config $testroot/config.expected
303 ret=$?
304 if [ $ret -ne 0 ]; then
305 diff -u $testroot/config.expected \
306 $testroot/repo-clone/config
307 fi
308 test_done "$testroot" "$ret"
311 test_clone_mirror() {
312 local testroot=`test_init clone_mirror`
313 local testurl=ssh://127.0.0.1/$testroot
314 local commit_id=`git_show_head $testroot/repo`
316 got branch -r $testroot/repo -c $commit_id foo
317 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
318 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
319 local tag_id=`got ref -r $testroot/repo -l \
320 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
322 got clone -q -m $testurl/repo $testroot/repo-clone
323 ret=$?
324 if [ $ret -ne 0 ]; then
325 echo "got clone command failed unexpectedly" >&2
326 test_done "$testroot" "$ret"
327 return 1
328 fi
330 got ref -l -r $testroot/repo-clone > $testroot/stdout
332 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
333 # refs/heads/foo is missing because we're not fetching all branches
334 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
335 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
336 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
338 cmp -s $testroot/stdout $testroot/stdout.expected
339 ret=$?
340 if [ $ret -ne 0 ]; then
341 diff -u $testroot/stdout.expected $testroot/stdout
342 test_done "$testroot" "$ret"
343 return 1
344 fi
346 cat > $testroot/got.conf.expected <<EOF
347 remote "origin" {
348 server 127.0.0.1
349 protocol ssh
350 repository "$testroot/repo"
351 branch { "master" }
352 mirror_references yes
354 EOF
355 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
356 ret=$?
357 if [ $ret -ne 0 ]; then
358 diff -u $testroot/got.conf.expected \
359 $testroot/repo-clone/got.conf
360 test_done "$testroot" "$ret"
361 return 1
362 fi
364 cat > $testroot/config.expected <<EOF
365 [core]
366 repositoryformatversion = 0
367 filemode = true
368 bare = true
370 [remote "origin"]
371 url = ssh://127.0.0.1$testroot/repo
372 fetch = refs/heads/master:refs/heads/master
373 fetch = refs/tags/*:refs/tags/*
374 EOF
375 cmp -s $testroot/repo-clone/config $testroot/config.expected
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/config.expected \
379 $testroot/repo-clone/config
380 fi
381 test_done "$testroot" "$ret"
384 test_clone_mirror_all() {
385 local testroot=`test_init clone_mirror_all`
386 local testurl=ssh://127.0.0.1/$testroot
387 local commit_id=`git_show_head $testroot/repo`
389 got branch -r $testroot/repo -c $commit_id foo
390 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
391 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
392 local tag_id=`got ref -r $testroot/repo -l \
393 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
395 got clone -q -m -a $testurl/repo $testroot/repo-clone
396 ret=$?
397 if [ $ret -ne 0 ]; then
398 echo "got clone command failed unexpectedly" >&2
399 test_done "$testroot" "$ret"
400 return 1
401 fi
403 got ref -l -r $testroot/repo-clone > $testroot/stdout
405 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
406 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
407 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
408 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
409 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
411 cmp -s $testroot/stdout $testroot/stdout.expected
412 ret=$?
413 if [ $ret -ne 0 ]; then
414 diff -u $testroot/stdout.expected $testroot/stdout
415 test_done "$testroot" "$ret"
416 return 1
417 fi
419 cat > $testroot/got.conf.expected <<EOF
420 remote "origin" {
421 server 127.0.0.1
422 protocol ssh
423 repository "$testroot/repo"
424 mirror_references yes
425 fetch_all_branches yes
427 EOF
428 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
429 ret=$?
430 if [ $ret -ne 0 ]; then
431 diff -u $testroot/got.conf.expected \
432 $testroot/repo-clone/got.conf
433 test_done "$testroot" "$ret"
434 return 1
435 fi
437 cat > $testroot/config.expected <<EOF
438 [core]
439 repositoryformatversion = 0
440 filemode = true
441 bare = true
443 [remote "origin"]
444 url = ssh://127.0.0.1$testroot/repo
445 fetch = refs/heads/*:refs/heads/*
446 fetch = refs/tags/*:refs/tags/*
447 EOF
448 cmp -s $testroot/repo-clone/config $testroot/config.expected
449 ret=$?
450 if [ $ret -ne 0 ]; then
451 diff -u $testroot/config.expected \
452 $testroot/repo-clone/config
453 fi
454 test_done "$testroot" "$ret"
457 test_clone_reference() {
458 local testroot=`test_init clone_reference`
459 local testurl=ssh://127.0.0.1/$testroot
460 local commit_id=`git_show_head $testroot/repo`
462 got branch -r $testroot/repo -c $commit_id foo
463 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
464 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
465 local tag_id=`got ref -r $testroot/repo -l \
466 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
468 got clone -q -R hoo $testurl/repo $testroot/repo-clone
469 ret=$?
470 if [ $ret -ne 0 ]; then
471 echo "got clone command failed unexpectedly" >&2
472 test_done "$testroot" "$ret"
473 return 1
474 fi
476 got ref -l -r $testroot/repo-clone > $testroot/stdout
478 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
479 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
480 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
481 >> $testroot/stdout.expected
482 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
483 >> $testroot/stdout.expected
484 echo "refs/remotes/origin/master: $commit_id" \
485 >> $testroot/stdout.expected
486 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
488 cmp -s $testroot/stdout $testroot/stdout.expected
489 ret=$?
490 if [ $ret -ne 0 ]; then
491 diff -u $testroot/stdout.expected $testroot/stdout
492 test_done "$testroot" "$ret"
493 return 1
494 fi
496 cat > $testroot/got.conf.expected <<EOF
497 remote "origin" {
498 server 127.0.0.1
499 protocol ssh
500 repository "$testroot/repo"
501 branch { "master" }
502 reference { "hoo" }
504 EOF
505 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
506 ret=$?
507 if [ $ret -ne 0 ]; then
508 diff -u $testroot/got.conf.expected \
509 $testroot/repo-clone/got.conf
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 cat > $testroot/config.expected <<EOF
515 [core]
516 repositoryformatversion = 0
517 filemode = true
518 bare = true
520 [remote "origin"]
521 url = ssh://127.0.0.1$testroot/repo
522 fetch = refs/heads/master:refs/remotes/origin/master
523 fetch = refs/hoo:refs/remotes/origin/hoo
524 fetch = refs/tags/*:refs/tags/*
525 EOF
526 cmp -s $testroot/repo-clone/config $testroot/config.expected
527 ret=$?
528 if [ $ret -ne 0 ]; then
529 diff -u $testroot/config.expected \
530 $testroot/repo-clone/config
531 fi
532 test_done "$testroot" "$ret"
535 test_clone_branch_and_reference() {
536 local testroot=`test_init clone_reference`
537 local testurl=ssh://127.0.0.1/$testroot
538 local commit_id=`git_show_head $testroot/repo`
540 got branch -r $testroot/repo -c $commit_id foo
541 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
542 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
543 local tag_id=`got ref -r $testroot/repo -l \
544 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
546 got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
547 ret=$?
548 if [ $ret -ne 0 ]; then
549 echo "got clone command failed unexpectedly" >&2
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 got ref -l -r $testroot/repo-clone > $testroot/stdout
556 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
557 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
558 echo "refs/remotes/origin/foo: $commit_id" \
559 >> $testroot/stdout.expected
560 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
561 >> $testroot/stdout.expected
562 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
564 cmp -s $testroot/stdout $testroot/stdout.expected
565 ret=$?
566 if [ $ret -ne 0 ]; then
567 diff -u $testroot/stdout.expected $testroot/stdout
568 test_done "$testroot" "$ret"
569 return 1
570 fi
572 cat > $testroot/got.conf.expected <<EOF
573 remote "origin" {
574 server 127.0.0.1
575 protocol ssh
576 repository "$testroot/repo"
577 branch { "foo" }
578 reference { "hoo/boo/zoo" }
580 EOF
581 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
582 ret=$?
583 if [ $ret -ne 0 ]; then
584 diff -u $testroot/got.conf.expected \
585 $testroot/repo-clone/got.conf
586 test_done "$testroot" "$ret"
587 return 1
588 fi
590 cat > $testroot/config.expected <<EOF
591 [core]
592 repositoryformatversion = 0
593 filemode = true
594 bare = true
596 [remote "origin"]
597 url = ssh://127.0.0.1$testroot/repo
598 fetch = refs/heads/foo:refs/remotes/origin/foo
599 fetch = refs/hoo/boo/zoo:refs/remotes/origin/hoo/boo/zoo
600 fetch = refs/tags/*:refs/tags/*
601 EOF
602 cmp -s $testroot/repo-clone/config $testroot/config.expected
603 ret=$?
604 if [ $ret -ne 0 ]; then
605 diff -u $testroot/config.expected \
606 $testroot/repo-clone/config
607 fi
608 test_done "$testroot" "$ret"
611 test_clone_reference_mirror() {
612 local testroot=`test_init clone_reference_mirror`
613 local testurl=ssh://127.0.0.1/$testroot
614 local commit_id=`git_show_head $testroot/repo`
616 got branch -r $testroot/repo -c $commit_id foo
617 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
618 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
619 local tag_id=`got ref -r $testroot/repo -l \
620 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
622 got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
623 ret=$?
624 if [ $ret -ne 0 ]; then
625 echo "got clone command failed unexpectedly" >&2
626 test_done "$testroot" "$ret"
627 return 1
628 fi
630 got ref -l -r $testroot/repo-clone > $testroot/stdout
632 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
633 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
634 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
635 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
637 cmp -s $testroot/stdout $testroot/stdout.expected
638 ret=$?
639 if [ $ret -ne 0 ]; then
640 diff -u $testroot/stdout.expected $testroot/stdout
641 test_done "$testroot" "$ret"
642 return 1
643 fi
645 cat > $testroot/got.conf.expected <<EOF
646 remote "origin" {
647 server 127.0.0.1
648 protocol ssh
649 repository "$testroot/repo"
650 branch { "master" }
651 reference { "hoo" }
652 mirror_references yes
654 EOF
655 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
656 ret=$?
657 if [ $ret -ne 0 ]; then
658 diff -u $testroot/got.conf.expected \
659 $testroot/repo-clone/got.conf
660 test_done "$testroot" "$ret"
661 return 1
662 fi
664 cat > $testroot/config.expected <<EOF
665 [core]
666 repositoryformatversion = 0
667 filemode = true
668 bare = true
670 [remote "origin"]
671 url = ssh://127.0.0.1$testroot/repo
672 fetch = refs/heads/master:refs/heads/master
673 fetch = refs/hoo:refs/hoo
674 fetch = refs/tags/*:refs/tags/*
675 EOF
676 cmp -s $testroot/repo-clone/config $testroot/config.expected
677 ret=$?
678 if [ $ret -ne 0 ]; then
679 diff -u $testroot/config.expected \
680 $testroot/repo-clone/config
681 fi
682 test_done "$testroot" "$ret"
685 test_clone_multiple_branches() {
686 local testroot=`test_init clone_multiple_branches`
687 local testurl=ssh://127.0.0.1/$testroot
688 local commit_id=`git_show_head $testroot/repo`
690 got branch -r $testroot/repo -c $commit_id foo
691 got branch -r $testroot/repo -c $commit_id bar
693 got clone -q -b foo -b bar $testurl/repo $testroot/repo-clone
694 ret=$?
695 if [ $ret -ne 0 ]; then
696 echo "got clone command failed unexpectedly" >&2
697 test_done "$testroot" "$ret"
698 return 1
699 fi
701 got ref -l -r $testroot/repo-clone > $testroot/stdout
703 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
704 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
705 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
706 echo "refs/remotes/origin/bar: $commit_id" \
707 >> $testroot/stdout.expected
708 echo "refs/remotes/origin/foo: $commit_id" \
709 >> $testroot/stdout.expected
711 cmp -s $testroot/stdout $testroot/stdout.expected
712 ret=$?
713 if [ $ret -ne 0 ]; then
714 diff -u $testroot/stdout.expected $testroot/stdout
715 test_done "$testroot" "$ret"
716 return 1
717 fi
719 cat > $testroot/got.conf.expected <<EOF
720 remote "origin" {
721 server 127.0.0.1
722 protocol ssh
723 repository "$testroot/repo"
724 branch { "foo" "bar" }
726 EOF
727 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
728 ret=$?
729 if [ $ret -ne 0 ]; then
730 diff -u $testroot/got.conf.expected \
731 $testroot/repo-clone/got.conf
732 test_done "$testroot" "$ret"
733 return 1
734 fi
736 cat > $testroot/config.expected <<EOF
737 [core]
738 repositoryformatversion = 0
739 filemode = true
740 bare = true
742 [remote "origin"]
743 url = ssh://127.0.0.1$testroot/repo
744 fetch = refs/heads/foo:refs/remotes/origin/foo
745 fetch = refs/heads/bar:refs/remotes/origin/bar
746 fetch = refs/tags/*:refs/tags/*
747 EOF
748 cmp -s $testroot/repo-clone/config $testroot/config.expected
749 ret=$?
750 if [ $ret -ne 0 ]; then
751 diff -u $testroot/config.expected \
752 $testroot/repo-clone/config
753 fi
754 test_done "$testroot" "$ret"
757 test_parseargs "$@"
758 run_test test_clone_basic
759 run_test test_clone_list
760 run_test test_clone_branch
761 run_test test_clone_all
762 run_test test_clone_mirror
763 run_test test_clone_mirror_all
764 run_test test_clone_reference
765 run_test test_clone_branch_and_reference
766 run_test test_clone_reference_mirror
767 run_test test_clone_multiple_branches