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-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
49 fi
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
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 -ne 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 ret=$?
72 if [ $ret -ne 0 ]; then
73 echo "got ref command failed unexpectedly" >&2
74 test_done "$testroot" "$ret"
75 return 1
76 fi
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
91 fi
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" }
99 }
100 EOF
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
108 fi
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/*
120 EOF
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
126 fi
127 test_done "$testroot" "$ret"
130 test_clone_list() {
131 local testroot=`test_init clone_list`
132 local testurl=ssh://127.0.0.1$testroot
133 local commit_id=`git_show_head $testroot/repo`
135 got branch -r $testroot/repo -c $commit_id foo
136 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
137 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
139 got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
140 ret=$?
141 if [ $ret -ne 0 ]; then
142 echo "got clone command failed unexpectedly" >&2
143 test_done "$testroot" "$ret"
144 return 1
145 fi
147 echo "Connecting to $testurl/repo" > $testroot/stdout.expected
148 got ref -l -r $testroot/repo >> $testroot/stdout.expected
150 cmp -s $testroot/stdout $testroot/stdout.expected
151 ret=$?
152 if [ $ret -ne 0 ]; then
153 diff -u $testroot/stdout.expected $testroot/stdout
154 fi
155 test_done "$testroot" "$ret"
158 test_clone_branch() {
159 local testroot=`test_init clone_branch`
160 local testurl=ssh://127.0.0.1/$testroot
161 local commit_id=`git_show_head $testroot/repo`
163 got branch -r $testroot/repo -c $commit_id foo
164 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
165 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
166 local tag_id=`got ref -r $testroot/repo -l \
167 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
169 got clone -q -b foo $testurl/repo $testroot/repo-clone
170 ret=$?
171 if [ $ret -ne 0 ]; then
172 echo "got clone command failed unexpectedly" >&2
173 test_done "$testroot" "$ret"
174 return 1
175 fi
177 got ref -l -r $testroot/repo-clone > $testroot/stdout
179 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
180 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
181 # refs/heads/master is missing because it wasn't passed via -b
182 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
183 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
184 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
186 cmp -s $testroot/stdout $testroot/stdout.expected
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 cat > $testroot/got.conf.expected <<EOF
195 remote "origin" {
196 server 127.0.0.1
197 protocol ssh
198 repository "$testroot/repo"
199 branch { "foo" }
201 EOF
202 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
203 ret=$?
204 if [ $ret -ne 0 ]; then
205 diff -u $testroot/got.conf.expected \
206 $testroot/repo-clone/got.conf
207 test_done "$testroot" "$ret"
208 return 1
209 fi
211 cat > $testroot/config.expected <<EOF
212 [core]
213 repositoryformatversion = 0
214 filemode = true
215 bare = true
217 [remote "origin"]
218 url = ssh://127.0.0.1$testroot/repo
219 fetch = refs/heads/foo:refs/remotes/origin/foo
220 fetch = refs/tags/*:refs/tags/*
221 EOF
222 cmp -s $testroot/repo-clone/config $testroot/config.expected
223 ret=$?
224 if [ $ret -ne 0 ]; then
225 diff -u $testroot/config.expected \
226 $testroot/repo-clone/config
227 fi
228 test_done "$testroot" "$ret"
231 test_clone_all() {
232 local testroot=`test_init clone_all`
233 local testurl=ssh://127.0.0.1/$testroot
234 local commit_id=`git_show_head $testroot/repo`
236 got branch -r $testroot/repo -c $commit_id foo
237 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
238 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
239 local tag_id=`got ref -r $testroot/repo -l \
240 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
242 got clone -q -a $testurl/repo $testroot/repo-clone
243 ret=$?
244 if [ $ret -ne 0 ]; then
245 echo "got clone command failed unexpectedly" >&2
246 test_done "$testroot" "$ret"
247 return 1
248 fi
250 got ref -l -r $testroot/repo-clone > $testroot/stdout
252 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
253 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
254 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
255 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
256 >> $testroot/stdout.expected
257 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
258 echo "refs/remotes/origin/master: $commit_id" \
259 >> $testroot/stdout.expected
260 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
261 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
263 cmp -s $testroot/stdout $testroot/stdout.expected
264 ret=$?
265 if [ $ret -ne 0 ]; then
266 diff -u $testroot/stdout.expected $testroot/stdout
267 test_done "$testroot" "$ret"
268 return 1
269 fi
271 cat > $testroot/got.conf.expected <<EOF
272 remote "origin" {
273 server 127.0.0.1
274 protocol ssh
275 repository "$testroot/repo"
276 fetch_all_branches yes
278 EOF
279 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
280 ret=$?
281 if [ $ret -ne 0 ]; then
282 diff -u $testroot/got.conf.expected \
283 $testroot/repo-clone/got.conf
284 test_done "$testroot" "$ret"
285 return 1
286 fi
288 cat > $testroot/config.expected <<EOF
289 [core]
290 repositoryformatversion = 0
291 filemode = true
292 bare = true
294 [remote "origin"]
295 url = ssh://127.0.0.1$testroot/repo
296 fetch = refs/heads/*:refs/remotes/origin/*
297 fetch = refs/tags/*:refs/tags/*
298 EOF
299 cmp -s $testroot/repo-clone/config $testroot/config.expected
300 ret=$?
301 if [ $ret -ne 0 ]; then
302 diff -u $testroot/config.expected \
303 $testroot/repo-clone/config
304 fi
305 test_done "$testroot" "$ret"
308 test_clone_mirror() {
309 local testroot=`test_init clone_mirror`
310 local testurl=ssh://127.0.0.1/$testroot
311 local commit_id=`git_show_head $testroot/repo`
313 got branch -r $testroot/repo -c $commit_id foo
314 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
315 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
316 local tag_id=`got ref -r $testroot/repo -l \
317 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
319 got clone -q -m $testurl/repo $testroot/repo-clone
320 ret=$?
321 if [ $ret -ne 0 ]; then
322 echo "got clone command failed unexpectedly" >&2
323 test_done "$testroot" "$ret"
324 return 1
325 fi
327 got ref -l -r $testroot/repo-clone > $testroot/stdout
329 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
330 # refs/heads/foo is missing because we're not fetching all branches
331 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
332 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
333 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
335 cmp -s $testroot/stdout $testroot/stdout.expected
336 ret=$?
337 if [ $ret -ne 0 ]; then
338 diff -u $testroot/stdout.expected $testroot/stdout
339 test_done "$testroot" "$ret"
340 return 1
341 fi
343 cat > $testroot/got.conf.expected <<EOF
344 remote "origin" {
345 server 127.0.0.1
346 protocol ssh
347 repository "$testroot/repo"
348 branch { "master" }
349 mirror_references yes
351 EOF
352 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
353 ret=$?
354 if [ $ret -ne 0 ]; then
355 diff -u $testroot/got.conf.expected \
356 $testroot/repo-clone/got.conf
357 test_done "$testroot" "$ret"
358 return 1
359 fi
361 cat > $testroot/config.expected <<EOF
362 [core]
363 repositoryformatversion = 0
364 filemode = true
365 bare = true
367 [remote "origin"]
368 url = ssh://127.0.0.1$testroot/repo
369 fetch = refs/heads/master:refs/heads/master
370 fetch = refs/tags/*:refs/tags/*
371 EOF
372 cmp -s $testroot/repo-clone/config $testroot/config.expected
373 ret=$?
374 if [ $ret -ne 0 ]; then
375 diff -u $testroot/config.expected \
376 $testroot/repo-clone/config
377 fi
378 test_done "$testroot" "$ret"
381 test_clone_mirror_all() {
382 local testroot=`test_init clone_mirror_all`
383 local testurl=ssh://127.0.0.1/$testroot
384 local commit_id=`git_show_head $testroot/repo`
386 got branch -r $testroot/repo -c $commit_id foo
387 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
388 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
389 local tag_id=`got ref -r $testroot/repo -l \
390 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
392 got clone -q -m -a $testurl/repo $testroot/repo-clone
393 ret=$?
394 if [ $ret -ne 0 ]; then
395 echo "got clone command failed unexpectedly" >&2
396 test_done "$testroot" "$ret"
397 return 1
398 fi
400 got ref -l -r $testroot/repo-clone > $testroot/stdout
402 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
403 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
404 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
405 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
406 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
408 cmp -s $testroot/stdout $testroot/stdout.expected
409 ret=$?
410 if [ $ret -ne 0 ]; then
411 diff -u $testroot/stdout.expected $testroot/stdout
412 test_done "$testroot" "$ret"
413 return 1
414 fi
416 cat > $testroot/got.conf.expected <<EOF
417 remote "origin" {
418 server 127.0.0.1
419 protocol ssh
420 repository "$testroot/repo"
421 mirror_references yes
422 fetch_all_branches yes
424 EOF
425 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
426 ret=$?
427 if [ $ret -ne 0 ]; then
428 diff -u $testroot/got.conf.expected \
429 $testroot/repo-clone/got.conf
430 test_done "$testroot" "$ret"
431 return 1
432 fi
434 cat > $testroot/config.expected <<EOF
435 [core]
436 repositoryformatversion = 0
437 filemode = true
438 bare = true
440 [remote "origin"]
441 url = ssh://127.0.0.1$testroot/repo
442 fetch = refs/heads/*:refs/heads/*
443 fetch = refs/tags/*:refs/tags/*
444 EOF
445 cmp -s $testroot/repo-clone/config $testroot/config.expected
446 ret=$?
447 if [ $ret -ne 0 ]; then
448 diff -u $testroot/config.expected \
449 $testroot/repo-clone/config
450 fi
451 test_done "$testroot" "$ret"
454 test_clone_reference() {
455 local testroot=`test_init clone_reference`
456 local testurl=ssh://127.0.0.1/$testroot
457 local commit_id=`git_show_head $testroot/repo`
459 got branch -r $testroot/repo -c $commit_id foo
460 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
461 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
462 local tag_id=`got ref -r $testroot/repo -l \
463 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
465 got clone -q -R hoo $testurl/repo $testroot/repo-clone
466 ret=$?
467 if [ $ret -ne 0 ]; then
468 echo "got clone command failed unexpectedly" >&2
469 test_done "$testroot" "$ret"
470 return 1
471 fi
473 got ref -l -r $testroot/repo-clone > $testroot/stdout
475 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
476 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
477 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
478 >> $testroot/stdout.expected
479 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
480 >> $testroot/stdout.expected
481 echo "refs/remotes/origin/master: $commit_id" \
482 >> $testroot/stdout.expected
483 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
485 cmp -s $testroot/stdout $testroot/stdout.expected
486 ret=$?
487 if [ $ret -ne 0 ]; then
488 diff -u $testroot/stdout.expected $testroot/stdout
489 test_done "$testroot" "$ret"
490 return 1
491 fi
493 cat > $testroot/got.conf.expected <<EOF
494 remote "origin" {
495 server 127.0.0.1
496 protocol ssh
497 repository "$testroot/repo"
498 branch { "master" }
499 reference { "hoo" }
501 EOF
502 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
503 ret=$?
504 if [ $ret -ne 0 ]; then
505 diff -u $testroot/got.conf.expected \
506 $testroot/repo-clone/got.conf
507 test_done "$testroot" "$ret"
508 return 1
509 fi
511 cat > $testroot/config.expected <<EOF
512 [core]
513 repositoryformatversion = 0
514 filemode = true
515 bare = true
517 [remote "origin"]
518 url = ssh://127.0.0.1$testroot/repo
519 fetch = refs/heads/master:refs/remotes/origin/master
520 fetch = refs/hoo:refs/remotes/origin/hoo
521 fetch = refs/tags/*:refs/tags/*
522 EOF
523 cmp -s $testroot/repo-clone/config $testroot/config.expected
524 ret=$?
525 if [ $ret -ne 0 ]; then
526 diff -u $testroot/config.expected \
527 $testroot/repo-clone/config
528 fi
529 test_done "$testroot" "$ret"
532 test_clone_branch_and_reference() {
533 local testroot=`test_init clone_reference`
534 local testurl=ssh://127.0.0.1/$testroot
535 local commit_id=`git_show_head $testroot/repo`
537 got branch -r $testroot/repo -c $commit_id foo
538 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
539 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
540 local tag_id=`got ref -r $testroot/repo -l \
541 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
543 got clone -q -R hoo/boo/zoo -b foo $testurl/repo $testroot/repo-clone
544 ret=$?
545 if [ $ret -ne 0 ]; then
546 echo "got clone command failed unexpectedly" >&2
547 test_done "$testroot" "$ret"
548 return 1
549 fi
551 got ref -l -r $testroot/repo-clone > $testroot/stdout
553 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
554 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
555 echo "refs/remotes/origin/foo: $commit_id" \
556 >> $testroot/stdout.expected
557 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
558 >> $testroot/stdout.expected
559 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
561 cmp -s $testroot/stdout $testroot/stdout.expected
562 ret=$?
563 if [ $ret -ne 0 ]; then
564 diff -u $testroot/stdout.expected $testroot/stdout
565 test_done "$testroot" "$ret"
566 return 1
567 fi
569 cat > $testroot/got.conf.expected <<EOF
570 remote "origin" {
571 server 127.0.0.1
572 protocol ssh
573 repository "$testroot/repo"
574 branch { "foo" }
575 reference { "hoo/boo/zoo" }
577 EOF
578 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
579 ret=$?
580 if [ $ret -ne 0 ]; then
581 diff -u $testroot/got.conf.expected \
582 $testroot/repo-clone/got.conf
583 test_done "$testroot" "$ret"
584 return 1
585 fi
587 cat > $testroot/config.expected <<EOF
588 [core]
589 repositoryformatversion = 0
590 filemode = true
591 bare = true
593 [remote "origin"]
594 url = ssh://127.0.0.1$testroot/repo
595 fetch = refs/heads/foo:refs/remotes/origin/foo
596 fetch = refs/hoo/boo/zoo:refs/remotes/origin/hoo/boo/zoo
597 fetch = refs/tags/*:refs/tags/*
598 EOF
599 cmp -s $testroot/repo-clone/config $testroot/config.expected
600 ret=$?
601 if [ $ret -ne 0 ]; then
602 diff -u $testroot/config.expected \
603 $testroot/repo-clone/config
604 fi
605 test_done "$testroot" "$ret"
608 test_clone_reference_mirror() {
609 local testroot=`test_init clone_reference_mirror`
610 local testurl=ssh://127.0.0.1/$testroot
611 local commit_id=`git_show_head $testroot/repo`
613 got branch -r $testroot/repo -c $commit_id foo
614 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
615 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
616 local tag_id=`got ref -r $testroot/repo -l \
617 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
619 got clone -q -R hoo -m $testurl/repo $testroot/repo-clone
620 ret=$?
621 if [ $ret -ne 0 ]; then
622 echo "got clone command failed unexpectedly" >&2
623 test_done "$testroot" "$ret"
624 return 1
625 fi
627 got ref -l -r $testroot/repo-clone > $testroot/stdout
629 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
630 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
631 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
632 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
634 cmp -s $testroot/stdout $testroot/stdout.expected
635 ret=$?
636 if [ $ret -ne 0 ]; then
637 diff -u $testroot/stdout.expected $testroot/stdout
638 test_done "$testroot" "$ret"
639 return 1
640 fi
642 cat > $testroot/got.conf.expected <<EOF
643 remote "origin" {
644 server 127.0.0.1
645 protocol ssh
646 repository "$testroot/repo"
647 branch { "master" }
648 reference { "hoo" }
649 mirror_references yes
651 EOF
652 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
653 ret=$?
654 if [ $ret -ne 0 ]; then
655 diff -u $testroot/got.conf.expected \
656 $testroot/repo-clone/got.conf
657 test_done "$testroot" "$ret"
658 return 1
659 fi
661 cat > $testroot/config.expected <<EOF
662 [core]
663 repositoryformatversion = 0
664 filemode = true
665 bare = true
667 [remote "origin"]
668 url = ssh://127.0.0.1$testroot/repo
669 fetch = refs/heads/master:refs/heads/master
670 fetch = refs/hoo:refs/hoo
671 fetch = refs/tags/*:refs/tags/*
672 EOF
673 cmp -s $testroot/repo-clone/config $testroot/config.expected
674 ret=$?
675 if [ $ret -ne 0 ]; then
676 diff -u $testroot/config.expected \
677 $testroot/repo-clone/config
678 fi
679 test_done "$testroot" "$ret"
682 test_clone_multiple_branches() {
683 local testroot=`test_init clone_multiple_branches`
684 local testurl=ssh://127.0.0.1/$testroot
685 local commit_id=`git_show_head $testroot/repo`
687 got branch -r $testroot/repo -c $commit_id foo
688 got branch -r $testroot/repo -c $commit_id bar
690 got clone -q -b foo -b bar $testurl/repo $testroot/repo-clone
691 ret=$?
692 if [ $ret -ne 0 ]; then
693 echo "got clone command failed unexpectedly" >&2
694 test_done "$testroot" "$ret"
695 return 1
696 fi
698 got ref -l -r $testroot/repo-clone > $testroot/stdout
700 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
701 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
702 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
703 echo "refs/remotes/origin/bar: $commit_id" \
704 >> $testroot/stdout.expected
705 echo "refs/remotes/origin/foo: $commit_id" \
706 >> $testroot/stdout.expected
708 cmp -s $testroot/stdout $testroot/stdout.expected
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
712 test_done "$testroot" "$ret"
713 return 1
714 fi
716 cat > $testroot/got.conf.expected <<EOF
717 remote "origin" {
718 server 127.0.0.1
719 protocol ssh
720 repository "$testroot/repo"
721 branch { "foo" "bar" }
723 EOF
724 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
725 ret=$?
726 if [ $ret -ne 0 ]; then
727 diff -u $testroot/got.conf.expected \
728 $testroot/repo-clone/got.conf
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 cat > $testroot/config.expected <<EOF
734 [core]
735 repositoryformatversion = 0
736 filemode = true
737 bare = true
739 [remote "origin"]
740 url = ssh://127.0.0.1$testroot/repo
741 fetch = refs/heads/foo:refs/remotes/origin/foo
742 fetch = refs/heads/bar:refs/remotes/origin/bar
743 fetch = refs/tags/*:refs/tags/*
744 EOF
745 cmp -s $testroot/repo-clone/config $testroot/config.expected
746 ret=$?
747 if [ $ret -ne 0 ]; then
748 diff -u $testroot/config.expected \
749 $testroot/repo-clone/config
750 fi
751 test_done "$testroot" "$ret"
754 test_clone_dangling_headref() {
755 local testroot=`test_init clone_dangling_headref`
756 local testurl=ssh://127.0.0.1/$testroot
757 local commit_id=`git_show_head $testroot/repo`
759 got branch -r $testroot/repo -d master > /dev/null
760 got branch -r $testroot/repo -c $commit_id foo
762 got ref -l -r $testroot/repo > $testroot/stdout
764 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
765 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
766 # refs/heads/master is missing because it was deleted above
768 cmp -s $testroot/stdout $testroot/stdout.expected
769 ret=$?
770 if [ $ret -ne 0 ]; then
771 diff -u $testroot/stdout.expected $testroot/stdout
772 test_done "$testroot" "$ret"
773 return 1
774 fi
776 got clone -q -b foo $testurl/repo $testroot/repo-clone
777 ret=$?
778 if [ $ret -ne 0 ]; then
779 echo "got clone command failed unexpectedly" >&2
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 got ref -l -r $testroot/repo-clone > $testroot/stdout
786 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
787 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
788 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
790 cmp -s $testroot/stdout $testroot/stdout.expected
791 ret=$?
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/stdout.expected $testroot/stdout
794 test_done "$testroot" "$ret"
795 return 1
796 fi
798 cat > $testroot/got.conf.expected <<EOF
799 remote "origin" {
800 server 127.0.0.1
801 protocol ssh
802 repository "$testroot/repo"
803 branch { "foo" }
805 EOF
806 cmp -s $testroot/repo-clone/got.conf $testroot/got.conf.expected
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 diff -u $testroot/got.conf.expected \
810 $testroot/repo-clone/got.conf
811 test_done "$testroot" "$ret"
812 return 1
813 fi
815 cat > $testroot/config.expected <<EOF
816 [core]
817 repositoryformatversion = 0
818 filemode = true
819 bare = true
821 [remote "origin"]
822 url = ssh://127.0.0.1$testroot/repo
823 fetch = refs/heads/foo:refs/remotes/origin/foo
824 fetch = refs/tags/*:refs/tags/*
825 EOF
826 cmp -s $testroot/repo-clone/config $testroot/config.expected
827 ret=$?
828 if [ $ret -ne 0 ]; then
829 diff -u $testroot/config.expected \
830 $testroot/repo-clone/config
831 fi
832 test_done "$testroot" "$ret"
835 test_parseargs "$@"
836 run_test test_clone_basic
837 run_test test_clone_list
838 run_test test_clone_branch
839 run_test test_clone_all
840 run_test test_clone_mirror
841 run_test test_clone_mirror_all
842 run_test test_clone_reference
843 run_test test_clone_branch_and_reference
844 run_test test_clone_reference_mirror
845 run_test test_clone_multiple_branches
846 run_test test_clone_dangling_headref