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" != "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/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
85 ret="$?"
86 if [ "$ret" != "0" ]; then
87 diff -u $testroot/stdout.expected $testroot/stdout
88 test_done "$testroot" "$ret"
89 return 1
90 fi
92 cat > $testroot/got.conf.expected <<EOF
93 remote "origin" {
94 server 127.0.0.1
95 protocol ssh
96 repository "$testroot/repo"
97 branch { "master" }
98 }
99 EOF
100 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
101 ret="$?"
102 if [ "$ret" != "0" ]; then
103 diff -u $testroot/got.conf.expected \
104 $testroot/repo-clone/got.conf
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 cat > $testroot/config.expected <<EOF
110 [core]
111 repositoryformatversion = 0
112 filemode = true
113 bare = true
115 [remote "origin"]
116 url = ssh://127.0.0.1$testroot/repo
117 fetch = refs/heads/master:refs/remotes/origin/master
118 fetch = refs/tags/*:refs/tags/*
119 EOF
120 cmp -s $testroot/repo-clone/config $testroot/config.expected
121 ret="$?"
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/config.expected \
124 $testroot/repo-clone/config
125 fi
126 test_done "$testroot" "$ret"
129 test_clone_list() {
130 local testroot=`test_init clone_list`
131 local testurl=ssh://127.0.0.1/$testroot
132 local commit_id=`git_show_head $testroot/repo`
134 got branch -r $testroot/repo -c $commit_id foo
135 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
136 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
138 got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 echo "got clone command failed unexpectedly" >&2
142 test_done "$testroot" "$ret"
143 return 1
144 fi
146 echo "Connecting to 127.0.0.1" > $testroot/stdout.expected
147 got ref -l -r $testroot/repo >> $testroot/stdout.expected
149 cmp -s $testroot/stdout $testroot/stdout.expected
150 ret="$?"
151 if [ "$ret" != "0" ]; then
152 diff -u $testroot/stdout.expected $testroot/stdout
153 fi
154 test_done "$testroot" "$ret"
157 test_clone_branch() {
158 local testroot=`test_init clone_branch`
159 local testurl=ssh://127.0.0.1/$testroot
160 local commit_id=`git_show_head $testroot/repo`
162 got branch -r $testroot/repo -c $commit_id foo
163 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
164 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
165 local tag_id=`got ref -r $testroot/repo -l \
166 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
168 got clone -q -b foo $testurl/repo $testroot/repo-clone
169 ret="$?"
170 if [ "$ret" != "0" ]; then
171 echo "got clone command failed unexpectedly" >&2
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 got ref -l -r $testroot/repo-clone > $testroot/stdout
178 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
179 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
180 # refs/heads/master is missing because it wasn't passed via -b
181 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
182 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
183 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
185 cmp -s $testroot/stdout $testroot/stdout.expected
186 ret="$?"
187 if [ "$ret" != "0" ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$ret"
190 return 1
191 fi
193 cat > $testroot/got.conf.expected <<EOF
194 remote "origin" {
195 server 127.0.0.1
196 protocol ssh
197 repository "$testroot/repo"
198 branch { "foo" }
200 EOF
201 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
202 ret="$?"
203 if [ "$ret" != "0" ]; then
204 diff -u $testroot/got.conf.expected \
205 $testroot/repo-clone/got.conf
206 test_done "$testroot" "$ret"
207 return 1
208 fi
210 cat > $testroot/config.expected <<EOF
211 [core]
212 repositoryformatversion = 0
213 filemode = true
214 bare = true
216 [remote "origin"]
217 url = ssh://127.0.0.1$testroot/repo
218 fetch = refs/heads/foo:refs/remotes/origin/foo
219 fetch = refs/tags/*:refs/tags/*
220 EOF
221 cmp -s $testroot/repo-clone/config $testroot/config.expected
222 ret="$?"
223 if [ "$ret" != "0" ]; then
224 diff -u $testroot/config.expected \
225 $testroot/repo-clone/config
226 fi
227 test_done "$testroot" "$ret"
230 test_clone_all() {
231 local testroot=`test_init clone_all`
232 local testurl=ssh://127.0.0.1/$testroot
233 local commit_id=`git_show_head $testroot/repo`
235 got branch -r $testroot/repo -c $commit_id foo
236 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
237 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
238 local tag_id=`got ref -r $testroot/repo -l \
239 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
241 got clone -q -a $testurl/repo $testroot/repo-clone
242 ret="$?"
243 if [ "$ret" != "0" ]; then
244 echo "got clone command failed unexpectedly" >&2
245 test_done "$testroot" "$ret"
246 return 1
247 fi
249 got ref -l -r $testroot/repo-clone > $testroot/stdout
251 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
252 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
253 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
254 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
255 >> $testroot/stdout.expected
256 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
257 echo "refs/remotes/origin/master: $commit_id" \
258 >> $testroot/stdout.expected
259 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
260 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
262 cmp -s $testroot/stdout $testroot/stdout.expected
263 ret="$?"
264 if [ "$ret" != "0" ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 cat > $testroot/got.conf.expected <<EOF
271 remote "origin" {
272 server 127.0.0.1
273 protocol ssh
274 repository "$testroot/repo"
275 fetch-all-branches yes
277 EOF
278 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
279 ret="$?"
280 if [ "$ret" != "0" ]; then
281 diff -u $testroot/got.conf.expected \
282 $testroot/repo-clone/got.conf
283 test_done "$testroot" "$ret"
284 return 1
285 fi
287 cat > $testroot/config.expected <<EOF
288 [core]
289 repositoryformatversion = 0
290 filemode = true
291 bare = true
293 [remote "origin"]
294 url = ssh://127.0.0.1$testroot/repo
295 fetch = refs/heads/*:refs/remotes/origin/*
296 fetch = refs/tags/*:refs/tags/*
297 EOF
298 cmp -s $testroot/repo-clone/config $testroot/config.expected
299 ret="$?"
300 if [ "$ret" != "0" ]; then
301 diff -u $testroot/config.expected \
302 $testroot/repo-clone/config
303 fi
304 test_done "$testroot" "$ret"
307 test_clone_mirror() {
308 local testroot=`test_init clone_mirror`
309 local testurl=ssh://127.0.0.1/$testroot
310 local commit_id=`git_show_head $testroot/repo`
312 got branch -r $testroot/repo -c $commit_id foo
313 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
314 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
315 local tag_id=`got ref -r $testroot/repo -l \
316 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
318 got clone -q -m $testurl/repo $testroot/repo-clone
319 ret="$?"
320 if [ "$ret" != "0" ]; then
321 echo "got clone command failed unexpectedly" >&2
322 test_done "$testroot" "$ret"
323 return 1
324 fi
326 got ref -l -r $testroot/repo-clone > $testroot/stdout
328 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
329 # refs/heads/foo is missing because we're not fetching all branches
330 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
331 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
332 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
334 cmp -s $testroot/stdout $testroot/stdout.expected
335 ret="$?"
336 if [ "$ret" != "0" ]; then
337 diff -u $testroot/stdout.expected $testroot/stdout
338 test_done "$testroot" "$ret"
339 return 1
340 fi
342 cat > $testroot/got.conf.expected <<EOF
343 remote "origin" {
344 server 127.0.0.1
345 protocol ssh
346 repository "$testroot/repo"
347 branch { "master" }
348 mirror-references yes
350 EOF
351 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
352 ret="$?"
353 if [ "$ret" != "0" ]; then
354 diff -u $testroot/got.conf.expected \
355 $testroot/repo-clone/got.conf
356 test_done "$testroot" "$ret"
357 return 1
358 fi
360 cat > $testroot/config.expected <<EOF
361 [core]
362 repositoryformatversion = 0
363 filemode = true
364 bare = true
366 [remote "origin"]
367 url = ssh://127.0.0.1$testroot/repo
368 fetch = refs/heads/master:refs/heads/master
369 fetch = refs/tags/*:refs/tags/*
370 EOF
371 cmp -s $testroot/repo-clone/config $testroot/config.expected
372 ret="$?"
373 if [ "$ret" != "0" ]; then
374 diff -u $testroot/config.expected \
375 $testroot/repo-clone/config
376 fi
377 test_done "$testroot" "$ret"
380 test_clone_mirror_all() {
381 local testroot=`test_init clone_mirror_all`
382 local testurl=ssh://127.0.0.1/$testroot
383 local commit_id=`git_show_head $testroot/repo`
385 got branch -r $testroot/repo -c $commit_id foo
386 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
387 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
388 local tag_id=`got ref -r $testroot/repo -l \
389 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
391 got clone -q -m -a $testurl/repo $testroot/repo-clone
392 ret="$?"
393 if [ "$ret" != "0" ]; then
394 echo "got clone command failed unexpectedly" >&2
395 test_done "$testroot" "$ret"
396 return 1
397 fi
399 got ref -l -r $testroot/repo-clone > $testroot/stdout
401 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
402 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
403 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
404 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
405 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
407 cmp -s $testroot/stdout $testroot/stdout.expected
408 ret="$?"
409 if [ "$ret" != "0" ]; then
410 diff -u $testroot/stdout.expected $testroot/stdout
411 test_done "$testroot" "$ret"
412 return 1
413 fi
415 cat > $testroot/got.conf.expected <<EOF
416 remote "origin" {
417 server 127.0.0.1
418 protocol ssh
419 repository "$testroot/repo"
420 mirror-references yes
421 fetch-all-branches yes
423 EOF
424 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
425 ret="$?"
426 if [ "$ret" != "0" ]; then
427 diff -u $testroot/got.conf.expected \
428 $testroot/repo-clone/got.conf
429 test_done "$testroot" "$ret"
430 return 1
431 fi
433 cat > $testroot/config.expected <<EOF
434 [core]
435 repositoryformatversion = 0
436 filemode = true
437 bare = true
439 [remote "origin"]
440 url = ssh://127.0.0.1$testroot/repo
441 fetch = refs/heads/*:refs/heads/*
442 fetch = refs/tags/*:refs/tags/*
443 EOF
444 cmp -s $testroot/repo-clone/config $testroot/config.expected
445 ret="$?"
446 if [ "$ret" != "0" ]; then
447 diff -u $testroot/config.expected \
448 $testroot/repo-clone/config
449 fi
450 test_done "$testroot" "$ret"
453 test_clone_reference() {
454 local testroot=`test_init clone_reference`
455 local testurl=ssh://127.0.0.1/$testroot
456 local commit_id=`git_show_head $testroot/repo`
458 got branch -r $testroot/repo -c $commit_id foo
459 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
460 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
461 local tag_id=`got ref -r $testroot/repo -l \
462 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
464 got clone -q -R hoo $testurl/repo $testroot/repo-clone
465 ret="$?"
466 if [ "$ret" != "0" ]; then
467 echo "got clone command failed unexpectedly" >&2
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 got ref -l -r $testroot/repo-clone > $testroot/stdout
474 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
475 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
476 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
477 >> $testroot/stdout.expected
478 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
479 >> $testroot/stdout.expected
480 echo "refs/remotes/origin/master: $commit_id" \
481 >> $testroot/stdout.expected
482 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
484 cmp -s $testroot/stdout $testroot/stdout.expected
485 ret="$?"
486 if [ "$ret" != "0" ]; then
487 diff -u $testroot/stdout.expected $testroot/stdout
488 test_done "$testroot" "$ret"
489 return 1
490 fi
492 cat > $testroot/got.conf.expected <<EOF
493 remote "origin" {
494 server 127.0.0.1
495 protocol ssh
496 repository "$testroot/repo"
497 branch { "master" }
498 reference { "hoo" }
500 EOF
501 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
502 ret="$?"
503 if [ "$ret" != "0" ]; then
504 diff -u $testroot/got.conf.expected \
505 $testroot/repo-clone/got.conf
506 test_done "$testroot" "$ret"
507 return 1
508 fi
510 cat > $testroot/config.expected <<EOF
511 [core]
512 repositoryformatversion = 0
513 filemode = true
514 bare = true
516 [remote "origin"]
517 url = ssh://127.0.0.1$testroot/repo
518 fetch = refs/heads/master:refs/remotes/origin/master
519 fetch = refs/hoo:refs/remotes/origin/hoo
520 fetch = refs/tags/*:refs/tags/*
521 EOF
522 cmp -s $testroot/repo-clone/config $testroot/config.expected
523 ret="$?"
524 if [ "$ret" != "0" ]; then
525 diff -u $testroot/config.expected \
526 $testroot/repo-clone/config
527 fi
528 test_done "$testroot" "$ret"
531 test_clone_branch_and_reference() {
532 local testroot=`test_init clone_reference`
533 local testurl=ssh://127.0.0.1/$testroot
534 local commit_id=`git_show_head $testroot/repo`
536 got branch -r $testroot/repo -c $commit_id foo
537 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
538 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
539 local tag_id=`got ref -r $testroot/repo -l \
540 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
542 got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
543 ret="$?"
544 if [ "$ret" != "0" ]; then
545 echo "got clone command failed unexpectedly" >&2
546 test_done "$testroot" "$ret"
547 return 1
548 fi
550 got ref -l -r $testroot/repo-clone > $testroot/stdout
552 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
553 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
554 echo "refs/remotes/origin/foo: $commit_id" \
555 >> $testroot/stdout.expected
556 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
557 >> $testroot/stdout.expected
558 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
560 cmp -s $testroot/stdout $testroot/stdout.expected
561 ret="$?"
562 if [ "$ret" != "0" ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 test_done "$testroot" "$ret"
565 return 1
566 fi
568 cat > $testroot/got.conf.expected <<EOF
569 remote "origin" {
570 server 127.0.0.1
571 protocol ssh
572 repository "$testroot/repo"
573 branch { "foo" }
574 reference { "hoo/boo/zoo" }
576 EOF
577 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
578 ret="$?"
579 if [ "$ret" != "0" ]; then
580 diff -u $testroot/got.conf.expected \
581 $testroot/repo-clone/got.conf
582 test_done "$testroot" "$ret"
583 return 1
584 fi
586 cat > $testroot/config.expected <<EOF
587 [core]
588 repositoryformatversion = 0
589 filemode = true
590 bare = true
592 [remote "origin"]
593 url = ssh://127.0.0.1$testroot/repo
594 fetch = refs/heads/foo:refs/remotes/origin/foo
595 fetch = refs/hoo/boo/zoo:refs/remotes/origin/hoo/boo/zoo
596 fetch = refs/tags/*:refs/tags/*
597 EOF
598 cmp -s $testroot/repo-clone/config $testroot/config.expected
599 ret="$?"
600 if [ "$ret" != "0" ]; then
601 diff -u $testroot/config.expected \
602 $testroot/repo-clone/config
603 fi
604 test_done "$testroot" "$ret"
607 test_clone_reference_mirror() {
608 local testroot=`test_init clone_reference_mirror`
609 local testurl=ssh://127.0.0.1/$testroot
610 local commit_id=`git_show_head $testroot/repo`
612 got branch -r $testroot/repo -c $commit_id foo
613 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
614 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
615 local tag_id=`got ref -r $testroot/repo -l \
616 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
618 got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
619 ret="$?"
620 if [ "$ret" != "0" ]; then
621 echo "got clone command failed unexpectedly" >&2
622 test_done "$testroot" "$ret"
623 return 1
624 fi
626 got ref -l -r $testroot/repo-clone > $testroot/stdout
628 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
629 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
630 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
631 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
633 cmp -s $testroot/stdout $testroot/stdout.expected
634 ret="$?"
635 if [ "$ret" != "0" ]; then
636 diff -u $testroot/stdout.expected $testroot/stdout
637 test_done "$testroot" "$ret"
638 return 1
639 fi
641 cat > $testroot/got.conf.expected <<EOF
642 remote "origin" {
643 server 127.0.0.1
644 protocol ssh
645 repository "$testroot/repo"
646 branch { "master" }
647 reference { "hoo" }
648 mirror-references yes
650 EOF
651 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
652 ret="$?"
653 if [ "$ret" != "0" ]; then
654 diff -u $testroot/got.conf.expected \
655 $testroot/repo-clone/got.conf
656 test_done "$testroot" "$ret"
657 return 1
658 fi
660 cat > $testroot/config.expected <<EOF
661 [core]
662 repositoryformatversion = 0
663 filemode = true
664 bare = true
666 [remote "origin"]
667 url = ssh://127.0.0.1$testroot/repo
668 fetch = refs/heads/master:refs/heads/master
669 fetch = refs/hoo:refs/hoo
670 fetch = refs/tags/*:refs/tags/*
671 EOF
672 cmp -s $testroot/repo-clone/config $testroot/config.expected
673 ret="$?"
674 if [ "$ret" != "0" ]; then
675 diff -u $testroot/config.expected \
676 $testroot/repo-clone/config
677 fi
678 test_done "$testroot" "$ret"
681 test_clone_multiple_branches() {
682 local testroot=`test_init clone_multiple_branches`
683 local testurl=ssh://127.0.0.1/$testroot
684 local commit_id=`git_show_head $testroot/repo`
686 got branch -r $testroot/repo -c $commit_id foo
687 got branch -r $testroot/repo -c $commit_id bar
689 got clone -q -b foo -b bar $testurl/repo $testroot/repo-clone
690 ret="$?"
691 if [ "$ret" != "0" ]; then
692 echo "got clone command failed unexpectedly" >&2
693 test_done "$testroot" "$ret"
694 return 1
695 fi
697 got ref -l -r $testroot/repo-clone > $testroot/stdout
699 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
700 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
701 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
702 echo "refs/remotes/origin/bar: $commit_id" \
703 >> $testroot/stdout.expected
704 echo "refs/remotes/origin/foo: $commit_id" \
705 >> $testroot/stdout.expected
707 cmp -s $testroot/stdout $testroot/stdout.expected
708 ret="$?"
709 if [ "$ret" != "0" ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 cat > $testroot/got.conf.expected <<EOF
716 remote "origin" {
717 server 127.0.0.1
718 protocol ssh
719 repository "$testroot/repo"
720 branch { "foo" "bar" }
722 EOF
723 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 diff -u $testroot/got.conf.expected \
727 $testroot/repo-clone/got.conf
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 cat > $testroot/config.expected <<EOF
733 [core]
734 repositoryformatversion = 0
735 filemode = true
736 bare = true
738 [remote "origin"]
739 url = ssh://127.0.0.1$testroot/repo
740 fetch = refs/heads/foo:refs/remotes/origin/foo
741 fetch = refs/heads/bar:refs/remotes/origin/bar
742 fetch = refs/tags/*:refs/tags/*
743 EOF
744 cmp -s $testroot/repo-clone/config $testroot/config.expected
745 ret="$?"
746 if [ "$ret" != "0" ]; then
747 diff -u $testroot/config.expected \
748 $testroot/repo-clone/config
749 fi
750 test_done "$testroot" "$ret"
753 test_parseargs "$@"
754 run_test test_clone_basic
755 run_test test_clone_list
756 run_test test_clone_branch
757 run_test test_clone_all
758 run_test test_clone_mirror
759 run_test test_clone_mirror_all
760 run_test test_clone_reference
761 run_test test_clone_branch_and_reference
762 run_test test_clone_reference_mirror
763 run_test test_clone_multiple_branches