Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_send_basic() {
20 local testroot=`test_init send_basic`
21 local testurl=ssh://127.0.0.1/$testroot
22 local commit_id=`git_show_head $testroot/repo`
24 got clone -q $testurl/repo $testroot/repo-clone
25 ret="$?"
26 if [ "$ret" != "0" ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
29 return 1
30 fi
31 cat > $testroot/repo/.git/got.conf <<EOF
32 remote "origin" {
33 protocol ssh
34 server 127.0.0.1
35 repository "$testroot/repo-clone"
36 }
37 EOF
38 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
39 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
40 | tr -d ' ' | cut -d: -f2`
42 echo "modified alpha" > $testroot/repo/alpha
43 (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" != "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" != "0" ]; then
62 diff -u $testroot/stdout.expected $testroot/stdout
63 test_done "$testroot" "$ret"
64 return 1
65 fi
67 got ref -l -r $testroot/repo > $testroot/stdout
68 if [ "$ret" != "0" ]; then
69 echo "got ref command failed unexpectedly" >&2
70 test_done "$testroot" "$ret"
71 return 1
72 fi
74 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
75 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
76 echo "refs/remotes/origin/master: $commit_id2" \
77 >> $testroot/stdout.expected
78 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
80 cmp -s $testroot/stdout $testroot/stdout.expected
81 ret="$?"
82 if [ "$ret" != "0" ]; then
83 diff -u $testroot/stdout.expected $testroot/stdout
84 test_done "$testroot" "$ret"
85 return 1
86 fi
88 got ref -l -r $testroot/repo-clone > $testroot/stdout
89 if [ "$ret" != "0" ]; then
90 echo "got ref command failed unexpectedly" >&2
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
96 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
97 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
98 >> $testroot/stdout.expected
99 echo "refs/remotes/origin/master: $commit_id" \
100 >> $testroot/stdout.expected
102 cmp -s $testroot/stdout $testroot/stdout.expected
103 ret="$?"
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 test_done "$testroot" "$ret"
107 return 1
108 fi
110 got tree -r $testroot/repo-clone -c $commit_id2 -i -R \
111 > $testroot/stdout
112 got tree -r $testroot/repo -c $commit_id2 -i -R \
113 > $testroot/stdout.expected
114 cmp -s $testroot/stdout $testroot/stdout.expected
115 ret="$?"
116 if [ "$ret" != "0" ]; then
117 diff -u $testroot/stdout.expected $testroot/stdout
118 test_done "$testroot" "$ret"
119 return 1
120 fi
122 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
123 ret="$?"
124 if [ "$ret" != "0" ]; then
125 echo "got send command failed unexpectedly" >&2
126 test_done "$testroot" "$ret"
127 return 1
128 fi
130 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
131 echo "Already up-to-date" >> $testroot/stdout.expected
132 cmp -s $testroot/stdout $testroot/stdout.expected
133 ret="$?"
134 if [ "$ret" != "0" ]; then
135 diff -u $testroot/stdout.expected $testroot/stdout
136 test_done "$testroot" "$ret"
137 return 1
138 fi
140 git_fsck "$testroot" "$testroot/repo-clone"
141 ret="$?"
142 test_done "$testroot" "$ret"
145 test_send_rebase_required() {
146 local testroot=`test_init send_rebase_required`
147 local testurl=ssh://127.0.0.1/$testroot
148 local commit_id=`git_show_head $testroot/repo`
150 got clone -q $testurl/repo $testroot/repo-clone
151 ret="$?"
152 if [ "$ret" != "0" ]; then
153 echo "got clone command failed unexpectedly" >&2
154 test_done "$testroot" "$ret"
155 return 1
156 fi
157 cat > $testroot/repo/.git/got.conf <<EOF
158 remote "origin" {
159 protocol ssh
160 server 127.0.0.1
161 repository "$testroot/repo-clone"
163 EOF
164 echo "modified alpha" > $testroot/repo/alpha
165 git_commit $testroot/repo -m "modified alpha"
166 local commit_id2=`git_show_head $testroot/repo`
168 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
169 echo "modified alpha, too" > $testroot/wt-clone/alpha
170 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
172 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
173 ret="$?"
174 if [ "$ret" = "0" ]; then
175 echo "got send command succeeded unexpectedly" >&2
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 echo -n > $testroot/stdout.expected
181 cmp -s $testroot/stdout $testroot/stdout.expected
182 ret="$?"
183 if [ "$ret" != "0" ]; then
184 diff -u $testroot/stdout.expected $testroot/stdout
185 test_done "$testroot" "$ret"
186 return 1
187 fi
189 echo "got: refs/heads/master: fetch and rebase required" \
190 > $testroot/stderr.expected
191 cmp -s $testroot/stderr $testroot/stderr.expected
192 ret="$?"
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stderr.expected $testroot/stderr
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 git_fsck "$testroot" "$testroot/repo-clone"
200 ret="$?"
201 test_done "$testroot" "$ret"
204 test_send_rebase_required_overwrite() {
205 local testroot=`test_init send_rebase_required_overwrite`
206 local testurl=ssh://127.0.0.1/$testroot
207 local commit_id=`git_show_head $testroot/repo`
209 got clone -q $testurl/repo $testroot/repo-clone
210 ret="$?"
211 if [ "$ret" != "0" ]; then
212 echo "got clone command failed unexpectedly" >&2
213 test_done "$testroot" "$ret"
214 return 1
215 fi
216 cat > $testroot/repo/.git/got.conf <<EOF
217 remote "foobar" {
218 protocol ssh
219 server 127.0.0.1
220 repository "$testroot/repo-clone"
222 EOF
223 echo "modified alpha" > $testroot/repo/alpha
224 git_commit $testroot/repo -m "modified alpha"
225 local commit_id2=`git_show_head $testroot/repo`
227 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
228 echo "modified alpha, too" > $testroot/wt-clone/alpha
229 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
230 local commit_id3=`git_show_head $testroot/repo-clone`
232 # non-default remote requires an explicit argument
233 got send -q -r $testroot/repo -f > $testroot/stdout \
234 2> $testroot/stderr
235 ret="$?"
236 if [ "$ret" = "0" ]; then
237 echo "got send command succeeded unexpectedly" >&2
238 test_done "$testroot" "$ret"
239 return 1
240 fi
241 echo "got: origin: remote repository not found" \
242 > $testroot/stderr.expected
243 cmp -s $testroot/stderr $testroot/stderr.expected
244 ret="$?"
245 if [ "$ret" != "0" ]; then
246 diff -u $testroot/stderr.expected $testroot/stderr
247 test_done "$testroot" "$ret"
248 return 1
249 fi
251 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
252 2> $testroot/stderr
253 ret="$?"
254 if [ "$ret" != "0" ]; then
255 echo "got send command failed unexpectedly" >&2
256 test_done "$testroot" "$ret"
257 return 1
258 fi
260 echo -n > $testroot/stdout.expected
261 cmp -s $testroot/stdout $testroot/stdout.expected
262 ret="$?"
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 got ref -l -r $testroot/repo > $testroot/stdout
270 if [ "$ret" != "0" ]; then
271 echo "got ref command failed unexpectedly" >&2
272 test_done "$testroot" "$ret"
273 return 1
274 fi
276 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
277 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
278 echo "refs/remotes/foobar/master: $commit_id2" \
279 >> $testroot/stdout.expected
281 cmp -s $testroot/stdout $testroot/stdout.expected
282 ret="$?"
283 if [ "$ret" != "0" ]; then
284 diff -u $testroot/stdout.expected $testroot/stdout
285 test_done "$testroot" "$ret"
286 return 1
287 fi
289 got ref -l -r $testroot/repo-clone > $testroot/stdout
290 if [ "$ret" != "0" ]; then
291 echo "got ref command failed unexpectedly" >&2
292 test_done "$testroot" "$ret"
293 return 1
294 fi
296 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
297 cut -d ':' -f 2 | tr -d ' ')`
298 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
299 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
300 >> $testroot/stdout.expected
301 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
302 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
303 >> $testroot/stdout.expected
304 echo "refs/remotes/origin/master: $commit_id" \
305 >> $testroot/stdout.expected
307 cmp -s $testroot/stdout $testroot/stdout.expected
308 ret="$?"
309 if [ "$ret" != "0" ]; then
310 diff -u $testroot/stdout.expected $testroot/stdout
311 test_done "$testroot" "$ret"
312 return 1
313 fi
315 git_fsck "$testroot" "$testroot/repo-clone"
316 ret="$?"
317 test_done "$testroot" "$ret"
320 test_send_delete() {
321 local testroot=`test_init send_delete`
322 local testurl=ssh://127.0.0.1/$testroot
323 local commit_id=`git_show_head $testroot/repo`
325 # branch1 exists in both repositories
326 got branch -r $testroot/repo branch1
328 got clone -a -q $testurl/repo $testroot/repo-clone
329 ret="$?"
330 if [ "$ret" != "0" ]; then
331 echo "got clone command failed unexpectedly" >&2
332 test_done "$testroot" "$ret"
333 return 1
334 fi
335 cat > $testroot/repo/.git/got.conf <<EOF
336 remote "origin" {
337 protocol ssh
338 server 127.0.0.1
339 repository "$testroot/repo-clone"
341 EOF
342 # branch2 exists only in the remote repository
343 got branch -r $testroot/repo-clone branch2
345 got ref -l -r $testroot/repo-clone > $testroot/stdout
346 if [ "$ret" != "0" ]; then
347 echo "got ref command failed unexpectedly" >&2
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
353 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
354 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
355 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
357 # Sending changes for a branch and deleting it at the same
358 # time is not allowed.
359 got send -q -r $testroot/repo -d branch1 -b branch1 \
360 > $testroot/stdout 2> $testroot/stderr
361 ret="$?"
362 if [ "$ret" = "0" ]; then
363 echo "got send command succeeded unexpectedly" >&2
364 test_done "$testroot" "$ret"
365 return 1
366 fi
367 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
368 > $testroot/stderr.expected
369 echo ": reference cannot be deleted" >> $testroot/stderr.expected
370 cmp -s $testroot/stderr $testroot/stderr.expected
371 ret="$?"
372 if [ "$ret" != "0" ]; then
373 diff -u $testroot/stderr.expected $testroot/stderr
374 test_done "$testroot" "$ret"
375 return 1
376 fi
378 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
379 > $testroot/stdout 2> $testroot/stderr
380 ret="$?"
381 if [ "$ret" != "0" ]; then
382 echo "got send command failed unexpectedly" >&2
383 test_done "$testroot" "$ret"
384 return 1
385 fi
387 got send -r $testroot/repo -d refs/heads/branch2 origin \
388 > $testroot/stdout 2>$testroot/stderr
389 ret="$?"
390 if [ "$ret" != "0" ]; then
391 echo "got send command failed unexpectedly" >&2
392 test_done "$testroot" "$ret"
393 return 1
394 fi
396 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
397 echo "Server has deleted refs/heads/branch2" \
398 >> $testroot/stdout.expected
400 cmp -s $testroot/stdout $testroot/stdout.expected
401 ret="$?"
402 if [ "$ret" != "0" ]; then
403 diff -u $testroot/stdout.expected $testroot/stdout
404 test_done "$testroot" "$ret"
405 return 1
406 fi
408 # branchX exists in neither repository
409 got send -q -r $testroot/repo -d refs/heads/branchX origin \
410 > $testroot/stdout 2> $testroot/stderr
411 ret="$?"
412 if [ "$ret" = "0" ]; then
413 echo "got send command succeeded unexpectedly" >&2
414 test_done "$testroot" "$ret"
415 return 1
416 fi
417 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
418 > $testroot/stderr.expected
419 echo "repository: no such reference found" >> $testroot/stderr.expected
420 echo "got: no such reference found" >> $testroot/stderr.expected
421 cmp -s $testroot/stderr $testroot/stderr.expected
422 ret="$?"
423 if [ "$ret" != "0" ]; then
424 diff -u $testroot/stderr.expected $testroot/stderr
425 test_done "$testroot" "$ret"
426 return 1
427 fi
429 # References outside of refs/heads/ cannot be deleted with 'got send'.
430 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
431 > $testroot/stdout 2> $testroot/stderr
432 ret="$?"
433 if [ "$ret" = "0" ]; then
434 echo "got send command succeeded unexpectedly" >&2
435 test_done "$testroot" "$ret"
436 return 1
437 fi
438 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
439 > $testroot/stderr.expected
440 echo "in remote repository: no such reference found" \
441 >> $testroot/stderr.expected
442 echo "got: no such reference found" >> $testroot/stderr.expected
443 cmp -s $testroot/stderr $testroot/stderr.expected
444 ret="$?"
445 if [ "$ret" != "0" ]; then
446 diff -u $testroot/stderr.expected $testroot/stderr
447 test_done "$testroot" "$ret"
448 return 1
449 fi
451 got ref -l -r $testroot/repo > $testroot/stdout
452 if [ "$ret" != "0" ]; then
453 echo "got ref command failed unexpectedly" >&2
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
459 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
460 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
462 cmp -s $testroot/stdout $testroot/stdout.expected
463 ret="$?"
464 if [ "$ret" != "0" ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 test_done "$testroot" "$ret"
467 return 1
468 fi
470 got ref -l -r $testroot/repo-clone > $testroot/stdout
471 if [ "$ret" != "0" ]; then
472 echo "got ref command failed unexpectedly" >&2
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
478 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
479 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
480 >> $testroot/stdout.expected
481 echo "refs/remotes/origin/branch1: $commit_id" \
482 >> $testroot/stdout.expected
483 echo "refs/remotes/origin/master: $commit_id" \
484 >> $testroot/stdout.expected
486 cmp -s $testroot/stdout $testroot/stdout.expected
487 ret="$?"
488 if [ "$ret" != "0" ]; then
489 diff -u $testroot/stdout.expected $testroot/stdout
490 test_done "$testroot" "$ret"
491 return 1
492 fi
494 git_fsck "$testroot" "$testroot/repo-clone"
495 ret="$?"
496 test_done "$testroot" "$ret"
499 test_send_clone_and_send() {
500 local testroot=`test_init send_clone_and_send`
501 local testurl=ssh://127.0.0.1/$testroot
502 local commit_id=`git_show_head $testroot/repo`
504 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
506 got clone -q $testurl/repo $testroot/repo-clone
507 ret="$?"
508 if [ "$ret" != "0" ]; then
509 echo "got clone command failed unexpectedly" >&2
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 got checkout $testroot/repo-clone $testroot/wt >/dev/null
515 echo "modified alpha" > $testroot/wt/alpha
516 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
517 local commit_id2=`git_show_head $testroot/repo-clone`
519 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
520 ret="$?"
521 if [ "$ret" != "0" ]; then
522 echo "got send command failed unexpectedly" >&2
523 test_done "$testroot" "$ret"
524 return 1
525 fi
527 echo -n > $testroot/stdout.expected
528 cmp -s $testroot/stdout $testroot/stdout.expected
529 ret="$?"
530 if [ "$ret" != "0" ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done "$testroot" "$ret"
533 return 1
534 fi
536 got ref -l -r $testroot/repo > $testroot/stdout
537 if [ "$ret" != "0" ]; then
538 echo "got ref command failed unexpectedly" >&2
539 test_done "$testroot" "$ret"
540 return 1
541 fi
543 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
544 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
546 cmp -s $testroot/stdout $testroot/stdout.expected
547 ret="$?"
548 if [ "$ret" != "0" ]; then
549 diff -u $testroot/stdout.expected $testroot/stdout
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 got ref -l -r $testroot/repo-clone > $testroot/stdout
555 if [ "$ret" != "0" ]; then
556 echo "got ref command failed unexpectedly" >&2
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
562 cut -d ':' -f 2 | tr -d ' ')`
563 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
564 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
565 >> $testroot/stdout.expected
566 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
567 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
568 >> $testroot/stdout.expected
569 echo "refs/remotes/origin/master: $commit_id2" \
570 >> $testroot/stdout.expected
572 cmp -s $testroot/stdout $testroot/stdout.expected
573 ret="$?"
574 if [ "$ret" != "0" ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 git_fsck "$testroot" "$testroot/repo-clone"
581 ret="$?"
582 test_done "$testroot" "$ret"
585 test_send_tags() {
586 local testroot=`test_init send_tags`
587 local testurl=ssh://127.0.0.1/$testroot
588 local commit_id=`git_show_head $testroot/repo`
590 got clone -q $testurl/repo $testroot/repo-clone
591 ret="$?"
592 if [ "$ret" != "0" ]; then
593 echo "got clone command failed unexpectedly" >&2
594 test_done "$testroot" "$ret"
595 return 1
596 fi
597 cat > $testroot/repo/.git/got.conf <<EOF
598 remote "origin" {
599 protocol ssh
600 server 127.0.0.1
601 repository "$testroot/repo-clone"
603 EOF
604 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
605 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
606 | tr -d ' ' | cut -d: -f2`
608 echo "modified alpha" > $testroot/repo/alpha
609 git_commit $testroot/repo -m "modified alpha"
610 local commit_id2=`git_show_head $testroot/repo`
612 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
613 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
614 | tr -d ' ' | cut -d: -f2`
616 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
617 ret="$?"
618 if [ "$ret" != "0" ]; then
619 echo "got send command failed unexpectedly" >&2
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo -n > $testroot/stdout.expected
625 cmp -s $testroot/stdout $testroot/stdout.expected
626 ret="$?"
627 if [ "$ret" != "0" ]; then
628 diff -u $testroot/stdout.expected $testroot/stdout
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 got ref -l -r $testroot/repo > $testroot/stdout
634 if [ "$ret" != "0" ]; then
635 echo "got ref command failed unexpectedly" >&2
636 test_done "$testroot" "$ret"
637 return 1
638 fi
640 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
641 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
642 echo "refs/remotes/origin/master: $commit_id2" \
643 >> $testroot/stdout.expected
644 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
645 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
647 cmp -s $testroot/stdout $testroot/stdout.expected
648 ret="$?"
649 if [ "$ret" != "0" ]; then
650 diff -u $testroot/stdout.expected $testroot/stdout
651 test_done "$testroot" "$ret"
652 return 1
653 fi
655 got ref -l -r $testroot/repo-clone > $testroot/stdout
656 if [ "$ret" != "0" ]; then
657 echo "got ref command failed unexpectedly" >&2
658 test_done "$testroot" "$ret"
659 return 1
660 fi
662 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
663 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
664 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
665 >> $testroot/stdout.expected
666 echo "refs/remotes/origin/master: $commit_id" \
667 >> $testroot/stdout.expected
668 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
669 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
671 cmp -s $testroot/stdout $testroot/stdout.expected
672 ret="$?"
673 if [ "$ret" != "0" ]; then
674 diff -u $testroot/stdout.expected $testroot/stdout
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
680 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
681 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
682 cmp -s $testroot/stdout $testroot/stdout.expected
683 ret="$?"
684 if [ "$ret" != "0" ]; then
685 diff -u $testroot/stdout.expected $testroot/stdout
686 test_done "$testroot" "$ret"
687 return 1
688 fi
690 # Send the same tags again. This should be a no-op.
691 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
692 ret="$?"
693 if [ "$ret" != "0" ]; then
694 echo "got send command failed unexpectedly" >&2
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 echo -n > $testroot/stdout.expected
700 cmp -s $testroot/stdout $testroot/stdout.expected
701 ret="$?"
702 if [ "$ret" != "0" ]; then
703 diff -u $testroot/stdout.expected $testroot/stdout
704 test_done "$testroot" "$ret"
705 return 1
706 fi
708 # Overwriting an existing tag 'got send -f'.
709 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
710 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
711 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
712 | tr -d ' ' | cut -d: -f2`
714 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
715 2> $testroot/stderr
716 ret="$?"
717 if [ "$ret" = "0" ]; then
718 echo "got send command succeeded unexpectedly" >&2
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 echo "got: refs/tags/1.0: tag already exists on server" \
724 > $testroot/stderr.expected
725 cmp -s $testroot/stderr $testroot/stderr.expected
726 ret="$?"
727 if [ "$ret" != "0" ]; then
728 diff -u $testroot/stderr.expected $testroot/stderr
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 # attempting the same with -T should fail, too
734 got send -q -r $testroot/repo -T > $testroot/stdout \
735 2> $testroot/stderr
736 ret="$?"
737 if [ "$ret" = "0" ]; then
738 echo "got send command succeeded unexpectedly" >&2
739 test_done "$testroot" "$ret"
740 return 1
741 fi
743 echo "got: refs/tags/1.0: tag already exists on server" \
744 > $testroot/stderr.expected
745 cmp -s $testroot/stderr $testroot/stderr.expected
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/stderr.expected $testroot/stderr
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
754 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
755 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
756 cmp -s $testroot/stdout $testroot/stdout.expected
757 ret="$?"
758 if [ "$ret" != "0" ]; then
759 diff -u $testroot/stdout.expected $testroot/stdout
760 test_done "$testroot" "$ret"
761 return 1
762 fi
764 # overwrite the 1.0 tag only
765 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
766 2> $testroot/stderr
767 ret="$?"
768 if [ "$ret" != "0" ]; then
769 echo "got send command failed unexpectedly" >&2
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
775 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
776 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
777 cmp -s $testroot/stdout $testroot/stdout.expected
778 ret="$?"
779 if [ "$ret" != "0" ]; then
780 diff -u $testroot/stdout.expected $testroot/stdout
781 test_done "$testroot" "$ret"
782 return 1
783 fi
785 got checkout $testroot/repo $testroot/wt > /dev/null
786 echo 'new line in file alpha' >> $testroot/wt/alpha
787 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
789 # Send the new commit in isolation.
790 got send -q -r $testroot/repo > $testroot/stdout \
791 2> $testroot/stderr
792 ret="$?"
793 if [ "$ret" != "0" ]; then
794 echo "got send command failed unexpectedly" >&2
795 test_done "$testroot" "$ret"
796 return 1
797 fi
799 # Now tag it and send the tag.
800 # Verify that just the new tag object gets sent.
801 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
802 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
803 | tr -d ' ' | cut -d: -f2`
805 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
806 2> $testroot/stderr
807 ret="$?"
808 if [ "$ret" != "0" ]; then
809 echo "got send command failed unexpectedly" >&2
810 test_done "$testroot" "$ret"
811 return 1
812 fi
813 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
814 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
815 $testroot/stdout; then
816 echo "got send did apparently pack too many objects:" >&2
817 cat $testroot/stdout.raw >&2
818 test_done "$testroot" "1"
819 return 1
820 fi
822 git_fsck "$testroot" "$testroot/repo-clone"
823 ret="$?"
824 test_done "$testroot" "$ret"
827 test_send_tag_of_deleted_branch() {
828 local testroot=`test_init send_tag_of_deleted_branch`
829 local testurl=ssh://127.0.0.1/$testroot
830 local commit_id=`git_show_head $testroot/repo`
832 got clone -q $testurl/repo $testroot/repo-clone
833 ret="$?"
834 if [ "$ret" != "0" ]; then
835 echo "got clone command failed unexpectedly" >&2
836 test_done "$testroot" "$ret"
837 return 1
838 fi
839 cat > $testroot/repo/.git/got.conf <<EOF
840 remote "origin" {
841 protocol ssh
842 server 127.0.0.1
843 repository "$testroot/repo-clone"
845 EOF
846 got branch -r $testroot/repo foo
848 # modify alpha on branch foo
849 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
850 echo boo >> $testroot/wt/beta
851 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
852 > /dev/null)
853 local commit_id2=`git_show_branch_head $testroot/repo foo`
855 # tag HEAD commit of branch foo
856 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
857 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
858 | tr -d ' ' | cut -d: -f2`
860 # delete the branch; commit is now only reachable via tags/1.0
861 got branch -r $testroot/repo -d foo > /dev/null
863 # unrelated change on master branch, then try sending this branch
864 # and the tag
865 echo "modified alpha" > $testroot/repo/alpha
866 git_commit $testroot/repo -m "modified alpha"
867 local commit_id3=`git_show_head $testroot/repo`
869 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
870 ret="$?"
871 if [ "$ret" != "0" ]; then
872 echo "got send command failed unexpectedly" >&2
873 test_done "$testroot" "$ret"
874 return 1
875 fi
877 echo -n > $testroot/stdout.expected
878 cmp -s $testroot/stdout $testroot/stdout.expected
879 ret="$?"
880 if [ "$ret" != "0" ]; then
881 diff -u $testroot/stdout.expected $testroot/stdout
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 got ref -l -r $testroot/repo > $testroot/stdout
887 if [ "$ret" != "0" ]; then
888 echo "got ref command failed unexpectedly" >&2
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
894 cut -d ':' -f 2 | tr -d ' ')`
895 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
896 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
897 >> $testroot/stdout.expected
898 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
899 echo "refs/remotes/origin/master: $commit_id3" \
900 >> $testroot/stdout.expected
901 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
903 cmp -s $testroot/stdout $testroot/stdout.expected
904 ret="$?"
905 if [ "$ret" != "0" ]; then
906 diff -u $testroot/stdout.expected $testroot/stdout
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 got ref -l -r $testroot/repo-clone > $testroot/stdout
912 if [ "$ret" != "0" ]; then
913 echo "got ref command failed unexpectedly" >&2
914 test_done "$testroot" "$ret"
915 return 1
916 fi
918 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
919 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
920 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
921 >> $testroot/stdout.expected
922 echo "refs/remotes/origin/master: $commit_id" \
923 >> $testroot/stdout.expected
924 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
926 cmp -s $testroot/stdout $testroot/stdout.expected
927 ret="$?"
928 if [ "$ret" != "0" ]; then
929 diff -u $testroot/stdout.expected $testroot/stdout
930 test_done "$testroot" "$ret"
931 return 1
932 fi
934 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
935 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
937 cmp -s $testroot/stdout $testroot/stdout.expected
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 git_fsck "$testroot" "$testroot/repo-clone"
946 ret="$?"
947 test_done "$testroot" "$ret"
950 test_send_new_branch() {
951 local testroot=`test_init send_new_branch`
952 local testurl=ssh://127.0.0.1/$testroot
953 local commit_id=`git_show_head $testroot/repo`
955 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
957 got clone -q $testurl/repo $testroot/repo-clone
958 ret="$?"
959 if [ "$ret" != "0" ]; then
960 echo "got clone command failed unexpectedly" >&2
961 test_done "$testroot" "$ret"
962 return 1
963 fi
965 got branch -r $testroot/repo-clone foo >/dev/null
966 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
967 echo "modified alpha" > $testroot/wt/alpha
968 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
969 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
971 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
972 ret="$?"
973 if [ "$ret" != "0" ]; then
974 echo "got send command failed unexpectedly" >&2
975 test_done "$testroot" "$ret"
976 return 1
977 fi
979 echo -n > $testroot/stdout.expected
980 cmp -s $testroot/stdout $testroot/stdout.expected
981 ret="$?"
982 if [ "$ret" != "0" ]; then
983 diff -u $testroot/stdout.expected $testroot/stdout
984 test_done "$testroot" "$ret"
985 return 1
986 fi
988 got ref -l -r $testroot/repo > $testroot/stdout
989 if [ "$ret" != "0" ]; then
990 echo "got ref command failed unexpectedly" >&2
991 test_done "$testroot" "$ret"
992 return 1
993 fi
995 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
996 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
997 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
999 cmp -s $testroot/stdout $testroot/stdout.expected
1000 ret="$?"
1001 if [ "$ret" != "0" ]; then
1002 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1004 return 1
1007 got ref -l -r $testroot/repo-clone > $testroot/stdout
1008 if [ "$ret" != "0" ]; then
1009 echo "got ref command failed unexpectedly" >&2
1010 test_done "$testroot" "$ret"
1011 return 1
1014 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1015 cut -d ':' -f 2 | tr -d ' ')`
1016 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1017 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1018 >> $testroot/stdout.expected
1019 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1020 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1021 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1022 >> $testroot/stdout.expected
1023 echo "refs/remotes/origin/foo: $commit_id2" \
1024 >> $testroot/stdout.expected
1025 echo "refs/remotes/origin/master: $commit_id" \
1026 >> $testroot/stdout.expected
1028 cmp -s $testroot/stdout $testroot/stdout.expected
1029 ret="$?"
1030 if [ "$ret" != "0" ]; then
1031 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1033 return 1
1036 git_fsck "$testroot" "$testroot/repo-clone"
1037 ret="$?"
1038 test_done "$testroot" "$ret"
1041 test_send_all_branches() {
1042 local testroot=`test_init send_all_branches`
1043 local testurl=ssh://127.0.0.1/$testroot
1044 local commit_id=`git_show_head $testroot/repo`
1046 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1048 got clone -q $testurl/repo $testroot/repo-clone
1049 ret="$?"
1050 if [ "$ret" != "0" ]; then
1051 echo "got clone command failed unexpectedly" >&2
1052 test_done "$testroot" "$ret"
1053 return 1
1056 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1057 echo "modified alpha" > $testroot/wt/alpha
1058 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1059 local commit_id2=`git_show_head $testroot/repo-clone`
1061 got branch -r $testroot/repo-clone foo >/dev/null
1062 (cd $testroot/wt && got update -b foo >/dev/null)
1063 echo "modified beta on new branch foo" > $testroot/wt/beta
1064 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1065 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1067 got branch -r $testroot/repo-clone bar >/dev/null
1068 (cd $testroot/wt && got update -b bar >/dev/null)
1069 echo "modified beta again on new branch bar" > $testroot/wt/beta
1070 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1071 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1073 got ref -l -r $testroot/repo-clone > $testroot/stdout
1074 if [ "$ret" != "0" ]; then
1075 echo "got ref command failed unexpectedly" >&2
1076 test_done "$testroot" "$ret"
1077 return 1
1080 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1081 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1082 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1083 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1085 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1086 2> $testroot/stderr
1087 ret="$?"
1088 if [ "$ret" = "0" ]; then
1089 echo "got send command succeeded unexpectedly" >&2
1090 test_done "$testroot" "$ret"
1091 return 1
1093 echo "got: -a and -b options are mutually exclusive" \
1094 > $testroot/stderr.expected
1095 cmp -s $testroot/stderr $testroot/stderr.expected
1096 ret="$?"
1097 if [ "$ret" != "0" ]; then
1098 diff -u $testroot/stderr.expected $testroot/stderr
1099 test_done "$testroot" "$ret"
1100 return 1
1103 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1104 2> $testroot/stderr
1105 ret="$?"
1106 if [ "$ret" != "0" ]; then
1107 echo "got send command failed unexpectedly" >&2
1108 test_done "$testroot" "$ret"
1109 return 1
1112 echo -n > $testroot/stdout.expected
1113 cmp -s $testroot/stdout $testroot/stdout.expected
1114 ret="$?"
1115 if [ "$ret" != "0" ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1118 return 1
1121 got ref -l -r $testroot/repo > $testroot/stdout
1122 if [ "$ret" != "0" ]; then
1123 echo "got ref command failed unexpectedly" >&2
1124 test_done "$testroot" "$ret"
1125 return 1
1128 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1129 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1130 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1131 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1133 cmp -s $testroot/stdout $testroot/stdout.expected
1134 ret="$?"
1135 if [ "$ret" != "0" ]; then
1136 diff -u $testroot/stdout.expected $testroot/stdout
1137 test_done "$testroot" "$ret"
1138 return 1
1141 got ref -l -r $testroot/repo-clone > $testroot/stdout
1142 if [ "$ret" != "0" ]; then
1143 echo "got ref command failed unexpectedly" >&2
1144 test_done "$testroot" "$ret"
1145 return 1
1148 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1149 cut -d ':' -f 2 | tr -d ' ')`
1150 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1151 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1152 >> $testroot/stdout.expected
1153 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1154 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1155 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1156 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1157 >> $testroot/stdout.expected
1158 echo "refs/remotes/origin/bar: $commit_id4" \
1159 >> $testroot/stdout.expected
1160 echo "refs/remotes/origin/foo: $commit_id3" \
1161 >> $testroot/stdout.expected
1162 echo "refs/remotes/origin/master: $commit_id2" \
1163 >> $testroot/stdout.expected
1165 cmp -s $testroot/stdout $testroot/stdout.expected
1166 ret="$?"
1167 if [ "$ret" != "0" ]; then
1168 diff -u $testroot/stdout.expected $testroot/stdout
1169 test_done "$testroot" "$ret"
1170 return 1
1173 git_fsck "$testroot" "$testroot/repo-clone"
1174 ret="$?"
1175 test_done "$testroot" "$ret"
1178 test_send_to_empty_repo() {
1179 local testroot=`test_init send_to_empty_repo`
1180 local testurl=ssh://127.0.0.1/$testroot
1181 local commit_id=`git_show_head $testroot/repo`
1183 got init $testroot/repo2
1185 ret="$?"
1186 if [ "$ret" != "0" ]; then
1187 echo "got clone command failed unexpectedly" >&2
1188 test_done "$testroot" "$ret"
1189 return 1
1191 cat > $testroot/repo/.git/got.conf <<EOF
1192 remote "origin" {
1193 protocol ssh
1194 server 127.0.0.1
1195 repository "$testroot/repo2"
1197 EOF
1198 echo "modified alpha" > $testroot/repo/alpha
1199 git_commit $testroot/repo -m "modified alpha"
1200 local commit_id2=`git_show_head $testroot/repo`
1202 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1203 ret="$?"
1204 if [ "$ret" != "0" ]; then
1205 echo "got send command failed unexpectedly" >&2
1206 test_done "$testroot" "$ret"
1207 return 1
1210 echo -n > $testroot/stdout.expected
1211 cmp -s $testroot/stdout $testroot/stdout.expected
1212 ret="$?"
1213 if [ "$ret" != "0" ]; then
1214 diff -u $testroot/stdout.expected $testroot/stdout
1215 test_done "$testroot" "$ret"
1216 return 1
1219 # XXX Workaround: We cannot give the target for HEAD to 'got init'
1220 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1222 got ref -l -r $testroot/repo > $testroot/stdout
1223 if [ "$ret" != "0" ]; then
1224 echo "got ref command failed unexpectedly" >&2
1225 test_done "$testroot" "$ret"
1226 return 1
1229 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1230 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1231 echo "refs/remotes/origin/master: $commit_id2" \
1232 >> $testroot/stdout.expected
1234 cmp -s $testroot/stdout $testroot/stdout.expected
1235 ret="$?"
1236 if [ "$ret" != "0" ]; then
1237 diff -u $testroot/stdout.expected $testroot/stdout
1238 test_done "$testroot" "$ret"
1239 return 1
1242 got ref -l -r $testroot/repo2 > $testroot/stdout
1243 if [ "$ret" != "0" ]; then
1244 echo "got ref command failed unexpectedly" >&2
1245 test_done "$testroot" "$ret"
1246 return 1
1249 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1250 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1252 cmp -s $testroot/stdout $testroot/stdout.expected
1253 ret="$?"
1254 if [ "$ret" != "0" ]; then
1255 diff -u $testroot/stdout.expected $testroot/stdout
1256 test_done "$testroot" "$ret"
1257 return 1
1260 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1261 ret="$?"
1262 if [ "$ret" != "0" ]; then
1263 echo "got send command failed unexpectedly" >&2
1264 test_done "$testroot" "$ret"
1265 return 1
1268 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1269 echo "Already up-to-date" >> $testroot/stdout.expected
1270 cmp -s $testroot/stdout $testroot/stdout.expected
1271 ret="$?"
1272 if [ "$ret" != "0" ]; then
1273 diff -u $testroot/stdout.expected $testroot/stdout
1274 test_done "$testroot" "$ret"
1275 return 1
1278 git_fsck "$testroot" "$testroot/repo2"
1279 ret="$?"
1280 test_done "$testroot" "$ret"
1283 test_send_and_fetch_config() {
1284 local testroot=`test_init send_fetch_conf`
1285 local testurl=ssh://127.0.0.1/$testroot
1286 local commit_id=`git_show_head $testroot/repo`
1288 got clone -q $testurl/repo $testroot/repo-clone
1289 ret="$?"
1290 if [ "$ret" != "0" ]; then
1291 echo "got clone command failed unexpectedly" >&2
1292 test_done "$testroot" "$ret"
1293 return 1
1296 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1297 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1298 | tr -d ' ' | cut -d: -f2`
1300 cp -R $testroot/repo-clone $testroot/repo-clone2
1301 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1302 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1303 | tr -d ' ' | cut -d: -f2`
1305 cat > $testroot/repo/.git/got.conf <<EOF
1306 remote "origin" {
1307 protocol ssh
1308 server 127.0.0.1
1309 send {
1310 repository "$testroot/repo-clone"
1312 fetch {
1313 repository "$testroot/repo-clone2"
1316 EOF
1317 got ref -l -r $testroot/repo > $testroot/stdout
1318 if [ "$ret" != "0" ]; then
1319 echo "got ref command failed unexpectedly" >&2
1320 test_done "$testroot" "$ret"
1321 return 1
1324 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1325 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1326 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1327 cmp -s $testroot/stdout $testroot/stdout.expected
1328 ret="$?"
1329 if [ "$ret" != "0" ]; then
1330 diff -u $testroot/stdout.expected $testroot/stdout
1331 test_done "$testroot" "$ret"
1332 return 1
1335 # fetch tag 2.0 from repo-clone2
1336 got fetch -q -r $testroot/repo > $testroot/stdout
1337 ret="$?"
1338 if [ "$ret" != "0" ]; then
1339 echo "got fetch command failed unexpectedly" >&2
1340 test_done "$testroot" "$ret"
1341 return 1
1344 got ref -l -r $testroot/repo > $testroot/stdout
1345 if [ "$ret" != "0" ]; then
1346 echo "got ref command failed unexpectedly" >&2
1347 test_done "$testroot" "$ret"
1348 return 1
1351 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1352 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1353 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1354 >> $testroot/stdout.expected
1355 echo "refs/remotes/origin/master: $commit_id" \
1356 >> $testroot/stdout.expected
1357 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1358 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1359 cmp -s $testroot/stdout $testroot/stdout.expected
1360 ret="$?"
1361 if [ "$ret" != "0" ]; then
1362 diff -u $testroot/stdout.expected $testroot/stdout
1363 test_done "$testroot" "$ret"
1364 return 1
1367 # send tag 1.0 to repo-clone
1368 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1369 ret="$?"
1370 if [ "$ret" != "0" ]; then
1371 echo "got send command failed unexpectedly" >&2
1372 test_done "$testroot" "$ret"
1373 return 1
1376 got ref -l -r $testroot/repo-clone > $testroot/stdout
1377 if [ "$ret" != "0" ]; then
1378 echo "got ref command failed unexpectedly" >&2
1379 test_done "$testroot" "$ret"
1380 return 1
1383 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1384 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1385 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1386 >> $testroot/stdout.expected
1387 echo "refs/remotes/origin/master: $commit_id" \
1388 >> $testroot/stdout.expected
1389 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1391 cmp -s $testroot/stdout $testroot/stdout.expected
1392 ret="$?"
1393 if [ "$ret" != "0" ]; then
1394 diff -u $testroot/stdout.expected $testroot/stdout
1395 test_done "$testroot" "$ret"
1396 return 1
1399 git_fsck "$testroot" "$testroot/repo-clone"
1400 ret="$?"
1401 test_done "$testroot" "$ret"
1404 test_send_config() {
1405 local testroot=`test_init send_fetch_conf`
1406 local testurl=ssh://127.0.0.1/$testroot
1407 local commit_id=`git_show_head $testroot/repo`
1409 got clone -q $testurl/repo $testroot/repo-clone
1410 ret="$?"
1411 if [ "$ret" != "0" ]; then
1412 echo "got clone command failed unexpectedly" >&2
1413 test_done "$testroot" "$ret"
1414 return 1
1417 cat > $testroot/repo/.git/got.conf <<EOF
1418 remote "origin" {
1419 protocol ssh
1420 server 127.0.0.1
1421 branch foo
1422 repository "$testroot/repo-clone"
1424 EOF
1425 got ref -l -r $testroot/repo-clone > $testroot/stdout
1426 if [ "$ret" != "0" ]; then
1427 echo "got ref command failed unexpectedly" >&2
1428 test_done "$testroot" "$ret"
1429 return 1
1432 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1433 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1434 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1435 >> $testroot/stdout.expected
1436 echo "refs/remotes/origin/master: $commit_id" \
1437 >> $testroot/stdout.expected
1439 cmp -s $testroot/stdout $testroot/stdout.expected
1440 ret="$?"
1441 if [ "$ret" != "0" ]; then
1442 diff -u $testroot/stdout.expected $testroot/stdout
1443 test_done "$testroot" "$ret"
1444 return 1
1447 got branch -r $testroot/repo foo
1449 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1450 ret="$?"
1451 if [ "$ret" != "0" ]; then
1452 echo "got send command failed unexpectedly" >&2
1453 test_done "$testroot" "$ret"
1454 return 1
1457 got ref -l -r $testroot/repo-clone > $testroot/stdout
1458 if [ "$ret" != "0" ]; then
1459 echo "got ref command failed unexpectedly" >&2
1460 test_done "$testroot" "$ret"
1461 return 1
1464 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1465 echo "refs/heads/foo: $commit_id" >> $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" != "0" ]; then
1475 diff -u $testroot/stdout.expected $testroot/stdout
1476 test_done "$testroot" "$ret"
1477 return 1
1480 git_fsck "$testroot" "$testroot/repo-clone"
1481 ret="$?"
1482 test_done "$testroot" "$ret"
1485 test_parseargs "$@"
1486 run_test test_send_basic
1487 run_test test_send_rebase_required
1488 run_test test_send_rebase_required_overwrite
1489 run_test test_send_delete
1490 run_test test_send_clone_and_send
1491 run_test test_send_tags
1492 run_test test_send_tag_of_deleted_branch
1493 run_test test_send_new_branch
1494 run_test test_send_all_branches
1495 run_test test_send_to_empty_repo
1496 run_test test_send_and_fetch_config
1497 run_test test_send_config