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\" ssh://127.0.0.1$testroot/repo-clone" \
133 > $testroot/stdout.expected
134 echo "Already up-to-date" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout $testroot/stdout.expected
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 test_done "$testroot" "$ret"
140 return 1
141 fi
143 git_fsck "$testroot" "$testroot/repo-clone"
144 ret=$?
145 test_done "$testroot" "$ret"
148 test_send_rebase_required() {
149 local testroot=`test_init send_rebase_required`
150 local testurl=ssh://127.0.0.1/$testroot
151 local commit_id=`git_show_head $testroot/repo`
153 got clone -q $testurl/repo $testroot/repo-clone
154 ret=$?
155 if [ $ret -ne 0 ]; then
156 echo "got clone command failed unexpectedly" >&2
157 test_done "$testroot" "$ret"
158 return 1
159 fi
160 cat > $testroot/repo/.git/got.conf <<EOF
161 remote "origin" {
162 protocol ssh
163 server 127.0.0.1
164 repository "$testroot/repo-clone"
166 EOF
167 echo "modified alpha" > $testroot/repo/alpha
168 git_commit $testroot/repo -m "modified alpha"
169 local commit_id2=`git_show_head $testroot/repo`
171 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
172 echo "modified alpha, too" > $testroot/wt-clone/alpha
173 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
175 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
176 ret=$?
177 if [ $ret -eq 0 ]; then
178 echo "got send command succeeded unexpectedly" >&2
179 test_done "$testroot" 1
180 return 1
181 fi
183 echo -n > $testroot/stdout.expected
184 cmp -s $testroot/stdout $testroot/stdout.expected
185 ret=$?
186 if [ $ret -ne 0 ]; then
187 diff -u $testroot/stdout.expected $testroot/stdout
188 test_done "$testroot" "$ret"
189 return 1
190 fi
192 echo "got: refs/heads/master: fetch and rebase required" \
193 > $testroot/stderr.expected
194 cmp -s $testroot/stderr $testroot/stderr.expected
195 ret=$?
196 if [ $ret -ne 0 ]; then
197 diff -u $testroot/stderr.expected $testroot/stderr
198 test_done "$testroot" "$ret"
199 return 1
200 fi
202 git_fsck "$testroot" "$testroot/repo-clone"
203 ret=$?
204 test_done "$testroot" "$ret"
207 test_send_rebase_required_overwrite() {
208 local testroot=`test_init send_rebase_required_overwrite`
209 local testurl=ssh://127.0.0.1/$testroot
210 local commit_id=`git_show_head $testroot/repo`
212 got clone -q $testurl/repo $testroot/repo-clone
213 ret=$?
214 if [ $ret -ne 0 ]; then
215 echo "got clone command failed unexpectedly" >&2
216 test_done "$testroot" "$ret"
217 return 1
218 fi
219 cat > $testroot/repo/.git/got.conf <<EOF
220 remote "foobar" {
221 protocol ssh
222 server 127.0.0.1
223 repository "$testroot/repo-clone"
225 EOF
226 echo "modified alpha" > $testroot/repo/alpha
227 git_commit $testroot/repo -m "modified alpha"
228 local commit_id2=`git_show_head $testroot/repo`
230 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
231 echo "modified alpha, too" > $testroot/wt-clone/alpha
232 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
233 local commit_id3=`git_show_head $testroot/repo-clone`
235 # non-default remote requires an explicit argument
236 got send -q -r $testroot/repo -f > $testroot/stdout \
237 2> $testroot/stderr
238 ret=$?
239 if [ $ret -eq 0 ]; then
240 echo "got send command succeeded unexpectedly" >&2
241 test_done "$testroot" 1
242 return 1
243 fi
244 echo "got: origin: remote repository not found" \
245 > $testroot/stderr.expected
246 cmp -s $testroot/stderr $testroot/stderr.expected
247 ret=$?
248 if [ $ret -ne 0 ]; then
249 diff -u $testroot/stderr.expected $testroot/stderr
250 test_done "$testroot" "$ret"
251 return 1
252 fi
254 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
255 2> $testroot/stderr
256 ret=$?
257 if [ $ret -ne 0 ]; then
258 echo "got send command failed unexpectedly" >&2
259 test_done "$testroot" "$ret"
260 return 1
261 fi
263 echo -n > $testroot/stdout.expected
264 cmp -s $testroot/stdout $testroot/stdout.expected
265 ret=$?
266 if [ $ret -ne 0 ]; then
267 diff -u $testroot/stdout.expected $testroot/stdout
268 test_done "$testroot" "$ret"
269 return 1
270 fi
272 got ref -l -r $testroot/repo > $testroot/stdout
273 ret=$?
274 if [ $ret -ne 0 ]; then
275 echo "got ref command failed unexpectedly" >&2
276 test_done "$testroot" "$ret"
277 return 1
278 fi
280 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
281 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
282 echo "refs/remotes/foobar/master: $commit_id2" \
283 >> $testroot/stdout.expected
285 cmp -s $testroot/stdout $testroot/stdout.expected
286 ret=$?
287 if [ $ret -ne 0 ]; then
288 diff -u $testroot/stdout.expected $testroot/stdout
289 test_done "$testroot" "$ret"
290 return 1
291 fi
293 got ref -l -r $testroot/repo-clone > $testroot/stdout
294 ret=$?
295 if [ $ret -ne 0 ]; then
296 echo "got ref command failed unexpectedly" >&2
297 test_done "$testroot" "$ret"
298 return 1
299 fi
301 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
302 cut -d ':' -f 2 | tr -d ' ')`
303 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
304 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
305 >> $testroot/stdout.expected
306 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
307 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
308 >> $testroot/stdout.expected
309 echo "refs/remotes/origin/master: $commit_id" \
310 >> $testroot/stdout.expected
312 cmp -s $testroot/stdout $testroot/stdout.expected
313 ret=$?
314 if [ $ret -ne 0 ]; then
315 diff -u $testroot/stdout.expected $testroot/stdout
316 test_done "$testroot" "$ret"
317 return 1
318 fi
320 git_fsck "$testroot" "$testroot/repo-clone"
321 ret=$?
322 test_done "$testroot" "$ret"
325 test_send_delete() {
326 local testroot=`test_init send_delete`
327 local testurl=ssh://127.0.0.1/$testroot
328 local commit_id=`git_show_head $testroot/repo`
330 # branch1 exists in both repositories
331 got branch -r $testroot/repo branch1
333 got clone -a -q $testurl/repo $testroot/repo-clone
334 ret=$?
335 if [ $ret -ne 0 ]; then
336 echo "got clone command failed unexpectedly" >&2
337 test_done "$testroot" "$ret"
338 return 1
339 fi
340 cat > $testroot/repo/.git/got.conf <<EOF
341 remote "origin" {
342 protocol ssh
343 server 127.0.0.1
344 repository "$testroot/repo-clone"
346 EOF
347 # branch2 exists only in the remote repository
348 got branch -r $testroot/repo-clone branch2
350 got ref -l -r $testroot/repo-clone > $testroot/stdout
351 ret=$?
352 if [ $ret -ne 0 ]; then
353 echo "got ref command failed unexpectedly" >&2
354 test_done "$testroot" "$ret"
355 return 1
356 fi
358 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
359 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
360 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
361 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
363 # Sending changes for a branch and deleting it at the same
364 # time is not allowed.
365 got send -q -r $testroot/repo -d branch1 -b branch1 \
366 > $testroot/stdout 2> $testroot/stderr
367 ret=$?
368 if [ $ret -eq 0 ]; then
369 echo "got send command succeeded unexpectedly" >&2
370 test_done "$testroot" 1
371 return 1
372 fi
373 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
374 > $testroot/stderr.expected
375 echo ": reference cannot be deleted" >> $testroot/stderr.expected
376 cmp -s $testroot/stderr $testroot/stderr.expected
377 ret=$?
378 if [ $ret -ne 0 ]; then
379 diff -u $testroot/stderr.expected $testroot/stderr
380 test_done "$testroot" "$ret"
381 return 1
382 fi
384 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
385 > $testroot/stdout 2> $testroot/stderr
386 ret=$?
387 if [ $ret -ne 0 ]; then
388 echo "got send command failed unexpectedly" >&2
389 test_done "$testroot" "$ret"
390 return 1
391 fi
393 got send -r $testroot/repo -d refs/heads/branch2 origin \
394 > $testroot/stdout 2>$testroot/stderr
395 ret=$?
396 if [ $ret -ne 0 ]; then
397 echo "got send command failed unexpectedly" >&2
398 test_done "$testroot" "$ret"
399 return 1
400 fi
402 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo-clone" \
403 > $testroot/stdout.expected
404 echo "Server has deleted refs/heads/branch2" \
405 >> $testroot/stdout.expected
407 cmp -s $testroot/stdout $testroot/stdout.expected
408 ret=$?
409 if [ $ret -ne 0 ]; then
410 diff -u $testroot/stdout.expected $testroot/stdout
411 test_done "$testroot" "$ret"
412 return 1
413 fi
415 # branchX exists in neither repository
416 got send -q -r $testroot/repo -d refs/heads/branchX origin \
417 > $testroot/stdout 2> $testroot/stderr
418 ret=$?
419 if [ $ret -eq 0 ]; then
420 echo "got send command succeeded unexpectedly" >&2
421 test_done "$testroot" 1
422 return 1
423 fi
424 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
425 > $testroot/stderr.expected
426 echo "repository: no such reference found" >> $testroot/stderr.expected
427 echo "got: no such reference found" >> $testroot/stderr.expected
428 cmp -s $testroot/stderr $testroot/stderr.expected
429 ret=$?
430 if [ $ret -ne 0 ]; then
431 diff -u $testroot/stderr.expected $testroot/stderr
432 test_done "$testroot" "$ret"
433 return 1
434 fi
436 # References outside of refs/heads/ cannot be deleted with 'got send'.
437 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
438 > $testroot/stdout 2> $testroot/stderr
439 ret=$?
440 if [ $ret -eq 0 ]; then
441 echo "got send command succeeded unexpectedly" >&2
442 test_done "$testroot" 1
443 return 1
444 fi
445 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
446 > $testroot/stderr.expected
447 echo "in remote repository: no such reference found" \
448 >> $testroot/stderr.expected
449 echo "got: no such reference found" >> $testroot/stderr.expected
450 cmp -s $testroot/stderr $testroot/stderr.expected
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/stderr.expected $testroot/stderr
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 got ref -l -r $testroot/repo > $testroot/stdout
459 ret=$?
460 if [ $ret -ne 0 ]; then
461 echo "got ref command failed unexpectedly" >&2
462 test_done "$testroot" "$ret"
463 return 1
464 fi
466 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
467 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
468 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
470 cmp -s $testroot/stdout $testroot/stdout.expected
471 ret=$?
472 if [ $ret -ne 0 ]; then
473 diff -u $testroot/stdout.expected $testroot/stdout
474 test_done "$testroot" "$ret"
475 return 1
476 fi
478 got ref -l -r $testroot/repo-clone > $testroot/stdout
479 ret=$?
480 if [ $ret -ne 0 ]; then
481 echo "got ref command failed unexpectedly" >&2
482 test_done "$testroot" "$ret"
483 return 1
484 fi
486 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
487 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
488 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
489 >> $testroot/stdout.expected
490 echo "refs/remotes/origin/branch1: $commit_id" \
491 >> $testroot/stdout.expected
492 echo "refs/remotes/origin/master: $commit_id" \
493 >> $testroot/stdout.expected
495 cmp -s $testroot/stdout $testroot/stdout.expected
496 ret=$?
497 if [ $ret -ne 0 ]; then
498 diff -u $testroot/stdout.expected $testroot/stdout
499 test_done "$testroot" "$ret"
500 return 1
501 fi
503 git_fsck "$testroot" "$testroot/repo-clone"
504 ret=$?
505 test_done "$testroot" "$ret"
508 test_send_clone_and_send() {
509 local testroot=`test_init send_clone_and_send`
510 local testurl=ssh://127.0.0.1/$testroot
511 local commit_id=`git_show_head $testroot/repo`
513 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
515 got clone -q $testurl/repo $testroot/repo-clone
516 ret=$?
517 if [ $ret -ne 0 ]; then
518 echo "got clone command failed unexpectedly" >&2
519 test_done "$testroot" "$ret"
520 return 1
521 fi
523 got checkout $testroot/repo-clone $testroot/wt >/dev/null
524 echo "modified alpha" > $testroot/wt/alpha
525 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
526 local commit_id2=`git_show_head $testroot/repo-clone`
528 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
529 ret=$?
530 if [ $ret -ne 0 ]; then
531 echo "got send command failed unexpectedly" >&2
532 test_done "$testroot" "$ret"
533 return 1
534 fi
536 echo -n > $testroot/stdout.expected
537 cmp -s $testroot/stdout $testroot/stdout.expected
538 ret=$?
539 if [ $ret -ne 0 ]; then
540 diff -u $testroot/stdout.expected $testroot/stdout
541 test_done "$testroot" "$ret"
542 return 1
543 fi
545 got ref -l -r $testroot/repo > $testroot/stdout
546 ret=$?
547 if [ $ret -ne 0 ]; then
548 echo "got ref command failed unexpectedly" >&2
549 test_done "$testroot" "$ret"
550 return 1
551 fi
553 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
554 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
556 cmp -s $testroot/stdout $testroot/stdout.expected
557 ret=$?
558 if [ $ret -ne 0 ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
561 return 1
562 fi
564 got ref -l -r $testroot/repo-clone > $testroot/stdout
565 ret=$?
566 if [ $ret -ne 0 ]; then
567 echo "got ref command failed unexpectedly" >&2
568 test_done "$testroot" "$ret"
569 return 1
570 fi
572 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
573 cut -d ':' -f 2 | tr -d ' ')`
574 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
575 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
576 >> $testroot/stdout.expected
577 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
578 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
579 >> $testroot/stdout.expected
580 echo "refs/remotes/origin/master: $commit_id2" \
581 >> $testroot/stdout.expected
583 cmp -s $testroot/stdout $testroot/stdout.expected
584 ret=$?
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
588 return 1
589 fi
591 git_fsck "$testroot" "$testroot/repo-clone"
592 ret=$?
593 test_done "$testroot" "$ret"
596 test_send_tags() {
597 local testroot=`test_init send_tags`
598 local testurl=ssh://127.0.0.1/$testroot
599 local commit_id=`git_show_head $testroot/repo`
601 got clone -q $testurl/repo $testroot/repo-clone
602 ret=$?
603 if [ $ret -ne 0 ]; then
604 echo "got clone command failed unexpectedly" >&2
605 test_done "$testroot" "$ret"
606 return 1
607 fi
608 cat > $testroot/repo/.git/got.conf <<EOF
609 remote "origin" {
610 protocol ssh
611 server 127.0.0.1
612 repository "$testroot/repo-clone"
614 EOF
615 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
616 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
617 | tr -d ' ' | cut -d: -f2`
619 echo "modified alpha" > $testroot/repo/alpha
620 git_commit $testroot/repo -m "modified alpha"
621 local commit_id2=`git_show_head $testroot/repo`
623 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
624 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
625 | tr -d ' ' | cut -d: -f2`
627 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
628 ret=$?
629 if [ $ret -ne 0 ]; then
630 echo "got send command failed unexpectedly" >&2
631 test_done "$testroot" "$ret"
632 return 1
633 fi
635 echo -n > $testroot/stdout.expected
636 cmp -s $testroot/stdout $testroot/stdout.expected
637 ret=$?
638 if [ $ret -ne 0 ]; then
639 diff -u $testroot/stdout.expected $testroot/stdout
640 test_done "$testroot" "$ret"
641 return 1
642 fi
644 got ref -l -r $testroot/repo > $testroot/stdout
645 ret=$?
646 if [ $ret -ne 0 ]; then
647 echo "got ref command failed unexpectedly" >&2
648 test_done "$testroot" "$ret"
649 return 1
650 fi
652 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
653 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
654 echo "refs/remotes/origin/master: $commit_id2" \
655 >> $testroot/stdout.expected
656 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
657 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
659 cmp -s $testroot/stdout $testroot/stdout.expected
660 ret=$?
661 if [ $ret -ne 0 ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
663 test_done "$testroot" "$ret"
664 return 1
665 fi
667 got ref -l -r $testroot/repo-clone > $testroot/stdout
668 ret=$?
669 if [ $ret -ne 0 ]; then
670 echo "got ref command failed unexpectedly" >&2
671 test_done "$testroot" "$ret"
672 return 1
673 fi
675 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
676 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
677 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
678 >> $testroot/stdout.expected
679 echo "refs/remotes/origin/master: $commit_id" \
680 >> $testroot/stdout.expected
681 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
682 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
684 cmp -s $testroot/stdout $testroot/stdout.expected
685 ret=$?
686 if [ $ret -ne 0 ]; then
687 diff -u $testroot/stdout.expected $testroot/stdout
688 test_done "$testroot" "$ret"
689 return 1
690 fi
692 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
693 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
694 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
695 cmp -s $testroot/stdout $testroot/stdout.expected
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 test_done "$testroot" "$ret"
700 return 1
701 fi
703 # Send the same tags again. This should be a no-op.
704 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
705 ret=$?
706 if [ $ret -ne 0 ]; then
707 echo "got send command failed unexpectedly" >&2
708 test_done "$testroot" "$ret"
709 return 1
710 fi
712 echo -n > $testroot/stdout.expected
713 cmp -s $testroot/stdout $testroot/stdout.expected
714 ret=$?
715 if [ $ret -ne 0 ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 # Overwriting an existing tag 'got send -f'.
722 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
723 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
724 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
725 | tr -d ' ' | cut -d: -f2`
727 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
728 2> $testroot/stderr
729 ret=$?
730 if [ $ret -eq 0 ]; then
731 echo "got send command succeeded unexpectedly" >&2
732 test_done "$testroot" 1
733 return 1
734 fi
736 echo "got: refs/tags/1.0: tag already exists on server" \
737 > $testroot/stderr.expected
738 cmp -s $testroot/stderr $testroot/stderr.expected
739 ret=$?
740 if [ $ret -ne 0 ]; then
741 diff -u $testroot/stderr.expected $testroot/stderr
742 test_done "$testroot" "$ret"
743 return 1
744 fi
746 # attempting the same with -T should fail, too
747 got send -q -r $testroot/repo -T > $testroot/stdout \
748 2> $testroot/stderr
749 ret=$?
750 if [ $ret -eq 0 ]; then
751 echo "got send command succeeded unexpectedly" >&2
752 test_done "$testroot" 1
753 return 1
754 fi
756 echo "got: refs/tags/1.0: tag already exists on server" \
757 > $testroot/stderr.expected
758 cmp -s $testroot/stderr $testroot/stderr.expected
759 ret=$?
760 if [ $ret -ne 0 ]; then
761 diff -u $testroot/stderr.expected $testroot/stderr
762 test_done "$testroot" "$ret"
763 return 1
764 fi
766 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
767 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
768 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
769 cmp -s $testroot/stdout $testroot/stdout.expected
770 ret=$?
771 if [ $ret -ne 0 ]; then
772 diff -u $testroot/stdout.expected $testroot/stdout
773 test_done "$testroot" "$ret"
774 return 1
775 fi
777 # overwrite the 1.0 tag only
778 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
779 2> $testroot/stderr
780 ret=$?
781 if [ $ret -ne 0 ]; then
782 echo "got send command failed unexpectedly" >&2
783 test_done "$testroot" "$ret"
784 return 1
785 fi
787 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
788 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
789 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
790 cmp -s $testroot/stdout $testroot/stdout.expected
791 ret=$?
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/stdout.expected $testroot/stdout
794 test_done "$testroot" "$ret"
795 return 1
796 fi
798 got checkout $testroot/repo $testroot/wt > /dev/null
799 echo 'new line in file alpha' >> $testroot/wt/alpha
800 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
802 # Send the new commit in isolation.
803 got send -q -r $testroot/repo > $testroot/stdout \
804 2> $testroot/stderr
805 ret=$?
806 if [ $ret -ne 0 ]; then
807 echo "got send command failed unexpectedly" >&2
808 test_done "$testroot" "$ret"
809 return 1
810 fi
812 # Now tag it and send the tag.
813 # Verify that just the new tag object gets sent.
814 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
815 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
816 | tr -d ' ' | cut -d: -f2`
818 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
819 2> $testroot/stderr
820 ret=$?
821 if [ $ret -ne 0 ]; then
822 echo "got send command failed unexpectedly" >&2
823 test_done "$testroot" "$ret"
824 return 1
825 fi
826 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
827 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
828 $testroot/stdout; then
829 echo "got send did apparently pack too many objects:" >&2
830 cat $testroot/stdout.raw >&2
831 test_done "$testroot" "1"
832 return 1
833 fi
835 git_fsck "$testroot" "$testroot/repo-clone"
836 ret=$?
837 test_done "$testroot" "$ret"
840 test_send_tag_of_deleted_branch() {
841 local testroot=`test_init send_tag_of_deleted_branch`
842 local testurl=ssh://127.0.0.1/$testroot
843 local commit_id=`git_show_head $testroot/repo`
845 got clone -q $testurl/repo $testroot/repo-clone
846 ret=$?
847 if [ $ret -ne 0 ]; then
848 echo "got clone command failed unexpectedly" >&2
849 test_done "$testroot" "$ret"
850 return 1
851 fi
852 cat > $testroot/repo/.git/got.conf <<EOF
853 remote "origin" {
854 protocol ssh
855 server 127.0.0.1
856 repository "$testroot/repo-clone"
858 EOF
859 got branch -r $testroot/repo foo
861 # modify beta on branch foo
862 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
863 echo boo >> $testroot/wt/beta
864 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
865 > /dev/null)
866 echo buu >> $testroot/wt/beta
867 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
868 > /dev/null)
869 echo baa >> $testroot/wt/beta
870 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
871 > /dev/null)
872 local commit_id2=`git_show_branch_head $testroot/repo foo`
874 # tag HEAD commit of branch foo
875 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
876 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
877 | tr -d ' ' | cut -d: -f2`
879 # delete the branch; commit is now only reachable via tags/1.0
880 got branch -r $testroot/repo -d foo > /dev/null
882 # unrelated change on master branch, then try sending this branch
883 # and the tag
884 echo "modified alpha" > $testroot/repo/alpha
885 git_commit $testroot/repo -m "modified alpha"
886 local commit_id3=`git_show_head $testroot/repo`
888 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
889 ret=$?
890 if [ $ret -ne 0 ]; then
891 echo "got send command failed unexpectedly" >&2
892 test_done "$testroot" "$ret"
893 return 1
894 fi
896 echo -n > $testroot/stdout.expected
897 cmp -s $testroot/stdout $testroot/stdout.expected
898 ret=$?
899 if [ $ret -ne 0 ]; then
900 diff -u $testroot/stdout.expected $testroot/stdout
901 test_done "$testroot" "$ret"
902 return 1
903 fi
905 got ref -l -r $testroot/repo > $testroot/stdout
906 ret=$?
907 if [ $ret -ne 0 ]; then
908 echo "got ref command failed unexpectedly" >&2
909 test_done "$testroot" "$ret"
910 return 1
911 fi
913 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
914 cut -d ':' -f 2 | tr -d ' ')`
915 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
916 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
917 >> $testroot/stdout.expected
918 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
919 echo "refs/remotes/origin/master: $commit_id3" \
920 >> $testroot/stdout.expected
921 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
923 cmp -s $testroot/stdout $testroot/stdout.expected
924 ret=$?
925 if [ $ret -ne 0 ]; then
926 diff -u $testroot/stdout.expected $testroot/stdout
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 got ref -l -r $testroot/repo-clone > $testroot/stdout
932 ret=$?
933 if [ $ret -ne 0 ]; then
934 echo "got ref command failed unexpectedly" >&2
935 test_done "$testroot" "$ret"
936 return 1
937 fi
939 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
940 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
941 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
942 >> $testroot/stdout.expected
943 echo "refs/remotes/origin/master: $commit_id" \
944 >> $testroot/stdout.expected
945 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
947 cmp -s $testroot/stdout $testroot/stdout.expected
948 ret=$?
949 if [ $ret -ne 0 ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 test_done "$testroot" "$ret"
952 return 1
953 fi
955 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
956 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
958 cmp -s $testroot/stdout $testroot/stdout.expected
959 ret=$?
960 if [ $ret -ne 0 ]; then
961 diff -u $testroot/stdout.expected $testroot/stdout
962 test_done "$testroot" "$ret"
963 return 1
964 fi
966 git_fsck "$testroot" "$testroot/repo-clone"
967 ret=$?
968 test_done "$testroot" "$ret"
971 test_send_new_branch() {
972 local testroot=`test_init send_new_branch`
973 local testurl=ssh://127.0.0.1/$testroot
974 local commit_id=`git_show_head $testroot/repo`
976 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
978 got clone -q $testurl/repo $testroot/repo-clone
979 ret=$?
980 if [ $ret -ne 0 ]; then
981 echo "got clone command failed unexpectedly" >&2
982 test_done "$testroot" "$ret"
983 return 1
984 fi
986 got branch -r $testroot/repo-clone foo >/dev/null
987 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
988 echo "modified alpha" > $testroot/wt/alpha
989 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
990 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
992 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
993 ret=$?
994 if [ $ret -ne 0 ]; then
995 echo "got send command failed unexpectedly" >&2
996 test_done "$testroot" "$ret"
997 return 1
998 fi
1000 echo -n > $testroot/stdout.expected
1001 cmp -s $testroot/stdout $testroot/stdout.expected
1002 ret=$?
1003 if [ $ret -ne 0 ]; then
1004 diff -u $testroot/stdout.expected $testroot/stdout
1005 test_done "$testroot" "$ret"
1006 return 1
1009 got ref -l -r $testroot/repo > $testroot/stdout
1010 ret=$?
1011 if [ $ret -ne 0 ]; then
1012 echo "got ref command failed unexpectedly" >&2
1013 test_done "$testroot" "$ret"
1014 return 1
1017 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1018 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1019 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1021 cmp -s $testroot/stdout $testroot/stdout.expected
1022 ret=$?
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1025 test_done "$testroot" "$ret"
1026 return 1
1029 got ref -l -r $testroot/repo-clone > $testroot/stdout
1030 ret=$?
1031 if [ $ret -ne 0 ]; then
1032 echo "got ref command failed unexpectedly" >&2
1033 test_done "$testroot" "$ret"
1034 return 1
1037 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1038 cut -d ':' -f 2 | tr -d ' ')`
1039 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1040 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1041 >> $testroot/stdout.expected
1042 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1043 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1044 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1045 >> $testroot/stdout.expected
1046 echo "refs/remotes/origin/foo: $commit_id2" \
1047 >> $testroot/stdout.expected
1048 echo "refs/remotes/origin/master: $commit_id" \
1049 >> $testroot/stdout.expected
1051 cmp -s $testroot/stdout $testroot/stdout.expected
1052 ret=$?
1053 if [ $ret -ne 0 ]; then
1054 diff -u $testroot/stdout.expected $testroot/stdout
1055 test_done "$testroot" "$ret"
1056 return 1
1059 git_fsck "$testroot" "$testroot/repo-clone"
1060 ret=$?
1061 test_done "$testroot" "$ret"
1064 test_send_all_branches() {
1065 local testroot=`test_init send_all_branches`
1066 local testurl=ssh://127.0.0.1/$testroot
1067 local commit_id=`git_show_head $testroot/repo`
1069 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1071 got clone -q $testurl/repo $testroot/repo-clone
1072 ret=$?
1073 if [ $ret -ne 0 ]; then
1074 echo "got clone command failed unexpectedly" >&2
1075 test_done "$testroot" "$ret"
1076 return 1
1079 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1080 echo "modified alpha" > $testroot/wt/alpha
1081 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1082 local commit_id2=`git_show_head $testroot/repo-clone`
1084 got branch -r $testroot/repo-clone foo >/dev/null
1085 (cd $testroot/wt && got update -b foo >/dev/null)
1086 echo "modified beta on new branch foo" > $testroot/wt/beta
1087 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1088 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1090 got branch -r $testroot/repo-clone bar >/dev/null
1091 (cd $testroot/wt && got update -b bar >/dev/null)
1092 echo "modified beta again on new branch bar" > $testroot/wt/beta
1093 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1094 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1096 got ref -l -r $testroot/repo-clone > $testroot/stdout
1097 ret=$?
1098 if [ $ret -ne 0 ]; then
1099 echo "got ref command failed unexpectedly" >&2
1100 test_done "$testroot" "$ret"
1101 return 1
1104 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1105 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1106 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1107 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1109 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1110 2> $testroot/stderr
1111 ret=$?
1112 if [ $ret -eq 0 ]; then
1113 echo "got send command succeeded unexpectedly" >&2
1114 test_done "$testroot" 1
1115 return 1
1117 echo "got: -a and -b options are mutually exclusive" \
1118 > $testroot/stderr.expected
1119 cmp -s $testroot/stderr $testroot/stderr.expected
1120 ret=$?
1121 if [ $ret -ne 0 ]; then
1122 diff -u $testroot/stderr.expected $testroot/stderr
1123 test_done "$testroot" "$ret"
1124 return 1
1127 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1128 2> $testroot/stderr
1129 ret=$?
1130 if [ $ret -ne 0 ]; then
1131 echo "got send command failed unexpectedly" >&2
1132 test_done "$testroot" "$ret"
1133 return 1
1136 echo -n > $testroot/stdout.expected
1137 cmp -s $testroot/stdout $testroot/stdout.expected
1138 ret=$?
1139 if [ $ret -ne 0 ]; then
1140 diff -u $testroot/stdout.expected $testroot/stdout
1141 test_done "$testroot" "$ret"
1142 return 1
1145 got ref -l -r $testroot/repo > $testroot/stdout
1146 ret=$?
1147 if [ $ret -ne 0 ]; then
1148 echo "got ref command failed unexpectedly" >&2
1149 test_done "$testroot" "$ret"
1150 return 1
1153 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1154 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1155 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1156 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1158 cmp -s $testroot/stdout $testroot/stdout.expected
1159 ret=$?
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/stdout.expected $testroot/stdout
1162 test_done "$testroot" "$ret"
1163 return 1
1166 got ref -l -r $testroot/repo-clone > $testroot/stdout
1167 ret=$?
1168 if [ $ret -ne 0 ]; then
1169 echo "got ref command failed unexpectedly" >&2
1170 test_done "$testroot" "$ret"
1171 return 1
1174 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1175 cut -d ':' -f 2 | tr -d ' ')`
1176 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1177 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1178 >> $testroot/stdout.expected
1179 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1180 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1181 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1182 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1183 >> $testroot/stdout.expected
1184 echo "refs/remotes/origin/bar: $commit_id4" \
1185 >> $testroot/stdout.expected
1186 echo "refs/remotes/origin/foo: $commit_id3" \
1187 >> $testroot/stdout.expected
1188 echo "refs/remotes/origin/master: $commit_id2" \
1189 >> $testroot/stdout.expected
1191 cmp -s $testroot/stdout $testroot/stdout.expected
1192 ret=$?
1193 if [ $ret -ne 0 ]; then
1194 diff -u $testroot/stdout.expected $testroot/stdout
1195 test_done "$testroot" "$ret"
1196 return 1
1199 git_fsck "$testroot" "$testroot/repo-clone"
1200 ret=$?
1201 test_done "$testroot" "$ret"
1204 test_send_to_empty_repo() {
1205 local testroot=`test_init send_to_empty_repo`
1206 local testurl=ssh://127.0.0.1/$testroot
1207 local commit_id=`git_show_head $testroot/repo`
1209 gotadmin init $testroot/repo2
1211 ret=$?
1212 if [ $ret -ne 0 ]; then
1213 echo "got clone command failed unexpectedly" >&2
1214 test_done "$testroot" "$ret"
1215 return 1
1217 cat > $testroot/repo/.git/got.conf <<EOF
1218 remote "origin" {
1219 protocol ssh
1220 server 127.0.0.1
1221 repository "$testroot/repo2"
1223 EOF
1224 echo "modified alpha" > $testroot/repo/alpha
1225 git_commit $testroot/repo -m "modified alpha"
1226 local commit_id2=`git_show_head $testroot/repo`
1228 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1229 ret=$?
1230 if [ $ret -ne 0 ]; then
1231 echo "got send command failed unexpectedly" >&2
1232 test_done "$testroot" "$ret"
1233 return 1
1236 echo -n > $testroot/stdout.expected
1237 cmp -s $testroot/stdout $testroot/stdout.expected
1238 ret=$?
1239 if [ $ret -ne 0 ]; then
1240 diff -u $testroot/stdout.expected $testroot/stdout
1241 test_done "$testroot" "$ret"
1242 return 1
1245 # XXX Workaround: We cannot give the target for HEAD to 'gotadmin init'
1246 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1248 got ref -l -r $testroot/repo > $testroot/stdout
1249 ret=$?
1250 if [ $ret -ne 0 ]; then
1251 echo "got ref command failed unexpectedly" >&2
1252 test_done "$testroot" "$ret"
1253 return 1
1256 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1257 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1258 echo "refs/remotes/origin/master: $commit_id2" \
1259 >> $testroot/stdout.expected
1261 cmp -s $testroot/stdout $testroot/stdout.expected
1262 ret=$?
1263 if [ $ret -ne 0 ]; then
1264 diff -u $testroot/stdout.expected $testroot/stdout
1265 test_done "$testroot" "$ret"
1266 return 1
1269 got ref -l -r $testroot/repo2 > $testroot/stdout
1270 ret=$?
1271 if [ $ret -ne 0 ]; then
1272 echo "got ref command failed unexpectedly" >&2
1273 test_done "$testroot" "$ret"
1274 return 1
1277 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1278 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1280 cmp -s $testroot/stdout $testroot/stdout.expected
1281 ret=$?
1282 if [ $ret -ne 0 ]; then
1283 diff -u $testroot/stdout.expected $testroot/stdout
1284 test_done "$testroot" "$ret"
1285 return 1
1288 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1289 ret=$?
1290 if [ $ret -ne 0 ]; then
1291 echo "got send command failed unexpectedly" >&2
1292 test_done "$testroot" "$ret"
1293 return 1
1296 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo2" \
1297 > $testroot/stdout.expected
1298 echo "Already up-to-date" >> $testroot/stdout.expected
1299 cmp -s $testroot/stdout $testroot/stdout.expected
1300 ret=$?
1301 if [ $ret -ne 0 ]; then
1302 diff -u $testroot/stdout.expected $testroot/stdout
1303 test_done "$testroot" "$ret"
1304 return 1
1307 git_fsck "$testroot" "$testroot/repo2"
1308 ret=$?
1309 test_done "$testroot" "$ret"
1312 test_send_and_fetch_config() {
1313 local testroot=`test_init send_fetch_conf`
1314 local testurl=ssh://127.0.0.1/$testroot
1315 local commit_id=`git_show_head $testroot/repo`
1317 got clone -q $testurl/repo $testroot/repo-clone
1318 ret=$?
1319 if [ $ret -ne 0 ]; then
1320 echo "got clone command failed unexpectedly" >&2
1321 test_done "$testroot" "$ret"
1322 return 1
1325 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1326 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1327 | tr -d ' ' | cut -d: -f2`
1329 cp -R $testroot/repo-clone $testroot/repo-clone2
1330 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1331 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1332 | tr -d ' ' | cut -d: -f2`
1334 cat > $testroot/repo/.git/got.conf <<EOF
1335 remote "origin" {
1336 protocol ssh
1337 server 127.0.0.1
1338 send {
1339 repository "$testroot/repo-clone"
1341 fetch {
1342 repository "$testroot/repo-clone2"
1345 EOF
1346 got ref -l -r $testroot/repo > $testroot/stdout
1347 ret=$?
1348 if [ $ret -ne 0 ]; then
1349 echo "got ref command failed unexpectedly" >&2
1350 test_done "$testroot" "$ret"
1351 return 1
1354 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1355 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1356 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1357 cmp -s $testroot/stdout $testroot/stdout.expected
1358 ret=$?
1359 if [ $ret -ne 0 ]; then
1360 diff -u $testroot/stdout.expected $testroot/stdout
1361 test_done "$testroot" "$ret"
1362 return 1
1365 # fetch tag 2.0 from repo-clone2
1366 got fetch -q -r $testroot/repo > $testroot/stdout
1367 ret=$?
1368 if [ $ret -ne 0 ]; then
1369 echo "got fetch command failed unexpectedly" >&2
1370 test_done "$testroot" "$ret"
1371 return 1
1374 got ref -l -r $testroot/repo > $testroot/stdout
1375 ret=$?
1376 if [ $ret -ne 0 ]; then
1377 echo "got ref command failed unexpectedly" >&2
1378 test_done "$testroot" "$ret"
1379 return 1
1382 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1383 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1384 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1385 >> $testroot/stdout.expected
1386 echo "refs/remotes/origin/master: $commit_id" \
1387 >> $testroot/stdout.expected
1388 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1389 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1390 cmp -s $testroot/stdout $testroot/stdout.expected
1391 ret=$?
1392 if [ $ret -ne 0 ]; then
1393 diff -u $testroot/stdout.expected $testroot/stdout
1394 test_done "$testroot" "$ret"
1395 return 1
1398 # send tag 1.0 to repo-clone
1399 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1400 ret=$?
1401 if [ $ret -ne 0 ]; then
1402 echo "got send command failed unexpectedly" >&2
1403 test_done "$testroot" "$ret"
1404 return 1
1407 got ref -l -r $testroot/repo-clone > $testroot/stdout
1408 ret=$?
1409 if [ $ret -ne 0 ]; then
1410 echo "got ref command failed unexpectedly" >&2
1411 test_done "$testroot" "$ret"
1412 return 1
1415 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1416 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1417 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1418 >> $testroot/stdout.expected
1419 echo "refs/remotes/origin/master: $commit_id" \
1420 >> $testroot/stdout.expected
1421 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1423 cmp -s $testroot/stdout $testroot/stdout.expected
1424 ret=$?
1425 if [ $ret -ne 0 ]; then
1426 diff -u $testroot/stdout.expected $testroot/stdout
1427 test_done "$testroot" "$ret"
1428 return 1
1431 git_fsck "$testroot" "$testroot/repo-clone"
1432 ret=$?
1433 test_done "$testroot" "$ret"
1436 test_send_config() {
1437 local testroot=`test_init send_fetch_conf`
1438 local testurl=ssh://127.0.0.1/$testroot
1439 local commit_id=`git_show_head $testroot/repo`
1441 got clone -q $testurl/repo $testroot/repo-clone
1442 ret=$?
1443 if [ $ret -ne 0 ]; then
1444 echo "got clone command failed unexpectedly" >&2
1445 test_done "$testroot" "$ret"
1446 return 1
1449 cat > $testroot/repo/.git/got.conf <<EOF
1450 remote "origin" {
1451 protocol ssh
1452 server 127.0.0.1
1453 branch foo
1454 repository "$testroot/repo-clone"
1456 EOF
1457 got ref -l -r $testroot/repo-clone > $testroot/stdout
1458 ret=$?
1459 if [ $ret -ne 0 ]; then
1460 echo "got ref command failed unexpectedly" >&2
1461 test_done "$testroot" "$ret"
1462 return 1
1465 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1466 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1467 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1468 >> $testroot/stdout.expected
1469 echo "refs/remotes/origin/master: $commit_id" \
1470 >> $testroot/stdout.expected
1472 cmp -s $testroot/stdout $testroot/stdout.expected
1473 ret=$?
1474 if [ $ret -ne 0 ]; then
1475 diff -u $testroot/stdout.expected $testroot/stdout
1476 test_done "$testroot" "$ret"
1477 return 1
1480 got branch -r $testroot/repo foo
1482 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1483 ret=$?
1484 if [ $ret -ne 0 ]; then
1485 echo "got send command failed unexpectedly" >&2
1486 test_done "$testroot" "$ret"
1487 return 1
1490 got ref -l -r $testroot/repo-clone > $testroot/stdout
1491 ret=$?
1492 if [ $ret -ne 0 ]; then
1493 echo "got ref command failed unexpectedly" >&2
1494 test_done "$testroot" "$ret"
1495 return 1
1498 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1499 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1500 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1501 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1502 >> $testroot/stdout.expected
1503 echo "refs/remotes/origin/master: $commit_id" \
1504 >> $testroot/stdout.expected
1506 cmp -s $testroot/stdout $testroot/stdout.expected
1507 ret=$?
1508 if [ $ret -ne 0 ]; then
1509 diff -u $testroot/stdout.expected $testroot/stdout
1510 test_done "$testroot" "$ret"
1511 return 1
1514 git_fsck "$testroot" "$testroot/repo-clone"
1515 ret=$?
1516 test_done "$testroot" "$ret"
1519 test_send_rejected() {
1520 local testroot=`test_init send_rejected`
1521 local testurl=ssh://127.0.0.1/$testroot
1522 local commit_id=`git_show_head $testroot/repo`
1524 if ! got clone -q "$testurl/repo" "$testroot/repo-clone"; then
1525 echo "got clone command failed unexpectedly" >&2
1526 test_done "$testroot" 1
1527 return 1
1530 mkdir "$testroot/repo-clone/hooks"
1531 cat <<'EOF' >$testroot/repo-clone/hooks/update
1532 case "$1" in
1533 *master*)
1534 echo "rejecting push on master branch"
1535 exit 1
1537 esac
1538 exit 0
1539 EOF
1540 chmod +x "$testroot/repo-clone/hooks/update"
1542 cat > $testroot/repo/.git/got.conf <<EOF
1543 remote "origin" {
1544 protocol ssh
1545 server 127.0.0.1
1546 repository "$testroot/repo-clone"
1548 EOF
1550 echo "modified alpha" >$testroot/repo/alpha
1551 git_commit "$testroot/repo" -m "modified alpha"
1553 got send -q -r "$testroot/repo" >$testroot/stdout 2>$testroot/stderr
1554 ret=$?
1555 if [ $ret -ne 0 ]; then
1556 echo "got send command failed unexpectedly" >&2
1557 test_done "$testroot" $ret
1558 return 1
1561 touch "$testroot/stdout.expected"
1562 if ! cmp -s "$testroot/stdout.expected" "$testroot/stdout"; then
1563 diff -u "$testroot/stdout.expected" "$testroot/stdout"
1564 test_done "$testroot" 1
1565 return 1
1568 cat <<EOF >$testroot/stderr.expected
1569 rejecting push on master branch
1570 error: hook declined to update refs/heads/master
1571 EOF
1573 if ! cmp -s "$testroot/stderr.expected" "$testroot/stderr"; then
1574 diff -u "$testroot/stderr.expected" "$testroot/stderr"
1575 test_done "$testroot" 1
1576 return 1
1579 test_done "$testroot" 0
1582 test_parseargs "$@"
1583 run_test test_send_basic
1584 run_test test_send_rebase_required
1585 run_test test_send_rebase_required_overwrite
1586 run_test test_send_delete
1587 run_test test_send_clone_and_send
1588 run_test test_send_tags
1589 run_test test_send_tag_of_deleted_branch
1590 run_test test_send_new_branch
1591 run_test test_send_all_branches
1592 run_test test_send_to_empty_repo
1593 run_test test_send_and_fetch_config
1594 run_test test_send_config
1595 run_test test_send_rejected