portable: release 0.93
[got-portable.git] / regress / cmdline / clone.sh
bloba628193de0dbc52a980b83ef2f3fd49071ce4605
1 #!/bin/sh
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.
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
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
39 got log -l0 -p -r $testroot/repo-clone | \
40 sed 's@master, origin/master@master@g' \
41 > $testroot/log-repo-clone
43 cmp -s $testroot/log-repo $testroot/log-repo-clone
44 ret=$?
45 if [ $ret -ne 0 ]; then
46 echo "log -p output of cloned repository differs" >&2
47 test_done "$testroot" "$ret"
48 return 1
51 got ref -l -r $testroot/repo > $testroot/stdout
52 ret=$?
53 if [ $ret -ne 0 ]; then
54 echo "got ref command failed unexpectedly" >&2
55 test_done "$testroot" "$ret"
56 return 1
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 -ne 0 ]; then
65 diff -u $testroot/stdout.expected $testroot/stdout
66 test_done "$testroot" "$ret"
67 return 1
70 got ref -l -r $testroot/repo-clone > $testroot/stdout
71 ret=$?
72 if [ $ret -ne 0 ]; then
73 echo "got ref command failed unexpectedly" >&2
74 test_done "$testroot" "$ret"
75 return 1
78 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
79 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
80 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
81 >> $testroot/stdout.expected
82 echo "refs/remotes/origin/master: $commit_id" \
83 >> $testroot/stdout.expected
85 cmp -s $testroot/stdout $testroot/stdout.expected
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 diff -u $testroot/stdout.expected $testroot/stdout
89 test_done "$testroot" "$ret"
90 return 1
93 cat > $testroot/got.conf.expected <<EOF
94 remote "origin" {
95 server 127.0.0.1
96 protocol ssh
97 repository "$testroot/repo"
98 branch { "master" }
101 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
102 ret=$?
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/got.conf.expected \
105 $testroot/repo-clone/got.conf
106 test_done "$testroot" "$ret"
107 return 1
110 cat > $testroot/config.expected <<EOF
111 [core]
112 repositoryformatversion = 0
113 filemode = true
114 bare = true
116 [remote "origin"]
117 url = ssh://127.0.0.1$testroot/repo
118 fetch = refs/heads/master:refs/remotes/origin/master
119 fetch = refs/tags/*:refs/tags/*
121 cmp -s $testroot/repo-clone/config $testroot/config.expected
122 ret=$?
123 if [ $ret -ne 0 ]; then
124 diff -u $testroot/config.expected \
125 $testroot/repo-clone/config
127 test_done "$testroot" "$ret"
130 test_clone_quoting() {
131 local testroot=`test_init clone_basic`
133 got log -l0 -p -r "$testroot/repo" > $testroot/log-repo
135 (cd "$testroot" && cp -R repo "rock'n roll.git")
137 got clone -q "ssh://127.0.0.1/$testroot/rock'n roll.git" \
138 "$testroot/rock-clone"
139 ret=$?
140 if [ $ret -ne 0 ]; then
141 echo "got clone failed unexpectedly" >&2
142 test_done "$testroot" "$ret"
143 return 1
146 got log -l0 -p -r "$testroot/rock-clone" | \
147 sed 's@master, origin/master@master@g' \
148 >$testroot/log-repo-clone
150 cmp -s "$testroot/log-repo" "$testroot/log-repo-clone"
151 ret=$?
152 if [ $ret -ne 0 ]; then
153 echo "log -p output of cloned repository differs" >&2
154 diff -u "$testroot/log-repo" "$testroot/log-repo-clone"
155 test_done "$testroot" "$ret"
157 test_done "$testroot" "$ret"
160 test_clone_list() {
161 local testroot=`test_init clone_list`
162 local testurl=ssh://127.0.0.1$testroot
163 local commit_id=`git_show_head $testroot/repo`
165 got branch -r $testroot/repo -c $commit_id foo
166 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
167 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
169 got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
170 ret=$?
171 if [ $ret -ne 0 ]; then
172 echo "got clone command failed unexpectedly" >&2
173 test_done "$testroot" "$ret"
174 return 1
177 echo "Connecting to $testurl/repo" > $testroot/stdout.expected
178 got ref -l -r $testroot/repo >> $testroot/stdout.expected
180 cmp -s $testroot/stdout $testroot/stdout.expected
181 ret=$?
182 if [ $ret -ne 0 ]; then
183 diff -u $testroot/stdout.expected $testroot/stdout
185 test_done "$testroot" "$ret"
188 test_clone_branch() {
189 local testroot=`test_init clone_branch`
190 local testurl=ssh://127.0.0.1/$testroot
191 local commit_id=`git_show_head $testroot/repo`
193 got branch -r $testroot/repo -c $commit_id foo
194 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
195 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
196 local tag_id=`got ref -r $testroot/repo -l \
197 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
199 got clone -q -b foo $testurl/repo $testroot/repo-clone
200 ret=$?
201 if [ $ret -ne 0 ]; then
202 echo "got clone command failed unexpectedly" >&2
203 test_done "$testroot" "$ret"
204 return 1
207 got ref -l -r $testroot/repo-clone > $testroot/stdout
209 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
210 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
211 # refs/heads/master is missing because it wasn't passed via -b
212 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
213 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
214 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
216 cmp -s $testroot/stdout $testroot/stdout.expected
217 ret=$?
218 if [ $ret -ne 0 ]; then
219 diff -u $testroot/stdout.expected $testroot/stdout
220 test_done "$testroot" "$ret"
221 return 1
224 cat > $testroot/got.conf.expected <<EOF
225 remote "origin" {
226 server 127.0.0.1
227 protocol ssh
228 repository "$testroot/repo"
229 branch { "foo" }
232 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
233 ret=$?
234 if [ $ret -ne 0 ]; then
235 diff -u $testroot/got.conf.expected \
236 $testroot/repo-clone/got.conf
237 test_done "$testroot" "$ret"
238 return 1
241 cat > $testroot/config.expected <<EOF
242 [core]
243 repositoryformatversion = 0
244 filemode = true
245 bare = true
247 [remote "origin"]
248 url = ssh://127.0.0.1$testroot/repo
249 fetch = refs/heads/foo:refs/remotes/origin/foo
250 fetch = refs/tags/*:refs/tags/*
252 cmp -s $testroot/repo-clone/config $testroot/config.expected
253 ret=$?
254 if [ $ret -ne 0 ]; then
255 diff -u $testroot/config.expected \
256 $testroot/repo-clone/config
258 test_done "$testroot" "$ret"
261 test_clone_all() {
262 local testroot=`test_init clone_all`
263 local testurl=ssh://127.0.0.1/$testroot
264 local commit_id=`git_show_head $testroot/repo`
266 got branch -r $testroot/repo -c $commit_id foo
267 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
268 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
269 local tag_id=`got ref -r $testroot/repo -l \
270 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
272 got clone -q -a $testurl/repo $testroot/repo-clone
273 ret=$?
274 if [ $ret -ne 0 ]; then
275 echo "got clone command failed unexpectedly" >&2
276 test_done "$testroot" "$ret"
277 return 1
280 got ref -l -r $testroot/repo-clone > $testroot/stdout
282 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
283 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
284 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
285 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
286 >> $testroot/stdout.expected
287 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
288 echo "refs/remotes/origin/master: $commit_id" \
289 >> $testroot/stdout.expected
290 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
291 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
293 cmp -s $testroot/stdout $testroot/stdout.expected
294 ret=$?
295 if [ $ret -ne 0 ]; then
296 diff -u $testroot/stdout.expected $testroot/stdout
297 test_done "$testroot" "$ret"
298 return 1
301 cat > $testroot/got.conf.expected <<EOF
302 remote "origin" {
303 server 127.0.0.1
304 protocol ssh
305 repository "$testroot/repo"
306 fetch_all_branches yes
309 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
310 ret=$?
311 if [ $ret -ne 0 ]; then
312 diff -u $testroot/got.conf.expected \
313 $testroot/repo-clone/got.conf
314 test_done "$testroot" "$ret"
315 return 1
318 cat > $testroot/config.expected <<EOF
319 [core]
320 repositoryformatversion = 0
321 filemode = true
322 bare = true
324 [remote "origin"]
325 url = ssh://127.0.0.1$testroot/repo
326 fetch = refs/heads/*:refs/remotes/origin/*
327 fetch = refs/tags/*:refs/tags/*
329 cmp -s $testroot/repo-clone/config $testroot/config.expected
330 ret=$?
331 if [ $ret -ne 0 ]; then
332 diff -u $testroot/config.expected \
333 $testroot/repo-clone/config
335 test_done "$testroot" "$ret"
338 test_clone_mirror() {
339 local testroot=`test_init clone_mirror`
340 local testurl=ssh://127.0.0.1/$testroot
341 local commit_id=`git_show_head $testroot/repo`
343 got branch -r $testroot/repo -c $commit_id foo
344 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
345 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
346 local tag_id=`got ref -r $testroot/repo -l \
347 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
349 got clone -q -m $testurl/repo $testroot/repo-clone
350 ret=$?
351 if [ $ret -ne 0 ]; then
352 echo "got clone command failed unexpectedly" >&2
353 test_done "$testroot" "$ret"
354 return 1
357 got ref -l -r $testroot/repo-clone > $testroot/stdout
359 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
360 # refs/heads/foo is missing because we're not fetching all branches
361 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
362 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
363 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
365 cmp -s $testroot/stdout $testroot/stdout.expected
366 ret=$?
367 if [ $ret -ne 0 ]; then
368 diff -u $testroot/stdout.expected $testroot/stdout
369 test_done "$testroot" "$ret"
370 return 1
373 cat > $testroot/got.conf.expected <<EOF
374 remote "origin" {
375 server 127.0.0.1
376 protocol ssh
377 repository "$testroot/repo"
378 branch { "master" }
379 mirror_references yes
382 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
383 ret=$?
384 if [ $ret -ne 0 ]; then
385 diff -u $testroot/got.conf.expected \
386 $testroot/repo-clone/got.conf
387 test_done "$testroot" "$ret"
388 return 1
391 cat > $testroot/config.expected <<EOF
392 [core]
393 repositoryformatversion = 0
394 filemode = true
395 bare = true
397 [remote "origin"]
398 url = ssh://127.0.0.1$testroot/repo
399 fetch = refs/heads/master:refs/heads/master
400 fetch = refs/tags/*:refs/tags/*
402 cmp -s $testroot/repo-clone/config $testroot/config.expected
403 ret=$?
404 if [ $ret -ne 0 ]; then
405 diff -u $testroot/config.expected \
406 $testroot/repo-clone/config
408 test_done "$testroot" "$ret"
411 test_clone_mirror_all() {
412 local testroot=`test_init clone_mirror_all`
413 local testurl=ssh://127.0.0.1/$testroot
414 local commit_id=`git_show_head $testroot/repo`
416 got branch -r $testroot/repo -c $commit_id foo
417 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
418 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
419 local tag_id=`got ref -r $testroot/repo -l \
420 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
422 got clone -q -m -a $testurl/repo $testroot/repo-clone
423 ret=$?
424 if [ $ret -ne 0 ]; then
425 echo "got clone command failed unexpectedly" >&2
426 test_done "$testroot" "$ret"
427 return 1
430 got ref -l -r $testroot/repo-clone > $testroot/stdout
432 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
433 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
434 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
435 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
436 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
438 cmp -s $testroot/stdout $testroot/stdout.expected
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
446 cat > $testroot/got.conf.expected <<EOF
447 remote "origin" {
448 server 127.0.0.1
449 protocol ssh
450 repository "$testroot/repo"
451 mirror_references yes
452 fetch_all_branches yes
455 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
456 ret=$?
457 if [ $ret -ne 0 ]; then
458 diff -u $testroot/got.conf.expected \
459 $testroot/repo-clone/got.conf
460 test_done "$testroot" "$ret"
461 return 1
464 cat > $testroot/config.expected <<EOF
465 [core]
466 repositoryformatversion = 0
467 filemode = true
468 bare = true
470 [remote "origin"]
471 url = ssh://127.0.0.1$testroot/repo
472 fetch = refs/heads/*:refs/heads/*
473 fetch = refs/tags/*:refs/tags/*
475 cmp -s $testroot/repo-clone/config $testroot/config.expected
476 ret=$?
477 if [ $ret -ne 0 ]; then
478 diff -u $testroot/config.expected \
479 $testroot/repo-clone/config
481 test_done "$testroot" "$ret"
484 test_clone_reference() {
485 local testroot=`test_init clone_reference`
486 local testurl=ssh://127.0.0.1/$testroot
487 local commit_id=`git_show_head $testroot/repo`
489 got branch -r $testroot/repo -c $commit_id foo
490 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
491 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
492 local tag_id=`got ref -r $testroot/repo -l \
493 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
495 got clone -q -R hoo $testurl/repo $testroot/repo-clone
496 ret=$?
497 if [ $ret -ne 0 ]; then
498 echo "got clone command failed unexpectedly" >&2
499 test_done "$testroot" "$ret"
500 return 1
503 got ref -l -r $testroot/repo-clone > $testroot/stdout
505 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
506 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
507 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
508 >> $testroot/stdout.expected
509 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
510 >> $testroot/stdout.expected
511 echo "refs/remotes/origin/master: $commit_id" \
512 >> $testroot/stdout.expected
513 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
515 cmp -s $testroot/stdout $testroot/stdout.expected
516 ret=$?
517 if [ $ret -ne 0 ]; then
518 diff -u $testroot/stdout.expected $testroot/stdout
519 test_done "$testroot" "$ret"
520 return 1
523 cat > $testroot/got.conf.expected <<EOF
524 remote "origin" {
525 server 127.0.0.1
526 protocol ssh
527 repository "$testroot/repo"
528 branch { "master" }
529 reference { "hoo" }
532 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
533 ret=$?
534 if [ $ret -ne 0 ]; then
535 diff -u $testroot/got.conf.expected \
536 $testroot/repo-clone/got.conf
537 test_done "$testroot" "$ret"
538 return 1
541 cat > $testroot/config.expected <<EOF
542 [core]
543 repositoryformatversion = 0
544 filemode = true
545 bare = true
547 [remote "origin"]
548 url = ssh://127.0.0.1$testroot/repo
549 fetch = refs/heads/master:refs/remotes/origin/master
550 fetch = refs/hoo:refs/remotes/origin/hoo
551 fetch = refs/tags/*:refs/tags/*
553 cmp -s $testroot/repo-clone/config $testroot/config.expected
554 ret=$?
555 if [ $ret -ne 0 ]; then
556 diff -u $testroot/config.expected \
557 $testroot/repo-clone/config
559 test_done "$testroot" "$ret"
562 test_clone_branch_and_reference() {
563 local testroot=`test_init clone_reference`
564 local testurl=ssh://127.0.0.1/$testroot
565 local commit_id=`git_show_head $testroot/repo`
567 got branch -r $testroot/repo -c $commit_id foo
568 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
569 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
570 local tag_id=`got ref -r $testroot/repo -l \
571 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
573 got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
574 ret=$?
575 if [ $ret -ne 0 ]; then
576 echo "got clone command failed unexpectedly" >&2
577 test_done "$testroot" "$ret"
578 return 1
581 got ref -l -r $testroot/repo-clone > $testroot/stdout
583 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
584 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
585 echo "refs/remotes/origin/foo: $commit_id" \
586 >> $testroot/stdout.expected
587 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
588 >> $testroot/stdout.expected
589 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
591 cmp -s $testroot/stdout $testroot/stdout.expected
592 ret=$?
593 if [ $ret -ne 0 ]; then
594 diff -u $testroot/stdout.expected $testroot/stdout
595 test_done "$testroot" "$ret"
596 return 1
599 cat > $testroot/got.conf.expected <<EOF
600 remote "origin" {
601 server 127.0.0.1
602 protocol ssh
603 repository "$testroot/repo"
604 branch { "foo" }
605 reference { "hoo/boo/zoo" }
608 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
609 ret=$?
610 if [ $ret -ne 0 ]; then
611 diff -u $testroot/got.conf.expected \
612 $testroot/repo-clone/got.conf
613 test_done "$testroot" "$ret"
614 return 1
617 cat > $testroot/config.expected <<EOF
618 [core]
619 repositoryformatversion = 0
620 filemode = true
621 bare = true
623 [remote "origin"]
624 url = ssh://127.0.0.1$testroot/repo
625 fetch = refs/heads/foo:refs/remotes/origin/foo
626 fetch = refs/hoo/boo/zoo:refs/remotes/origin/hoo/boo/zoo
627 fetch = refs/tags/*:refs/tags/*
629 cmp -s $testroot/repo-clone/config $testroot/config.expected
630 ret=$?
631 if [ $ret -ne 0 ]; then
632 diff -u $testroot/config.expected \
633 $testroot/repo-clone/config
635 test_done "$testroot" "$ret"
638 test_clone_reference_mirror() {
639 local testroot=`test_init clone_reference_mirror`
640 local testurl=ssh://127.0.0.1/$testroot
641 local commit_id=`git_show_head $testroot/repo`
643 got branch -r $testroot/repo -c $commit_id foo
644 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
645 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
646 local tag_id=`got ref -r $testroot/repo -l \
647 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
649 got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
650 ret=$?
651 if [ $ret -ne 0 ]; then
652 echo "got clone command failed unexpectedly" >&2
653 test_done "$testroot" "$ret"
654 return 1
657 got ref -l -r $testroot/repo-clone > $testroot/stdout
659 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
660 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
661 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
662 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
664 cmp -s $testroot/stdout $testroot/stdout.expected
665 ret=$?
666 if [ $ret -ne 0 ]; then
667 diff -u $testroot/stdout.expected $testroot/stdout
668 test_done "$testroot" "$ret"
669 return 1
672 cat > $testroot/got.conf.expected <<EOF
673 remote "origin" {
674 server 127.0.0.1
675 protocol ssh
676 repository "$testroot/repo"
677 branch { "master" }
678 reference { "hoo" }
679 mirror_references yes
682 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
683 ret=$?
684 if [ $ret -ne 0 ]; then
685 diff -u $testroot/got.conf.expected \
686 $testroot/repo-clone/got.conf
687 test_done "$testroot" "$ret"
688 return 1
691 cat > $testroot/config.expected <<EOF
692 [core]
693 repositoryformatversion = 0
694 filemode = true
695 bare = true
697 [remote "origin"]
698 url = ssh://127.0.0.1$testroot/repo
699 fetch = refs/heads/master:refs/heads/master
700 fetch = refs/hoo:refs/hoo
701 fetch = refs/tags/*:refs/tags/*
703 cmp -s $testroot/repo-clone/config $testroot/config.expected
704 ret=$?
705 if [ $ret -ne 0 ]; then
706 diff -u $testroot/config.expected \
707 $testroot/repo-clone/config
709 test_done "$testroot" "$ret"
712 test_clone_multiple_branches() {
713 local testroot=`test_init clone_multiple_branches`
714 local testurl=ssh://127.0.0.1/$testroot
715 local commit_id=`git_show_head $testroot/repo`
717 got branch -r $testroot/repo -c $commit_id foo
718 got branch -r $testroot/repo -c $commit_id bar
720 got clone -q -b foo -b bar $testurl/repo $testroot/repo-clone
721 ret=$?
722 if [ $ret -ne 0 ]; then
723 echo "got clone command failed unexpectedly" >&2
724 test_done "$testroot" "$ret"
725 return 1
728 got ref -l -r $testroot/repo-clone > $testroot/stdout
730 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
731 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
732 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
733 echo "refs/remotes/origin/bar: $commit_id" \
734 >> $testroot/stdout.expected
735 echo "refs/remotes/origin/foo: $commit_id" \
736 >> $testroot/stdout.expected
738 cmp -s $testroot/stdout $testroot/stdout.expected
739 ret=$?
740 if [ $ret -ne 0 ]; then
741 diff -u $testroot/stdout.expected $testroot/stdout
742 test_done "$testroot" "$ret"
743 return 1
746 cat > $testroot/got.conf.expected <<EOF
747 remote "origin" {
748 server 127.0.0.1
749 protocol ssh
750 repository "$testroot/repo"
751 branch { "foo" "bar" }
754 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
755 ret=$?
756 if [ $ret -ne 0 ]; then
757 diff -u $testroot/got.conf.expected \
758 $testroot/repo-clone/got.conf
759 test_done "$testroot" "$ret"
760 return 1
763 cat > $testroot/config.expected <<EOF
764 [core]
765 repositoryformatversion = 0
766 filemode = true
767 bare = true
769 [remote "origin"]
770 url = ssh://127.0.0.1$testroot/repo
771 fetch = refs/heads/foo:refs/remotes/origin/foo
772 fetch = refs/heads/bar:refs/remotes/origin/bar
773 fetch = refs/tags/*:refs/tags/*
775 cmp -s $testroot/repo-clone/config $testroot/config.expected
776 ret=$?
777 if [ $ret -ne 0 ]; then
778 diff -u $testroot/config.expected \
779 $testroot/repo-clone/config
781 test_done "$testroot" "$ret"
784 test_clone_dangling_headref() {
785 local testroot=`test_init clone_dangling_headref`
786 local testurl=ssh://127.0.0.1/$testroot
787 local commit_id=`git_show_head $testroot/repo`
789 got branch -r $testroot/repo -d master > /dev/null
790 got branch -r $testroot/repo -c $commit_id foo
792 got ref -l -r $testroot/repo > $testroot/stdout
794 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
795 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
796 # refs/heads/master is missing because it was deleted above
798 cmp -s $testroot/stdout $testroot/stdout.expected
799 ret=$?
800 if [ $ret -ne 0 ]; then
801 diff -u $testroot/stdout.expected $testroot/stdout
802 test_done "$testroot" "$ret"
803 return 1
806 got clone -q -b foo $testurl/repo $testroot/repo-clone
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 echo "got clone command failed unexpectedly" >&2
810 test_done "$testroot" "$ret"
811 return 1
814 got ref -l -r $testroot/repo-clone > $testroot/stdout
816 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
817 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
818 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
820 cmp -s $testroot/stdout $testroot/stdout.expected
821 ret=$?
822 if [ $ret -ne 0 ]; then
823 diff -u $testroot/stdout.expected $testroot/stdout
824 test_done "$testroot" "$ret"
825 return 1
828 cat > $testroot/got.conf.expected <<EOF
829 remote "origin" {
830 server 127.0.0.1
831 protocol ssh
832 repository "$testroot/repo"
833 branch { "foo" }
836 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
837 ret=$?
838 if [ $ret -ne 0 ]; then
839 diff -u $testroot/got.conf.expected \
840 $testroot/repo-clone/got.conf
841 test_done "$testroot" "$ret"
842 return 1
845 cat > $testroot/config.expected <<EOF
846 [core]
847 repositoryformatversion = 0
848 filemode = true
849 bare = true
851 [remote "origin"]
852 url = ssh://127.0.0.1$testroot/repo
853 fetch = refs/heads/foo:refs/remotes/origin/foo
854 fetch = refs/tags/*:refs/tags/*
856 cmp -s $testroot/repo-clone/config $testroot/config.expected
857 ret=$?
858 if [ $ret -ne 0 ]; then
859 diff -u $testroot/config.expected \
860 $testroot/repo-clone/config
862 test_done "$testroot" "$ret"
865 test_parseargs "$@"
866 run_test test_clone_basic
867 run_test test_clone_quoting
868 run_test test_clone_list
869 run_test test_clone_branch
870 run_test test_clone_all
871 run_test test_clone_mirror
872 run_test test_clone_mirror_all
873 run_test test_clone_reference
874 run_test test_clone_branch_and_reference
875 run_test test_clone_reference_mirror
876 run_test test_clone_multiple_branches
877 run_test test_clone_dangling_headref