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 -ne 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 (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
56 fi
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
65 fi
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
73 fi
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
87 fi
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
95 fi
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
110 fi
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
122 fi
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
130 fi
132 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
133 echo "Already up-to-date" >> $testroot/stdout.expected
134 cmp -s $testroot/stdout $testroot/stdout.expected
135 ret=$?
136 if [ $ret -ne 0 ]; then
137 diff -u $testroot/stdout.expected $testroot/stdout
138 test_done "$testroot" "$ret"
139 return 1
140 fi
142 git_fsck "$testroot" "$testroot/repo-clone"
143 ret=$?
144 test_done "$testroot" "$ret"
147 test_send_rebase_required() {
148 local testroot=`test_init send_rebase_required`
149 local testurl=ssh://127.0.0.1/$testroot
150 local commit_id=`git_show_head $testroot/repo`
152 got clone -q $testurl/repo $testroot/repo-clone
153 ret=$?
154 if [ $ret -ne 0 ]; then
155 echo "got clone command failed unexpectedly" >&2
156 test_done "$testroot" "$ret"
157 return 1
158 fi
159 cat > $testroot/repo/.git/got.conf <<EOF
160 remote "origin" {
161 protocol ssh
162 server 127.0.0.1
163 repository "$testroot/repo-clone"
165 EOF
166 echo "modified alpha" > $testroot/repo/alpha
167 git_commit $testroot/repo -m "modified alpha"
168 local commit_id2=`git_show_head $testroot/repo`
170 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
171 echo "modified alpha, too" > $testroot/wt-clone/alpha
172 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
174 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
175 ret=$?
176 if [ $ret -eq 0 ]; then
177 echo "got send command succeeded unexpectedly" >&2
178 test_done "$testroot" 1
179 return 1
180 fi
182 echo -n > $testroot/stdout.expected
183 cmp -s $testroot/stdout $testroot/stdout.expected
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 diff -u $testroot/stdout.expected $testroot/stdout
187 test_done "$testroot" "$ret"
188 return 1
189 fi
191 echo "got: refs/heads/master: fetch and rebase required" \
192 > $testroot/stderr.expected
193 cmp -s $testroot/stderr $testroot/stderr.expected
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 diff -u $testroot/stderr.expected $testroot/stderr
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 git_fsck "$testroot" "$testroot/repo-clone"
202 ret=$?
203 test_done "$testroot" "$ret"
206 test_send_rebase_required_overwrite() {
207 local testroot=`test_init send_rebase_required_overwrite`
208 local testurl=ssh://127.0.0.1/$testroot
209 local commit_id=`git_show_head $testroot/repo`
211 got clone -q $testurl/repo $testroot/repo-clone
212 ret=$?
213 if [ $ret -ne 0 ]; then
214 echo "got clone command failed unexpectedly" >&2
215 test_done "$testroot" "$ret"
216 return 1
217 fi
218 cat > $testroot/repo/.git/got.conf <<EOF
219 remote "foobar" {
220 protocol ssh
221 server 127.0.0.1
222 repository "$testroot/repo-clone"
224 EOF
225 echo "modified alpha" > $testroot/repo/alpha
226 git_commit $testroot/repo -m "modified alpha"
227 local commit_id2=`git_show_head $testroot/repo`
229 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
230 echo "modified alpha, too" > $testroot/wt-clone/alpha
231 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
232 local commit_id3=`git_show_head $testroot/repo-clone`
234 # non-default remote requires an explicit argument
235 got send -q -r $testroot/repo -f > $testroot/stdout \
236 2> $testroot/stderr
237 ret=$?
238 if [ $ret -eq 0 ]; then
239 echo "got send command succeeded unexpectedly" >&2
240 test_done "$testroot" 1
241 return 1
242 fi
243 echo "got: origin: remote repository not found" \
244 > $testroot/stderr.expected
245 cmp -s $testroot/stderr $testroot/stderr.expected
246 ret=$?
247 if [ $ret -ne 0 ]; then
248 diff -u $testroot/stderr.expected $testroot/stderr
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
254 2> $testroot/stderr
255 ret=$?
256 if [ $ret -ne 0 ]; then
257 echo "got send command failed unexpectedly" >&2
258 test_done "$testroot" "$ret"
259 return 1
260 fi
262 echo -n > $testroot/stdout.expected
263 cmp -s $testroot/stdout $testroot/stdout.expected
264 ret=$?
265 if [ $ret -ne 0 ]; then
266 diff -u $testroot/stdout.expected $testroot/stdout
267 test_done "$testroot" "$ret"
268 return 1
269 fi
271 got ref -l -r $testroot/repo > $testroot/stdout
272 ret=$?
273 if [ $ret -ne 0 ]; then
274 echo "got ref command failed unexpectedly" >&2
275 test_done "$testroot" "$ret"
276 return 1
277 fi
279 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
280 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
281 echo "refs/remotes/foobar/master: $commit_id2" \
282 >> $testroot/stdout.expected
284 cmp -s $testroot/stdout $testroot/stdout.expected
285 ret=$?
286 if [ $ret -ne 0 ]; then
287 diff -u $testroot/stdout.expected $testroot/stdout
288 test_done "$testroot" "$ret"
289 return 1
290 fi
292 got ref -l -r $testroot/repo-clone > $testroot/stdout
293 ret=$?
294 if [ $ret -ne 0 ]; then
295 echo "got ref command failed unexpectedly" >&2
296 test_done "$testroot" "$ret"
297 return 1
298 fi
300 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
301 cut -d ':' -f 2 | tr -d ' ')`
302 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
303 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
304 >> $testroot/stdout.expected
305 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
306 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
307 >> $testroot/stdout.expected
308 echo "refs/remotes/origin/master: $commit_id" \
309 >> $testroot/stdout.expected
311 cmp -s $testroot/stdout $testroot/stdout.expected
312 ret=$?
313 if [ $ret -ne 0 ]; then
314 diff -u $testroot/stdout.expected $testroot/stdout
315 test_done "$testroot" "$ret"
316 return 1
317 fi
319 git_fsck "$testroot" "$testroot/repo-clone"
320 ret=$?
321 test_done "$testroot" "$ret"
324 test_send_delete() {
325 local testroot=`test_init send_delete`
326 local testurl=ssh://127.0.0.1/$testroot
327 local commit_id=`git_show_head $testroot/repo`
329 # branch1 exists in both repositories
330 got branch -r $testroot/repo branch1
332 got clone -a -q $testurl/repo $testroot/repo-clone
333 ret=$?
334 if [ $ret -ne 0 ]; then
335 echo "got clone command failed unexpectedly" >&2
336 test_done "$testroot" "$ret"
337 return 1
338 fi
339 cat > $testroot/repo/.git/got.conf <<EOF
340 remote "origin" {
341 protocol ssh
342 server 127.0.0.1
343 repository "$testroot/repo-clone"
345 EOF
346 # branch2 exists only in the remote repository
347 got branch -r $testroot/repo-clone branch2
349 got ref -l -r $testroot/repo-clone > $testroot/stdout
350 ret=$?
351 if [ $ret -ne 0 ]; then
352 echo "got ref command failed unexpectedly" >&2
353 test_done "$testroot" "$ret"
354 return 1
355 fi
357 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
358 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
359 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
360 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
362 # Sending changes for a branch and deleting it at the same
363 # time is not allowed.
364 got send -q -r $testroot/repo -d branch1 -b branch1 \
365 > $testroot/stdout 2> $testroot/stderr
366 ret=$?
367 if [ $ret -eq 0 ]; then
368 echo "got send command succeeded unexpectedly" >&2
369 test_done "$testroot" 1
370 return 1
371 fi
372 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
373 > $testroot/stderr.expected
374 echo ": reference cannot be deleted" >> $testroot/stderr.expected
375 cmp -s $testroot/stderr $testroot/stderr.expected
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stderr.expected $testroot/stderr
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
384 > $testroot/stdout 2> $testroot/stderr
385 ret=$?
386 if [ $ret -ne 0 ]; then
387 echo "got send command failed unexpectedly" >&2
388 test_done "$testroot" "$ret"
389 return 1
390 fi
392 got send -r $testroot/repo -d refs/heads/branch2 origin \
393 > $testroot/stdout 2>$testroot/stderr
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 echo "got send command failed unexpectedly" >&2
397 test_done "$testroot" "$ret"
398 return 1
399 fi
401 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
402 echo "Server has deleted refs/heads/branch2" \
403 >> $testroot/stdout.expected
405 cmp -s $testroot/stdout $testroot/stdout.expected
406 ret=$?
407 if [ $ret -ne 0 ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 test_done "$testroot" "$ret"
410 return 1
411 fi
413 # branchX exists in neither repository
414 got send -q -r $testroot/repo -d refs/heads/branchX origin \
415 > $testroot/stdout 2> $testroot/stderr
416 ret=$?
417 if [ $ret -eq 0 ]; then
418 echo "got send command succeeded unexpectedly" >&2
419 test_done "$testroot" 1
420 return 1
421 fi
422 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
423 > $testroot/stderr.expected
424 echo "repository: no such reference found" >> $testroot/stderr.expected
425 echo "got: no such reference found" >> $testroot/stderr.expected
426 cmp -s $testroot/stderr $testroot/stderr.expected
427 ret=$?
428 if [ $ret -ne 0 ]; then
429 diff -u $testroot/stderr.expected $testroot/stderr
430 test_done "$testroot" "$ret"
431 return 1
432 fi
434 # References outside of refs/heads/ cannot be deleted with 'got send'.
435 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
436 > $testroot/stdout 2> $testroot/stderr
437 ret=$?
438 if [ $ret -eq 0 ]; then
439 echo "got send command succeeded unexpectedly" >&2
440 test_done "$testroot" 1
441 return 1
442 fi
443 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
444 > $testroot/stderr.expected
445 echo "in remote repository: no such reference found" \
446 >> $testroot/stderr.expected
447 echo "got: no such reference found" >> $testroot/stderr.expected
448 cmp -s $testroot/stderr $testroot/stderr.expected
449 ret=$?
450 if [ $ret -ne 0 ]; then
451 diff -u $testroot/stderr.expected $testroot/stderr
452 test_done "$testroot" "$ret"
453 return 1
454 fi
456 got ref -l -r $testroot/repo > $testroot/stdout
457 ret=$?
458 if [ $ret -ne 0 ]; then
459 echo "got ref command failed unexpectedly" >&2
460 test_done "$testroot" "$ret"
461 return 1
462 fi
464 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
465 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
466 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
468 cmp -s $testroot/stdout $testroot/stdout.expected
469 ret=$?
470 if [ $ret -ne 0 ]; then
471 diff -u $testroot/stdout.expected $testroot/stdout
472 test_done "$testroot" "$ret"
473 return 1
474 fi
476 got ref -l -r $testroot/repo-clone > $testroot/stdout
477 ret=$?
478 if [ $ret -ne 0 ]; then
479 echo "got ref command failed unexpectedly" >&2
480 test_done "$testroot" "$ret"
481 return 1
482 fi
484 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
485 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
486 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
487 >> $testroot/stdout.expected
488 echo "refs/remotes/origin/branch1: $commit_id" \
489 >> $testroot/stdout.expected
490 echo "refs/remotes/origin/master: $commit_id" \
491 >> $testroot/stdout.expected
493 cmp -s $testroot/stdout $testroot/stdout.expected
494 ret=$?
495 if [ $ret -ne 0 ]; then
496 diff -u $testroot/stdout.expected $testroot/stdout
497 test_done "$testroot" "$ret"
498 return 1
499 fi
501 git_fsck "$testroot" "$testroot/repo-clone"
502 ret=$?
503 test_done "$testroot" "$ret"
506 test_send_clone_and_send() {
507 local testroot=`test_init send_clone_and_send`
508 local testurl=ssh://127.0.0.1/$testroot
509 local commit_id=`git_show_head $testroot/repo`
511 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
513 got clone -q $testurl/repo $testroot/repo-clone
514 ret=$?
515 if [ $ret -ne 0 ]; then
516 echo "got clone command failed unexpectedly" >&2
517 test_done "$testroot" "$ret"
518 return 1
519 fi
521 got checkout $testroot/repo-clone $testroot/wt >/dev/null
522 echo "modified alpha" > $testroot/wt/alpha
523 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
524 local commit_id2=`git_show_head $testroot/repo-clone`
526 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
527 ret=$?
528 if [ $ret -ne 0 ]; then
529 echo "got send command failed unexpectedly" >&2
530 test_done "$testroot" "$ret"
531 return 1
532 fi
534 echo -n > $testroot/stdout.expected
535 cmp -s $testroot/stdout $testroot/stdout.expected
536 ret=$?
537 if [ $ret -ne 0 ]; then
538 diff -u $testroot/stdout.expected $testroot/stdout
539 test_done "$testroot" "$ret"
540 return 1
541 fi
543 got ref -l -r $testroot/repo > $testroot/stdout
544 ret=$?
545 if [ $ret -ne 0 ]; then
546 echo "got ref command failed unexpectedly" >&2
547 test_done "$testroot" "$ret"
548 return 1
549 fi
551 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
552 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
554 cmp -s $testroot/stdout $testroot/stdout.expected
555 ret=$?
556 if [ $ret -ne 0 ]; then
557 diff -u $testroot/stdout.expected $testroot/stdout
558 test_done "$testroot" "$ret"
559 return 1
560 fi
562 got ref -l -r $testroot/repo-clone > $testroot/stdout
563 ret=$?
564 if [ $ret -ne 0 ]; then
565 echo "got ref command failed unexpectedly" >&2
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
571 cut -d ':' -f 2 | tr -d ' ')`
572 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
573 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
574 >> $testroot/stdout.expected
575 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
576 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
577 >> $testroot/stdout.expected
578 echo "refs/remotes/origin/master: $commit_id2" \
579 >> $testroot/stdout.expected
581 cmp -s $testroot/stdout $testroot/stdout.expected
582 ret=$?
583 if [ $ret -ne 0 ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 test_done "$testroot" "$ret"
586 return 1
587 fi
589 git_fsck "$testroot" "$testroot/repo-clone"
590 ret=$?
591 test_done "$testroot" "$ret"
594 test_send_tags() {
595 local testroot=`test_init send_tags`
596 local testurl=ssh://127.0.0.1/$testroot
597 local commit_id=`git_show_head $testroot/repo`
599 got clone -q $testurl/repo $testroot/repo-clone
600 ret=$?
601 if [ $ret -ne 0 ]; then
602 echo "got clone command failed unexpectedly" >&2
603 test_done "$testroot" "$ret"
604 return 1
605 fi
606 cat > $testroot/repo/.git/got.conf <<EOF
607 remote "origin" {
608 protocol ssh
609 server 127.0.0.1
610 repository "$testroot/repo-clone"
612 EOF
613 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
614 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
615 | tr -d ' ' | cut -d: -f2`
617 echo "modified alpha" > $testroot/repo/alpha
618 git_commit $testroot/repo -m "modified alpha"
619 local commit_id2=`git_show_head $testroot/repo`
621 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
622 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
623 | tr -d ' ' | cut -d: -f2`
625 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
626 ret=$?
627 if [ $ret -ne 0 ]; then
628 echo "got send command failed unexpectedly" >&2
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 echo -n > $testroot/stdout.expected
634 cmp -s $testroot/stdout $testroot/stdout.expected
635 ret=$?
636 if [ $ret -ne 0 ]; then
637 diff -u $testroot/stdout.expected $testroot/stdout
638 test_done "$testroot" "$ret"
639 return 1
640 fi
642 got ref -l -r $testroot/repo > $testroot/stdout
643 ret=$?
644 if [ $ret -ne 0 ]; then
645 echo "got ref command failed unexpectedly" >&2
646 test_done "$testroot" "$ret"
647 return 1
648 fi
650 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
651 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
652 echo "refs/remotes/origin/master: $commit_id2" \
653 >> $testroot/stdout.expected
654 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
655 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
657 cmp -s $testroot/stdout $testroot/stdout.expected
658 ret=$?
659 if [ $ret -ne 0 ]; then
660 diff -u $testroot/stdout.expected $testroot/stdout
661 test_done "$testroot" "$ret"
662 return 1
663 fi
665 got ref -l -r $testroot/repo-clone > $testroot/stdout
666 ret=$?
667 if [ $ret -ne 0 ]; then
668 echo "got ref command failed unexpectedly" >&2
669 test_done "$testroot" "$ret"
670 return 1
671 fi
673 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
674 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
675 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
676 >> $testroot/stdout.expected
677 echo "refs/remotes/origin/master: $commit_id" \
678 >> $testroot/stdout.expected
679 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
680 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
682 cmp -s $testroot/stdout $testroot/stdout.expected
683 ret=$?
684 if [ $ret -ne 0 ]; then
685 diff -u $testroot/stdout.expected $testroot/stdout
686 test_done "$testroot" "$ret"
687 return 1
688 fi
690 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
691 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
692 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
693 cmp -s $testroot/stdout $testroot/stdout.expected
694 ret=$?
695 if [ $ret -ne 0 ]; then
696 diff -u $testroot/stdout.expected $testroot/stdout
697 test_done "$testroot" "$ret"
698 return 1
699 fi
701 # Send the same tags again. This should be a no-op.
702 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
703 ret=$?
704 if [ $ret -ne 0 ]; then
705 echo "got send command failed unexpectedly" >&2
706 test_done "$testroot" "$ret"
707 return 1
708 fi
710 echo -n > $testroot/stdout.expected
711 cmp -s $testroot/stdout $testroot/stdout.expected
712 ret=$?
713 if [ $ret -ne 0 ]; then
714 diff -u $testroot/stdout.expected $testroot/stdout
715 test_done "$testroot" "$ret"
716 return 1
717 fi
719 # Overwriting an existing tag 'got send -f'.
720 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
721 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
722 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
723 | tr -d ' ' | cut -d: -f2`
725 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
726 2> $testroot/stderr
727 ret=$?
728 if [ $ret -eq 0 ]; then
729 echo "got send command succeeded unexpectedly" >&2
730 test_done "$testroot" 1
731 return 1
732 fi
734 echo "got: refs/tags/1.0: tag already exists on server" \
735 > $testroot/stderr.expected
736 cmp -s $testroot/stderr $testroot/stderr.expected
737 ret=$?
738 if [ $ret -ne 0 ]; then
739 diff -u $testroot/stderr.expected $testroot/stderr
740 test_done "$testroot" "$ret"
741 return 1
742 fi
744 # attempting the same with -T should fail, too
745 got send -q -r $testroot/repo -T > $testroot/stdout \
746 2> $testroot/stderr
747 ret=$?
748 if [ $ret -eq 0 ]; then
749 echo "got send command succeeded unexpectedly" >&2
750 test_done "$testroot" 1
751 return 1
752 fi
754 echo "got: refs/tags/1.0: tag already exists on server" \
755 > $testroot/stderr.expected
756 cmp -s $testroot/stderr $testroot/stderr.expected
757 ret=$?
758 if [ $ret -ne 0 ]; then
759 diff -u $testroot/stderr.expected $testroot/stderr
760 test_done "$testroot" "$ret"
761 return 1
762 fi
764 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
765 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
766 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
767 cmp -s $testroot/stdout $testroot/stdout.expected
768 ret=$?
769 if [ $ret -ne 0 ]; then
770 diff -u $testroot/stdout.expected $testroot/stdout
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 # overwrite the 1.0 tag only
776 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
777 2> $testroot/stderr
778 ret=$?
779 if [ $ret -ne 0 ]; then
780 echo "got send command failed unexpectedly" >&2
781 test_done "$testroot" "$ret"
782 return 1
783 fi
785 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
786 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
787 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
788 cmp -s $testroot/stdout $testroot/stdout.expected
789 ret=$?
790 if [ $ret -ne 0 ]; then
791 diff -u $testroot/stdout.expected $testroot/stdout
792 test_done "$testroot" "$ret"
793 return 1
794 fi
796 got checkout $testroot/repo $testroot/wt > /dev/null
797 echo 'new line in file alpha' >> $testroot/wt/alpha
798 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
800 # Send the new commit in isolation.
801 got send -q -r $testroot/repo > $testroot/stdout \
802 2> $testroot/stderr
803 ret=$?
804 if [ $ret -ne 0 ]; then
805 echo "got send command failed unexpectedly" >&2
806 test_done "$testroot" "$ret"
807 return 1
808 fi
810 # Now tag it and send the tag.
811 # Verify that just the new tag object gets sent.
812 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
813 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
814 | tr -d ' ' | cut -d: -f2`
816 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
817 2> $testroot/stderr
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 echo "got send command failed unexpectedly" >&2
821 test_done "$testroot" "$ret"
822 return 1
823 fi
824 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
825 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
826 $testroot/stdout; then
827 echo "got send did apparently pack too many objects:" >&2
828 cat $testroot/stdout.raw >&2
829 test_done "$testroot" "1"
830 return 1
831 fi
833 git_fsck "$testroot" "$testroot/repo-clone"
834 ret=$?
835 test_done "$testroot" "$ret"
838 test_send_tag_of_deleted_branch() {
839 local testroot=`test_init send_tag_of_deleted_branch`
840 local testurl=ssh://127.0.0.1/$testroot
841 local commit_id=`git_show_head $testroot/repo`
843 got clone -q $testurl/repo $testroot/repo-clone
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 echo "got clone command failed unexpectedly" >&2
847 test_done "$testroot" "$ret"
848 return 1
849 fi
850 cat > $testroot/repo/.git/got.conf <<EOF
851 remote "origin" {
852 protocol ssh
853 server 127.0.0.1
854 repository "$testroot/repo-clone"
856 EOF
857 got branch -r $testroot/repo foo
859 # modify beta on branch foo
860 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
861 echo boo >> $testroot/wt/beta
862 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
863 > /dev/null)
864 echo buu >> $testroot/wt/beta
865 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
866 > /dev/null)
867 echo baa >> $testroot/wt/beta
868 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
869 > /dev/null)
870 local commit_id2=`git_show_branch_head $testroot/repo foo`
872 # tag HEAD commit of branch foo
873 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
874 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
875 | tr -d ' ' | cut -d: -f2`
877 # delete the branch; commit is now only reachable via tags/1.0
878 got branch -r $testroot/repo -d foo > /dev/null
880 # unrelated change on master branch, then try sending this branch
881 # and the tag
882 echo "modified alpha" > $testroot/repo/alpha
883 git_commit $testroot/repo -m "modified alpha"
884 local commit_id3=`git_show_head $testroot/repo`
886 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
887 ret=$?
888 if [ $ret -ne 0 ]; then
889 echo "got send command failed unexpectedly" >&2
890 test_done "$testroot" "$ret"
891 return 1
892 fi
894 echo -n > $testroot/stdout.expected
895 cmp -s $testroot/stdout $testroot/stdout.expected
896 ret=$?
897 if [ $ret -ne 0 ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
899 test_done "$testroot" "$ret"
900 return 1
901 fi
903 got ref -l -r $testroot/repo > $testroot/stdout
904 ret=$?
905 if [ $ret -ne 0 ]; then
906 echo "got ref command failed unexpectedly" >&2
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
912 cut -d ':' -f 2 | tr -d ' ')`
913 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
914 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
915 >> $testroot/stdout.expected
916 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
917 echo "refs/remotes/origin/master: $commit_id3" \
918 >> $testroot/stdout.expected
919 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
921 cmp -s $testroot/stdout $testroot/stdout.expected
922 ret=$?
923 if [ $ret -ne 0 ]; then
924 diff -u $testroot/stdout.expected $testroot/stdout
925 test_done "$testroot" "$ret"
926 return 1
927 fi
929 got ref -l -r $testroot/repo-clone > $testroot/stdout
930 ret=$?
931 if [ $ret -ne 0 ]; then
932 echo "got ref command failed unexpectedly" >&2
933 test_done "$testroot" "$ret"
934 return 1
935 fi
937 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
938 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
939 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
940 >> $testroot/stdout.expected
941 echo "refs/remotes/origin/master: $commit_id" \
942 >> $testroot/stdout.expected
943 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
945 cmp -s $testroot/stdout $testroot/stdout.expected
946 ret=$?
947 if [ $ret -ne 0 ]; then
948 diff -u $testroot/stdout.expected $testroot/stdout
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
954 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
956 cmp -s $testroot/stdout $testroot/stdout.expected
957 ret=$?
958 if [ $ret -ne 0 ]; then
959 diff -u $testroot/stdout.expected $testroot/stdout
960 test_done "$testroot" "$ret"
961 return 1
962 fi
964 git_fsck "$testroot" "$testroot/repo-clone"
965 ret=$?
966 test_done "$testroot" "$ret"
969 test_send_new_branch() {
970 local testroot=`test_init send_new_branch`
971 local testurl=ssh://127.0.0.1/$testroot
972 local commit_id=`git_show_head $testroot/repo`
974 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
976 got clone -q $testurl/repo $testroot/repo-clone
977 ret=$?
978 if [ $ret -ne 0 ]; then
979 echo "got clone command failed unexpectedly" >&2
980 test_done "$testroot" "$ret"
981 return 1
982 fi
984 got branch -r $testroot/repo-clone foo >/dev/null
985 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
986 echo "modified alpha" > $testroot/wt/alpha
987 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
988 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
990 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
991 ret=$?
992 if [ $ret -ne 0 ]; then
993 echo "got send command failed unexpectedly" >&2
994 test_done "$testroot" "$ret"
995 return 1
996 fi
998 echo -n > $testroot/stdout.expected
999 cmp -s $testroot/stdout $testroot/stdout.expected
1000 ret=$?
1001 if [ $ret -ne 0 ]; then
1002 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1004 return 1
1007 got ref -l -r $testroot/repo > $testroot/stdout
1008 ret=$?
1009 if [ $ret -ne 0 ]; then
1010 echo "got ref command failed unexpectedly" >&2
1011 test_done "$testroot" "$ret"
1012 return 1
1015 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1016 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1017 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1019 cmp -s $testroot/stdout $testroot/stdout.expected
1020 ret=$?
1021 if [ $ret -ne 0 ]; then
1022 diff -u $testroot/stdout.expected $testroot/stdout
1023 test_done "$testroot" "$ret"
1024 return 1
1027 got ref -l -r $testroot/repo-clone > $testroot/stdout
1028 ret=$?
1029 if [ $ret -ne 0 ]; then
1030 echo "got ref command failed unexpectedly" >&2
1031 test_done "$testroot" "$ret"
1032 return 1
1035 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1036 cut -d ':' -f 2 | tr -d ' ')`
1037 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1038 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1039 >> $testroot/stdout.expected
1040 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1041 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1042 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1043 >> $testroot/stdout.expected
1044 echo "refs/remotes/origin/foo: $commit_id2" \
1045 >> $testroot/stdout.expected
1046 echo "refs/remotes/origin/master: $commit_id" \
1047 >> $testroot/stdout.expected
1049 cmp -s $testroot/stdout $testroot/stdout.expected
1050 ret=$?
1051 if [ $ret -ne 0 ]; then
1052 diff -u $testroot/stdout.expected $testroot/stdout
1053 test_done "$testroot" "$ret"
1054 return 1
1057 git_fsck "$testroot" "$testroot/repo-clone"
1058 ret=$?
1059 test_done "$testroot" "$ret"
1062 test_send_all_branches() {
1063 local testroot=`test_init send_all_branches`
1064 local testurl=ssh://127.0.0.1/$testroot
1065 local commit_id=`git_show_head $testroot/repo`
1067 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1069 got clone -q $testurl/repo $testroot/repo-clone
1070 ret=$?
1071 if [ $ret -ne 0 ]; then
1072 echo "got clone command failed unexpectedly" >&2
1073 test_done "$testroot" "$ret"
1074 return 1
1077 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1078 echo "modified alpha" > $testroot/wt/alpha
1079 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1080 local commit_id2=`git_show_head $testroot/repo-clone`
1082 got branch -r $testroot/repo-clone foo >/dev/null
1083 (cd $testroot/wt && got update -b foo >/dev/null)
1084 echo "modified beta on new branch foo" > $testroot/wt/beta
1085 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1086 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1088 got branch -r $testroot/repo-clone bar >/dev/null
1089 (cd $testroot/wt && got update -b bar >/dev/null)
1090 echo "modified beta again on new branch bar" > $testroot/wt/beta
1091 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1092 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1094 got ref -l -r $testroot/repo-clone > $testroot/stdout
1095 ret=$?
1096 if [ $ret -ne 0 ]; then
1097 echo "got ref command failed unexpectedly" >&2
1098 test_done "$testroot" "$ret"
1099 return 1
1102 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1103 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1104 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1105 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1107 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1108 2> $testroot/stderr
1109 ret=$?
1110 if [ $ret -eq 0 ]; then
1111 echo "got send command succeeded unexpectedly" >&2
1112 test_done "$testroot" 1
1113 return 1
1115 echo "got: -a and -b options are mutually exclusive" \
1116 > $testroot/stderr.expected
1117 cmp -s $testroot/stderr $testroot/stderr.expected
1118 ret=$?
1119 if [ $ret -ne 0 ]; then
1120 diff -u $testroot/stderr.expected $testroot/stderr
1121 test_done "$testroot" "$ret"
1122 return 1
1125 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1126 2> $testroot/stderr
1127 ret=$?
1128 if [ $ret -ne 0 ]; then
1129 echo "got send command failed unexpectedly" >&2
1130 test_done "$testroot" "$ret"
1131 return 1
1134 echo -n > $testroot/stdout.expected
1135 cmp -s $testroot/stdout $testroot/stdout.expected
1136 ret=$?
1137 if [ $ret -ne 0 ]; then
1138 diff -u $testroot/stdout.expected $testroot/stdout
1139 test_done "$testroot" "$ret"
1140 return 1
1143 got ref -l -r $testroot/repo > $testroot/stdout
1144 ret=$?
1145 if [ $ret -ne 0 ]; then
1146 echo "got ref command failed unexpectedly" >&2
1147 test_done "$testroot" "$ret"
1148 return 1
1151 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1152 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1153 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1154 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1156 cmp -s $testroot/stdout $testroot/stdout.expected
1157 ret=$?
1158 if [ $ret -ne 0 ]; then
1159 diff -u $testroot/stdout.expected $testroot/stdout
1160 test_done "$testroot" "$ret"
1161 return 1
1164 got ref -l -r $testroot/repo-clone > $testroot/stdout
1165 ret=$?
1166 if [ $ret -ne 0 ]; then
1167 echo "got ref command failed unexpectedly" >&2
1168 test_done "$testroot" "$ret"
1169 return 1
1172 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1173 cut -d ':' -f 2 | tr -d ' ')`
1174 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1175 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1176 >> $testroot/stdout.expected
1177 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1178 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1179 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1180 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1181 >> $testroot/stdout.expected
1182 echo "refs/remotes/origin/bar: $commit_id4" \
1183 >> $testroot/stdout.expected
1184 echo "refs/remotes/origin/foo: $commit_id3" \
1185 >> $testroot/stdout.expected
1186 echo "refs/remotes/origin/master: $commit_id2" \
1187 >> $testroot/stdout.expected
1189 cmp -s $testroot/stdout $testroot/stdout.expected
1190 ret=$?
1191 if [ $ret -ne 0 ]; then
1192 diff -u $testroot/stdout.expected $testroot/stdout
1193 test_done "$testroot" "$ret"
1194 return 1
1197 git_fsck "$testroot" "$testroot/repo-clone"
1198 ret=$?
1199 test_done "$testroot" "$ret"
1202 test_send_to_empty_repo() {
1203 local testroot=`test_init send_to_empty_repo`
1204 local testurl=ssh://127.0.0.1/$testroot
1205 local commit_id=`git_show_head $testroot/repo`
1207 gotadmin init $testroot/repo2
1209 ret=$?
1210 if [ $ret -ne 0 ]; then
1211 echo "got clone command failed unexpectedly" >&2
1212 test_done "$testroot" "$ret"
1213 return 1
1215 cat > $testroot/repo/.git/got.conf <<EOF
1216 remote "origin" {
1217 protocol ssh
1218 server 127.0.0.1
1219 repository "$testroot/repo2"
1221 EOF
1222 echo "modified alpha" > $testroot/repo/alpha
1223 git_commit $testroot/repo -m "modified alpha"
1224 local commit_id2=`git_show_head $testroot/repo`
1226 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1227 ret=$?
1228 if [ $ret -ne 0 ]; then
1229 echo "got send command failed unexpectedly" >&2
1230 test_done "$testroot" "$ret"
1231 return 1
1234 echo -n > $testroot/stdout.expected
1235 cmp -s $testroot/stdout $testroot/stdout.expected
1236 ret=$?
1237 if [ $ret -ne 0 ]; then
1238 diff -u $testroot/stdout.expected $testroot/stdout
1239 test_done "$testroot" "$ret"
1240 return 1
1243 # XXX Workaround: We cannot give the target for HEAD to 'gotadmin init'
1244 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1246 got ref -l -r $testroot/repo > $testroot/stdout
1247 ret=$?
1248 if [ $ret -ne 0 ]; then
1249 echo "got ref command failed unexpectedly" >&2
1250 test_done "$testroot" "$ret"
1251 return 1
1254 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1255 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1256 echo "refs/remotes/origin/master: $commit_id2" \
1257 >> $testroot/stdout.expected
1259 cmp -s $testroot/stdout $testroot/stdout.expected
1260 ret=$?
1261 if [ $ret -ne 0 ]; then
1262 diff -u $testroot/stdout.expected $testroot/stdout
1263 test_done "$testroot" "$ret"
1264 return 1
1267 got ref -l -r $testroot/repo2 > $testroot/stdout
1268 ret=$?
1269 if [ $ret -ne 0 ]; then
1270 echo "got ref command failed unexpectedly" >&2
1271 test_done "$testroot" "$ret"
1272 return 1
1275 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1276 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1278 cmp -s $testroot/stdout $testroot/stdout.expected
1279 ret=$?
1280 if [ $ret -ne 0 ]; then
1281 diff -u $testroot/stdout.expected $testroot/stdout
1282 test_done "$testroot" "$ret"
1283 return 1
1286 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1287 ret=$?
1288 if [ $ret -ne 0 ]; then
1289 echo "got send command failed unexpectedly" >&2
1290 test_done "$testroot" "$ret"
1291 return 1
1294 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1295 echo "Already up-to-date" >> $testroot/stdout.expected
1296 cmp -s $testroot/stdout $testroot/stdout.expected
1297 ret=$?
1298 if [ $ret -ne 0 ]; then
1299 diff -u $testroot/stdout.expected $testroot/stdout
1300 test_done "$testroot" "$ret"
1301 return 1
1304 git_fsck "$testroot" "$testroot/repo2"
1305 ret=$?
1306 test_done "$testroot" "$ret"
1309 test_send_and_fetch_config() {
1310 local testroot=`test_init send_fetch_conf`
1311 local testurl=ssh://127.0.0.1/$testroot
1312 local commit_id=`git_show_head $testroot/repo`
1314 got clone -q $testurl/repo $testroot/repo-clone
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 echo "got clone command failed unexpectedly" >&2
1318 test_done "$testroot" "$ret"
1319 return 1
1322 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1323 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1324 | tr -d ' ' | cut -d: -f2`
1326 cp -R $testroot/repo-clone $testroot/repo-clone2
1327 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1328 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1329 | tr -d ' ' | cut -d: -f2`
1331 cat > $testroot/repo/.git/got.conf <<EOF
1332 remote "origin" {
1333 protocol ssh
1334 server 127.0.0.1
1335 send {
1336 repository "$testroot/repo-clone"
1338 fetch {
1339 repository "$testroot/repo-clone2"
1342 EOF
1343 got ref -l -r $testroot/repo > $testroot/stdout
1344 ret=$?
1345 if [ $ret -ne 0 ]; then
1346 echo "got ref command failed unexpectedly" >&2
1347 test_done "$testroot" "$ret"
1348 return 1
1351 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1352 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1353 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1354 cmp -s $testroot/stdout $testroot/stdout.expected
1355 ret=$?
1356 if [ $ret -ne 0 ]; then
1357 diff -u $testroot/stdout.expected $testroot/stdout
1358 test_done "$testroot" "$ret"
1359 return 1
1362 # fetch tag 2.0 from repo-clone2
1363 got fetch -q -r $testroot/repo > $testroot/stdout
1364 ret=$?
1365 if [ $ret -ne 0 ]; then
1366 echo "got fetch command failed unexpectedly" >&2
1367 test_done "$testroot" "$ret"
1368 return 1
1371 got ref -l -r $testroot/repo > $testroot/stdout
1372 ret=$?
1373 if [ $ret -ne 0 ]; then
1374 echo "got ref command failed unexpectedly" >&2
1375 test_done "$testroot" "$ret"
1376 return 1
1379 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1380 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1381 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1382 >> $testroot/stdout.expected
1383 echo "refs/remotes/origin/master: $commit_id" \
1384 >> $testroot/stdout.expected
1385 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1386 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1387 cmp -s $testroot/stdout $testroot/stdout.expected
1388 ret=$?
1389 if [ $ret -ne 0 ]; then
1390 diff -u $testroot/stdout.expected $testroot/stdout
1391 test_done "$testroot" "$ret"
1392 return 1
1395 # send tag 1.0 to repo-clone
1396 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1397 ret=$?
1398 if [ $ret -ne 0 ]; then
1399 echo "got send command failed unexpectedly" >&2
1400 test_done "$testroot" "$ret"
1401 return 1
1404 got ref -l -r $testroot/repo-clone > $testroot/stdout
1405 ret=$?
1406 if [ $ret -ne 0 ]; then
1407 echo "got ref command failed unexpectedly" >&2
1408 test_done "$testroot" "$ret"
1409 return 1
1412 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1413 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1414 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1415 >> $testroot/stdout.expected
1416 echo "refs/remotes/origin/master: $commit_id" \
1417 >> $testroot/stdout.expected
1418 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1420 cmp -s $testroot/stdout $testroot/stdout.expected
1421 ret=$?
1422 if [ $ret -ne 0 ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1424 test_done "$testroot" "$ret"
1425 return 1
1428 git_fsck "$testroot" "$testroot/repo-clone"
1429 ret=$?
1430 test_done "$testroot" "$ret"
1433 test_send_config() {
1434 local testroot=`test_init send_fetch_conf`
1435 local testurl=ssh://127.0.0.1/$testroot
1436 local commit_id=`git_show_head $testroot/repo`
1438 got clone -q $testurl/repo $testroot/repo-clone
1439 ret=$?
1440 if [ $ret -ne 0 ]; then
1441 echo "got clone command failed unexpectedly" >&2
1442 test_done "$testroot" "$ret"
1443 return 1
1446 cat > $testroot/repo/.git/got.conf <<EOF
1447 remote "origin" {
1448 protocol ssh
1449 server 127.0.0.1
1450 branch foo
1451 repository "$testroot/repo-clone"
1453 EOF
1454 got ref -l -r $testroot/repo-clone > $testroot/stdout
1455 ret=$?
1456 if [ $ret -ne 0 ]; then
1457 echo "got ref command failed unexpectedly" >&2
1458 test_done "$testroot" "$ret"
1459 return 1
1462 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1463 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1464 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1465 >> $testroot/stdout.expected
1466 echo "refs/remotes/origin/master: $commit_id" \
1467 >> $testroot/stdout.expected
1469 cmp -s $testroot/stdout $testroot/stdout.expected
1470 ret=$?
1471 if [ $ret -ne 0 ]; then
1472 diff -u $testroot/stdout.expected $testroot/stdout
1473 test_done "$testroot" "$ret"
1474 return 1
1477 got branch -r $testroot/repo foo
1479 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1480 ret=$?
1481 if [ $ret -ne 0 ]; then
1482 echo "got send command failed unexpectedly" >&2
1483 test_done "$testroot" "$ret"
1484 return 1
1487 got ref -l -r $testroot/repo-clone > $testroot/stdout
1488 ret=$?
1489 if [ $ret -ne 0 ]; then
1490 echo "got ref command failed unexpectedly" >&2
1491 test_done "$testroot" "$ret"
1492 return 1
1495 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1496 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1497 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1498 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1499 >> $testroot/stdout.expected
1500 echo "refs/remotes/origin/master: $commit_id" \
1501 >> $testroot/stdout.expected
1503 cmp -s $testroot/stdout $testroot/stdout.expected
1504 ret=$?
1505 if [ $ret -ne 0 ]; then
1506 diff -u $testroot/stdout.expected $testroot/stdout
1507 test_done "$testroot" "$ret"
1508 return 1
1511 git_fsck "$testroot" "$testroot/repo-clone"
1512 ret=$?
1513 test_done "$testroot" "$ret"
1516 test_parseargs "$@"
1517 run_test test_send_basic
1518 run_test test_send_rebase_required
1519 run_test test_send_rebase_required_overwrite
1520 run_test test_send_delete
1521 run_test test_send_clone_and_send
1522 run_test test_send_tags
1523 run_test test_send_tag_of_deleted_branch
1524 run_test test_send_new_branch
1525 run_test test_send_all_branches
1526 run_test test_send_to_empty_repo
1527 run_test test_send_and_fetch_config
1528 run_test test_send_config