Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2021 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_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" != "0" ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
29 return 1
30 fi
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"
36 }
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 git_commit $testroot/repo -m "modified alpha"
44 local commit_id2=`git_show_head $testroot/repo`
46 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
47 ret="$?"
48 if [ "$ret" != "0" ]; then
49 echo "got send command failed unexpectedly" >&2
50 test_done "$testroot" "$ret"
51 return 1
52 fi
54 echo -n > $testroot/stdout.expected
55 cmp -s $testroot/stdout $testroot/stdout.expected
56 ret="$?"
57 if [ "$ret" != "0" ]; then
58 diff -u $testroot/stdout.expected $testroot/stdout
59 test_done "$testroot" "$ret"
60 return 1
61 fi
63 got ref -l -r $testroot/repo > $testroot/stdout
64 if [ "$ret" != "0" ]; then
65 echo "got ref command failed unexpectedly" >&2
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
71 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
72 echo "refs/remotes/origin/master: $commit_id2" \
73 >> $testroot/stdout.expected
74 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
76 cmp -s $testroot/stdout $testroot/stdout.expected
77 ret="$?"
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 got ref -l -r $testroot/repo-clone > $testroot/stdout
85 if [ "$ret" != "0" ]; then
86 echo "got ref command failed unexpectedly" >&2
87 test_done "$testroot" "$ret"
88 return 1
89 fi
91 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
92 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
93 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
94 >> $testroot/stdout.expected
95 echo "refs/remotes/origin/master: $commit_id" \
96 >> $testroot/stdout.expected
98 cmp -s $testroot/stdout $testroot/stdout.expected
99 ret="$?"
100 if [ "$ret" != "0" ]; then
101 diff -u $testroot/stdout.expected $testroot/stdout
102 test_done "$testroot" "$ret"
103 return 1
104 fi
106 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
107 ret="$?"
108 if [ "$ret" != "0" ]; then
109 echo "got send command failed unexpectedly" >&2
110 test_done "$testroot" "$ret"
111 return 1
112 fi
114 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
115 echo "Already up-to-date" >> $testroot/stdout.expected
116 cmp -s $testroot/stdout $testroot/stdout.expected
117 ret="$?"
118 if [ "$ret" != "0" ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
121 return 1
122 fi
124 git_fsck "$testroot" "$testroot/repo-clone"
125 ret="$?"
126 test_done "$testroot" "$ret"
129 test_send_rebase_required() {
130 local testroot=`test_init send_rebase_required`
131 local testurl=ssh://127.0.0.1/$testroot
132 local commit_id=`git_show_head $testroot/repo`
134 got clone -q $testurl/repo $testroot/repo-clone
135 ret="$?"
136 if [ "$ret" != "0" ]; then
137 echo "got clone command failed unexpectedly" >&2
138 test_done "$testroot" "$ret"
139 return 1
140 fi
141 cat > $testroot/repo/.git/got.conf <<EOF
142 remote "origin" {
143 protocol ssh
144 server 127.0.0.1
145 repository "$testroot/repo-clone"
147 EOF
148 echo "modified alpha" > $testroot/repo/alpha
149 git_commit $testroot/repo -m "modified alpha"
150 local commit_id2=`git_show_head $testroot/repo`
152 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
153 echo "modified alpha, too" > $testroot/wt-clone/alpha
154 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
156 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
157 ret="$?"
158 if [ "$ret" = "0" ]; then
159 echo "got send command succeeded unexpectedly" >&2
160 test_done "$testroot" "$ret"
161 return 1
162 fi
164 echo -n > $testroot/stdout.expected
165 cmp -s $testroot/stdout $testroot/stdout.expected
166 ret="$?"
167 if [ "$ret" != "0" ]; then
168 diff -u $testroot/stdout.expected $testroot/stdout
169 test_done "$testroot" "$ret"
170 return 1
171 fi
173 echo "got: refs/heads/master: fetch and rebase required" \
174 > $testroot/stderr.expected
175 cmp -s $testroot/stderr $testroot/stderr.expected
176 ret="$?"
177 if [ "$ret" != "0" ]; then
178 diff -u $testroot/stderr.expected $testroot/stderr
179 test_done "$testroot" "$ret"
180 return 1
181 fi
183 git_fsck "$testroot" "$testroot/repo-clone"
184 ret="$?"
185 test_done "$testroot" "$ret"
188 test_send_rebase_required_overwrite() {
189 local testroot=`test_init send_rebase_required_overwrite`
190 local testurl=ssh://127.0.0.1/$testroot
191 local commit_id=`git_show_head $testroot/repo`
193 got clone -q $testurl/repo $testroot/repo-clone
194 ret="$?"
195 if [ "$ret" != "0" ]; then
196 echo "got clone command failed unexpectedly" >&2
197 test_done "$testroot" "$ret"
198 return 1
199 fi
200 cat > $testroot/repo/.git/got.conf <<EOF
201 remote "foobar" {
202 protocol ssh
203 server 127.0.0.1
204 repository "$testroot/repo-clone"
206 EOF
207 echo "modified alpha" > $testroot/repo/alpha
208 git_commit $testroot/repo -m "modified alpha"
209 local commit_id2=`git_show_head $testroot/repo`
211 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
212 echo "modified alpha, too" > $testroot/wt-clone/alpha
213 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
214 local commit_id3=`git_show_head $testroot/repo-clone`
216 # non-default remote requires an explicit argument
217 got send -q -r $testroot/repo -f > $testroot/stdout \
218 2> $testroot/stderr
219 ret="$?"
220 if [ "$ret" = "0" ]; then
221 echo "got send command succeeded unexpectedly" >&2
222 test_done "$testroot" "$ret"
223 return 1
224 fi
225 echo "got: origin: remote repository not found" \
226 > $testroot/stderr.expected
227 cmp -s $testroot/stderr $testroot/stderr.expected
228 ret="$?"
229 if [ "$ret" != "0" ]; then
230 diff -u $testroot/stderr.expected $testroot/stderr
231 test_done "$testroot" "$ret"
232 return 1
233 fi
235 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
236 2> $testroot/stderr
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 echo "got send command failed unexpectedly" >&2
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 echo -n > $testroot/stdout.expected
245 cmp -s $testroot/stdout $testroot/stdout.expected
246 ret="$?"
247 if [ "$ret" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 got ref -l -r $testroot/repo > $testroot/stdout
254 if [ "$ret" != "0" ]; then
255 echo "got ref command failed unexpectedly" >&2
256 test_done "$testroot" "$ret"
257 return 1
258 fi
260 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
261 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
262 echo "refs/remotes/foobar/master: $commit_id2" \
263 >> $testroot/stdout.expected
265 cmp -s $testroot/stdout $testroot/stdout.expected
266 ret="$?"
267 if [ "$ret" != "0" ]; then
268 diff -u $testroot/stdout.expected $testroot/stdout
269 test_done "$testroot" "$ret"
270 return 1
271 fi
273 got ref -l -r $testroot/repo-clone > $testroot/stdout
274 if [ "$ret" != "0" ]; then
275 echo "got ref command failed unexpectedly" >&2
276 test_done "$testroot" "$ret"
277 return 1
278 fi
280 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
281 cut -d ':' -f 2 | tr -d ' ')`
282 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
283 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
284 >> $testroot/stdout.expected
285 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
286 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
287 >> $testroot/stdout.expected
288 echo "refs/remotes/origin/master: $commit_id" \
289 >> $testroot/stdout.expected
291 cmp -s $testroot/stdout $testroot/stdout.expected
292 ret="$?"
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/stdout.expected $testroot/stdout
295 test_done "$testroot" "$ret"
296 return 1
297 fi
299 git_fsck "$testroot" "$testroot/repo-clone"
300 ret="$?"
301 test_done "$testroot" "$ret"
304 test_send_delete() {
305 local testroot=`test_init send_delete`
306 local testurl=ssh://127.0.0.1/$testroot
307 local commit_id=`git_show_head $testroot/repo`
309 # branch1 exists in both repositories
310 got branch -r $testroot/repo branch1
312 got clone -a -q $testurl/repo $testroot/repo-clone
313 ret="$?"
314 if [ "$ret" != "0" ]; then
315 echo "got clone command failed unexpectedly" >&2
316 test_done "$testroot" "$ret"
317 return 1
318 fi
319 cat > $testroot/repo/.git/got.conf <<EOF
320 remote "origin" {
321 protocol ssh
322 server 127.0.0.1
323 repository "$testroot/repo-clone"
325 EOF
326 # branch2 exists only in the remote repository
327 got branch -r $testroot/repo-clone branch2
329 got ref -l -r $testroot/repo-clone > $testroot/stdout
330 if [ "$ret" != "0" ]; then
331 echo "got ref command failed unexpectedly" >&2
332 test_done "$testroot" "$ret"
333 return 1
334 fi
336 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
337 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
338 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
339 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
341 # Sending changes for a branch and deleting it at the same
342 # time is not allowed.
343 got send -q -r $testroot/repo -d branch1 -b branch1 \
344 > $testroot/stdout 2> $testroot/stderr
345 ret="$?"
346 if [ "$ret" = "0" ]; then
347 echo "got send command succeeded unexpectedly" >&2
348 test_done "$testroot" "$ret"
349 return 1
350 fi
351 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
352 > $testroot/stderr.expected
353 echo ": reference cannot be deleted" >> $testroot/stderr.expected
354 cmp -s $testroot/stderr $testroot/stderr.expected
355 ret="$?"
356 if [ "$ret" != "0" ]; then
357 diff -u $testroot/stderr.expected $testroot/stderr
358 test_done "$testroot" "$ret"
359 return 1
360 fi
362 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
363 > $testroot/stdout 2> $testroot/stderr
364 ret="$?"
365 if [ "$ret" != "0" ]; then
366 echo "got send command failed unexpectedly" >&2
367 test_done "$testroot" "$ret"
368 return 1
369 fi
371 got send -r $testroot/repo -d refs/heads/branch2 origin \
372 > $testroot/stdout 2>$testroot/stderr
373 ret="$?"
374 if [ "$ret" != "0" ]; then
375 echo "got send command failed unexpectedly" >&2
376 test_done "$testroot" "$ret"
377 return 1
378 fi
380 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
381 echo "Server has deleted refs/heads/branch2" \
382 >> $testroot/stdout.expected
384 cmp -s $testroot/stdout $testroot/stdout.expected
385 ret="$?"
386 if [ "$ret" != "0" ]; then
387 diff -u $testroot/stdout.expected $testroot/stdout
388 test_done "$testroot" "$ret"
389 return 1
390 fi
392 # branchX exists in neither repository
393 got send -q -r $testroot/repo -d refs/heads/branchX origin \
394 > $testroot/stdout 2> $testroot/stderr
395 ret="$?"
396 if [ "$ret" = "0" ]; then
397 echo "got send command succeeded unexpectedly" >&2
398 test_done "$testroot" "$ret"
399 return 1
400 fi
401 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
402 > $testroot/stderr.expected
403 echo "repository: no such reference found" >> $testroot/stderr.expected
404 echo "got: no such reference found" >> $testroot/stderr.expected
405 cmp -s $testroot/stderr $testroot/stderr.expected
406 ret="$?"
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stderr.expected $testroot/stderr
409 test_done "$testroot" "$ret"
410 return 1
411 fi
413 # References outside of refs/heads/ cannot be deleted with 'got send'.
414 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
415 > $testroot/stdout 2> $testroot/stderr
416 ret="$?"
417 if [ "$ret" = "0" ]; then
418 echo "got send command succeeded unexpectedly" >&2
419 test_done "$testroot" "$ret"
420 return 1
421 fi
422 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
423 > $testroot/stderr.expected
424 echo "in remote repository: no such reference found" \
425 >> $testroot/stderr.expected
426 echo "got: no such reference found" >> $testroot/stderr.expected
427 cmp -s $testroot/stderr $testroot/stderr.expected
428 ret="$?"
429 if [ "$ret" != "0" ]; then
430 diff -u $testroot/stderr.expected $testroot/stderr
431 test_done "$testroot" "$ret"
432 return 1
433 fi
435 got ref -l -r $testroot/repo > $testroot/stdout
436 if [ "$ret" != "0" ]; then
437 echo "got ref command failed unexpectedly" >&2
438 test_done "$testroot" "$ret"
439 return 1
440 fi
442 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
443 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
444 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
446 cmp -s $testroot/stdout $testroot/stdout.expected
447 ret="$?"
448 if [ "$ret" != "0" ]; then
449 diff -u $testroot/stdout.expected $testroot/stdout
450 test_done "$testroot" "$ret"
451 return 1
452 fi
454 got ref -l -r $testroot/repo-clone > $testroot/stdout
455 if [ "$ret" != "0" ]; then
456 echo "got ref command failed unexpectedly" >&2
457 test_done "$testroot" "$ret"
458 return 1
459 fi
461 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
462 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
463 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
464 >> $testroot/stdout.expected
465 echo "refs/remotes/origin/branch1: $commit_id" \
466 >> $testroot/stdout.expected
467 echo "refs/remotes/origin/master: $commit_id" \
468 >> $testroot/stdout.expected
470 cmp -s $testroot/stdout $testroot/stdout.expected
471 ret="$?"
472 if [ "$ret" != "0" ]; then
473 diff -u $testroot/stdout.expected $testroot/stdout
474 test_done "$testroot" "$ret"
475 return 1
476 fi
478 git_fsck "$testroot" "$testroot/repo-clone"
479 ret="$?"
480 test_done "$testroot" "$ret"
483 test_send_clone_and_send() {
484 local testroot=`test_init send_clone_and_send`
485 local testurl=ssh://127.0.0.1/$testroot
486 local commit_id=`git_show_head $testroot/repo`
488 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
490 got clone -q $testurl/repo $testroot/repo-clone
491 ret="$?"
492 if [ "$ret" != "0" ]; then
493 echo "got clone command failed unexpectedly" >&2
494 test_done "$testroot" "$ret"
495 return 1
496 fi
498 got checkout $testroot/repo-clone $testroot/wt >/dev/null
499 echo "modified alpha" > $testroot/wt/alpha
500 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
501 local commit_id2=`git_show_head $testroot/repo-clone`
503 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
504 ret="$?"
505 if [ "$ret" != "0" ]; then
506 echo "got send command failed unexpectedly" >&2
507 test_done "$testroot" "$ret"
508 return 1
509 fi
511 echo -n > $testroot/stdout.expected
512 cmp -s $testroot/stdout $testroot/stdout.expected
513 ret="$?"
514 if [ "$ret" != "0" ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 got ref -l -r $testroot/repo > $testroot/stdout
521 if [ "$ret" != "0" ]; then
522 echo "got ref command failed unexpectedly" >&2
523 test_done "$testroot" "$ret"
524 return 1
525 fi
527 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
528 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
530 cmp -s $testroot/stdout $testroot/stdout.expected
531 ret="$?"
532 if [ "$ret" != "0" ]; then
533 diff -u $testroot/stdout.expected $testroot/stdout
534 test_done "$testroot" "$ret"
535 return 1
536 fi
538 got ref -l -r $testroot/repo-clone > $testroot/stdout
539 if [ "$ret" != "0" ]; then
540 echo "got ref command failed unexpectedly" >&2
541 test_done "$testroot" "$ret"
542 return 1
543 fi
545 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
546 cut -d ':' -f 2 | tr -d ' ')`
547 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
548 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
549 >> $testroot/stdout.expected
550 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
551 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
552 >> $testroot/stdout.expected
553 echo "refs/remotes/origin/master: $commit_id2" \
554 >> $testroot/stdout.expected
556 cmp -s $testroot/stdout $testroot/stdout.expected
557 ret="$?"
558 if [ "$ret" != "0" ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
561 return 1
562 fi
564 git_fsck "$testroot" "$testroot/repo-clone"
565 ret="$?"
566 test_done "$testroot" "$ret"
569 test_send_tags() {
570 local testroot=`test_init send_tags`
571 local testurl=ssh://127.0.0.1/$testroot
572 local commit_id=`git_show_head $testroot/repo`
574 got clone -q $testurl/repo $testroot/repo-clone
575 ret="$?"
576 if [ "$ret" != "0" ]; then
577 echo "got clone command failed unexpectedly" >&2
578 test_done "$testroot" "$ret"
579 return 1
580 fi
581 cat > $testroot/repo/.git/got.conf <<EOF
582 remote "origin" {
583 protocol ssh
584 server 127.0.0.1
585 repository "$testroot/repo-clone"
587 EOF
588 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
589 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
590 | tr -d ' ' | cut -d: -f2`
592 echo "modified alpha" > $testroot/repo/alpha
593 git_commit $testroot/repo -m "modified alpha"
594 local commit_id2=`git_show_head $testroot/repo`
596 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
597 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
598 | tr -d ' ' | cut -d: -f2`
600 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
601 ret="$?"
602 if [ "$ret" != "0" ]; then
603 echo "got send command failed unexpectedly" >&2
604 test_done "$testroot" "$ret"
605 return 1
606 fi
608 echo -n > $testroot/stdout.expected
609 cmp -s $testroot/stdout $testroot/stdout.expected
610 ret="$?"
611 if [ "$ret" != "0" ]; then
612 diff -u $testroot/stdout.expected $testroot/stdout
613 test_done "$testroot" "$ret"
614 return 1
615 fi
617 got ref -l -r $testroot/repo > $testroot/stdout
618 if [ "$ret" != "0" ]; then
619 echo "got ref command failed unexpectedly" >&2
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
625 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
626 echo "refs/remotes/origin/master: $commit_id2" \
627 >> $testroot/stdout.expected
628 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
629 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
631 cmp -s $testroot/stdout $testroot/stdout.expected
632 ret="$?"
633 if [ "$ret" != "0" ]; then
634 diff -u $testroot/stdout.expected $testroot/stdout
635 test_done "$testroot" "$ret"
636 return 1
637 fi
639 got ref -l -r $testroot/repo-clone > $testroot/stdout
640 if [ "$ret" != "0" ]; then
641 echo "got ref command failed unexpectedly" >&2
642 test_done "$testroot" "$ret"
643 return 1
644 fi
646 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
647 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
648 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
649 >> $testroot/stdout.expected
650 echo "refs/remotes/origin/master: $commit_id" \
651 >> $testroot/stdout.expected
652 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
653 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
655 cmp -s $testroot/stdout $testroot/stdout.expected
656 ret="$?"
657 if [ "$ret" != "0" ]; then
658 diff -u $testroot/stdout.expected $testroot/stdout
659 test_done "$testroot" "$ret"
660 return 1
661 fi
663 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
664 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
665 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
666 cmp -s $testroot/stdout $testroot/stdout.expected
667 ret="$?"
668 if [ "$ret" != "0" ]; then
669 diff -u $testroot/stdout.expected $testroot/stdout
670 test_done "$testroot" "$ret"
671 return 1
672 fi
674 # Overwriting an existing tag 'got send -f'.
675 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
676 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
677 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
678 | tr -d ' ' | cut -d: -f2`
680 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
681 2> $testroot/stderr
682 ret="$?"
683 if [ "$ret" = "0" ]; then
684 echo "got send command succeeded unexpectedly" >&2
685 test_done "$testroot" "$ret"
686 return 1
687 fi
689 echo "got: refs/tags/1.0: tag already exists on server" \
690 > $testroot/stderr.expected
691 cmp -s $testroot/stderr $testroot/stderr.expected
692 ret="$?"
693 if [ "$ret" != "0" ]; then
694 diff -u $testroot/stderr.expected $testroot/stderr
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 # attempting the same with -T should fail, too
700 got send -q -r $testroot/repo -T > $testroot/stdout \
701 2> $testroot/stderr
702 ret="$?"
703 if [ "$ret" = "0" ]; then
704 echo "got send command succeeded unexpectedly" >&2
705 test_done "$testroot" "$ret"
706 return 1
707 fi
709 echo "got: refs/tags/1.0: tag already exists on server" \
710 > $testroot/stderr.expected
711 cmp -s $testroot/stderr $testroot/stderr.expected
712 ret="$?"
713 if [ "$ret" != "0" ]; then
714 diff -u $testroot/stderr.expected $testroot/stderr
715 test_done "$testroot" "$ret"
716 return 1
717 fi
719 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
720 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
721 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
722 cmp -s $testroot/stdout $testroot/stdout.expected
723 ret="$?"
724 if [ "$ret" != "0" ]; then
725 diff -u $testroot/stdout.expected $testroot/stdout
726 test_done "$testroot" "$ret"
727 return 1
728 fi
730 # overwrite the 1.0 tag only
731 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
732 2> $testroot/stderr
733 ret="$?"
734 if [ "$ret" != "0" ]; then
735 echo "got send command failed unexpectedly" >&2
736 test_done "$testroot" "$ret"
737 return 1
738 fi
740 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
741 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
742 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
743 cmp -s $testroot/stdout $testroot/stdout.expected
744 ret="$?"
745 if [ "$ret" != "0" ]; then
746 diff -u $testroot/stdout.expected $testroot/stdout
747 test_done "$testroot" "$ret"
748 return 1
749 fi
751 got checkout $testroot/repo $testroot/wt > /dev/null
752 echo 'new line in file alpha' >> $testroot/wt/alpha
753 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
755 # Send the new commit in isolation.
756 got send -q -r $testroot/repo > $testroot/stdout \
757 2> $testroot/stderr
758 ret="$?"
759 if [ "$ret" != "0" ]; then
760 echo "got send command failed unexpectedly" >&2
761 test_done "$testroot" "$ret"
762 return 1
763 fi
765 # Now tag it and send the tag.
766 # Verify that just the new tag object gets sent.
767 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
768 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
769 | tr -d ' ' | cut -d: -f2`
771 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
772 2> $testroot/stderr
773 ret="$?"
774 if [ "$ret" != "0" ]; then
775 echo "got send command failed unexpectedly" >&2
776 test_done "$testroot" "$ret"
777 return 1
778 fi
779 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
780 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
781 $testroot/stdout; then
782 echo "got send did apparently pack too many objects:" >&2
783 cat $testroot/stdout.raw >&2
784 test_done "$testroot" "1"
785 return 1
786 fi
788 git_fsck "$testroot" "$testroot/repo-clone"
789 ret="$?"
790 test_done "$testroot" "$ret"
793 test_send_tag_of_deleted_branch() {
794 local testroot=`test_init send_tag_of_deleted_branch`
795 local testurl=ssh://127.0.0.1/$testroot
796 local commit_id=`git_show_head $testroot/repo`
798 got clone -q $testurl/repo $testroot/repo-clone
799 ret="$?"
800 if [ "$ret" != "0" ]; then
801 echo "got clone command failed unexpectedly" >&2
802 test_done "$testroot" "$ret"
803 return 1
804 fi
805 cat > $testroot/repo/.git/got.conf <<EOF
806 remote "origin" {
807 protocol ssh
808 server 127.0.0.1
809 repository "$testroot/repo-clone"
811 EOF
812 got branch -r $testroot/repo foo
814 # modify alpha on branch foo
815 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
816 echo boo >> $testroot/wt/beta
817 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
818 > /dev/null)
819 local commit_id2=`git_show_branch_head $testroot/repo foo`
821 # tag HEAD commit of branch foo
822 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
823 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
824 | tr -d ' ' | cut -d: -f2`
826 # delete the branch; commit is now only reachable via tags/1.0
827 got branch -r $testroot/repo -d foo > /dev/null
829 # unrelated change on master branch, then try sending this branch
830 # and the tag
831 echo "modified alpha" > $testroot/repo/alpha
832 git_commit $testroot/repo -m "modified alpha"
833 local commit_id3=`git_show_head $testroot/repo`
835 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
836 ret="$?"
837 if [ "$ret" != "0" ]; then
838 echo "got send command failed unexpectedly" >&2
839 test_done "$testroot" "$ret"
840 return 1
841 fi
843 echo -n > $testroot/stdout.expected
844 cmp -s $testroot/stdout $testroot/stdout.expected
845 ret="$?"
846 if [ "$ret" != "0" ]; then
847 diff -u $testroot/stdout.expected $testroot/stdout
848 test_done "$testroot" "$ret"
849 return 1
850 fi
852 got ref -l -r $testroot/repo > $testroot/stdout
853 if [ "$ret" != "0" ]; then
854 echo "got ref command failed unexpectedly" >&2
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
860 cut -d ':' -f 2 | tr -d ' ')`
861 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
862 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
863 >> $testroot/stdout.expected
864 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
865 echo "refs/remotes/origin/master: $commit_id3" \
866 >> $testroot/stdout.expected
867 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
869 cmp -s $testroot/stdout $testroot/stdout.expected
870 ret="$?"
871 if [ "$ret" != "0" ]; then
872 diff -u $testroot/stdout.expected $testroot/stdout
873 test_done "$testroot" "$ret"
874 return 1
875 fi
877 got ref -l -r $testroot/repo-clone > $testroot/stdout
878 if [ "$ret" != "0" ]; then
879 echo "got ref command failed unexpectedly" >&2
880 test_done "$testroot" "$ret"
881 return 1
882 fi
884 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
885 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
886 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
887 >> $testroot/stdout.expected
888 echo "refs/remotes/origin/master: $commit_id" \
889 >> $testroot/stdout.expected
890 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
892 cmp -s $testroot/stdout $testroot/stdout.expected
893 ret="$?"
894 if [ "$ret" != "0" ]; then
895 diff -u $testroot/stdout.expected $testroot/stdout
896 test_done "$testroot" "$ret"
897 return 1
898 fi
900 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
901 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
903 cmp -s $testroot/stdout $testroot/stdout.expected
904 ret="$?"
905 if [ "$ret" != "0" ]; then
906 diff -u $testroot/stdout.expected $testroot/stdout
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 git_fsck "$testroot" "$testroot/repo-clone"
912 ret="$?"
913 test_done "$testroot" "$ret"
916 test_send_new_branch() {
917 local testroot=`test_init send_new_branch`
918 local testurl=ssh://127.0.0.1/$testroot
919 local commit_id=`git_show_head $testroot/repo`
921 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
923 got clone -q $testurl/repo $testroot/repo-clone
924 ret="$?"
925 if [ "$ret" != "0" ]; then
926 echo "got clone command failed unexpectedly" >&2
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 got branch -r $testroot/repo-clone foo >/dev/null
932 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
933 echo "modified alpha" > $testroot/wt/alpha
934 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
935 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
937 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 echo "got send command failed unexpectedly" >&2
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 echo -n > $testroot/stdout.expected
946 cmp -s $testroot/stdout $testroot/stdout.expected
947 ret="$?"
948 if [ "$ret" != "0" ]; then
949 diff -u $testroot/stdout.expected $testroot/stdout
950 test_done "$testroot" "$ret"
951 return 1
952 fi
954 got ref -l -r $testroot/repo > $testroot/stdout
955 if [ "$ret" != "0" ]; then
956 echo "got ref command failed unexpectedly" >&2
957 test_done "$testroot" "$ret"
958 return 1
959 fi
961 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
962 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
963 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
965 cmp -s $testroot/stdout $testroot/stdout.expected
966 ret="$?"
967 if [ "$ret" != "0" ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
969 test_done "$testroot" "$ret"
970 return 1
971 fi
973 got ref -l -r $testroot/repo-clone > $testroot/stdout
974 if [ "$ret" != "0" ]; then
975 echo "got ref command failed unexpectedly" >&2
976 test_done "$testroot" "$ret"
977 return 1
978 fi
980 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
981 cut -d ':' -f 2 | tr -d ' ')`
982 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
983 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
984 >> $testroot/stdout.expected
985 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
986 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
987 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
988 >> $testroot/stdout.expected
989 echo "refs/remotes/origin/foo: $commit_id2" \
990 >> $testroot/stdout.expected
991 echo "refs/remotes/origin/master: $commit_id" \
992 >> $testroot/stdout.expected
994 cmp -s $testroot/stdout $testroot/stdout.expected
995 ret="$?"
996 if [ "$ret" != "0" ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 test_done "$testroot" "$ret"
999 return 1
1002 git_fsck "$testroot" "$testroot/repo-clone"
1003 ret="$?"
1004 test_done "$testroot" "$ret"
1007 test_send_all_branches() {
1008 local testroot=`test_init send_all_branches`
1009 local testurl=ssh://127.0.0.1/$testroot
1010 local commit_id=`git_show_head $testroot/repo`
1012 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1014 got clone -q $testurl/repo $testroot/repo-clone
1015 ret="$?"
1016 if [ "$ret" != "0" ]; then
1017 echo "got clone command failed unexpectedly" >&2
1018 test_done "$testroot" "$ret"
1019 return 1
1022 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1023 echo "modified alpha" > $testroot/wt/alpha
1024 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1025 local commit_id2=`git_show_head $testroot/repo-clone`
1027 got branch -r $testroot/repo-clone foo >/dev/null
1028 (cd $testroot/wt && got update -b foo >/dev/null)
1029 echo "modified beta on new branch foo" > $testroot/wt/beta
1030 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1031 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1033 got branch -r $testroot/repo-clone bar >/dev/null
1034 (cd $testroot/wt && got update -b bar >/dev/null)
1035 echo "modified beta again on new branch bar" > $testroot/wt/beta
1036 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1037 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1039 got ref -l -r $testroot/repo-clone > $testroot/stdout
1040 if [ "$ret" != "0" ]; then
1041 echo "got ref command failed unexpectedly" >&2
1042 test_done "$testroot" "$ret"
1043 return 1
1046 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1047 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1048 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1049 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1051 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1052 2> $testroot/stderr
1053 ret="$?"
1054 if [ "$ret" = "0" ]; then
1055 echo "got send command succeeded unexpectedly" >&2
1056 test_done "$testroot" "$ret"
1057 return 1
1059 echo "got: -a and -b options are mutually exclusive" \
1060 > $testroot/stderr.expected
1061 cmp -s $testroot/stderr $testroot/stderr.expected
1062 ret="$?"
1063 if [ "$ret" != "0" ]; then
1064 diff -u $testroot/stderr.expected $testroot/stderr
1065 test_done "$testroot" "$ret"
1066 return 1
1069 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1070 2> $testroot/stderr
1071 ret="$?"
1072 if [ "$ret" != "0" ]; then
1073 echo "got send command failed unexpectedly" >&2
1074 test_done "$testroot" "$ret"
1075 return 1
1078 echo -n > $testroot/stdout.expected
1079 cmp -s $testroot/stdout $testroot/stdout.expected
1080 ret="$?"
1081 if [ "$ret" != "0" ]; then
1082 diff -u $testroot/stdout.expected $testroot/stdout
1083 test_done "$testroot" "$ret"
1084 return 1
1087 got ref -l -r $testroot/repo > $testroot/stdout
1088 if [ "$ret" != "0" ]; then
1089 echo "got ref command failed unexpectedly" >&2
1090 test_done "$testroot" "$ret"
1091 return 1
1094 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1095 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1096 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1097 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1099 cmp -s $testroot/stdout $testroot/stdout.expected
1100 ret="$?"
1101 if [ "$ret" != "0" ]; then
1102 diff -u $testroot/stdout.expected $testroot/stdout
1103 test_done "$testroot" "$ret"
1104 return 1
1107 got ref -l -r $testroot/repo-clone > $testroot/stdout
1108 if [ "$ret" != "0" ]; then
1109 echo "got ref command failed unexpectedly" >&2
1110 test_done "$testroot" "$ret"
1111 return 1
1114 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1115 cut -d ':' -f 2 | tr -d ' ')`
1116 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1117 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1118 >> $testroot/stdout.expected
1119 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1120 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1121 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1122 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1123 >> $testroot/stdout.expected
1124 echo "refs/remotes/origin/bar: $commit_id4" \
1125 >> $testroot/stdout.expected
1126 echo "refs/remotes/origin/foo: $commit_id3" \
1127 >> $testroot/stdout.expected
1128 echo "refs/remotes/origin/master: $commit_id2" \
1129 >> $testroot/stdout.expected
1131 cmp -s $testroot/stdout $testroot/stdout.expected
1132 ret="$?"
1133 if [ "$ret" != "0" ]; then
1134 diff -u $testroot/stdout.expected $testroot/stdout
1135 test_done "$testroot" "$ret"
1136 return 1
1139 git_fsck "$testroot" "$testroot/repo-clone"
1140 ret="$?"
1141 test_done "$testroot" "$ret"
1144 test_send_to_empty_repo() {
1145 local testroot=`test_init send_to_empty_repo`
1146 local testurl=ssh://127.0.0.1/$testroot
1147 local commit_id=`git_show_head $testroot/repo`
1149 got init $testroot/repo2
1151 ret="$?"
1152 if [ "$ret" != "0" ]; then
1153 echo "got clone command failed unexpectedly" >&2
1154 test_done "$testroot" "$ret"
1155 return 1
1157 cat > $testroot/repo/.git/got.conf <<EOF
1158 remote "origin" {
1159 protocol ssh
1160 server 127.0.0.1
1161 repository "$testroot/repo2"
1163 EOF
1164 echo "modified alpha" > $testroot/repo/alpha
1165 git_commit $testroot/repo -m "modified alpha"
1166 local commit_id2=`git_show_head $testroot/repo`
1168 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1169 ret="$?"
1170 if [ "$ret" != "0" ]; then
1171 echo "got send command failed unexpectedly" >&2
1172 test_done "$testroot" "$ret"
1173 return 1
1176 echo -n > $testroot/stdout.expected
1177 cmp -s $testroot/stdout $testroot/stdout.expected
1178 ret="$?"
1179 if [ "$ret" != "0" ]; then
1180 diff -u $testroot/stdout.expected $testroot/stdout
1181 test_done "$testroot" "$ret"
1182 return 1
1185 # XXX Workaround: We cannot give the target for HEAD to 'got init'
1186 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1188 got ref -l -r $testroot/repo > $testroot/stdout
1189 if [ "$ret" != "0" ]; then
1190 echo "got ref command failed unexpectedly" >&2
1191 test_done "$testroot" "$ret"
1192 return 1
1195 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1196 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1197 echo "refs/remotes/origin/master: $commit_id2" \
1198 >> $testroot/stdout.expected
1200 cmp -s $testroot/stdout $testroot/stdout.expected
1201 ret="$?"
1202 if [ "$ret" != "0" ]; then
1203 diff -u $testroot/stdout.expected $testroot/stdout
1204 test_done "$testroot" "$ret"
1205 return 1
1208 got ref -l -r $testroot/repo2 > $testroot/stdout
1209 if [ "$ret" != "0" ]; then
1210 echo "got ref command failed unexpectedly" >&2
1211 test_done "$testroot" "$ret"
1212 return 1
1215 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1216 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1218 cmp -s $testroot/stdout $testroot/stdout.expected
1219 ret="$?"
1220 if [ "$ret" != "0" ]; then
1221 diff -u $testroot/stdout.expected $testroot/stdout
1222 test_done "$testroot" "$ret"
1223 return 1
1226 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1227 ret="$?"
1228 if [ "$ret" != "0" ]; then
1229 echo "got send command failed unexpectedly" >&2
1230 test_done "$testroot" "$ret"
1231 return 1
1234 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1235 echo "Already up-to-date" >> $testroot/stdout.expected
1236 cmp -s $testroot/stdout $testroot/stdout.expected
1237 ret="$?"
1238 if [ "$ret" != "0" ]; then
1239 diff -u $testroot/stdout.expected $testroot/stdout
1240 test_done "$testroot" "$ret"
1241 return 1
1244 git_fsck "$testroot" "$testroot/repo2"
1245 ret="$?"
1246 test_done "$testroot" "$ret"
1249 test_send_and_fetch_config() {
1250 local testroot=`test_init send_fetch_conf`
1251 local testurl=ssh://127.0.0.1/$testroot
1252 local commit_id=`git_show_head $testroot/repo`
1254 got clone -q $testurl/repo $testroot/repo-clone
1255 ret="$?"
1256 if [ "$ret" != "0" ]; then
1257 echo "got clone command failed unexpectedly" >&2
1258 test_done "$testroot" "$ret"
1259 return 1
1262 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1263 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1264 | tr -d ' ' | cut -d: -f2`
1266 cp -R $testroot/repo-clone $testroot/repo-clone2
1267 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1268 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1269 | tr -d ' ' | cut -d: -f2`
1271 cat > $testroot/repo/.git/got.conf <<EOF
1272 remote "origin" {
1273 protocol ssh
1274 server 127.0.0.1
1275 send {
1276 repository "$testroot/repo-clone"
1278 fetch {
1279 repository "$testroot/repo-clone2"
1282 EOF
1283 got ref -l -r $testroot/repo > $testroot/stdout
1284 if [ "$ret" != "0" ]; then
1285 echo "got ref command failed unexpectedly" >&2
1286 test_done "$testroot" "$ret"
1287 return 1
1290 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1291 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1292 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1293 cmp -s $testroot/stdout $testroot/stdout.expected
1294 ret="$?"
1295 if [ "$ret" != "0" ]; then
1296 diff -u $testroot/stdout.expected $testroot/stdout
1297 test_done "$testroot" "$ret"
1298 return 1
1301 # fetch tag 2.0 from repo-clone2
1302 got fetch -q -r $testroot/repo > $testroot/stdout
1303 ret="$?"
1304 if [ "$ret" != "0" ]; then
1305 echo "got fetch command failed unexpectedly" >&2
1306 test_done "$testroot" "$ret"
1307 return 1
1310 got ref -l -r $testroot/repo > $testroot/stdout
1311 if [ "$ret" != "0" ]; then
1312 echo "got ref command failed unexpectedly" >&2
1313 test_done "$testroot" "$ret"
1314 return 1
1317 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1318 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1319 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1320 >> $testroot/stdout.expected
1321 echo "refs/remotes/origin/master: $commit_id" \
1322 >> $testroot/stdout.expected
1323 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1324 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1325 cmp -s $testroot/stdout $testroot/stdout.expected
1326 ret="$?"
1327 if [ "$ret" != "0" ]; then
1328 diff -u $testroot/stdout.expected $testroot/stdout
1329 test_done "$testroot" "$ret"
1330 return 1
1333 # send tag 1.0 to repo-clone
1334 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1335 ret="$?"
1336 if [ "$ret" != "0" ]; then
1337 echo "got send command failed unexpectedly" >&2
1338 test_done "$testroot" "$ret"
1339 return 1
1342 got ref -l -r $testroot/repo-clone > $testroot/stdout
1343 if [ "$ret" != "0" ]; then
1344 echo "got ref command failed unexpectedly" >&2
1345 test_done "$testroot" "$ret"
1346 return 1
1349 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1350 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1351 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1352 >> $testroot/stdout.expected
1353 echo "refs/remotes/origin/master: $commit_id" \
1354 >> $testroot/stdout.expected
1355 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1357 cmp -s $testroot/stdout $testroot/stdout.expected
1358 ret="$?"
1359 if [ "$ret" != "0" ]; then
1360 diff -u $testroot/stdout.expected $testroot/stdout
1361 test_done "$testroot" "$ret"
1362 return 1
1365 git_fsck "$testroot" "$testroot/repo-clone"
1366 ret="$?"
1367 test_done "$testroot" "$ret"
1370 test_send_config() {
1371 local testroot=`test_init send_fetch_conf`
1372 local testurl=ssh://127.0.0.1/$testroot
1373 local commit_id=`git_show_head $testroot/repo`
1375 got clone -q $testurl/repo $testroot/repo-clone
1376 ret="$?"
1377 if [ "$ret" != "0" ]; then
1378 echo "got clone command failed unexpectedly" >&2
1379 test_done "$testroot" "$ret"
1380 return 1
1383 cat > $testroot/repo/.git/got.conf <<EOF
1384 remote "origin" {
1385 protocol ssh
1386 server 127.0.0.1
1387 branch foo
1388 repository "$testroot/repo-clone"
1390 EOF
1391 got ref -l -r $testroot/repo-clone > $testroot/stdout
1392 if [ "$ret" != "0" ]; then
1393 echo "got ref command failed unexpectedly" >&2
1394 test_done "$testroot" "$ret"
1395 return 1
1398 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1399 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1400 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1401 >> $testroot/stdout.expected
1402 echo "refs/remotes/origin/master: $commit_id" \
1403 >> $testroot/stdout.expected
1405 cmp -s $testroot/stdout $testroot/stdout.expected
1406 ret="$?"
1407 if [ "$ret" != "0" ]; then
1408 diff -u $testroot/stdout.expected $testroot/stdout
1409 test_done "$testroot" "$ret"
1410 return 1
1413 got branch -r $testroot/repo foo
1415 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1416 ret="$?"
1417 if [ "$ret" != "0" ]; then
1418 echo "got send command failed unexpectedly" >&2
1419 test_done "$testroot" "$ret"
1420 return 1
1423 got ref -l -r $testroot/repo-clone > $testroot/stdout
1424 if [ "$ret" != "0" ]; then
1425 echo "got ref command failed unexpectedly" >&2
1426 test_done "$testroot" "$ret"
1427 return 1
1430 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1431 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1432 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1433 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1434 >> $testroot/stdout.expected
1435 echo "refs/remotes/origin/master: $commit_id" \
1436 >> $testroot/stdout.expected
1438 cmp -s $testroot/stdout $testroot/stdout.expected
1439 ret="$?"
1440 if [ "$ret" != "0" ]; then
1441 diff -u $testroot/stdout.expected $testroot/stdout
1442 test_done "$testroot" "$ret"
1443 return 1
1446 git_fsck "$testroot" "$testroot/repo-clone"
1447 ret="$?"
1448 test_done "$testroot" "$ret"
1451 test_parseargs "$@"
1452 run_test test_send_basic
1453 run_test test_send_rebase_required
1454 run_test test_send_rebase_required_overwrite
1455 run_test test_send_delete
1456 run_test test_send_clone_and_send
1457 run_test test_send_tags
1458 run_test test_send_tag_of_deleted_branch
1459 run_test test_send_new_branch
1460 run_test test_send_all_branches
1461 run_test test_send_to_empty_repo
1462 run_test test_send_and_fetch_config
1463 run_test test_send_config