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 if [ $ret -ne 0 ]; then
69 echo "got ref command failed unexpectedly" >&2
70 test_done "$testroot" "$ret"
71 return 1
72 fi
74 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
75 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
76 echo "refs/remotes/origin/master: $commit_id2" \
77 >> $testroot/stdout.expected
78 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
80 cmp -s $testroot/stdout $testroot/stdout.expected
81 ret=$?
82 if [ $ret -ne 0 ]; then
83 diff -u $testroot/stdout.expected $testroot/stdout
84 test_done "$testroot" "$ret"
85 return 1
86 fi
88 got ref -l -r $testroot/repo-clone > $testroot/stdout
89 if [ $ret -ne 0 ]; then
90 echo "got ref command failed unexpectedly" >&2
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
96 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
97 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
98 >> $testroot/stdout.expected
99 echo "refs/remotes/origin/master: $commit_id" \
100 >> $testroot/stdout.expected
102 cmp -s $testroot/stdout $testroot/stdout.expected
103 ret=$?
104 if [ $ret -ne 0 ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 test_done "$testroot" "$ret"
107 return 1
108 fi
110 got tree -r $testroot/repo-clone -c $commit_id2 -i -R \
111 > $testroot/stdout
112 got tree -r $testroot/repo -c $commit_id2 -i -R \
113 > $testroot/stdout.expected
114 cmp -s $testroot/stdout $testroot/stdout.expected
115 ret=$?
116 if [ $ret -ne 0 ]; then
117 diff -u $testroot/stdout.expected $testroot/stdout
118 test_done "$testroot" "$ret"
119 return 1
120 fi
122 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
123 ret=$?
124 if [ $ret -ne 0 ]; then
125 echo "got send command failed unexpectedly" >&2
126 test_done "$testroot" "$ret"
127 return 1
128 fi
130 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
131 echo "Already up-to-date" >> $testroot/stdout.expected
132 cmp -s $testroot/stdout $testroot/stdout.expected
133 ret=$?
134 if [ $ret -ne 0 ]; then
135 diff -u $testroot/stdout.expected $testroot/stdout
136 test_done "$testroot" "$ret"
137 return 1
138 fi
140 git_fsck "$testroot" "$testroot/repo-clone"
141 ret=$?
142 test_done "$testroot" "$ret"
145 test_send_rebase_required() {
146 local testroot=`test_init send_rebase_required`
147 local testurl=ssh://127.0.0.1/$testroot
148 local commit_id=`git_show_head $testroot/repo`
150 got clone -q $testurl/repo $testroot/repo-clone
151 ret=$?
152 if [ $ret -ne 0 ]; then
153 echo "got clone command failed unexpectedly" >&2
154 test_done "$testroot" "$ret"
155 return 1
156 fi
157 cat > $testroot/repo/.git/got.conf <<EOF
158 remote "origin" {
159 protocol ssh
160 server 127.0.0.1
161 repository "$testroot/repo-clone"
163 EOF
164 echo "modified alpha" > $testroot/repo/alpha
165 git_commit $testroot/repo -m "modified alpha"
166 local commit_id2=`git_show_head $testroot/repo`
168 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
169 echo "modified alpha, too" > $testroot/wt-clone/alpha
170 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
172 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
173 ret=$?
174 if [ $ret -eq 0 ]; then
175 echo "got send command succeeded unexpectedly" >&2
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 echo -n > $testroot/stdout.expected
181 cmp -s $testroot/stdout $testroot/stdout.expected
182 ret=$?
183 if [ $ret -ne 0 ]; then
184 diff -u $testroot/stdout.expected $testroot/stdout
185 test_done "$testroot" "$ret"
186 return 1
187 fi
189 echo "got: refs/heads/master: fetch and rebase required" \
190 > $testroot/stderr.expected
191 cmp -s $testroot/stderr $testroot/stderr.expected
192 ret=$?
193 if [ $ret -ne 0 ]; then
194 diff -u $testroot/stderr.expected $testroot/stderr
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 git_fsck "$testroot" "$testroot/repo-clone"
200 ret=$?
201 test_done "$testroot" "$ret"
204 test_send_rebase_required_overwrite() {
205 local testroot=`test_init send_rebase_required_overwrite`
206 local testurl=ssh://127.0.0.1/$testroot
207 local commit_id=`git_show_head $testroot/repo`
209 got clone -q $testurl/repo $testroot/repo-clone
210 ret=$?
211 if [ $ret -ne 0 ]; then
212 echo "got clone command failed unexpectedly" >&2
213 test_done "$testroot" "$ret"
214 return 1
215 fi
216 cat > $testroot/repo/.git/got.conf <<EOF
217 remote "foobar" {
218 protocol ssh
219 server 127.0.0.1
220 repository "$testroot/repo-clone"
222 EOF
223 echo "modified alpha" > $testroot/repo/alpha
224 git_commit $testroot/repo -m "modified alpha"
225 local commit_id2=`git_show_head $testroot/repo`
227 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
228 echo "modified alpha, too" > $testroot/wt-clone/alpha
229 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
230 local commit_id3=`git_show_head $testroot/repo-clone`
232 # non-default remote requires an explicit argument
233 got send -q -r $testroot/repo -f > $testroot/stdout \
234 2> $testroot/stderr
235 ret=$?
236 if [ $ret -eq 0 ]; then
237 echo "got send command succeeded unexpectedly" >&2
238 test_done "$testroot" "$ret"
239 return 1
240 fi
241 echo "got: origin: remote repository not found" \
242 > $testroot/stderr.expected
243 cmp -s $testroot/stderr $testroot/stderr.expected
244 ret=$?
245 if [ $ret -ne 0 ]; then
246 diff -u $testroot/stderr.expected $testroot/stderr
247 test_done "$testroot" "$ret"
248 return 1
249 fi
251 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
252 2> $testroot/stderr
253 ret=$?
254 if [ $ret -ne 0 ]; then
255 echo "got send command failed unexpectedly" >&2
256 test_done "$testroot" "$ret"
257 return 1
258 fi
260 echo -n > $testroot/stdout.expected
261 cmp -s $testroot/stdout $testroot/stdout.expected
262 ret=$?
263 if [ $ret -ne 0 ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 got ref -l -r $testroot/repo > $testroot/stdout
270 if [ $ret -ne 0 ]; then
271 echo "got ref command failed unexpectedly" >&2
272 test_done "$testroot" "$ret"
273 return 1
274 fi
276 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
277 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
278 echo "refs/remotes/foobar/master: $commit_id2" \
279 >> $testroot/stdout.expected
281 cmp -s $testroot/stdout $testroot/stdout.expected
282 ret=$?
283 if [ $ret -ne 0 ]; then
284 diff -u $testroot/stdout.expected $testroot/stdout
285 test_done "$testroot" "$ret"
286 return 1
287 fi
289 got ref -l -r $testroot/repo-clone > $testroot/stdout
290 if [ $ret -ne 0 ]; then
291 echo "got ref command failed unexpectedly" >&2
292 test_done "$testroot" "$ret"
293 return 1
294 fi
296 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
297 cut -d ':' -f 2 | tr -d ' ')`
298 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
299 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
300 >> $testroot/stdout.expected
301 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
302 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
303 >> $testroot/stdout.expected
304 echo "refs/remotes/origin/master: $commit_id" \
305 >> $testroot/stdout.expected
307 cmp -s $testroot/stdout $testroot/stdout.expected
308 ret=$?
309 if [ $ret -ne 0 ]; then
310 diff -u $testroot/stdout.expected $testroot/stdout
311 test_done "$testroot" "$ret"
312 return 1
313 fi
315 git_fsck "$testroot" "$testroot/repo-clone"
316 ret=$?
317 test_done "$testroot" "$ret"
320 test_send_delete() {
321 local testroot=`test_init send_delete`
322 local testurl=ssh://127.0.0.1/$testroot
323 local commit_id=`git_show_head $testroot/repo`
325 # branch1 exists in both repositories
326 got branch -r $testroot/repo branch1
328 got clone -a -q $testurl/repo $testroot/repo-clone
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 echo "got clone command failed unexpectedly" >&2
332 test_done "$testroot" "$ret"
333 return 1
334 fi
335 cat > $testroot/repo/.git/got.conf <<EOF
336 remote "origin" {
337 protocol ssh
338 server 127.0.0.1
339 repository "$testroot/repo-clone"
341 EOF
342 # branch2 exists only in the remote repository
343 got branch -r $testroot/repo-clone branch2
345 got ref -l -r $testroot/repo-clone > $testroot/stdout
346 if [ $ret -ne 0 ]; then
347 echo "got ref command failed unexpectedly" >&2
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
353 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
354 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
355 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
357 # Sending changes for a branch and deleting it at the same
358 # time is not allowed.
359 got send -q -r $testroot/repo -d branch1 -b branch1 \
360 > $testroot/stdout 2> $testroot/stderr
361 ret=$?
362 if [ $ret -eq 0 ]; then
363 echo "got send command succeeded unexpectedly" >&2
364 test_done "$testroot" "$ret"
365 return 1
366 fi
367 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
368 > $testroot/stderr.expected
369 echo ": reference cannot be deleted" >> $testroot/stderr.expected
370 cmp -s $testroot/stderr $testroot/stderr.expected
371 ret=$?
372 if [ $ret -ne 0 ]; then
373 diff -u $testroot/stderr.expected $testroot/stderr
374 test_done "$testroot" "$ret"
375 return 1
376 fi
378 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
379 > $testroot/stdout 2> $testroot/stderr
380 ret=$?
381 if [ $ret -ne 0 ]; then
382 echo "got send command failed unexpectedly" >&2
383 test_done "$testroot" "$ret"
384 return 1
385 fi
387 got send -r $testroot/repo -d refs/heads/branch2 origin \
388 > $testroot/stdout 2>$testroot/stderr
389 ret=$?
390 if [ $ret -ne 0 ]; then
391 echo "got send command failed unexpectedly" >&2
392 test_done "$testroot" "$ret"
393 return 1
394 fi
396 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
397 echo "Server has deleted refs/heads/branch2" \
398 >> $testroot/stdout.expected
400 cmp -s $testroot/stdout $testroot/stdout.expected
401 ret=$?
402 if [ $ret -ne 0 ]; then
403 diff -u $testroot/stdout.expected $testroot/stdout
404 test_done "$testroot" "$ret"
405 return 1
406 fi
408 # branchX exists in neither repository
409 got send -q -r $testroot/repo -d refs/heads/branchX origin \
410 > $testroot/stdout 2> $testroot/stderr
411 ret=$?
412 if [ $ret -eq 0 ]; then
413 echo "got send command succeeded unexpectedly" >&2
414 test_done "$testroot" "$ret"
415 return 1
416 fi
417 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
418 > $testroot/stderr.expected
419 echo "repository: no such reference found" >> $testroot/stderr.expected
420 echo "got: no such reference found" >> $testroot/stderr.expected
421 cmp -s $testroot/stderr $testroot/stderr.expected
422 ret=$?
423 if [ $ret -ne 0 ]; then
424 diff -u $testroot/stderr.expected $testroot/stderr
425 test_done "$testroot" "$ret"
426 return 1
427 fi
429 # References outside of refs/heads/ cannot be deleted with 'got send'.
430 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
431 > $testroot/stdout 2> $testroot/stderr
432 ret=$?
433 if [ $ret -eq 0 ]; then
434 echo "got send command succeeded unexpectedly" >&2
435 test_done "$testroot" "$ret"
436 return 1
437 fi
438 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
439 > $testroot/stderr.expected
440 echo "in remote repository: no such reference found" \
441 >> $testroot/stderr.expected
442 echo "got: no such reference found" >> $testroot/stderr.expected
443 cmp -s $testroot/stderr $testroot/stderr.expected
444 ret=$?
445 if [ $ret -ne 0 ]; then
446 diff -u $testroot/stderr.expected $testroot/stderr
447 test_done "$testroot" "$ret"
448 return 1
449 fi
451 got ref -l -r $testroot/repo > $testroot/stdout
452 if [ $ret -ne 0 ]; then
453 echo "got ref command failed unexpectedly" >&2
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
459 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
460 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
462 cmp -s $testroot/stdout $testroot/stdout.expected
463 ret=$?
464 if [ $ret -ne 0 ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 test_done "$testroot" "$ret"
467 return 1
468 fi
470 got ref -l -r $testroot/repo-clone > $testroot/stdout
471 if [ $ret -ne 0 ]; then
472 echo "got ref command failed unexpectedly" >&2
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
478 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
479 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
480 >> $testroot/stdout.expected
481 echo "refs/remotes/origin/branch1: $commit_id" \
482 >> $testroot/stdout.expected
483 echo "refs/remotes/origin/master: $commit_id" \
484 >> $testroot/stdout.expected
486 cmp -s $testroot/stdout $testroot/stdout.expected
487 ret=$?
488 if [ $ret -ne 0 ]; then
489 diff -u $testroot/stdout.expected $testroot/stdout
490 test_done "$testroot" "$ret"
491 return 1
492 fi
494 git_fsck "$testroot" "$testroot/repo-clone"
495 ret=$?
496 test_done "$testroot" "$ret"
499 test_send_clone_and_send() {
500 local testroot=`test_init send_clone_and_send`
501 local testurl=ssh://127.0.0.1/$testroot
502 local commit_id=`git_show_head $testroot/repo`
504 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
506 got clone -q $testurl/repo $testroot/repo-clone
507 ret=$?
508 if [ $ret -ne 0 ]; then
509 echo "got clone command failed unexpectedly" >&2
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 got checkout $testroot/repo-clone $testroot/wt >/dev/null
515 echo "modified alpha" > $testroot/wt/alpha
516 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
517 local commit_id2=`git_show_head $testroot/repo-clone`
519 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
520 ret=$?
521 if [ $ret -ne 0 ]; then
522 echo "got send command failed unexpectedly" >&2
523 test_done "$testroot" "$ret"
524 return 1
525 fi
527 echo -n > $testroot/stdout.expected
528 cmp -s $testroot/stdout $testroot/stdout.expected
529 ret=$?
530 if [ $ret -ne 0 ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done "$testroot" "$ret"
533 return 1
534 fi
536 got ref -l -r $testroot/repo > $testroot/stdout
537 if [ $ret -ne 0 ]; then
538 echo "got ref command failed unexpectedly" >&2
539 test_done "$testroot" "$ret"
540 return 1
541 fi
543 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
544 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
546 cmp -s $testroot/stdout $testroot/stdout.expected
547 ret=$?
548 if [ $ret -ne 0 ]; then
549 diff -u $testroot/stdout.expected $testroot/stdout
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 got ref -l -r $testroot/repo-clone > $testroot/stdout
555 if [ $ret -ne 0 ]; then
556 echo "got ref command failed unexpectedly" >&2
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
562 cut -d ':' -f 2 | tr -d ' ')`
563 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
564 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
565 >> $testroot/stdout.expected
566 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
567 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
568 >> $testroot/stdout.expected
569 echo "refs/remotes/origin/master: $commit_id2" \
570 >> $testroot/stdout.expected
572 cmp -s $testroot/stdout $testroot/stdout.expected
573 ret=$?
574 if [ $ret -ne 0 ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 git_fsck "$testroot" "$testroot/repo-clone"
581 ret=$?
582 test_done "$testroot" "$ret"
585 test_send_tags() {
586 local testroot=`test_init send_tags`
587 local testurl=ssh://127.0.0.1/$testroot
588 local commit_id=`git_show_head $testroot/repo`
590 got clone -q $testurl/repo $testroot/repo-clone
591 ret=$?
592 if [ $ret -ne 0 ]; then
593 echo "got clone command failed unexpectedly" >&2
594 test_done "$testroot" "$ret"
595 return 1
596 fi
597 cat > $testroot/repo/.git/got.conf <<EOF
598 remote "origin" {
599 protocol ssh
600 server 127.0.0.1
601 repository "$testroot/repo-clone"
603 EOF
604 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
605 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
606 | tr -d ' ' | cut -d: -f2`
608 echo "modified alpha" > $testroot/repo/alpha
609 git_commit $testroot/repo -m "modified alpha"
610 local commit_id2=`git_show_head $testroot/repo`
612 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
613 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
614 | tr -d ' ' | cut -d: -f2`
616 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
617 ret=$?
618 if [ $ret -ne 0 ]; then
619 echo "got send command failed unexpectedly" >&2
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo -n > $testroot/stdout.expected
625 cmp -s $testroot/stdout $testroot/stdout.expected
626 ret=$?
627 if [ $ret -ne 0 ]; then
628 diff -u $testroot/stdout.expected $testroot/stdout
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 got ref -l -r $testroot/repo > $testroot/stdout
634 if [ $ret -ne 0 ]; then
635 echo "got ref command failed unexpectedly" >&2
636 test_done "$testroot" "$ret"
637 return 1
638 fi
640 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
641 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
642 echo "refs/remotes/origin/master: $commit_id2" \
643 >> $testroot/stdout.expected
644 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
645 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
647 cmp -s $testroot/stdout $testroot/stdout.expected
648 ret=$?
649 if [ $ret -ne 0 ]; then
650 diff -u $testroot/stdout.expected $testroot/stdout
651 test_done "$testroot" "$ret"
652 return 1
653 fi
655 got ref -l -r $testroot/repo-clone > $testroot/stdout
656 if [ $ret -ne 0 ]; then
657 echo "got ref command failed unexpectedly" >&2
658 test_done "$testroot" "$ret"
659 return 1
660 fi
662 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
663 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
664 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
665 >> $testroot/stdout.expected
666 echo "refs/remotes/origin/master: $commit_id" \
667 >> $testroot/stdout.expected
668 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
669 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
671 cmp -s $testroot/stdout $testroot/stdout.expected
672 ret=$?
673 if [ $ret -ne 0 ]; then
674 diff -u $testroot/stdout.expected $testroot/stdout
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
680 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
681 echo "tag 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 # Send the same tags again. This should be a no-op.
691 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
692 ret=$?
693 if [ $ret -ne 0 ]; then
694 echo "got send command failed unexpectedly" >&2
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 echo -n > $testroot/stdout.expected
700 cmp -s $testroot/stdout $testroot/stdout.expected
701 ret=$?
702 if [ $ret -ne 0 ]; then
703 diff -u $testroot/stdout.expected $testroot/stdout
704 test_done "$testroot" "$ret"
705 return 1
706 fi
708 # Overwriting an existing tag 'got send -f'.
709 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
710 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
711 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
712 | tr -d ' ' | cut -d: -f2`
714 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
715 2> $testroot/stderr
716 ret=$?
717 if [ $ret -eq 0 ]; then
718 echo "got send command succeeded unexpectedly" >&2
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 echo "got: refs/tags/1.0: tag already exists on server" \
724 > $testroot/stderr.expected
725 cmp -s $testroot/stderr $testroot/stderr.expected
726 ret=$?
727 if [ $ret -ne 0 ]; then
728 diff -u $testroot/stderr.expected $testroot/stderr
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 # attempting the same with -T should fail, too
734 got send -q -r $testroot/repo -T > $testroot/stdout \
735 2> $testroot/stderr
736 ret=$?
737 if [ $ret -eq 0 ]; then
738 echo "got send command succeeded unexpectedly" >&2
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "got: refs/tags/1.0: tag already exists on server" \
744 > $testroot/stderr.expected
745 cmp -s $testroot/stderr $testroot/stderr.expected
746 ret=$?
747 if [ $ret -ne 0 ]; then
748 diff -u $testroot/stderr.expected $testroot/stderr
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
754 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
755 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
756 cmp -s $testroot/stdout $testroot/stdout.expected
757 ret=$?
758 if [ $ret -ne 0 ]; then
759 diff -u $testroot/stdout.expected $testroot/stdout
760 test_done "$testroot" "$ret"
761 return 1
762 fi
764 # overwrite the 1.0 tag only
765 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
766 2> $testroot/stderr
767 ret=$?
768 if [ $ret -ne 0 ]; then
769 echo "got send command failed unexpectedly" >&2
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
775 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
776 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
777 cmp -s $testroot/stdout $testroot/stdout.expected
778 ret=$?
779 if [ $ret -ne 0 ]; then
780 diff -u $testroot/stdout.expected $testroot/stdout
781 test_done "$testroot" "$ret"
782 return 1
783 fi
785 got checkout $testroot/repo $testroot/wt > /dev/null
786 echo 'new line in file alpha' >> $testroot/wt/alpha
787 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
789 # Send the new commit in isolation.
790 got send -q -r $testroot/repo > $testroot/stdout \
791 2> $testroot/stderr
792 ret=$?
793 if [ $ret -ne 0 ]; then
794 echo "got send command failed unexpectedly" >&2
795 test_done "$testroot" "$ret"
796 return 1
797 fi
799 # Now tag it and send the tag.
800 # Verify that just the new tag object gets sent.
801 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
802 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
803 | tr -d ' ' | cut -d: -f2`
805 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
806 2> $testroot/stderr
807 ret=$?
808 if [ $ret -ne 0 ]; then
809 echo "got send command failed unexpectedly" >&2
810 test_done "$testroot" "$ret"
811 return 1
812 fi
813 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
814 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
815 $testroot/stdout; then
816 echo "got send did apparently pack too many objects:" >&2
817 cat $testroot/stdout.raw >&2
818 test_done "$testroot" "1"
819 return 1
820 fi
822 git_fsck "$testroot" "$testroot/repo-clone"
823 ret=$?
824 test_done "$testroot" "$ret"
827 test_send_tag_of_deleted_branch() {
828 local testroot=`test_init send_tag_of_deleted_branch`
829 local testurl=ssh://127.0.0.1/$testroot
830 local commit_id=`git_show_head $testroot/repo`
832 got clone -q $testurl/repo $testroot/repo-clone
833 ret=$?
834 if [ $ret -ne 0 ]; then
835 echo "got clone command failed unexpectedly" >&2
836 test_done "$testroot" "$ret"
837 return 1
838 fi
839 cat > $testroot/repo/.git/got.conf <<EOF
840 remote "origin" {
841 protocol ssh
842 server 127.0.0.1
843 repository "$testroot/repo-clone"
845 EOF
846 got branch -r $testroot/repo foo
848 # modify beta on branch foo
849 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
850 echo boo >> $testroot/wt/beta
851 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
852 > /dev/null)
853 echo buu >> $testroot/wt/beta
854 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
855 > /dev/null)
856 echo baa >> $testroot/wt/beta
857 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
858 > /dev/null)
859 local commit_id2=`git_show_branch_head $testroot/repo foo`
861 # tag HEAD commit of branch foo
862 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
863 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
864 | tr -d ' ' | cut -d: -f2`
866 # delete the branch; commit is now only reachable via tags/1.0
867 got branch -r $testroot/repo -d foo > /dev/null
869 # unrelated change on master branch, then try sending this branch
870 # and the tag
871 echo "modified alpha" > $testroot/repo/alpha
872 git_commit $testroot/repo -m "modified alpha"
873 local commit_id3=`git_show_head $testroot/repo`
875 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
876 ret=$?
877 if [ $ret -ne 0 ]; then
878 echo "got send command failed unexpectedly" >&2
879 test_done "$testroot" "$ret"
880 return 1
881 fi
883 echo -n > $testroot/stdout.expected
884 cmp -s $testroot/stdout $testroot/stdout.expected
885 ret=$?
886 if [ $ret -ne 0 ]; then
887 diff -u $testroot/stdout.expected $testroot/stdout
888 test_done "$testroot" "$ret"
889 return 1
890 fi
892 got ref -l -r $testroot/repo > $testroot/stdout
893 if [ $ret -ne 0 ]; then
894 echo "got ref command failed unexpectedly" >&2
895 test_done "$testroot" "$ret"
896 return 1
897 fi
899 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
900 cut -d ':' -f 2 | tr -d ' ')`
901 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
902 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
903 >> $testroot/stdout.expected
904 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
905 echo "refs/remotes/origin/master: $commit_id3" \
906 >> $testroot/stdout.expected
907 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
909 cmp -s $testroot/stdout $testroot/stdout.expected
910 ret=$?
911 if [ $ret -ne 0 ]; then
912 diff -u $testroot/stdout.expected $testroot/stdout
913 test_done "$testroot" "$ret"
914 return 1
915 fi
917 got ref -l -r $testroot/repo-clone > $testroot/stdout
918 if [ $ret -ne 0 ]; then
919 echo "got ref command failed unexpectedly" >&2
920 test_done "$testroot" "$ret"
921 return 1
922 fi
924 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
925 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
926 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
927 >> $testroot/stdout.expected
928 echo "refs/remotes/origin/master: $commit_id" \
929 >> $testroot/stdout.expected
930 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
932 cmp -s $testroot/stdout $testroot/stdout.expected
933 ret=$?
934 if [ $ret -ne 0 ]; then
935 diff -u $testroot/stdout.expected $testroot/stdout
936 test_done "$testroot" "$ret"
937 return 1
938 fi
940 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
941 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
943 cmp -s $testroot/stdout $testroot/stdout.expected
944 ret=$?
945 if [ $ret -ne 0 ]; then
946 diff -u $testroot/stdout.expected $testroot/stdout
947 test_done "$testroot" "$ret"
948 return 1
949 fi
951 git_fsck "$testroot" "$testroot/repo-clone"
952 ret=$?
953 test_done "$testroot" "$ret"
956 test_send_new_branch() {
957 local testroot=`test_init send_new_branch`
958 local testurl=ssh://127.0.0.1/$testroot
959 local commit_id=`git_show_head $testroot/repo`
961 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
963 got clone -q $testurl/repo $testroot/repo-clone
964 ret=$?
965 if [ $ret -ne 0 ]; then
966 echo "got clone command failed unexpectedly" >&2
967 test_done "$testroot" "$ret"
968 return 1
969 fi
971 got branch -r $testroot/repo-clone foo >/dev/null
972 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
973 echo "modified alpha" > $testroot/wt/alpha
974 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
975 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
977 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
978 ret=$?
979 if [ $ret -ne 0 ]; then
980 echo "got send command failed unexpectedly" >&2
981 test_done "$testroot" "$ret"
982 return 1
983 fi
985 echo -n > $testroot/stdout.expected
986 cmp -s $testroot/stdout $testroot/stdout.expected
987 ret=$?
988 if [ $ret -ne 0 ]; then
989 diff -u $testroot/stdout.expected $testroot/stdout
990 test_done "$testroot" "$ret"
991 return 1
992 fi
994 got ref -l -r $testroot/repo > $testroot/stdout
995 if [ $ret -ne 0 ]; then
996 echo "got ref command failed unexpectedly" >&2
997 test_done "$testroot" "$ret"
998 return 1
999 fi
1001 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1002 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1003 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1005 cmp -s $testroot/stdout $testroot/stdout.expected
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 diff -u $testroot/stdout.expected $testroot/stdout
1009 test_done "$testroot" "$ret"
1010 return 1
1013 got ref -l -r $testroot/repo-clone > $testroot/stdout
1014 if [ $ret -ne 0 ]; then
1015 echo "got ref command failed unexpectedly" >&2
1016 test_done "$testroot" "$ret"
1017 return 1
1020 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1021 cut -d ':' -f 2 | tr -d ' ')`
1022 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1023 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1024 >> $testroot/stdout.expected
1025 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1026 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1027 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1028 >> $testroot/stdout.expected
1029 echo "refs/remotes/origin/foo: $commit_id2" \
1030 >> $testroot/stdout.expected
1031 echo "refs/remotes/origin/master: $commit_id" \
1032 >> $testroot/stdout.expected
1034 cmp -s $testroot/stdout $testroot/stdout.expected
1035 ret=$?
1036 if [ $ret -ne 0 ]; then
1037 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1039 return 1
1042 git_fsck "$testroot" "$testroot/repo-clone"
1043 ret=$?
1044 test_done "$testroot" "$ret"
1047 test_send_all_branches() {
1048 local testroot=`test_init send_all_branches`
1049 local testurl=ssh://127.0.0.1/$testroot
1050 local commit_id=`git_show_head $testroot/repo`
1052 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1054 got clone -q $testurl/repo $testroot/repo-clone
1055 ret=$?
1056 if [ $ret -ne 0 ]; then
1057 echo "got clone command failed unexpectedly" >&2
1058 test_done "$testroot" "$ret"
1059 return 1
1062 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1063 echo "modified alpha" > $testroot/wt/alpha
1064 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1065 local commit_id2=`git_show_head $testroot/repo-clone`
1067 got branch -r $testroot/repo-clone foo >/dev/null
1068 (cd $testroot/wt && got update -b foo >/dev/null)
1069 echo "modified beta on new branch foo" > $testroot/wt/beta
1070 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1071 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1073 got branch -r $testroot/repo-clone bar >/dev/null
1074 (cd $testroot/wt && got update -b bar >/dev/null)
1075 echo "modified beta again on new branch bar" > $testroot/wt/beta
1076 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1077 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1079 got ref -l -r $testroot/repo-clone > $testroot/stdout
1080 if [ $ret -ne 0 ]; then
1081 echo "got ref command failed unexpectedly" >&2
1082 test_done "$testroot" "$ret"
1083 return 1
1086 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1087 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1088 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1089 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1091 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1092 2> $testroot/stderr
1093 ret=$?
1094 if [ $ret -eq 0 ]; then
1095 echo "got send command succeeded unexpectedly" >&2
1096 test_done "$testroot" "$ret"
1097 return 1
1099 echo "got: -a and -b options are mutually exclusive" \
1100 > $testroot/stderr.expected
1101 cmp -s $testroot/stderr $testroot/stderr.expected
1102 ret=$?
1103 if [ $ret -ne 0 ]; then
1104 diff -u $testroot/stderr.expected $testroot/stderr
1105 test_done "$testroot" "$ret"
1106 return 1
1109 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1110 2> $testroot/stderr
1111 ret=$?
1112 if [ $ret -ne 0 ]; then
1113 echo "got send command failed unexpectedly" >&2
1114 test_done "$testroot" "$ret"
1115 return 1
1118 echo -n > $testroot/stdout.expected
1119 cmp -s $testroot/stdout $testroot/stdout.expected
1120 ret=$?
1121 if [ $ret -ne 0 ]; then
1122 diff -u $testroot/stdout.expected $testroot/stdout
1123 test_done "$testroot" "$ret"
1124 return 1
1127 got ref -l -r $testroot/repo > $testroot/stdout
1128 if [ $ret -ne 0 ]; then
1129 echo "got ref command failed unexpectedly" >&2
1130 test_done "$testroot" "$ret"
1131 return 1
1134 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1135 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1136 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1137 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1139 cmp -s $testroot/stdout $testroot/stdout.expected
1140 ret=$?
1141 if [ $ret -ne 0 ]; then
1142 diff -u $testroot/stdout.expected $testroot/stdout
1143 test_done "$testroot" "$ret"
1144 return 1
1147 got ref -l -r $testroot/repo-clone > $testroot/stdout
1148 if [ $ret -ne 0 ]; then
1149 echo "got ref command failed unexpectedly" >&2
1150 test_done "$testroot" "$ret"
1151 return 1
1154 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1155 cut -d ':' -f 2 | tr -d ' ')`
1156 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1157 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1158 >> $testroot/stdout.expected
1159 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1160 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1161 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1162 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1163 >> $testroot/stdout.expected
1164 echo "refs/remotes/origin/bar: $commit_id4" \
1165 >> $testroot/stdout.expected
1166 echo "refs/remotes/origin/foo: $commit_id3" \
1167 >> $testroot/stdout.expected
1168 echo "refs/remotes/origin/master: $commit_id2" \
1169 >> $testroot/stdout.expected
1171 cmp -s $testroot/stdout $testroot/stdout.expected
1172 ret=$?
1173 if [ $ret -ne 0 ]; then
1174 diff -u $testroot/stdout.expected $testroot/stdout
1175 test_done "$testroot" "$ret"
1176 return 1
1179 git_fsck "$testroot" "$testroot/repo-clone"
1180 ret=$?
1181 test_done "$testroot" "$ret"
1184 test_send_to_empty_repo() {
1185 local testroot=`test_init send_to_empty_repo`
1186 local testurl=ssh://127.0.0.1/$testroot
1187 local commit_id=`git_show_head $testroot/repo`
1189 got init $testroot/repo2
1191 ret=$?
1192 if [ $ret -ne 0 ]; then
1193 echo "got clone command failed unexpectedly" >&2
1194 test_done "$testroot" "$ret"
1195 return 1
1197 cat > $testroot/repo/.git/got.conf <<EOF
1198 remote "origin" {
1199 protocol ssh
1200 server 127.0.0.1
1201 repository "$testroot/repo2"
1203 EOF
1204 echo "modified alpha" > $testroot/repo/alpha
1205 git_commit $testroot/repo -m "modified alpha"
1206 local commit_id2=`git_show_head $testroot/repo`
1208 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1209 ret=$?
1210 if [ $ret -ne 0 ]; then
1211 echo "got send command failed unexpectedly" >&2
1212 test_done "$testroot" "$ret"
1213 return 1
1216 echo -n > $testroot/stdout.expected
1217 cmp -s $testroot/stdout $testroot/stdout.expected
1218 ret=$?
1219 if [ $ret -ne 0 ]; then
1220 diff -u $testroot/stdout.expected $testroot/stdout
1221 test_done "$testroot" "$ret"
1222 return 1
1225 # XXX Workaround: We cannot give the target for HEAD to 'got init'
1226 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1228 got ref -l -r $testroot/repo > $testroot/stdout
1229 if [ $ret -ne 0 ]; then
1230 echo "got ref command failed unexpectedly" >&2
1231 test_done "$testroot" "$ret"
1232 return 1
1235 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1236 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1237 echo "refs/remotes/origin/master: $commit_id2" \
1238 >> $testroot/stdout.expected
1240 cmp -s $testroot/stdout $testroot/stdout.expected
1241 ret=$?
1242 if [ $ret -ne 0 ]; then
1243 diff -u $testroot/stdout.expected $testroot/stdout
1244 test_done "$testroot" "$ret"
1245 return 1
1248 got ref -l -r $testroot/repo2 > $testroot/stdout
1249 if [ $ret -ne 0 ]; then
1250 echo "got ref command failed unexpectedly" >&2
1251 test_done "$testroot" "$ret"
1252 return 1
1255 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1256 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1258 cmp -s $testroot/stdout $testroot/stdout.expected
1259 ret=$?
1260 if [ $ret -ne 0 ]; then
1261 diff -u $testroot/stdout.expected $testroot/stdout
1262 test_done "$testroot" "$ret"
1263 return 1
1266 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1267 ret=$?
1268 if [ $ret -ne 0 ]; then
1269 echo "got send command failed unexpectedly" >&2
1270 test_done "$testroot" "$ret"
1271 return 1
1274 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1275 echo "Already up-to-date" >> $testroot/stdout.expected
1276 cmp -s $testroot/stdout $testroot/stdout.expected
1277 ret=$?
1278 if [ $ret -ne 0 ]; then
1279 diff -u $testroot/stdout.expected $testroot/stdout
1280 test_done "$testroot" "$ret"
1281 return 1
1284 git_fsck "$testroot" "$testroot/repo2"
1285 ret=$?
1286 test_done "$testroot" "$ret"
1289 test_send_and_fetch_config() {
1290 local testroot=`test_init send_fetch_conf`
1291 local testurl=ssh://127.0.0.1/$testroot
1292 local commit_id=`git_show_head $testroot/repo`
1294 got clone -q $testurl/repo $testroot/repo-clone
1295 ret=$?
1296 if [ $ret -ne 0 ]; then
1297 echo "got clone command failed unexpectedly" >&2
1298 test_done "$testroot" "$ret"
1299 return 1
1302 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1303 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1304 | tr -d ' ' | cut -d: -f2`
1306 cp -R $testroot/repo-clone $testroot/repo-clone2
1307 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1308 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1309 | tr -d ' ' | cut -d: -f2`
1311 cat > $testroot/repo/.git/got.conf <<EOF
1312 remote "origin" {
1313 protocol ssh
1314 server 127.0.0.1
1315 send {
1316 repository "$testroot/repo-clone"
1318 fetch {
1319 repository "$testroot/repo-clone2"
1322 EOF
1323 got ref -l -r $testroot/repo > $testroot/stdout
1324 if [ $ret -ne 0 ]; then
1325 echo "got ref command failed unexpectedly" >&2
1326 test_done "$testroot" "$ret"
1327 return 1
1330 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1331 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1332 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1333 cmp -s $testroot/stdout $testroot/stdout.expected
1334 ret=$?
1335 if [ $ret -ne 0 ]; then
1336 diff -u $testroot/stdout.expected $testroot/stdout
1337 test_done "$testroot" "$ret"
1338 return 1
1341 # fetch tag 2.0 from repo-clone2
1342 got fetch -q -r $testroot/repo > $testroot/stdout
1343 ret=$?
1344 if [ $ret -ne 0 ]; then
1345 echo "got fetch command failed unexpectedly" >&2
1346 test_done "$testroot" "$ret"
1347 return 1
1350 got ref -l -r $testroot/repo > $testroot/stdout
1351 if [ $ret -ne 0 ]; then
1352 echo "got ref command failed unexpectedly" >&2
1353 test_done "$testroot" "$ret"
1354 return 1
1357 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1358 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1359 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1360 >> $testroot/stdout.expected
1361 echo "refs/remotes/origin/master: $commit_id" \
1362 >> $testroot/stdout.expected
1363 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1364 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1365 cmp -s $testroot/stdout $testroot/stdout.expected
1366 ret=$?
1367 if [ $ret -ne 0 ]; then
1368 diff -u $testroot/stdout.expected $testroot/stdout
1369 test_done "$testroot" "$ret"
1370 return 1
1373 # send tag 1.0 to repo-clone
1374 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1375 ret=$?
1376 if [ $ret -ne 0 ]; then
1377 echo "got send command failed unexpectedly" >&2
1378 test_done "$testroot" "$ret"
1379 return 1
1382 got ref -l -r $testroot/repo-clone > $testroot/stdout
1383 if [ $ret -ne 0 ]; then
1384 echo "got ref command failed unexpectedly" >&2
1385 test_done "$testroot" "$ret"
1386 return 1
1389 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1390 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1391 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1392 >> $testroot/stdout.expected
1393 echo "refs/remotes/origin/master: $commit_id" \
1394 >> $testroot/stdout.expected
1395 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1397 cmp -s $testroot/stdout $testroot/stdout.expected
1398 ret=$?
1399 if [ $ret -ne 0 ]; then
1400 diff -u $testroot/stdout.expected $testroot/stdout
1401 test_done "$testroot" "$ret"
1402 return 1
1405 git_fsck "$testroot" "$testroot/repo-clone"
1406 ret=$?
1407 test_done "$testroot" "$ret"
1410 test_send_config() {
1411 local testroot=`test_init send_fetch_conf`
1412 local testurl=ssh://127.0.0.1/$testroot
1413 local commit_id=`git_show_head $testroot/repo`
1415 got clone -q $testurl/repo $testroot/repo-clone
1416 ret=$?
1417 if [ $ret -ne 0 ]; then
1418 echo "got clone command failed unexpectedly" >&2
1419 test_done "$testroot" "$ret"
1420 return 1
1423 cat > $testroot/repo/.git/got.conf <<EOF
1424 remote "origin" {
1425 protocol ssh
1426 server 127.0.0.1
1427 branch foo
1428 repository "$testroot/repo-clone"
1430 EOF
1431 got ref -l -r $testroot/repo-clone > $testroot/stdout
1432 if [ $ret -ne 0 ]; then
1433 echo "got ref command failed unexpectedly" >&2
1434 test_done "$testroot" "$ret"
1435 return 1
1438 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1439 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1440 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1441 >> $testroot/stdout.expected
1442 echo "refs/remotes/origin/master: $commit_id" \
1443 >> $testroot/stdout.expected
1445 cmp -s $testroot/stdout $testroot/stdout.expected
1446 ret=$?
1447 if [ $ret -ne 0 ]; then
1448 diff -u $testroot/stdout.expected $testroot/stdout
1449 test_done "$testroot" "$ret"
1450 return 1
1453 got branch -r $testroot/repo foo
1455 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1456 ret=$?
1457 if [ $ret -ne 0 ]; then
1458 echo "got send command failed unexpectedly" >&2
1459 test_done "$testroot" "$ret"
1460 return 1
1463 got ref -l -r $testroot/repo-clone > $testroot/stdout
1464 if [ $ret -ne 0 ]; then
1465 echo "got ref command failed unexpectedly" >&2
1466 test_done "$testroot" "$ret"
1467 return 1
1470 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1471 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1472 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1473 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1474 >> $testroot/stdout.expected
1475 echo "refs/remotes/origin/master: $commit_id" \
1476 >> $testroot/stdout.expected
1478 cmp -s $testroot/stdout $testroot/stdout.expected
1479 ret=$?
1480 if [ $ret -ne 0 ]; then
1481 diff -u $testroot/stdout.expected $testroot/stdout
1482 test_done "$testroot" "$ret"
1483 return 1
1486 git_fsck "$testroot" "$testroot/repo-clone"
1487 ret=$?
1488 test_done "$testroot" "$ret"
1491 test_parseargs "$@"
1492 run_test test_send_basic
1493 run_test test_send_rebase_required
1494 run_test test_send_rebase_required_overwrite
1495 run_test test_send_delete
1496 run_test test_send_clone_and_send
1497 run_test test_send_tags
1498 run_test test_send_tag_of_deleted_branch
1499 run_test test_send_new_branch
1500 run_test test_send_all_branches
1501 run_test test_send_to_empty_repo
1502 run_test test_send_and_fetch_config
1503 run_test test_send_config