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 git -C $testroot/repo rm -q beta
44 (cd $testroot/repo && ln -s epsilon/zeta symlink)
45 git -C $testroot/repo add symlink
46 echo "new file alpha" > $testroot/repo/new
47 git -C $testroot/repo add new
48 git_commit $testroot/repo -m "modified alpha"
49 local commit_id2=`git_show_head $testroot/repo`
51 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
52 ret=$?
53 if [ $ret -ne 0 ]; then
54 echo "got send command failed unexpectedly" >&2
55 test_done "$testroot" "$ret"
56 return 1
57 fi
59 echo -n > $testroot/stdout.expected
60 cmp -s $testroot/stdout $testroot/stdout.expected
61 ret=$?
62 if [ $ret -ne 0 ]; then
63 diff -u $testroot/stdout.expected $testroot/stdout
64 test_done "$testroot" "$ret"
65 return 1
66 fi
68 got ref -l -r $testroot/repo > $testroot/stdout
69 ret=$?
70 if [ $ret -ne 0 ]; then
71 echo "got ref command failed unexpectedly" >&2
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
77 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
78 echo "refs/remotes/origin/master: $commit_id2" \
79 >> $testroot/stdout.expected
80 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
82 cmp -s $testroot/stdout $testroot/stdout.expected
83 ret=$?
84 if [ $ret -ne 0 ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
86 test_done "$testroot" "$ret"
87 return 1
88 fi
90 got ref -l -r $testroot/repo-clone > $testroot/stdout
91 ret=$?
92 if [ $ret -ne 0 ]; then
93 echo "got ref command failed unexpectedly" >&2
94 test_done "$testroot" "$ret"
95 return 1
96 fi
98 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
99 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
100 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
101 >> $testroot/stdout.expected
102 echo "refs/remotes/origin/master: $commit_id" \
103 >> $testroot/stdout.expected
105 cmp -s $testroot/stdout $testroot/stdout.expected
106 ret=$?
107 if [ $ret -ne 0 ]; then
108 diff -u $testroot/stdout.expected $testroot/stdout
109 test_done "$testroot" "$ret"
110 return 1
111 fi
113 got tree -r $testroot/repo-clone -c $commit_id2 -i -R \
114 > $testroot/stdout
115 got tree -r $testroot/repo -c $commit_id2 -i -R \
116 > $testroot/stdout.expected
117 cmp -s $testroot/stdout $testroot/stdout.expected
118 ret=$?
119 if [ $ret -ne 0 ]; then
120 diff -u $testroot/stdout.expected $testroot/stdout
121 test_done "$testroot" "$ret"
122 return 1
123 fi
125 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
126 ret=$?
127 if [ $ret -ne 0 ]; then
128 echo "got send command failed unexpectedly" >&2
129 test_done "$testroot" "$ret"
130 return 1
131 fi
133 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo-clone" \
134 > $testroot/stdout.expected
135 echo "Already up-to-date" >> $testroot/stdout.expected
136 cmp -s $testroot/stdout $testroot/stdout.expected
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 diff -u $testroot/stdout.expected $testroot/stdout
140 test_done "$testroot" "$ret"
141 return 1
142 fi
144 git_fsck "$testroot" "$testroot/repo-clone"
145 ret=$?
146 test_done "$testroot" "$ret"
149 test_send_rebase_required() {
150 local testroot=`test_init send_rebase_required`
151 local testurl=ssh://127.0.0.1/$testroot
152 local commit_id=`git_show_head $testroot/repo`
154 got clone -q $testurl/repo $testroot/repo-clone
155 ret=$?
156 if [ $ret -ne 0 ]; then
157 echo "got clone command failed unexpectedly" >&2
158 test_done "$testroot" "$ret"
159 return 1
160 fi
161 cat > $testroot/repo/.git/got.conf <<EOF
162 remote "origin" {
163 protocol ssh
164 server 127.0.0.1
165 repository "$testroot/repo-clone"
167 EOF
168 echo "modified alpha" > $testroot/repo/alpha
169 git_commit $testroot/repo -m "modified alpha"
170 local commit_id2=`git_show_head $testroot/repo`
172 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
173 echo "modified alpha, too" > $testroot/wt-clone/alpha
174 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
176 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
177 ret=$?
178 if [ $ret -eq 0 ]; then
179 echo "got send command succeeded unexpectedly" >&2
180 test_done "$testroot" 1
181 return 1
182 fi
184 echo -n > $testroot/stdout.expected
185 cmp -s $testroot/stdout $testroot/stdout.expected
186 ret=$?
187 if [ $ret -ne 0 ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$ret"
190 return 1
191 fi
193 echo "got: refs/heads/master: fetch and rebase required" \
194 > $testroot/stderr.expected
195 cmp -s $testroot/stderr $testroot/stderr.expected
196 ret=$?
197 if [ $ret -ne 0 ]; then
198 diff -u $testroot/stderr.expected $testroot/stderr
199 test_done "$testroot" "$ret"
200 return 1
201 fi
203 git_fsck "$testroot" "$testroot/repo-clone"
204 ret=$?
205 test_done "$testroot" "$ret"
208 test_send_rebase_required_overwrite() {
209 local testroot=`test_init send_rebase_required_overwrite`
210 local testurl=ssh://127.0.0.1/$testroot
211 local commit_id=`git_show_head $testroot/repo`
213 got clone -q $testurl/repo $testroot/repo-clone
214 ret=$?
215 if [ $ret -ne 0 ]; then
216 echo "got clone command failed unexpectedly" >&2
217 test_done "$testroot" "$ret"
218 return 1
219 fi
220 cat > $testroot/repo/.git/got.conf <<EOF
221 remote "foobar" {
222 protocol ssh
223 server 127.0.0.1
224 repository "$testroot/repo-clone"
226 EOF
227 echo "modified alpha" > $testroot/repo/alpha
228 git_commit $testroot/repo -m "modified alpha"
229 local commit_id2=`git_show_head $testroot/repo`
231 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
232 echo "modified alpha, too" > $testroot/wt-clone/alpha
233 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
234 local commit_id3=`git_show_head $testroot/repo-clone`
236 # non-default remote requires an explicit argument
237 got send -q -r $testroot/repo -f > $testroot/stdout \
238 2> $testroot/stderr
239 ret=$?
240 if [ $ret -eq 0 ]; then
241 echo "got send command succeeded unexpectedly" >&2
242 test_done "$testroot" 1
243 return 1
244 fi
245 echo "got: origin: remote repository not found" \
246 > $testroot/stderr.expected
247 cmp -s $testroot/stderr $testroot/stderr.expected
248 ret=$?
249 if [ $ret -ne 0 ]; then
250 diff -u $testroot/stderr.expected $testroot/stderr
251 test_done "$testroot" "$ret"
252 return 1
253 fi
255 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
256 2> $testroot/stderr
257 ret=$?
258 if [ $ret -ne 0 ]; then
259 echo "got send command failed unexpectedly" >&2
260 test_done "$testroot" "$ret"
261 return 1
262 fi
264 echo -n > $testroot/stdout.expected
265 cmp -s $testroot/stdout $testroot/stdout.expected
266 ret=$?
267 if [ $ret -ne 0 ]; then
268 diff -u $testroot/stdout.expected $testroot/stdout
269 test_done "$testroot" "$ret"
270 return 1
271 fi
273 got ref -l -r $testroot/repo > $testroot/stdout
274 ret=$?
275 if [ $ret -ne 0 ]; then
276 echo "got ref command failed unexpectedly" >&2
277 test_done "$testroot" "$ret"
278 return 1
279 fi
281 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
282 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
283 echo "refs/remotes/foobar/master: $commit_id2" \
284 >> $testroot/stdout.expected
286 cmp -s $testroot/stdout $testroot/stdout.expected
287 ret=$?
288 if [ $ret -ne 0 ]; then
289 diff -u $testroot/stdout.expected $testroot/stdout
290 test_done "$testroot" "$ret"
291 return 1
292 fi
294 got ref -l -r $testroot/repo-clone > $testroot/stdout
295 ret=$?
296 if [ $ret -ne 0 ]; then
297 echo "got ref command failed unexpectedly" >&2
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
303 cut -d ':' -f 2 | tr -d ' ')`
304 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
305 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
306 >> $testroot/stdout.expected
307 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
308 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
309 >> $testroot/stdout.expected
310 echo "refs/remotes/origin/master: $commit_id" \
311 >> $testroot/stdout.expected
313 cmp -s $testroot/stdout $testroot/stdout.expected
314 ret=$?
315 if [ $ret -ne 0 ]; then
316 diff -u $testroot/stdout.expected $testroot/stdout
317 test_done "$testroot" "$ret"
318 return 1
319 fi
321 git_fsck "$testroot" "$testroot/repo-clone"
322 ret=$?
323 test_done "$testroot" "$ret"
326 test_send_merge_commit() {
327 local testroot=`test_init send_merge_commit`
328 local testurl=ssh://127.0.0.1/$testroot
330 if ! got clone -q "$testurl/repo" "$testroot/repo-clone"; then
331 echo "got clone command failed unexpectedly" >&2
332 test_done "$testroot" 1
333 return 1
334 fi
336 echo 'upstream change' > $testroot/repo/alpha
337 git_commit $testroot/repo -m 'upstream change'
339 got checkout $testroot/repo-clone $testroot/wt-clone > /dev/null
340 echo 'downstream change' > $testroot/wt-clone/beta
341 (cd $testroot/wt-clone && got commit -m 'downstream change' > /dev/null)
343 got fetch -q -r $testroot/repo-clone
344 (cd $testroot/wt-clone && got update > /dev/null)
345 (cd $testroot/wt-clone && got merge origin/master > /dev/null)
346 ret=$?
347 if [ $ret -ne 0 ]; then
348 echo "got merge command failed unexpectedly" >&2
349 test_done "$testroot" "$ret"
350 return 1
351 fi
353 git -C $testroot/repo config receive.denyCurrentBranch ignore
355 got send -q -r $testroot/repo-clone
356 ret=$?
357 if [ $ret -ne 0 ]; then
358 test_done "$testroot" "$ret"
359 return 1
360 fi
362 test_done "$testroot" 0
365 test_send_delete() {
366 local testroot=`test_init send_delete`
367 local testurl=ssh://127.0.0.1/$testroot
368 local commit_id=`git_show_head $testroot/repo`
370 # branch1 exists in both repositories
371 got branch -r $testroot/repo branch1
373 got clone -a -q $testurl/repo $testroot/repo-clone
374 ret=$?
375 if [ $ret -ne 0 ]; then
376 echo "got clone command failed unexpectedly" >&2
377 test_done "$testroot" "$ret"
378 return 1
379 fi
380 cat > $testroot/repo/.git/got.conf <<EOF
381 remote "origin" {
382 protocol ssh
383 server 127.0.0.1
384 repository "$testroot/repo-clone"
386 EOF
387 # branch2 exists only in the remote repository
388 got branch -r $testroot/repo-clone branch2
390 got ref -l -r $testroot/repo-clone > $testroot/stdout
391 ret=$?
392 if [ $ret -ne 0 ]; then
393 echo "got ref command failed unexpectedly" >&2
394 test_done "$testroot" "$ret"
395 return 1
396 fi
398 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
399 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
400 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
401 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
403 # Sending changes for a branch and deleting it at the same
404 # time is not allowed.
405 got send -q -r $testroot/repo -d branch1 -b branch1 \
406 > $testroot/stdout 2> $testroot/stderr
407 ret=$?
408 if [ $ret -eq 0 ]; then
409 echo "got send command succeeded unexpectedly" >&2
410 test_done "$testroot" 1
411 return 1
412 fi
413 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
414 > $testroot/stderr.expected
415 echo ": reference cannot be deleted" >> $testroot/stderr.expected
416 cmp -s $testroot/stderr $testroot/stderr.expected
417 ret=$?
418 if [ $ret -ne 0 ]; then
419 diff -u $testroot/stderr.expected $testroot/stderr
420 test_done "$testroot" "$ret"
421 return 1
422 fi
424 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
425 > $testroot/stdout 2> $testroot/stderr
426 ret=$?
427 if [ $ret -ne 0 ]; then
428 echo "got send command failed unexpectedly" >&2
429 test_done "$testroot" "$ret"
430 return 1
431 fi
433 got send -r $testroot/repo -d refs/heads/branch2 origin \
434 > $testroot/stdout 2>$testroot/stderr
435 ret=$?
436 if [ $ret -ne 0 ]; then
437 echo "got send command failed unexpectedly" >&2
438 test_done "$testroot" "$ret"
439 return 1
440 fi
442 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo-clone" \
443 > $testroot/stdout.expected
444 echo "Server has deleted refs/heads/branch2" \
445 >> $testroot/stdout.expected
447 cmp -s $testroot/stdout $testroot/stdout.expected
448 ret=$?
449 if [ $ret -ne 0 ]; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" "$ret"
452 return 1
453 fi
455 # branchX exists in neither repository
456 got send -q -r $testroot/repo -d refs/heads/branchX origin \
457 > $testroot/stdout 2> $testroot/stderr
458 ret=$?
459 if [ $ret -eq 0 ]; then
460 echo "got send command succeeded unexpectedly" >&2
461 test_done "$testroot" 1
462 return 1
463 fi
464 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
465 > $testroot/stderr.expected
466 echo "repository: no such reference found" >> $testroot/stderr.expected
467 echo "got: no such reference found" >> $testroot/stderr.expected
468 cmp -s $testroot/stderr $testroot/stderr.expected
469 ret=$?
470 if [ $ret -ne 0 ]; then
471 diff -u $testroot/stderr.expected $testroot/stderr
472 test_done "$testroot" "$ret"
473 return 1
474 fi
476 # References outside of refs/heads/ cannot be deleted with 'got send'.
477 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
478 > $testroot/stdout 2> $testroot/stderr
479 ret=$?
480 if [ $ret -eq 0 ]; then
481 echo "got send command succeeded unexpectedly" >&2
482 test_done "$testroot" 1
483 return 1
484 fi
485 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
486 > $testroot/stderr.expected
487 echo "in remote repository: no such reference found" \
488 >> $testroot/stderr.expected
489 echo "got: no such reference found" >> $testroot/stderr.expected
490 cmp -s $testroot/stderr $testroot/stderr.expected
491 ret=$?
492 if [ $ret -ne 0 ]; then
493 diff -u $testroot/stderr.expected $testroot/stderr
494 test_done "$testroot" "$ret"
495 return 1
496 fi
498 got ref -l -r $testroot/repo > $testroot/stdout
499 ret=$?
500 if [ $ret -ne 0 ]; then
501 echo "got ref command failed unexpectedly" >&2
502 test_done "$testroot" "$ret"
503 return 1
504 fi
506 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
507 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
508 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
510 cmp -s $testroot/stdout $testroot/stdout.expected
511 ret=$?
512 if [ $ret -ne 0 ]; then
513 diff -u $testroot/stdout.expected $testroot/stdout
514 test_done "$testroot" "$ret"
515 return 1
516 fi
518 got ref -l -r $testroot/repo-clone > $testroot/stdout
519 ret=$?
520 if [ $ret -ne 0 ]; then
521 echo "got ref command failed unexpectedly" >&2
522 test_done "$testroot" "$ret"
523 return 1
524 fi
526 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
527 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
528 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
529 >> $testroot/stdout.expected
530 echo "refs/remotes/origin/branch1: $commit_id" \
531 >> $testroot/stdout.expected
532 echo "refs/remotes/origin/master: $commit_id" \
533 >> $testroot/stdout.expected
535 cmp -s $testroot/stdout $testroot/stdout.expected
536 ret=$?
537 if [ $ret -ne 0 ]; then
538 diff -u $testroot/stdout.expected $testroot/stdout
539 test_done "$testroot" "$ret"
540 return 1
541 fi
543 git_fsck "$testroot" "$testroot/repo-clone"
544 ret=$?
545 test_done "$testroot" "$ret"
548 test_send_clone_and_send() {
549 local testroot=`test_init send_clone_and_send`
550 local testurl=ssh://127.0.0.1/$testroot
551 local commit_id=`git_show_head $testroot/repo`
553 git -C $testroot/repo config receive.denyCurrentBranch ignore
555 got clone -q $testurl/repo $testroot/repo-clone
556 ret=$?
557 if [ $ret -ne 0 ]; then
558 echo "got clone command failed unexpectedly" >&2
559 test_done "$testroot" "$ret"
560 return 1
561 fi
563 got checkout $testroot/repo-clone $testroot/wt >/dev/null
564 echo "modified alpha" > $testroot/wt/alpha
565 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
566 local commit_id2=`git_show_head $testroot/repo-clone`
568 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
569 ret=$?
570 if [ $ret -ne 0 ]; then
571 echo "got send command failed unexpectedly" >&2
572 test_done "$testroot" "$ret"
573 return 1
574 fi
576 echo -n > $testroot/stdout.expected
577 cmp -s $testroot/stdout $testroot/stdout.expected
578 ret=$?
579 if [ $ret -ne 0 ]; then
580 diff -u $testroot/stdout.expected $testroot/stdout
581 test_done "$testroot" "$ret"
582 return 1
583 fi
585 got ref -l -r $testroot/repo > $testroot/stdout
586 ret=$?
587 if [ $ret -ne 0 ]; then
588 echo "got ref command failed unexpectedly" >&2
589 test_done "$testroot" "$ret"
590 return 1
591 fi
593 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
594 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
596 cmp -s $testroot/stdout $testroot/stdout.expected
597 ret=$?
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
601 return 1
602 fi
604 got ref -l -r $testroot/repo-clone > $testroot/stdout
605 ret=$?
606 if [ $ret -ne 0 ]; then
607 echo "got ref command failed unexpectedly" >&2
608 test_done "$testroot" "$ret"
609 return 1
610 fi
612 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
613 cut -d ':' -f 2 | tr -d ' ')`
614 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
615 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
616 >> $testroot/stdout.expected
617 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
618 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
619 >> $testroot/stdout.expected
620 echo "refs/remotes/origin/master: $commit_id2" \
621 >> $testroot/stdout.expected
623 cmp -s $testroot/stdout $testroot/stdout.expected
624 ret=$?
625 if [ $ret -ne 0 ]; then
626 diff -u $testroot/stdout.expected $testroot/stdout
627 test_done "$testroot" "$ret"
628 return 1
629 fi
631 git_fsck "$testroot" "$testroot/repo-clone"
632 ret=$?
633 test_done "$testroot" "$ret"
636 test_send_tags() {
637 local testroot=`test_init send_tags`
638 local testurl=ssh://127.0.0.1/$testroot
639 local commit_id=`git_show_head $testroot/repo`
641 got clone -q $testurl/repo $testroot/repo-clone
642 ret=$?
643 if [ $ret -ne 0 ]; then
644 echo "got clone command failed unexpectedly" >&2
645 test_done "$testroot" "$ret"
646 return 1
647 fi
648 cat > $testroot/repo/.git/got.conf <<EOF
649 remote "origin" {
650 protocol ssh
651 server 127.0.0.1
652 repository "$testroot/repo-clone"
654 EOF
655 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
656 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
657 | tr -d ' ' | cut -d: -f2`
659 echo "modified alpha" > $testroot/repo/alpha
660 git_commit $testroot/repo -m "modified alpha"
661 local commit_id2=`git_show_head $testroot/repo`
663 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
664 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
665 | tr -d ' ' | cut -d: -f2`
667 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
668 ret=$?
669 if [ $ret -ne 0 ]; then
670 echo "got send command failed unexpectedly" >&2
671 test_done "$testroot" "$ret"
672 return 1
673 fi
675 echo -n > $testroot/stdout.expected
676 cmp -s $testroot/stdout $testroot/stdout.expected
677 ret=$?
678 if [ $ret -ne 0 ]; then
679 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 got ref -l -r $testroot/repo > $testroot/stdout
685 ret=$?
686 if [ $ret -ne 0 ]; then
687 echo "got ref command failed unexpectedly" >&2
688 test_done "$testroot" "$ret"
689 return 1
690 fi
692 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
693 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
694 echo "refs/remotes/origin/master: $commit_id2" \
695 >> $testroot/stdout.expected
696 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
697 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
699 cmp -s $testroot/stdout $testroot/stdout.expected
700 ret=$?
701 if [ $ret -ne 0 ]; then
702 diff -u $testroot/stdout.expected $testroot/stdout
703 test_done "$testroot" "$ret"
704 return 1
705 fi
707 got ref -l -r $testroot/repo-clone > $testroot/stdout
708 ret=$?
709 if [ $ret -ne 0 ]; then
710 echo "got ref command failed unexpectedly" >&2
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
716 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
717 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
718 >> $testroot/stdout.expected
719 echo "refs/remotes/origin/master: $commit_id" \
720 >> $testroot/stdout.expected
721 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
722 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
724 cmp -s $testroot/stdout $testroot/stdout.expected
725 ret=$?
726 if [ $ret -ne 0 ]; then
727 diff -u $testroot/stdout.expected $testroot/stdout
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
733 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
734 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
735 cmp -s $testroot/stdout $testroot/stdout.expected
736 ret=$?
737 if [ $ret -ne 0 ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 # Send the same tags again. This should be a no-op.
744 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
745 ret=$?
746 if [ $ret -ne 0 ]; then
747 echo "got send command failed unexpectedly" >&2
748 test_done "$testroot" "$ret"
749 return 1
750 fi
752 echo -n > $testroot/stdout.expected
753 cmp -s $testroot/stdout $testroot/stdout.expected
754 ret=$?
755 if [ $ret -ne 0 ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
758 return 1
759 fi
761 # Overwriting an existing tag 'got send -f'.
762 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
763 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
764 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
765 | tr -d ' ' | cut -d: -f2`
767 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
768 2> $testroot/stderr
769 ret=$?
770 if [ $ret -eq 0 ]; then
771 echo "got send command succeeded unexpectedly" >&2
772 test_done "$testroot" 1
773 return 1
774 fi
776 echo "got: refs/tags/1.0: tag already exists on server" \
777 > $testroot/stderr.expected
778 cmp -s $testroot/stderr $testroot/stderr.expected
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stderr.expected $testroot/stderr
782 test_done "$testroot" "$ret"
783 return 1
784 fi
786 # attempting the same with -T should fail, too
787 got send -q -r $testroot/repo -T > $testroot/stdout \
788 2> $testroot/stderr
789 ret=$?
790 if [ $ret -eq 0 ]; then
791 echo "got send command succeeded unexpectedly" >&2
792 test_done "$testroot" 1
793 return 1
794 fi
796 echo "got: refs/tags/1.0: tag already exists on server" \
797 > $testroot/stderr.expected
798 cmp -s $testroot/stderr $testroot/stderr.expected
799 ret=$?
800 if [ $ret -ne 0 ]; then
801 diff -u $testroot/stderr.expected $testroot/stderr
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
807 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
808 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
809 cmp -s $testroot/stdout $testroot/stdout.expected
810 ret=$?
811 if [ $ret -ne 0 ]; then
812 diff -u $testroot/stdout.expected $testroot/stdout
813 test_done "$testroot" "$ret"
814 return 1
815 fi
817 # overwrite the 1.0 tag only
818 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
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
827 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
828 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
829 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
830 cmp -s $testroot/stdout $testroot/stdout.expected
831 ret=$?
832 if [ $ret -ne 0 ]; then
833 diff -u $testroot/stdout.expected $testroot/stdout
834 test_done "$testroot" "$ret"
835 return 1
836 fi
838 got checkout $testroot/repo $testroot/wt > /dev/null
839 echo 'new line in file alpha' >> $testroot/wt/alpha
840 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
842 # Send the new commit in isolation.
843 got send -q -r $testroot/repo > $testroot/stdout \
844 2> $testroot/stderr
845 ret=$?
846 if [ $ret -ne 0 ]; then
847 echo "got send command failed unexpectedly" >&2
848 test_done "$testroot" "$ret"
849 return 1
850 fi
852 # Now tag it and send the tag.
853 # Verify that just the new tag object gets sent.
854 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
855 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
856 | tr -d ' ' | cut -d: -f2`
858 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
859 2> $testroot/stderr
860 ret=$?
861 if [ $ret -ne 0 ]; then
862 echo "got send command failed unexpectedly" >&2
863 test_done "$testroot" "$ret"
864 return 1
865 fi
866 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
867 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
868 $testroot/stdout; then
869 echo "got send did apparently pack too many objects:" >&2
870 cat $testroot/stdout.raw >&2
871 test_done "$testroot" "1"
872 return 1
873 fi
875 git_fsck "$testroot" "$testroot/repo-clone"
876 ret=$?
877 test_done "$testroot" "$ret"
880 test_send_tag_of_deleted_branch() {
881 local testroot=`test_init send_tag_of_deleted_branch`
882 local testurl=ssh://127.0.0.1/$testroot
883 local commit_id=`git_show_head $testroot/repo`
885 got clone -q $testurl/repo $testroot/repo-clone
886 ret=$?
887 if [ $ret -ne 0 ]; then
888 echo "got clone command failed unexpectedly" >&2
889 test_done "$testroot" "$ret"
890 return 1
891 fi
892 cat > $testroot/repo/.git/got.conf <<EOF
893 remote "origin" {
894 protocol ssh
895 server 127.0.0.1
896 repository "$testroot/repo-clone"
898 EOF
899 got branch -r $testroot/repo foo
901 # modify beta on branch foo
902 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
903 echo boo >> $testroot/wt/beta
904 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
905 > /dev/null)
906 echo buu >> $testroot/wt/beta
907 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
908 > /dev/null)
909 echo baa >> $testroot/wt/beta
910 (cd $testroot/wt && got commit -m 'changed beta again on branch foo' \
911 > /dev/null)
912 local commit_id2=`git_show_branch_head $testroot/repo foo`
914 # tag HEAD commit of branch foo
915 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
916 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
917 | tr -d ' ' | cut -d: -f2`
919 # delete the branch; commit is now only reachable via tags/1.0
920 got branch -r $testroot/repo -d foo > /dev/null
922 # unrelated change on master branch, then try sending this branch
923 # and the tag
924 echo "modified alpha" > $testroot/repo/alpha
925 git_commit $testroot/repo -m "modified alpha"
926 local commit_id3=`git_show_head $testroot/repo`
928 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
929 ret=$?
930 if [ $ret -ne 0 ]; then
931 echo "got send command failed unexpectedly" >&2
932 test_done "$testroot" "$ret"
933 return 1
934 fi
936 echo -n > $testroot/stdout.expected
937 cmp -s $testroot/stdout $testroot/stdout.expected
938 ret=$?
939 if [ $ret -ne 0 ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 got ref -l -r $testroot/repo > $testroot/stdout
946 ret=$?
947 if [ $ret -ne 0 ]; then
948 echo "got ref command failed unexpectedly" >&2
949 test_done "$testroot" "$ret"
950 return 1
951 fi
953 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
954 cut -d ':' -f 2 | tr -d ' ')`
955 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
956 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
957 >> $testroot/stdout.expected
958 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
959 echo "refs/remotes/origin/master: $commit_id3" \
960 >> $testroot/stdout.expected
961 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
963 cmp -s $testroot/stdout $testroot/stdout.expected
964 ret=$?
965 if [ $ret -ne 0 ]; then
966 diff -u $testroot/stdout.expected $testroot/stdout
967 test_done "$testroot" "$ret"
968 return 1
969 fi
971 got ref -l -r $testroot/repo-clone > $testroot/stdout
972 ret=$?
973 if [ $ret -ne 0 ]; then
974 echo "got ref command failed unexpectedly" >&2
975 test_done "$testroot" "$ret"
976 return 1
977 fi
979 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
980 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
981 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
982 >> $testroot/stdout.expected
983 echo "refs/remotes/origin/master: $commit_id" \
984 >> $testroot/stdout.expected
985 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
987 cmp -s $testroot/stdout $testroot/stdout.expected
988 ret=$?
989 if [ $ret -ne 0 ]; then
990 diff -u $testroot/stdout.expected $testroot/stdout
991 test_done "$testroot" "$ret"
992 return 1
993 fi
995 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
996 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
998 cmp -s $testroot/stdout $testroot/stdout.expected
999 ret=$?
1000 if [ $ret -ne 0 ]; then
1001 diff -u $testroot/stdout.expected $testroot/stdout
1002 test_done "$testroot" "$ret"
1003 return 1
1006 git_fsck "$testroot" "$testroot/repo-clone"
1007 ret=$?
1008 test_done "$testroot" "$ret"
1011 test_send_new_branch() {
1012 local testroot=`test_init send_new_branch`
1013 local testurl=ssh://127.0.0.1/$testroot
1014 local commit_id=`git_show_head $testroot/repo`
1016 git -C $testroot/repo config receive.denyCurrentBranch ignore
1018 got clone -q $testurl/repo $testroot/repo-clone
1019 ret=$?
1020 if [ $ret -ne 0 ]; then
1021 echo "got clone command failed unexpectedly" >&2
1022 test_done "$testroot" "$ret"
1023 return 1
1026 got branch -r $testroot/repo-clone foo >/dev/null
1027 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
1028 echo "modified alpha" > $testroot/wt/alpha
1029 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1030 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
1032 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
1033 ret=$?
1034 if [ $ret -ne 0 ]; then
1035 echo "got send command failed unexpectedly" >&2
1036 test_done "$testroot" "$ret"
1037 return 1
1040 echo -n > $testroot/stdout.expected
1041 cmp -s $testroot/stdout $testroot/stdout.expected
1042 ret=$?
1043 if [ $ret -ne 0 ]; then
1044 diff -u $testroot/stdout.expected $testroot/stdout
1045 test_done "$testroot" "$ret"
1046 return 1
1049 got ref -l -r $testroot/repo > $testroot/stdout
1050 ret=$?
1051 if [ $ret -ne 0 ]; then
1052 echo "got ref command failed unexpectedly" >&2
1053 test_done "$testroot" "$ret"
1054 return 1
1057 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1058 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1059 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1061 cmp -s $testroot/stdout $testroot/stdout.expected
1062 ret=$?
1063 if [ $ret -ne 0 ]; then
1064 diff -u $testroot/stdout.expected $testroot/stdout
1065 test_done "$testroot" "$ret"
1066 return 1
1069 got ref -l -r $testroot/repo-clone > $testroot/stdout
1070 ret=$?
1071 if [ $ret -ne 0 ]; then
1072 echo "got ref command failed unexpectedly" >&2
1073 test_done "$testroot" "$ret"
1074 return 1
1077 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1078 cut -d ':' -f 2 | tr -d ' ')`
1079 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1080 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1081 >> $testroot/stdout.expected
1082 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1083 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1084 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1085 >> $testroot/stdout.expected
1086 echo "refs/remotes/origin/foo: $commit_id2" \
1087 >> $testroot/stdout.expected
1088 echo "refs/remotes/origin/master: $commit_id" \
1089 >> $testroot/stdout.expected
1091 cmp -s $testroot/stdout $testroot/stdout.expected
1092 ret=$?
1093 if [ $ret -ne 0 ]; then
1094 diff -u $testroot/stdout.expected $testroot/stdout
1095 test_done "$testroot" "$ret"
1096 return 1
1099 git_fsck "$testroot" "$testroot/repo-clone"
1100 ret=$?
1101 test_done "$testroot" "$ret"
1104 test_send_all_branches() {
1105 local testroot=`test_init send_all_branches`
1106 local testurl=ssh://127.0.0.1/$testroot
1107 local commit_id=`git_show_head $testroot/repo`
1109 git -C $testroot/repo config receive.denyCurrentBranch ignore
1111 got clone -q $testurl/repo $testroot/repo-clone
1112 ret=$?
1113 if [ $ret -ne 0 ]; then
1114 echo "got clone command failed unexpectedly" >&2
1115 test_done "$testroot" "$ret"
1116 return 1
1119 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1120 echo "modified alpha" > $testroot/wt/alpha
1121 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1122 local commit_id2=`git_show_head $testroot/repo-clone`
1124 got branch -r $testroot/repo-clone foo >/dev/null
1125 (cd $testroot/wt && got update -b foo >/dev/null)
1126 echo "modified beta on new branch foo" > $testroot/wt/beta
1127 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1128 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1130 got branch -r $testroot/repo-clone bar >/dev/null
1131 (cd $testroot/wt && got update -b bar >/dev/null)
1132 echo "modified beta again on new branch bar" > $testroot/wt/beta
1133 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1134 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1136 got ref -l -r $testroot/repo-clone > $testroot/stdout
1137 ret=$?
1138 if [ $ret -ne 0 ]; then
1139 echo "got ref command failed unexpectedly" >&2
1140 test_done "$testroot" "$ret"
1141 return 1
1144 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1145 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1146 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1147 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1149 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1150 2> $testroot/stderr
1151 ret=$?
1152 if [ $ret -eq 0 ]; then
1153 echo "got send command succeeded unexpectedly" >&2
1154 test_done "$testroot" 1
1155 return 1
1157 echo "got: -a and -b options are mutually exclusive" \
1158 > $testroot/stderr.expected
1159 cmp -s $testroot/stderr $testroot/stderr.expected
1160 ret=$?
1161 if [ $ret -ne 0 ]; then
1162 diff -u $testroot/stderr.expected $testroot/stderr
1163 test_done "$testroot" "$ret"
1164 return 1
1167 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1168 2> $testroot/stderr
1169 ret=$?
1170 if [ $ret -ne 0 ]; then
1171 echo "got send command failed unexpectedly" >&2
1172 test_done "$testroot" "$ret"
1173 return 1
1176 echo -n > $testroot/stdout.expected
1177 cmp -s $testroot/stdout $testroot/stdout.expected
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 diff -u $testroot/stdout.expected $testroot/stdout
1181 test_done "$testroot" "$ret"
1182 return 1
1185 got ref -l -r $testroot/repo > $testroot/stdout
1186 ret=$?
1187 if [ $ret -ne 0 ]; then
1188 echo "got ref command failed unexpectedly" >&2
1189 test_done "$testroot" "$ret"
1190 return 1
1193 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1194 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1195 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1196 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1198 cmp -s $testroot/stdout $testroot/stdout.expected
1199 ret=$?
1200 if [ $ret -ne 0 ]; then
1201 diff -u $testroot/stdout.expected $testroot/stdout
1202 test_done "$testroot" "$ret"
1203 return 1
1206 got ref -l -r $testroot/repo-clone > $testroot/stdout
1207 ret=$?
1208 if [ $ret -ne 0 ]; then
1209 echo "got ref command failed unexpectedly" >&2
1210 test_done "$testroot" "$ret"
1211 return 1
1214 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1215 cut -d ':' -f 2 | tr -d ' ')`
1216 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1217 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1218 >> $testroot/stdout.expected
1219 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1220 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1221 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1222 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1223 >> $testroot/stdout.expected
1224 echo "refs/remotes/origin/bar: $commit_id4" \
1225 >> $testroot/stdout.expected
1226 echo "refs/remotes/origin/foo: $commit_id3" \
1227 >> $testroot/stdout.expected
1228 echo "refs/remotes/origin/master: $commit_id2" \
1229 >> $testroot/stdout.expected
1231 cmp -s $testroot/stdout $testroot/stdout.expected
1232 ret=$?
1233 if [ $ret -ne 0 ]; then
1234 diff -u $testroot/stdout.expected $testroot/stdout
1235 test_done "$testroot" "$ret"
1236 return 1
1239 git_fsck "$testroot" "$testroot/repo-clone"
1240 ret=$?
1241 test_done "$testroot" "$ret"
1244 test_send_to_empty_repo() {
1245 local testroot=`test_init send_to_empty_repo`
1246 local testurl=ssh://127.0.0.1/$testroot
1247 local commit_id=`git_show_head $testroot/repo`
1249 gotadmin init $testroot/repo2
1251 ret=$?
1252 if [ $ret -ne 0 ]; then
1253 echo "got clone command failed unexpectedly" >&2
1254 test_done "$testroot" "$ret"
1255 return 1
1257 cat > $testroot/repo/.git/got.conf <<EOF
1258 remote "origin" {
1259 protocol ssh
1260 server 127.0.0.1
1261 repository "$testroot/repo2"
1263 EOF
1264 echo "modified alpha" > $testroot/repo/alpha
1265 git_commit $testroot/repo -m "modified alpha"
1266 local commit_id2=`git_show_head $testroot/repo`
1268 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1269 ret=$?
1270 if [ $ret -ne 0 ]; then
1271 echo "got send command failed unexpectedly" >&2
1272 test_done "$testroot" "$ret"
1273 return 1
1276 echo -n > $testroot/stdout.expected
1277 cmp -s $testroot/stdout $testroot/stdout.expected
1278 ret=$?
1279 if [ $ret -ne 0 ]; then
1280 diff -u $testroot/stdout.expected $testroot/stdout
1281 test_done "$testroot" "$ret"
1282 return 1
1285 # XXX Workaround: We cannot give the target for HEAD to 'gotadmin init'
1286 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1288 got ref -l -r $testroot/repo > $testroot/stdout
1289 ret=$?
1290 if [ $ret -ne 0 ]; then
1291 echo "got ref command failed unexpectedly" >&2
1292 test_done "$testroot" "$ret"
1293 return 1
1296 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1297 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1298 echo "refs/remotes/origin/master: $commit_id2" \
1299 >> $testroot/stdout.expected
1301 cmp -s $testroot/stdout $testroot/stdout.expected
1302 ret=$?
1303 if [ $ret -ne 0 ]; then
1304 diff -u $testroot/stdout.expected $testroot/stdout
1305 test_done "$testroot" "$ret"
1306 return 1
1309 got ref -l -r $testroot/repo2 > $testroot/stdout
1310 ret=$?
1311 if [ $ret -ne 0 ]; then
1312 echo "got ref command failed unexpectedly" >&2
1313 test_done "$testroot" "$ret"
1314 return 1
1317 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1318 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1320 cmp -s $testroot/stdout $testroot/stdout.expected
1321 ret=$?
1322 if [ $ret -ne 0 ]; then
1323 diff -u $testroot/stdout.expected $testroot/stdout
1324 test_done "$testroot" "$ret"
1325 return 1
1328 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1329 ret=$?
1330 if [ $ret -ne 0 ]; then
1331 echo "got send command failed unexpectedly" >&2
1332 test_done "$testroot" "$ret"
1333 return 1
1336 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo2" \
1337 > $testroot/stdout.expected
1338 echo "Already up-to-date" >> $testroot/stdout.expected
1339 cmp -s $testroot/stdout $testroot/stdout.expected
1340 ret=$?
1341 if [ $ret -ne 0 ]; then
1342 diff -u $testroot/stdout.expected $testroot/stdout
1343 test_done "$testroot" "$ret"
1344 return 1
1347 git_fsck "$testroot" "$testroot/repo2"
1348 ret=$?
1349 test_done "$testroot" "$ret"
1352 test_send_and_fetch_config() {
1353 local testroot=`test_init send_fetch_conf`
1354 local testurl=ssh://127.0.0.1/$testroot
1355 local commit_id=`git_show_head $testroot/repo`
1357 got clone -q $testurl/repo $testroot/repo-clone
1358 ret=$?
1359 if [ $ret -ne 0 ]; then
1360 echo "got clone command failed unexpectedly" >&2
1361 test_done "$testroot" "$ret"
1362 return 1
1365 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1366 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1367 | tr -d ' ' | cut -d: -f2`
1369 cp -R $testroot/repo-clone $testroot/repo-clone2
1370 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1371 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1372 | tr -d ' ' | cut -d: -f2`
1374 cat > $testroot/repo/.git/got.conf <<EOF
1375 remote "origin" {
1376 protocol ssh
1377 server 127.0.0.1
1378 send {
1379 repository "$testroot/repo-clone"
1381 fetch {
1382 repository "$testroot/repo-clone2"
1385 EOF
1386 got ref -l -r $testroot/repo > $testroot/stdout
1387 ret=$?
1388 if [ $ret -ne 0 ]; then
1389 echo "got ref command failed unexpectedly" >&2
1390 test_done "$testroot" "$ret"
1391 return 1
1394 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1395 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1396 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 # fetch tag 2.0 from repo-clone2
1406 got fetch -q -r $testroot/repo > $testroot/stdout
1407 ret=$?
1408 if [ $ret -ne 0 ]; then
1409 echo "got fetch command failed unexpectedly" >&2
1410 test_done "$testroot" "$ret"
1411 return 1
1414 got ref -l -r $testroot/repo > $testroot/stdout
1415 ret=$?
1416 if [ $ret -ne 0 ]; then
1417 echo "got ref command failed unexpectedly" >&2
1418 test_done "$testroot" "$ret"
1419 return 1
1422 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1423 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1424 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1425 >> $testroot/stdout.expected
1426 echo "refs/remotes/origin/master: $commit_id" \
1427 >> $testroot/stdout.expected
1428 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1429 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1430 cmp -s $testroot/stdout $testroot/stdout.expected
1431 ret=$?
1432 if [ $ret -ne 0 ]; then
1433 diff -u $testroot/stdout.expected $testroot/stdout
1434 test_done "$testroot" "$ret"
1435 return 1
1438 # send tag 1.0 to repo-clone
1439 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1440 ret=$?
1441 if [ $ret -ne 0 ]; then
1442 echo "got send command failed unexpectedly" >&2
1443 test_done "$testroot" "$ret"
1444 return 1
1447 got ref -l -r $testroot/repo-clone > $testroot/stdout
1448 ret=$?
1449 if [ $ret -ne 0 ]; then
1450 echo "got ref command failed unexpectedly" >&2
1451 test_done "$testroot" "$ret"
1452 return 1
1455 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1456 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1457 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1458 >> $testroot/stdout.expected
1459 echo "refs/remotes/origin/master: $commit_id" \
1460 >> $testroot/stdout.expected
1461 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1463 cmp -s $testroot/stdout $testroot/stdout.expected
1464 ret=$?
1465 if [ $ret -ne 0 ]; then
1466 diff -u $testroot/stdout.expected $testroot/stdout
1467 test_done "$testroot" "$ret"
1468 return 1
1471 git_fsck "$testroot" "$testroot/repo-clone"
1472 ret=$?
1473 test_done "$testroot" "$ret"
1476 test_send_config() {
1477 local testroot=`test_init send_config`
1478 local testurl=ssh://127.0.0.1/$testroot
1479 local commit_id=`git_show_head $testroot/repo`
1481 got clone -q $testurl/repo $testroot/repo-clone
1482 ret=$?
1483 if [ $ret -ne 0 ]; then
1484 echo "got clone command failed unexpectedly" >&2
1485 test_done "$testroot" "$ret"
1486 return 1
1489 cat > $testroot/repo/.git/got.conf <<EOF
1490 remote "origin" {
1491 protocol ssh
1492 server 127.0.0.1
1493 branch foo
1494 repository "$testroot/repo-clone"
1496 EOF
1497 got ref -l -r $testroot/repo-clone > $testroot/stdout
1498 ret=$?
1499 if [ $ret -ne 0 ]; then
1500 echo "got ref command failed unexpectedly" >&2
1501 test_done "$testroot" "$ret"
1502 return 1
1505 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1506 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1507 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1508 >> $testroot/stdout.expected
1509 echo "refs/remotes/origin/master: $commit_id" \
1510 >> $testroot/stdout.expected
1512 cmp -s $testroot/stdout $testroot/stdout.expected
1513 ret=$?
1514 if [ $ret -ne 0 ]; then
1515 diff -u $testroot/stdout.expected $testroot/stdout
1516 test_done "$testroot" "$ret"
1517 return 1
1520 got branch -r $testroot/repo foo
1522 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1523 ret=$?
1524 if [ $ret -ne 0 ]; then
1525 echo "got send command failed unexpectedly" >&2
1526 test_done "$testroot" "$ret"
1527 return 1
1530 got ref -l -r $testroot/repo-clone > $testroot/stdout
1531 ret=$?
1532 if [ $ret -ne 0 ]; then
1533 echo "got ref command failed unexpectedly" >&2
1534 test_done "$testroot" "$ret"
1535 return 1
1538 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1539 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1540 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1541 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1542 >> $testroot/stdout.expected
1543 echo "refs/remotes/origin/master: $commit_id" \
1544 >> $testroot/stdout.expected
1546 cmp -s $testroot/stdout $testroot/stdout.expected
1547 ret=$?
1548 if [ $ret -ne 0 ]; then
1549 diff -u $testroot/stdout.expected $testroot/stdout
1550 test_done "$testroot" "$ret"
1551 return 1
1554 git_fsck "$testroot" "$testroot/repo-clone"
1555 ret=$?
1556 test_done "$testroot" "$ret"
1559 test_send_gitconfig() {
1560 local testroot=`test_init send_config`
1561 local testurl=ssh://127.0.0.1/$testroot
1562 local commit_id=`git_show_head $testroot/repo`
1564 git init -q --bare $testroot/upstream-repo
1565 ret=$?
1566 if [ $ret -ne 0 ]; then
1567 echo "git init failed unexpectedly" >&2
1568 test_done "$testroot" "$ret"
1569 return 1
1572 cat >> $testroot/repo/.git/config <<EOF
1573 [remote "hasnourl"]
1574 unrelated = setting
1575 [remote "foo"]
1576 url = $testurl/upstream-repo
1577 [remote "another"]
1578 url = $testurl/some-other-repo
1579 EOF
1581 # unset in a subshell to avoid affecting our environment
1582 (unset GOT_IGNORE_GITCONFIG && got send -q -r $testroot/repo foo)
1583 ret=$?
1584 if [ $ret -ne 0 ]; then
1585 echo "got send command failed unexpectedly" >&2
1586 test_done "$testroot" "$ret"
1587 return 1
1590 got ref -l -r $testroot/upstream-repo > $testroot/stdout
1592 cat > $testroot/stdout.expected <<-EOF
1593 HEAD: refs/heads/master
1594 refs/heads/master: $commit_id
1595 EOF
1597 cmp -s $testroot/stdout $testroot/stdout.expected
1598 ret=$?
1599 if [ $ret -ne 0 ]; then
1600 diff -u $testroot/stdout.expected $testroot/stdout
1602 test_done "$testroot" "$ret"
1605 test_send_rejected() {
1606 local testroot=`test_init send_rejected`
1607 local testurl=ssh://127.0.0.1/$testroot
1608 local commit_id=`git_show_head $testroot/repo`
1610 if ! got clone -q "$testurl/repo" "$testroot/repo-clone"; then
1611 echo "got clone command failed unexpectedly" >&2
1612 test_done "$testroot" 1
1613 return 1
1616 mkdir "$testroot/repo-clone/hooks"
1617 cat <<'EOF' >$testroot/repo-clone/hooks/update
1618 case "$1" in
1619 *master*)
1620 echo "rejecting push on master branch"
1621 exit 1
1623 esac
1624 exit 0
1625 EOF
1626 chmod +x "$testroot/repo-clone/hooks/update"
1628 cat > $testroot/repo/.git/got.conf <<EOF
1629 remote "origin" {
1630 protocol ssh
1631 server 127.0.0.1
1632 repository "$testroot/repo-clone"
1634 EOF
1636 echo "modified alpha" >$testroot/repo/alpha
1637 git_commit "$testroot/repo" -m "modified alpha"
1639 got send -q -r "$testroot/repo" >$testroot/stdout 2>$testroot/stderr
1640 ret=$?
1641 if [ $ret -ne 0 ]; then
1642 echo "got send command failed unexpectedly" >&2
1643 test_done "$testroot" $ret
1644 return 1
1647 touch "$testroot/stdout.expected"
1648 if ! cmp -s "$testroot/stdout.expected" "$testroot/stdout"; then
1649 diff -u "$testroot/stdout.expected" "$testroot/stdout"
1650 test_done "$testroot" 1
1651 return 1
1654 cat <<EOF >$testroot/stderr.expected
1655 rejecting push on master branch
1656 error: hook declined to update refs/heads/master
1657 EOF
1659 if ! cmp -s "$testroot/stderr.expected" "$testroot/stderr"; then
1660 diff -u "$testroot/stderr.expected" "$testroot/stderr"
1661 test_done "$testroot" 1
1662 return 1
1665 test_done "$testroot" 0
1668 test_parseargs "$@"
1669 run_test test_send_basic
1670 run_test test_send_rebase_required
1671 run_test test_send_rebase_required_overwrite
1672 run_test test_send_merge_commit
1673 run_test test_send_delete
1674 run_test test_send_clone_and_send
1675 run_test test_send_tags
1676 run_test test_send_tag_of_deleted_branch
1677 run_test test_send_new_branch
1678 run_test test_send_all_branches
1679 run_test test_send_to_empty_repo
1680 run_test test_send_and_fetch_config
1681 run_test test_send_config
1682 run_test test_send_gitconfig
1683 run_test test_send_rejected