portable: release 0.93
[got-portable.git] / regress / cmdline / send.sh
blob95122a61da8bdfe16b530a54988fda3e5870a4ee
1 #!/bin/sh
3 # Copyright (c) 2021 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_send_basic() {
20 local testroot=`test_init send_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
31 cat > $testroot/repo/.git/got.conf <<EOF
32 remote "origin" {
33 protocol ssh
34 server 127.0.0.1
35 repository "$testroot/repo-clone"
37 EOF
38 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
39 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
40 | tr -d ' ' | cut -d: -f2`
42 echo "modified alpha" > $testroot/repo/alpha
43 (cd $testroot/repo && git rm -q beta)
44 (cd $testroot/repo && ln -s epsilon/zeta symlink && git add symlink)
45 echo "new file alpha" > $testroot/repo/new
46 (cd $testroot/repo && git add new)
47 git_commit $testroot/repo -m "modified alpha"
48 local commit_id2=`git_show_head $testroot/repo`
50 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 echo "got send command failed unexpectedly" >&2
54 test_done "$testroot" "$ret"
55 return 1
58 echo -n > $testroot/stdout.expected
59 cmp -s $testroot/stdout $testroot/stdout.expected
60 ret=$?
61 if [ $ret -ne 0 ]; then
62 diff -u $testroot/stdout.expected $testroot/stdout
63 test_done "$testroot" "$ret"
64 return 1
67 got ref -l -r $testroot/repo > $testroot/stdout
68 ret=$?
69 if [ $ret -ne 0 ]; then
70 echo "got ref command failed unexpectedly" >&2
71 test_done "$testroot" "$ret"
72 return 1
75 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
76 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
77 echo "refs/remotes/origin/master: $commit_id2" \
78 >> $testroot/stdout.expected
79 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
81 cmp -s $testroot/stdout $testroot/stdout.expected
82 ret=$?
83 if [ $ret -ne 0 ]; then
84 diff -u $testroot/stdout.expected $testroot/stdout
85 test_done "$testroot" "$ret"
86 return 1
89 got ref -l -r $testroot/repo-clone > $testroot/stdout
90 ret=$?
91 if [ $ret -ne 0 ]; then
92 echo "got ref command failed unexpectedly" >&2
93 test_done "$testroot" "$ret"
94 return 1
97 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
98 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
99 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
100 >> $testroot/stdout.expected
101 echo "refs/remotes/origin/master: $commit_id" \
102 >> $testroot/stdout.expected
104 cmp -s $testroot/stdout $testroot/stdout.expected
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/stdout.expected $testroot/stdout
108 test_done "$testroot" "$ret"
109 return 1
112 got tree -r $testroot/repo-clone -c $commit_id2 -i -R \
113 > $testroot/stdout
114 got tree -r $testroot/repo -c $commit_id2 -i -R \
115 > $testroot/stdout.expected
116 cmp -s $testroot/stdout $testroot/stdout.expected
117 ret=$?
118 if [ $ret -ne 0 ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
121 return 1
124 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
125 ret=$?
126 if [ $ret -ne 0 ]; then
127 echo "got send command failed unexpectedly" >&2
128 test_done "$testroot" "$ret"
129 return 1
132 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo-clone" \
133 > $testroot/stdout.expected
134 echo "Already up-to-date" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout $testroot/stdout.expected
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 test_done "$testroot" "$ret"
140 return 1
143 git_fsck "$testroot" "$testroot/repo-clone"
144 ret=$?
145 test_done "$testroot" "$ret"
148 test_send_rebase_required() {
149 local testroot=`test_init send_rebase_required`
150 local testurl=ssh://127.0.0.1/$testroot
151 local commit_id=`git_show_head $testroot/repo`
153 got clone -q $testurl/repo $testroot/repo-clone
154 ret=$?
155 if [ $ret -ne 0 ]; then
156 echo "got clone command failed unexpectedly" >&2
157 test_done "$testroot" "$ret"
158 return 1
160 cat > $testroot/repo/.git/got.conf <<EOF
161 remote "origin" {
162 protocol ssh
163 server 127.0.0.1
164 repository "$testroot/repo-clone"
167 echo "modified alpha" > $testroot/repo/alpha
168 git_commit $testroot/repo -m "modified alpha"
169 local commit_id2=`git_show_head $testroot/repo`
171 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
172 echo "modified alpha, too" > $testroot/wt-clone/alpha
173 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
175 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
176 ret=$?
177 if [ $ret -eq 0 ]; then
178 echo "got send command succeeded unexpectedly" >&2
179 test_done "$testroot" 1
180 return 1
183 echo -n > $testroot/stdout.expected
184 cmp -s $testroot/stdout $testroot/stdout.expected
185 ret=$?
186 if [ $ret -ne 0 ]; then
187 diff -u $testroot/stdout.expected $testroot/stdout
188 test_done "$testroot" "$ret"
189 return 1
192 echo "got: refs/heads/master: fetch and rebase required" \
193 > $testroot/stderr.expected
194 cmp -s $testroot/stderr $testroot/stderr.expected
195 ret=$?
196 if [ $ret -ne 0 ]; then
197 diff -u $testroot/stderr.expected $testroot/stderr
198 test_done "$testroot" "$ret"
199 return 1
202 git_fsck "$testroot" "$testroot/repo-clone"
203 ret=$?
204 test_done "$testroot" "$ret"
207 test_send_rebase_required_overwrite() {
208 local testroot=`test_init send_rebase_required_overwrite`
209 local testurl=ssh://127.0.0.1/$testroot
210 local commit_id=`git_show_head $testroot/repo`
212 got clone -q $testurl/repo $testroot/repo-clone
213 ret=$?
214 if [ $ret -ne 0 ]; then
215 echo "got clone command failed unexpectedly" >&2
216 test_done "$testroot" "$ret"
217 return 1
219 cat > $testroot/repo/.git/got.conf <<EOF
220 remote "foobar" {
221 protocol ssh
222 server 127.0.0.1
223 repository "$testroot/repo-clone"
226 echo "modified alpha" > $testroot/repo/alpha
227 git_commit $testroot/repo -m "modified alpha"
228 local commit_id2=`git_show_head $testroot/repo`
230 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
231 echo "modified alpha, too" > $testroot/wt-clone/alpha
232 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
233 local commit_id3=`git_show_head $testroot/repo-clone`
235 # non-default remote requires an explicit argument
236 got send -q -r $testroot/repo -f > $testroot/stdout \
237 2> $testroot/stderr
238 ret=$?
239 if [ $ret -eq 0 ]; then
240 echo "got send command succeeded unexpectedly" >&2
241 test_done "$testroot" 1
242 return 1
244 echo "got: origin: remote repository not found" \
245 > $testroot/stderr.expected
246 cmp -s $testroot/stderr $testroot/stderr.expected
247 ret=$?
248 if [ $ret -ne 0 ]; then
249 diff -u $testroot/stderr.expected $testroot/stderr
250 test_done "$testroot" "$ret"
251 return 1
254 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
255 2> $testroot/stderr
256 ret=$?
257 if [ $ret -ne 0 ]; then
258 echo "got send command failed unexpectedly" >&2
259 test_done "$testroot" "$ret"
260 return 1
263 echo -n > $testroot/stdout.expected
264 cmp -s $testroot/stdout $testroot/stdout.expected
265 ret=$?
266 if [ $ret -ne 0 ]; then
267 diff -u $testroot/stdout.expected $testroot/stdout
268 test_done "$testroot" "$ret"
269 return 1
272 got ref -l -r $testroot/repo > $testroot/stdout
273 ret=$?
274 if [ $ret -ne 0 ]; then
275 echo "got ref command failed unexpectedly" >&2
276 test_done "$testroot" "$ret"
277 return 1
280 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
281 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
282 echo "refs/remotes/foobar/master: $commit_id2" \
283 >> $testroot/stdout.expected
285 cmp -s $testroot/stdout $testroot/stdout.expected
286 ret=$?
287 if [ $ret -ne 0 ]; then
288 diff -u $testroot/stdout.expected $testroot/stdout
289 test_done "$testroot" "$ret"
290 return 1
293 got ref -l -r $testroot/repo-clone > $testroot/stdout
294 ret=$?
295 if [ $ret -ne 0 ]; then
296 echo "got ref command failed unexpectedly" >&2
297 test_done "$testroot" "$ret"
298 return 1
301 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
302 cut -d ':' -f 2 | tr -d ' ')`
303 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
304 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
305 >> $testroot/stdout.expected
306 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
307 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
308 >> $testroot/stdout.expected
309 echo "refs/remotes/origin/master: $commit_id" \
310 >> $testroot/stdout.expected
312 cmp -s $testroot/stdout $testroot/stdout.expected
313 ret=$?
314 if [ $ret -ne 0 ]; then
315 diff -u $testroot/stdout.expected $testroot/stdout
316 test_done "$testroot" "$ret"
317 return 1
320 git_fsck "$testroot" "$testroot/repo-clone"
321 ret=$?
322 test_done "$testroot" "$ret"
325 test_send_merge_commit() {
326 local testroot=`test_init send_merge_commit`
327 local testurl=ssh://127.0.0.1/$testroot
329 if ! got clone -q "$testurl/repo" "$testroot/repo-clone"; then
330 echo "got clone command failed unexpectedly" >&2
331 test_done "$testroot" 1
332 return 1
335 echo 'upstream change' > $testroot/repo/alpha
336 git_commit $testroot/repo -m 'upstream change'
338 got checkout $testroot/repo-clone $testroot/wt-clone > /dev/null
339 echo 'downstream change' > $testroot/wt-clone/beta
340 (cd $testroot/wt-clone && got commit -m 'downstream change' > /dev/null)
342 got fetch -q -r $testroot/repo-clone
343 (cd $testroot/wt-clone && got update > /dev/null)
344 (cd $testroot/wt-clone && got merge origin/master > /dev/null)
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 echo "got merge command failed unexpectedly" >&2
348 test_done "$testroot" "$ret"
349 return 1
352 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
354 got send -q -r $testroot/repo-clone
355 ret=$?
356 if [ $ret -ne 0 ]; then
357 test_done "$testroot" "$ret"
358 return 1
361 test_done "$testroot" 0
364 test_send_delete() {
365 local testroot=`test_init send_delete`
366 local testurl=ssh://127.0.0.1/$testroot
367 local commit_id=`git_show_head $testroot/repo`
369 # branch1 exists in both repositories
370 got branch -r $testroot/repo branch1
372 got clone -a -q $testurl/repo $testroot/repo-clone
373 ret=$?
374 if [ $ret -ne 0 ]; then
375 echo "got clone command failed unexpectedly" >&2
376 test_done "$testroot" "$ret"
377 return 1
379 cat > $testroot/repo/.git/got.conf <<EOF
380 remote "origin" {
381 protocol ssh
382 server 127.0.0.1
383 repository "$testroot/repo-clone"
386 # branch2 exists only in the remote repository
387 got branch -r $testroot/repo-clone branch2
389 got ref -l -r $testroot/repo-clone > $testroot/stdout
390 ret=$?
391 if [ $ret -ne 0 ]; then
392 echo "got ref command failed unexpectedly" >&2
393 test_done "$testroot" "$ret"
394 return 1
397 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
398 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
399 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
400 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
402 # Sending changes for a branch and deleting it at the same
403 # time is not allowed.
404 got send -q -r $testroot/repo -d branch1 -b branch1 \
405 > $testroot/stdout 2> $testroot/stderr
406 ret=$?
407 if [ $ret -eq 0 ]; then
408 echo "got send command succeeded unexpectedly" >&2
409 test_done "$testroot" 1
410 return 1
412 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
413 > $testroot/stderr.expected
414 echo ": reference cannot be deleted" >> $testroot/stderr.expected
415 cmp -s $testroot/stderr $testroot/stderr.expected
416 ret=$?
417 if [ $ret -ne 0 ]; then
418 diff -u $testroot/stderr.expected $testroot/stderr
419 test_done "$testroot" "$ret"
420 return 1
423 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
424 > $testroot/stdout 2> $testroot/stderr
425 ret=$?
426 if [ $ret -ne 0 ]; then
427 echo "got send command failed unexpectedly" >&2
428 test_done "$testroot" "$ret"
429 return 1
432 got send -r $testroot/repo -d refs/heads/branch2 origin \
433 > $testroot/stdout 2>$testroot/stderr
434 ret=$?
435 if [ $ret -ne 0 ]; then
436 echo "got send command failed unexpectedly" >&2
437 test_done "$testroot" "$ret"
438 return 1
441 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo-clone" \
442 > $testroot/stdout.expected
443 echo "Server has deleted refs/heads/branch2" \
444 >> $testroot/stdout.expected
446 cmp -s $testroot/stdout $testroot/stdout.expected
447 ret=$?
448 if [ $ret -ne 0 ]; then
449 diff -u $testroot/stdout.expected $testroot/stdout
450 test_done "$testroot" "$ret"
451 return 1
454 # branchX exists in neither repository
455 got send -q -r $testroot/repo -d refs/heads/branchX origin \
456 > $testroot/stdout 2> $testroot/stderr
457 ret=$?
458 if [ $ret -eq 0 ]; then
459 echo "got send command succeeded unexpectedly" >&2
460 test_done "$testroot" 1
461 return 1
463 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
464 > $testroot/stderr.expected
465 echo "repository: no such reference found" >> $testroot/stderr.expected
466 echo "got: no such reference found" >> $testroot/stderr.expected
467 cmp -s $testroot/stderr $testroot/stderr.expected
468 ret=$?
469 if [ $ret -ne 0 ]; then
470 diff -u $testroot/stderr.expected $testroot/stderr
471 test_done "$testroot" "$ret"
472 return 1
475 # References outside of refs/heads/ cannot be deleted with 'got send'.
476 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
477 > $testroot/stdout 2> $testroot/stderr
478 ret=$?
479 if [ $ret -eq 0 ]; then
480 echo "got send command succeeded unexpectedly" >&2
481 test_done "$testroot" 1
482 return 1
484 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
485 > $testroot/stderr.expected
486 echo "in remote repository: no such reference found" \
487 >> $testroot/stderr.expected
488 echo "got: no such reference found" >> $testroot/stderr.expected
489 cmp -s $testroot/stderr $testroot/stderr.expected
490 ret=$?
491 if [ $ret -ne 0 ]; then
492 diff -u $testroot/stderr.expected $testroot/stderr
493 test_done "$testroot" "$ret"
494 return 1
497 got ref -l -r $testroot/repo > $testroot/stdout
498 ret=$?
499 if [ $ret -ne 0 ]; then
500 echo "got ref command failed unexpectedly" >&2
501 test_done "$testroot" "$ret"
502 return 1
505 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
506 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
507 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
509 cmp -s $testroot/stdout $testroot/stdout.expected
510 ret=$?
511 if [ $ret -ne 0 ]; then
512 diff -u $testroot/stdout.expected $testroot/stdout
513 test_done "$testroot" "$ret"
514 return 1
517 got ref -l -r $testroot/repo-clone > $testroot/stdout
518 ret=$?
519 if [ $ret -ne 0 ]; then
520 echo "got ref command failed unexpectedly" >&2
521 test_done "$testroot" "$ret"
522 return 1
525 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
526 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
527 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
528 >> $testroot/stdout.expected
529 echo "refs/remotes/origin/branch1: $commit_id" \
530 >> $testroot/stdout.expected
531 echo "refs/remotes/origin/master: $commit_id" \
532 >> $testroot/stdout.expected
534 cmp -s $testroot/stdout $testroot/stdout.expected
535 ret=$?
536 if [ $ret -ne 0 ]; then
537 diff -u $testroot/stdout.expected $testroot/stdout
538 test_done "$testroot" "$ret"
539 return 1
542 git_fsck "$testroot" "$testroot/repo-clone"
543 ret=$?
544 test_done "$testroot" "$ret"
547 test_send_clone_and_send() {
548 local testroot=`test_init send_clone_and_send`
549 local testurl=ssh://127.0.0.1/$testroot
550 local commit_id=`git_show_head $testroot/repo`
552 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
554 got clone -q $testurl/repo $testroot/repo-clone
555 ret=$?
556 if [ $ret -ne 0 ]; then
557 echo "got clone command failed unexpectedly" >&2
558 test_done "$testroot" "$ret"
559 return 1
562 got checkout $testroot/repo-clone $testroot/wt >/dev/null
563 echo "modified alpha" > $testroot/wt/alpha
564 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
565 local commit_id2=`git_show_head $testroot/repo-clone`
567 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
568 ret=$?
569 if [ $ret -ne 0 ]; then
570 echo "got send command failed unexpectedly" >&2
571 test_done "$testroot" "$ret"
572 return 1
575 echo -n > $testroot/stdout.expected
576 cmp -s $testroot/stdout $testroot/stdout.expected
577 ret=$?
578 if [ $ret -ne 0 ]; then
579 diff -u $testroot/stdout.expected $testroot/stdout
580 test_done "$testroot" "$ret"
581 return 1
584 got ref -l -r $testroot/repo > $testroot/stdout
585 ret=$?
586 if [ $ret -ne 0 ]; then
587 echo "got ref command failed unexpectedly" >&2
588 test_done "$testroot" "$ret"
589 return 1
592 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
593 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
595 cmp -s $testroot/stdout $testroot/stdout.expected
596 ret=$?
597 if [ $ret -ne 0 ]; then
598 diff -u $testroot/stdout.expected $testroot/stdout
599 test_done "$testroot" "$ret"
600 return 1
603 got ref -l -r $testroot/repo-clone > $testroot/stdout
604 ret=$?
605 if [ $ret -ne 0 ]; then
606 echo "got ref command failed unexpectedly" >&2
607 test_done "$testroot" "$ret"
608 return 1
611 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
612 cut -d ':' -f 2 | tr -d ' ')`
613 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
614 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
615 >> $testroot/stdout.expected
616 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
617 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
618 >> $testroot/stdout.expected
619 echo "refs/remotes/origin/master: $commit_id2" \
620 >> $testroot/stdout.expected
622 cmp -s $testroot/stdout $testroot/stdout.expected
623 ret=$?
624 if [ $ret -ne 0 ]; then
625 diff -u $testroot/stdout.expected $testroot/stdout
626 test_done "$testroot" "$ret"
627 return 1
630 git_fsck "$testroot" "$testroot/repo-clone"
631 ret=$?
632 test_done "$testroot" "$ret"
635 test_send_tags() {
636 local testroot=`test_init send_tags`
637 local testurl=ssh://127.0.0.1/$testroot
638 local commit_id=`git_show_head $testroot/repo`
640 got clone -q $testurl/repo $testroot/repo-clone
641 ret=$?
642 if [ $ret -ne 0 ]; then
643 echo "got clone command failed unexpectedly" >&2
644 test_done "$testroot" "$ret"
645 return 1
647 cat > $testroot/repo/.git/got.conf <<EOF
648 remote "origin" {
649 protocol ssh
650 server 127.0.0.1
651 repository "$testroot/repo-clone"
654 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
655 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
656 | tr -d ' ' | cut -d: -f2`
658 echo "modified alpha" > $testroot/repo/alpha
659 git_commit $testroot/repo -m "modified alpha"
660 local commit_id2=`git_show_head $testroot/repo`
662 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
663 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
664 | tr -d ' ' | cut -d: -f2`
666 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
667 ret=$?
668 if [ $ret -ne 0 ]; then
669 echo "got send command failed unexpectedly" >&2
670 test_done "$testroot" "$ret"
671 return 1
674 echo -n > $testroot/stdout.expected
675 cmp -s $testroot/stdout $testroot/stdout.expected
676 ret=$?
677 if [ $ret -ne 0 ]; then
678 diff -u $testroot/stdout.expected $testroot/stdout
679 test_done "$testroot" "$ret"
680 return 1
683 got ref -l -r $testroot/repo > $testroot/stdout
684 ret=$?
685 if [ $ret -ne 0 ]; then
686 echo "got ref command failed unexpectedly" >&2
687 test_done "$testroot" "$ret"
688 return 1
691 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
692 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
693 echo "refs/remotes/origin/master: $commit_id2" \
694 >> $testroot/stdout.expected
695 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
696 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
698 cmp -s $testroot/stdout $testroot/stdout.expected
699 ret=$?
700 if [ $ret -ne 0 ]; then
701 diff -u $testroot/stdout.expected $testroot/stdout
702 test_done "$testroot" "$ret"
703 return 1
706 got ref -l -r $testroot/repo-clone > $testroot/stdout
707 ret=$?
708 if [ $ret -ne 0 ]; then
709 echo "got ref command failed unexpectedly" >&2
710 test_done "$testroot" "$ret"
711 return 1
714 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
715 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
716 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
717 >> $testroot/stdout.expected
718 echo "refs/remotes/origin/master: $commit_id" \
719 >> $testroot/stdout.expected
720 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
721 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
723 cmp -s $testroot/stdout $testroot/stdout.expected
724 ret=$?
725 if [ $ret -ne 0 ]; then
726 diff -u $testroot/stdout.expected $testroot/stdout
727 test_done "$testroot" "$ret"
728 return 1
731 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
732 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
733 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
734 cmp -s $testroot/stdout $testroot/stdout.expected
735 ret=$?
736 if [ $ret -ne 0 ]; then
737 diff -u $testroot/stdout.expected $testroot/stdout
738 test_done "$testroot" "$ret"
739 return 1
742 # Send the same tags again. This should be a no-op.
743 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 echo "got send command failed unexpectedly" >&2
747 test_done "$testroot" "$ret"
748 return 1
751 echo -n > $testroot/stdout.expected
752 cmp -s $testroot/stdout $testroot/stdout.expected
753 ret=$?
754 if [ $ret -ne 0 ]; then
755 diff -u $testroot/stdout.expected $testroot/stdout
756 test_done "$testroot" "$ret"
757 return 1
760 # Overwriting an existing tag 'got send -f'.
761 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
762 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
763 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
764 | tr -d ' ' | cut -d: -f2`
766 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
767 2> $testroot/stderr
768 ret=$?
769 if [ $ret -eq 0 ]; then
770 echo "got send command succeeded unexpectedly" >&2
771 test_done "$testroot" 1
772 return 1
775 echo "got: refs/tags/1.0: tag already exists on server" \
776 > $testroot/stderr.expected
777 cmp -s $testroot/stderr $testroot/stderr.expected
778 ret=$?
779 if [ $ret -ne 0 ]; then
780 diff -u $testroot/stderr.expected $testroot/stderr
781 test_done "$testroot" "$ret"
782 return 1
785 # attempting the same with -T should fail, too
786 got send -q -r $testroot/repo -T > $testroot/stdout \
787 2> $testroot/stderr
788 ret=$?
789 if [ $ret -eq 0 ]; then
790 echo "got send command succeeded unexpectedly" >&2
791 test_done "$testroot" 1
792 return 1
795 echo "got: refs/tags/1.0: tag already exists on server" \
796 > $testroot/stderr.expected
797 cmp -s $testroot/stderr $testroot/stderr.expected
798 ret=$?
799 if [ $ret -ne 0 ]; then
800 diff -u $testroot/stderr.expected $testroot/stderr
801 test_done "$testroot" "$ret"
802 return 1
805 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
806 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
807 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
808 cmp -s $testroot/stdout $testroot/stdout.expected
809 ret=$?
810 if [ $ret -ne 0 ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 test_done "$testroot" "$ret"
813 return 1
816 # overwrite the 1.0 tag only
817 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
818 2> $testroot/stderr
819 ret=$?
820 if [ $ret -ne 0 ]; then
821 echo "got send command failed unexpectedly" >&2
822 test_done "$testroot" "$ret"
823 return 1
826 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
827 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
828 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
829 cmp -s $testroot/stdout $testroot/stdout.expected
830 ret=$?
831 if [ $ret -ne 0 ]; then
832 diff -u $testroot/stdout.expected $testroot/stdout
833 test_done "$testroot" "$ret"
834 return 1
837 got checkout $testroot/repo $testroot/wt > /dev/null
838 echo 'new line in file alpha' >> $testroot/wt/alpha
839 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
841 # Send the new commit in isolation.
842 got send -q -r $testroot/repo > $testroot/stdout \
843 2> $testroot/stderr
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 echo "got send command failed unexpectedly" >&2
847 test_done "$testroot" "$ret"
848 return 1
851 # Now tag it and send the tag.
852 # Verify that just the new tag object gets sent.
853 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
854 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
855 | tr -d ' ' | cut -d: -f2`
857 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
858 2> $testroot/stderr
859 ret=$?
860 if [ $ret -ne 0 ]; then
861 echo "got send command failed unexpectedly" >&2
862 test_done "$testroot" "$ret"
863 return 1
865 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
866 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
867 $testroot/stdout; then
868 echo "got send did apparently pack too many objects:" >&2
869 cat $testroot/stdout.raw >&2
870 test_done "$testroot" "1"
871 return 1
874 git_fsck "$testroot" "$testroot/repo-clone"
875 ret=$?
876 test_done "$testroot" "$ret"
879 test_send_tag_of_deleted_branch() {
880 local testroot=`test_init send_tag_of_deleted_branch`
881 local testurl=ssh://127.0.0.1/$testroot
882 local commit_id=`git_show_head $testroot/repo`
884 got clone -q $testurl/repo $testroot/repo-clone
885 ret=$?
886 if [ $ret -ne 0 ]; then
887 echo "got clone command failed unexpectedly" >&2
888 test_done "$testroot" "$ret"
889 return 1
891 cat > $testroot/repo/.git/got.conf <<EOF
892 remote "origin" {
893 protocol ssh
894 server 127.0.0.1
895 repository "$testroot/repo-clone"
898 got branch -r $testroot/repo foo
900 # modify beta on branch foo
901 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
902 echo boo >> $testroot/wt/beta
903 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
904 > /dev/null)
905 echo buu >> $testroot/wt/beta
906 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
907 > /dev/null)
908 echo baa >> $testroot/wt/beta
909 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
910 > /dev/null)
911 local commit_id2=`git_show_branch_head $testroot/repo foo`
913 # tag HEAD commit of branch foo
914 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
915 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
916 | tr -d ' ' | cut -d: -f2`
918 # delete the branch; commit is now only reachable via tags/1.0
919 got branch -r $testroot/repo -d foo > /dev/null
921 # unrelated change on master branch, then try sending this branch
922 # and the tag
923 echo "modified alpha" > $testroot/repo/alpha
924 git_commit $testroot/repo -m "modified alpha"
925 local commit_id3=`git_show_head $testroot/repo`
927 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
928 ret=$?
929 if [ $ret -ne 0 ]; then
930 echo "got send command failed unexpectedly" >&2
931 test_done "$testroot" "$ret"
932 return 1
935 echo -n > $testroot/stdout.expected
936 cmp -s $testroot/stdout $testroot/stdout.expected
937 ret=$?
938 if [ $ret -ne 0 ]; then
939 diff -u $testroot/stdout.expected $testroot/stdout
940 test_done "$testroot" "$ret"
941 return 1
944 got ref -l -r $testroot/repo > $testroot/stdout
945 ret=$?
946 if [ $ret -ne 0 ]; then
947 echo "got ref command failed unexpectedly" >&2
948 test_done "$testroot" "$ret"
949 return 1
952 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
953 cut -d ':' -f 2 | tr -d ' ')`
954 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
955 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
956 >> $testroot/stdout.expected
957 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
958 echo "refs/remotes/origin/master: $commit_id3" \
959 >> $testroot/stdout.expected
960 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
962 cmp -s $testroot/stdout $testroot/stdout.expected
963 ret=$?
964 if [ $ret -ne 0 ]; then
965 diff -u $testroot/stdout.expected $testroot/stdout
966 test_done "$testroot" "$ret"
967 return 1
970 got ref -l -r $testroot/repo-clone > $testroot/stdout
971 ret=$?
972 if [ $ret -ne 0 ]; then
973 echo "got ref command failed unexpectedly" >&2
974 test_done "$testroot" "$ret"
975 return 1
978 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
979 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
980 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
981 >> $testroot/stdout.expected
982 echo "refs/remotes/origin/master: $commit_id" \
983 >> $testroot/stdout.expected
984 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
986 cmp -s $testroot/stdout $testroot/stdout.expected
987 ret=$?
988 if [ $ret -ne 0 ]; then
989 diff -u $testroot/stdout.expected $testroot/stdout
990 test_done "$testroot" "$ret"
991 return 1
994 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
995 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
997 cmp -s $testroot/stdout $testroot/stdout.expected
998 ret=$?
999 if [ $ret -ne 0 ]; then
1000 diff -u $testroot/stdout.expected $testroot/stdout
1001 test_done "$testroot" "$ret"
1002 return 1
1005 git_fsck "$testroot" "$testroot/repo-clone"
1006 ret=$?
1007 test_done "$testroot" "$ret"
1010 test_send_new_branch() {
1011 local testroot=`test_init send_new_branch`
1012 local testurl=ssh://127.0.0.1/$testroot
1013 local commit_id=`git_show_head $testroot/repo`
1015 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1017 got clone -q $testurl/repo $testroot/repo-clone
1018 ret=$?
1019 if [ $ret -ne 0 ]; then
1020 echo "got clone command failed unexpectedly" >&2
1021 test_done "$testroot" "$ret"
1022 return 1
1025 got branch -r $testroot/repo-clone foo >/dev/null
1026 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
1027 echo "modified alpha" > $testroot/wt/alpha
1028 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1029 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
1031 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
1032 ret=$?
1033 if [ $ret -ne 0 ]; then
1034 echo "got send command failed unexpectedly" >&2
1035 test_done "$testroot" "$ret"
1036 return 1
1039 echo -n > $testroot/stdout.expected
1040 cmp -s $testroot/stdout $testroot/stdout.expected
1041 ret=$?
1042 if [ $ret -ne 0 ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1045 return 1
1048 got ref -l -r $testroot/repo > $testroot/stdout
1049 ret=$?
1050 if [ $ret -ne 0 ]; then
1051 echo "got ref command failed unexpectedly" >&2
1052 test_done "$testroot" "$ret"
1053 return 1
1056 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1057 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1058 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1060 cmp -s $testroot/stdout $testroot/stdout.expected
1061 ret=$?
1062 if [ $ret -ne 0 ]; then
1063 diff -u $testroot/stdout.expected $testroot/stdout
1064 test_done "$testroot" "$ret"
1065 return 1
1068 got ref -l -r $testroot/repo-clone > $testroot/stdout
1069 ret=$?
1070 if [ $ret -ne 0 ]; then
1071 echo "got ref command failed unexpectedly" >&2
1072 test_done "$testroot" "$ret"
1073 return 1
1076 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1077 cut -d ':' -f 2 | tr -d ' ')`
1078 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1079 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1080 >> $testroot/stdout.expected
1081 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1082 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1083 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1084 >> $testroot/stdout.expected
1085 echo "refs/remotes/origin/foo: $commit_id2" \
1086 >> $testroot/stdout.expected
1087 echo "refs/remotes/origin/master: $commit_id" \
1088 >> $testroot/stdout.expected
1090 cmp -s $testroot/stdout $testroot/stdout.expected
1091 ret=$?
1092 if [ $ret -ne 0 ]; then
1093 diff -u $testroot/stdout.expected $testroot/stdout
1094 test_done "$testroot" "$ret"
1095 return 1
1098 git_fsck "$testroot" "$testroot/repo-clone"
1099 ret=$?
1100 test_done "$testroot" "$ret"
1103 test_send_all_branches() {
1104 local testroot=`test_init send_all_branches`
1105 local testurl=ssh://127.0.0.1/$testroot
1106 local commit_id=`git_show_head $testroot/repo`
1108 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1110 got clone -q $testurl/repo $testroot/repo-clone
1111 ret=$?
1112 if [ $ret -ne 0 ]; then
1113 echo "got clone command failed unexpectedly" >&2
1114 test_done "$testroot" "$ret"
1115 return 1
1118 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1119 echo "modified alpha" > $testroot/wt/alpha
1120 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1121 local commit_id2=`git_show_head $testroot/repo-clone`
1123 got branch -r $testroot/repo-clone foo >/dev/null
1124 (cd $testroot/wt && got update -b foo >/dev/null)
1125 echo "modified beta on new branch foo" > $testroot/wt/beta
1126 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1127 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1129 got branch -r $testroot/repo-clone bar >/dev/null
1130 (cd $testroot/wt && got update -b bar >/dev/null)
1131 echo "modified beta again on new branch bar" > $testroot/wt/beta
1132 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1133 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1135 got ref -l -r $testroot/repo-clone > $testroot/stdout
1136 ret=$?
1137 if [ $ret -ne 0 ]; then
1138 echo "got ref command failed unexpectedly" >&2
1139 test_done "$testroot" "$ret"
1140 return 1
1143 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1144 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1145 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1146 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1148 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1149 2> $testroot/stderr
1150 ret=$?
1151 if [ $ret -eq 0 ]; then
1152 echo "got send command succeeded unexpectedly" >&2
1153 test_done "$testroot" 1
1154 return 1
1156 echo "got: -a and -b options are mutually exclusive" \
1157 > $testroot/stderr.expected
1158 cmp -s $testroot/stderr $testroot/stderr.expected
1159 ret=$?
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/stderr.expected $testroot/stderr
1162 test_done "$testroot" "$ret"
1163 return 1
1166 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1167 2> $testroot/stderr
1168 ret=$?
1169 if [ $ret -ne 0 ]; then
1170 echo "got send command failed unexpectedly" >&2
1171 test_done "$testroot" "$ret"
1172 return 1
1175 echo -n > $testroot/stdout.expected
1176 cmp -s $testroot/stdout $testroot/stdout.expected
1177 ret=$?
1178 if [ $ret -ne 0 ]; then
1179 diff -u $testroot/stdout.expected $testroot/stdout
1180 test_done "$testroot" "$ret"
1181 return 1
1184 got ref -l -r $testroot/repo > $testroot/stdout
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 echo "got ref command failed unexpectedly" >&2
1188 test_done "$testroot" "$ret"
1189 return 1
1192 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1193 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1194 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1195 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1197 cmp -s $testroot/stdout $testroot/stdout.expected
1198 ret=$?
1199 if [ $ret -ne 0 ]; then
1200 diff -u $testroot/stdout.expected $testroot/stdout
1201 test_done "$testroot" "$ret"
1202 return 1
1205 got ref -l -r $testroot/repo-clone > $testroot/stdout
1206 ret=$?
1207 if [ $ret -ne 0 ]; then
1208 echo "got ref command failed unexpectedly" >&2
1209 test_done "$testroot" "$ret"
1210 return 1
1213 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1214 cut -d ':' -f 2 | tr -d ' ')`
1215 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1216 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1217 >> $testroot/stdout.expected
1218 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1219 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1220 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1221 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1222 >> $testroot/stdout.expected
1223 echo "refs/remotes/origin/bar: $commit_id4" \
1224 >> $testroot/stdout.expected
1225 echo "refs/remotes/origin/foo: $commit_id3" \
1226 >> $testroot/stdout.expected
1227 echo "refs/remotes/origin/master: $commit_id2" \
1228 >> $testroot/stdout.expected
1230 cmp -s $testroot/stdout $testroot/stdout.expected
1231 ret=$?
1232 if [ $ret -ne 0 ]; then
1233 diff -u $testroot/stdout.expected $testroot/stdout
1234 test_done "$testroot" "$ret"
1235 return 1
1238 git_fsck "$testroot" "$testroot/repo-clone"
1239 ret=$?
1240 test_done "$testroot" "$ret"
1243 test_send_to_empty_repo() {
1244 local testroot=`test_init send_to_empty_repo`
1245 local testurl=ssh://127.0.0.1/$testroot
1246 local commit_id=`git_show_head $testroot/repo`
1248 gotadmin init $testroot/repo2
1250 ret=$?
1251 if [ $ret -ne 0 ]; then
1252 echo "got clone command failed unexpectedly" >&2
1253 test_done "$testroot" "$ret"
1254 return 1
1256 cat > $testroot/repo/.git/got.conf <<EOF
1257 remote "origin" {
1258 protocol ssh
1259 server 127.0.0.1
1260 repository "$testroot/repo2"
1263 echo "modified alpha" > $testroot/repo/alpha
1264 git_commit $testroot/repo -m "modified alpha"
1265 local commit_id2=`git_show_head $testroot/repo`
1267 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1268 ret=$?
1269 if [ $ret -ne 0 ]; then
1270 echo "got send command failed unexpectedly" >&2
1271 test_done "$testroot" "$ret"
1272 return 1
1275 echo -n > $testroot/stdout.expected
1276 cmp -s $testroot/stdout $testroot/stdout.expected
1277 ret=$?
1278 if [ $ret -ne 0 ]; then
1279 diff -u $testroot/stdout.expected $testroot/stdout
1280 test_done "$testroot" "$ret"
1281 return 1
1284 # XXX Workaround: We cannot give the target for HEAD to 'gotadmin init'
1285 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1287 got ref -l -r $testroot/repo > $testroot/stdout
1288 ret=$?
1289 if [ $ret -ne 0 ]; then
1290 echo "got ref command failed unexpectedly" >&2
1291 test_done "$testroot" "$ret"
1292 return 1
1295 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1296 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1297 echo "refs/remotes/origin/master: $commit_id2" \
1298 >> $testroot/stdout.expected
1300 cmp -s $testroot/stdout $testroot/stdout.expected
1301 ret=$?
1302 if [ $ret -ne 0 ]; then
1303 diff -u $testroot/stdout.expected $testroot/stdout
1304 test_done "$testroot" "$ret"
1305 return 1
1308 got ref -l -r $testroot/repo2 > $testroot/stdout
1309 ret=$?
1310 if [ $ret -ne 0 ]; then
1311 echo "got ref command failed unexpectedly" >&2
1312 test_done "$testroot" "$ret"
1313 return 1
1316 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1317 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1319 cmp -s $testroot/stdout $testroot/stdout.expected
1320 ret=$?
1321 if [ $ret -ne 0 ]; then
1322 diff -u $testroot/stdout.expected $testroot/stdout
1323 test_done "$testroot" "$ret"
1324 return 1
1327 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1328 ret=$?
1329 if [ $ret -ne 0 ]; then
1330 echo "got send command failed unexpectedly" >&2
1331 test_done "$testroot" "$ret"
1332 return 1
1335 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo2" \
1336 > $testroot/stdout.expected
1337 echo "Already up-to-date" >> $testroot/stdout.expected
1338 cmp -s $testroot/stdout $testroot/stdout.expected
1339 ret=$?
1340 if [ $ret -ne 0 ]; then
1341 diff -u $testroot/stdout.expected $testroot/stdout
1342 test_done "$testroot" "$ret"
1343 return 1
1346 git_fsck "$testroot" "$testroot/repo2"
1347 ret=$?
1348 test_done "$testroot" "$ret"
1351 test_send_and_fetch_config() {
1352 local testroot=`test_init send_fetch_conf`
1353 local testurl=ssh://127.0.0.1/$testroot
1354 local commit_id=`git_show_head $testroot/repo`
1356 got clone -q $testurl/repo $testroot/repo-clone
1357 ret=$?
1358 if [ $ret -ne 0 ]; then
1359 echo "got clone command failed unexpectedly" >&2
1360 test_done "$testroot" "$ret"
1361 return 1
1364 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1365 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1366 | tr -d ' ' | cut -d: -f2`
1368 cp -R $testroot/repo-clone $testroot/repo-clone2
1369 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1370 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1371 | tr -d ' ' | cut -d: -f2`
1373 cat > $testroot/repo/.git/got.conf <<EOF
1374 remote "origin" {
1375 protocol ssh
1376 server 127.0.0.1
1377 send {
1378 repository "$testroot/repo-clone"
1380 fetch {
1381 repository "$testroot/repo-clone2"
1385 got ref -l -r $testroot/repo > $testroot/stdout
1386 ret=$?
1387 if [ $ret -ne 0 ]; then
1388 echo "got ref command failed unexpectedly" >&2
1389 test_done "$testroot" "$ret"
1390 return 1
1393 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1394 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1395 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1396 cmp -s $testroot/stdout $testroot/stdout.expected
1397 ret=$?
1398 if [ $ret -ne 0 ]; then
1399 diff -u $testroot/stdout.expected $testroot/stdout
1400 test_done "$testroot" "$ret"
1401 return 1
1404 # fetch tag 2.0 from repo-clone2
1405 got fetch -q -r $testroot/repo > $testroot/stdout
1406 ret=$?
1407 if [ $ret -ne 0 ]; then
1408 echo "got fetch command failed unexpectedly" >&2
1409 test_done "$testroot" "$ret"
1410 return 1
1413 got ref -l -r $testroot/repo > $testroot/stdout
1414 ret=$?
1415 if [ $ret -ne 0 ]; then
1416 echo "got ref command failed unexpectedly" >&2
1417 test_done "$testroot" "$ret"
1418 return 1
1421 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1422 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1423 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1424 >> $testroot/stdout.expected
1425 echo "refs/remotes/origin/master: $commit_id" \
1426 >> $testroot/stdout.expected
1427 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1428 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1429 cmp -s $testroot/stdout $testroot/stdout.expected
1430 ret=$?
1431 if [ $ret -ne 0 ]; then
1432 diff -u $testroot/stdout.expected $testroot/stdout
1433 test_done "$testroot" "$ret"
1434 return 1
1437 # send tag 1.0 to repo-clone
1438 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1439 ret=$?
1440 if [ $ret -ne 0 ]; then
1441 echo "got send command failed unexpectedly" >&2
1442 test_done "$testroot" "$ret"
1443 return 1
1446 got ref -l -r $testroot/repo-clone > $testroot/stdout
1447 ret=$?
1448 if [ $ret -ne 0 ]; then
1449 echo "got ref command failed unexpectedly" >&2
1450 test_done "$testroot" "$ret"
1451 return 1
1454 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1455 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1456 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1457 >> $testroot/stdout.expected
1458 echo "refs/remotes/origin/master: $commit_id" \
1459 >> $testroot/stdout.expected
1460 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1462 cmp -s $testroot/stdout $testroot/stdout.expected
1463 ret=$?
1464 if [ $ret -ne 0 ]; then
1465 diff -u $testroot/stdout.expected $testroot/stdout
1466 test_done "$testroot" "$ret"
1467 return 1
1470 git_fsck "$testroot" "$testroot/repo-clone"
1471 ret=$?
1472 test_done "$testroot" "$ret"
1475 test_send_config() {
1476 local testroot=`test_init send_config`
1477 local testurl=ssh://127.0.0.1/$testroot
1478 local commit_id=`git_show_head $testroot/repo`
1480 got clone -q $testurl/repo $testroot/repo-clone
1481 ret=$?
1482 if [ $ret -ne 0 ]; then
1483 echo "got clone command failed unexpectedly" >&2
1484 test_done "$testroot" "$ret"
1485 return 1
1488 cat > $testroot/repo/.git/got.conf <<EOF
1489 remote "origin" {
1490 protocol ssh
1491 server 127.0.0.1
1492 branch foo
1493 repository "$testroot/repo-clone"
1496 got ref -l -r $testroot/repo-clone > $testroot/stdout
1497 ret=$?
1498 if [ $ret -ne 0 ]; then
1499 echo "got ref command failed unexpectedly" >&2
1500 test_done "$testroot" "$ret"
1501 return 1
1504 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1505 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1506 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1507 >> $testroot/stdout.expected
1508 echo "refs/remotes/origin/master: $commit_id" \
1509 >> $testroot/stdout.expected
1511 cmp -s $testroot/stdout $testroot/stdout.expected
1512 ret=$?
1513 if [ $ret -ne 0 ]; then
1514 diff -u $testroot/stdout.expected $testroot/stdout
1515 test_done "$testroot" "$ret"
1516 return 1
1519 got branch -r $testroot/repo foo
1521 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1522 ret=$?
1523 if [ $ret -ne 0 ]; then
1524 echo "got send command failed unexpectedly" >&2
1525 test_done "$testroot" "$ret"
1526 return 1
1529 got ref -l -r $testroot/repo-clone > $testroot/stdout
1530 ret=$?
1531 if [ $ret -ne 0 ]; then
1532 echo "got ref command failed unexpectedly" >&2
1533 test_done "$testroot" "$ret"
1534 return 1
1537 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1538 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1539 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1540 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1541 >> $testroot/stdout.expected
1542 echo "refs/remotes/origin/master: $commit_id" \
1543 >> $testroot/stdout.expected
1545 cmp -s $testroot/stdout $testroot/stdout.expected
1546 ret=$?
1547 if [ $ret -ne 0 ]; then
1548 diff -u $testroot/stdout.expected $testroot/stdout
1549 test_done "$testroot" "$ret"
1550 return 1
1553 git_fsck "$testroot" "$testroot/repo-clone"
1554 ret=$?
1555 test_done "$testroot" "$ret"
1558 test_send_rejected() {
1559 local testroot=`test_init send_rejected`
1560 local testurl=ssh://127.0.0.1/$testroot
1561 local commit_id=`git_show_head $testroot/repo`
1563 if ! got clone -q "$testurl/repo" "$testroot/repo-clone"; then
1564 echo "got clone command failed unexpectedly" >&2
1565 test_done "$testroot" 1
1566 return 1
1569 mkdir "$testroot/repo-clone/hooks"
1570 cat <<'EOF' >$testroot/repo-clone/hooks/update
1571 case "$1" in
1572 *master*)
1573 echo "rejecting push on master branch"
1574 exit 1
1576 esac
1577 exit 0
1579 chmod +x "$testroot/repo-clone/hooks/update"
1581 cat > $testroot/repo/.git/got.conf <<EOF
1582 remote "origin" {
1583 protocol ssh
1584 server 127.0.0.1
1585 repository "$testroot/repo-clone"
1589 echo "modified alpha" >$testroot/repo/alpha
1590 git_commit "$testroot/repo" -m "modified alpha"
1592 got send -q -r "$testroot/repo" >$testroot/stdout 2>$testroot/stderr
1593 ret=$?
1594 if [ $ret -ne 0 ]; then
1595 echo "got send command failed unexpectedly" >&2
1596 test_done "$testroot" $ret
1597 return 1
1600 touch "$testroot/stdout.expected"
1601 if ! cmp -s "$testroot/stdout.expected" "$testroot/stdout"; then
1602 diff -u "$testroot/stdout.expected" "$testroot/stdout"
1603 test_done "$testroot" 1
1604 return 1
1607 cat <<EOF >$testroot/stderr.expected
1608 rejecting push on master branch
1609 error: hook declined to update refs/heads/master
1612 if ! cmp -s "$testroot/stderr.expected" "$testroot/stderr"; then
1613 diff -u "$testroot/stderr.expected" "$testroot/stderr"
1614 test_done "$testroot" 1
1615 return 1
1618 test_done "$testroot" 0
1621 test_parseargs "$@"
1622 run_test test_send_basic
1623 run_test test_send_rebase_required
1624 run_test test_send_rebase_required_overwrite
1625 run_test test_send_merge_commit
1626 run_test test_send_delete
1627 run_test test_send_clone_and_send
1628 run_test test_send_tags
1629 run_test test_send_tag_of_deleted_branch
1630 run_test test_send_new_branch
1631 run_test test_send_all_branches
1632 run_test test_send_to_empty_repo
1633 run_test test_send_and_fetch_config
1634 run_test test_send_config
1635 run_test test_send_rejected