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 # Overwriting an existing tag 'got send -f'.
691 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
692 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
693 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
694 | tr -d ' ' | cut -d: -f2`
696 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
697 2> $testroot/stderr
698 ret="$?"
699 if [ "$ret" = "0" ]; then
700 echo "got send command succeeded unexpectedly" >&2
701 test_done "$testroot" "$ret"
702 return 1
703 fi
705 echo "got: refs/tags/1.0: tag already exists on server" \
706 > $testroot/stderr.expected
707 cmp -s $testroot/stderr $testroot/stderr.expected
708 ret="$?"
709 if [ "$ret" != "0" ]; then
710 diff -u $testroot/stderr.expected $testroot/stderr
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 # attempting the same with -T should fail, too
716 got send -q -r $testroot/repo -T > $testroot/stdout \
717 2> $testroot/stderr
718 ret="$?"
719 if [ "$ret" = "0" ]; then
720 echo "got send command succeeded unexpectedly" >&2
721 test_done "$testroot" "$ret"
722 return 1
723 fi
725 echo "got: refs/tags/1.0: tag already exists on server" \
726 > $testroot/stderr.expected
727 cmp -s $testroot/stderr $testroot/stderr.expected
728 ret="$?"
729 if [ "$ret" != "0" ]; then
730 diff -u $testroot/stderr.expected $testroot/stderr
731 test_done "$testroot" "$ret"
732 return 1
733 fi
735 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
736 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
737 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
738 cmp -s $testroot/stdout $testroot/stdout.expected
739 ret="$?"
740 if [ "$ret" != "0" ]; then
741 diff -u $testroot/stdout.expected $testroot/stdout
742 test_done "$testroot" "$ret"
743 return 1
744 fi
746 # overwrite the 1.0 tag only
747 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
748 2> $testroot/stderr
749 ret="$?"
750 if [ "$ret" != "0" ]; then
751 echo "got send command failed unexpectedly" >&2
752 test_done "$testroot" "$ret"
753 return 1
754 fi
756 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
757 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
758 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
759 cmp -s $testroot/stdout $testroot/stdout.expected
760 ret="$?"
761 if [ "$ret" != "0" ]; then
762 diff -u $testroot/stdout.expected $testroot/stdout
763 test_done "$testroot" "$ret"
764 return 1
765 fi
767 got checkout $testroot/repo $testroot/wt > /dev/null
768 echo 'new line in file alpha' >> $testroot/wt/alpha
769 (cd $testroot/wt && got commit -m 'changing file alpha' > /dev/null)
771 # Send the new commit in isolation.
772 got send -q -r $testroot/repo > $testroot/stdout \
773 2> $testroot/stderr
774 ret="$?"
775 if [ "$ret" != "0" ]; then
776 echo "got send command failed unexpectedly" >&2
777 test_done "$testroot" "$ret"
778 return 1
779 fi
781 # Now tag it and send the tag.
782 # Verify that just the new tag object gets sent.
783 got tag -r $testroot/repo -m '3.0' 3.0 >/dev/null
784 tag_id4=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
785 | tr -d ' ' | cut -d: -f2`
787 got send -r $testroot/repo -t 3.0 > $testroot/stdout.raw \
788 2> $testroot/stderr
789 ret="$?"
790 if [ "$ret" != "0" ]; then
791 echo "got send command failed unexpectedly" >&2
792 test_done "$testroot" "$ret"
793 return 1
794 fi
795 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
796 if ! grep -q "packing 2 references; 1 object; deltify: 100%" \
797 $testroot/stdout; then
798 echo "got send did apparently pack too many objects:" >&2
799 cat $testroot/stdout.raw >&2
800 test_done "$testroot" "1"
801 return 1
802 fi
804 git_fsck "$testroot" "$testroot/repo-clone"
805 ret="$?"
806 test_done "$testroot" "$ret"
809 test_send_tag_of_deleted_branch() {
810 local testroot=`test_init send_tag_of_deleted_branch`
811 local testurl=ssh://127.0.0.1/$testroot
812 local commit_id=`git_show_head $testroot/repo`
814 got clone -q $testurl/repo $testroot/repo-clone
815 ret="$?"
816 if [ "$ret" != "0" ]; then
817 echo "got clone command failed unexpectedly" >&2
818 test_done "$testroot" "$ret"
819 return 1
820 fi
821 cat > $testroot/repo/.git/got.conf <<EOF
822 remote "origin" {
823 protocol ssh
824 server 127.0.0.1
825 repository "$testroot/repo-clone"
827 EOF
828 got branch -r $testroot/repo foo
830 # modify alpha on branch foo
831 got checkout -b foo $testroot/repo $testroot/wt > /dev/null
832 echo boo >> $testroot/wt/beta
833 (cd $testroot/wt && got commit -m 'changed beta on branch foo' \
834 > /dev/null)
835 local commit_id2=`git_show_branch_head $testroot/repo foo`
837 # tag HEAD commit of branch foo
838 got tag -r $testroot/repo -c foo -m '1.0' 1.0 > /dev/null
839 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
840 | tr -d ' ' | cut -d: -f2`
842 # delete the branch; commit is now only reachable via tags/1.0
843 got branch -r $testroot/repo -d foo > /dev/null
845 # unrelated change on master branch, then try sending this branch
846 # and the tag
847 echo "modified alpha" > $testroot/repo/alpha
848 git_commit $testroot/repo -m "modified alpha"
849 local commit_id3=`git_show_head $testroot/repo`
851 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
852 ret="$?"
853 if [ "$ret" != "0" ]; then
854 echo "got send command failed unexpectedly" >&2
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 echo -n > $testroot/stdout.expected
860 cmp -s $testroot/stdout $testroot/stdout.expected
861 ret="$?"
862 if [ "$ret" != "0" ]; then
863 diff -u $testroot/stdout.expected $testroot/stdout
864 test_done "$testroot" "$ret"
865 return 1
866 fi
868 got ref -l -r $testroot/repo > $testroot/stdout
869 if [ "$ret" != "0" ]; then
870 echo "got ref command failed unexpectedly" >&2
871 test_done "$testroot" "$ret"
872 return 1
873 fi
875 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
876 cut -d ':' -f 2 | tr -d ' ')`
877 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
878 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
879 >> $testroot/stdout.expected
880 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
881 echo "refs/remotes/origin/master: $commit_id3" \
882 >> $testroot/stdout.expected
883 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
885 cmp -s $testroot/stdout $testroot/stdout.expected
886 ret="$?"
887 if [ "$ret" != "0" ]; then
888 diff -u $testroot/stdout.expected $testroot/stdout
889 test_done "$testroot" "$ret"
890 return 1
891 fi
893 got ref -l -r $testroot/repo-clone > $testroot/stdout
894 if [ "$ret" != "0" ]; then
895 echo "got ref command failed unexpectedly" >&2
896 test_done "$testroot" "$ret"
897 return 1
898 fi
900 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
901 echo "refs/heads/master: $commit_id3" >> $testroot/stdout.expected
902 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
903 >> $testroot/stdout.expected
904 echo "refs/remotes/origin/master: $commit_id" \
905 >> $testroot/stdout.expected
906 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
908 cmp -s $testroot/stdout $testroot/stdout.expected
909 ret="$?"
910 if [ "$ret" != "0" ]; then
911 diff -u $testroot/stdout.expected $testroot/stdout
912 test_done "$testroot" "$ret"
913 return 1
914 fi
916 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
917 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
919 cmp -s $testroot/stdout $testroot/stdout.expected
920 ret="$?"
921 if [ "$ret" != "0" ]; then
922 diff -u $testroot/stdout.expected $testroot/stdout
923 test_done "$testroot" "$ret"
924 return 1
925 fi
927 git_fsck "$testroot" "$testroot/repo-clone"
928 ret="$?"
929 test_done "$testroot" "$ret"
932 test_send_new_branch() {
933 local testroot=`test_init send_new_branch`
934 local testurl=ssh://127.0.0.1/$testroot
935 local commit_id=`git_show_head $testroot/repo`
937 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
939 got clone -q $testurl/repo $testroot/repo-clone
940 ret="$?"
941 if [ "$ret" != "0" ]; then
942 echo "got clone command failed unexpectedly" >&2
943 test_done "$testroot" "$ret"
944 return 1
945 fi
947 got branch -r $testroot/repo-clone foo >/dev/null
948 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
949 echo "modified alpha" > $testroot/wt/alpha
950 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
951 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
953 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
954 ret="$?"
955 if [ "$ret" != "0" ]; then
956 echo "got send command failed unexpectedly" >&2
957 test_done "$testroot" "$ret"
958 return 1
959 fi
961 echo -n > $testroot/stdout.expected
962 cmp -s $testroot/stdout $testroot/stdout.expected
963 ret="$?"
964 if [ "$ret" != "0" ]; then
965 diff -u $testroot/stdout.expected $testroot/stdout
966 test_done "$testroot" "$ret"
967 return 1
968 fi
970 got ref -l -r $testroot/repo > $testroot/stdout
971 if [ "$ret" != "0" ]; then
972 echo "got ref command failed unexpectedly" >&2
973 test_done "$testroot" "$ret"
974 return 1
975 fi
977 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
978 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
979 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
981 cmp -s $testroot/stdout $testroot/stdout.expected
982 ret="$?"
983 if [ "$ret" != "0" ]; then
984 diff -u $testroot/stdout.expected $testroot/stdout
985 test_done "$testroot" "$ret"
986 return 1
987 fi
989 got ref -l -r $testroot/repo-clone > $testroot/stdout
990 if [ "$ret" != "0" ]; then
991 echo "got ref command failed unexpectedly" >&2
992 test_done "$testroot" "$ret"
993 return 1
994 fi
996 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
997 cut -d ':' -f 2 | tr -d ' ')`
998 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
999 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1000 >> $testroot/stdout.expected
1001 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
1002 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1003 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1004 >> $testroot/stdout.expected
1005 echo "refs/remotes/origin/foo: $commit_id2" \
1006 >> $testroot/stdout.expected
1007 echo "refs/remotes/origin/master: $commit_id" \
1008 >> $testroot/stdout.expected
1010 cmp -s $testroot/stdout $testroot/stdout.expected
1011 ret="$?"
1012 if [ "$ret" != "0" ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1015 return 1
1018 git_fsck "$testroot" "$testroot/repo-clone"
1019 ret="$?"
1020 test_done "$testroot" "$ret"
1023 test_send_all_branches() {
1024 local testroot=`test_init send_all_branches`
1025 local testurl=ssh://127.0.0.1/$testroot
1026 local commit_id=`git_show_head $testroot/repo`
1028 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
1030 got clone -q $testurl/repo $testroot/repo-clone
1031 ret="$?"
1032 if [ "$ret" != "0" ]; then
1033 echo "got clone command failed unexpectedly" >&2
1034 test_done "$testroot" "$ret"
1035 return 1
1038 got checkout $testroot/repo-clone $testroot/wt >/dev/null
1039 echo "modified alpha" > $testroot/wt/alpha
1040 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
1041 local commit_id2=`git_show_head $testroot/repo-clone`
1043 got branch -r $testroot/repo-clone foo >/dev/null
1044 (cd $testroot/wt && got update -b foo >/dev/null)
1045 echo "modified beta on new branch foo" > $testroot/wt/beta
1046 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1047 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
1049 got branch -r $testroot/repo-clone bar >/dev/null
1050 (cd $testroot/wt && got update -b bar >/dev/null)
1051 echo "modified beta again on new branch bar" > $testroot/wt/beta
1052 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
1053 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
1055 got ref -l -r $testroot/repo-clone > $testroot/stdout
1056 if [ "$ret" != "0" ]; then
1057 echo "got ref command failed unexpectedly" >&2
1058 test_done "$testroot" "$ret"
1059 return 1
1062 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1063 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1064 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1065 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1067 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
1068 2> $testroot/stderr
1069 ret="$?"
1070 if [ "$ret" = "0" ]; then
1071 echo "got send command succeeded unexpectedly" >&2
1072 test_done "$testroot" "$ret"
1073 return 1
1075 echo "got: -a and -b options are mutually exclusive" \
1076 > $testroot/stderr.expected
1077 cmp -s $testroot/stderr $testroot/stderr.expected
1078 ret="$?"
1079 if [ "$ret" != "0" ]; then
1080 diff -u $testroot/stderr.expected $testroot/stderr
1081 test_done "$testroot" "$ret"
1082 return 1
1085 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
1086 2> $testroot/stderr
1087 ret="$?"
1088 if [ "$ret" != "0" ]; then
1089 echo "got send command failed unexpectedly" >&2
1090 test_done "$testroot" "$ret"
1091 return 1
1094 echo -n > $testroot/stdout.expected
1095 cmp -s $testroot/stdout $testroot/stdout.expected
1096 ret="$?"
1097 if [ "$ret" != "0" ]; then
1098 diff -u $testroot/stdout.expected $testroot/stdout
1099 test_done "$testroot" "$ret"
1100 return 1
1103 got ref -l -r $testroot/repo > $testroot/stdout
1104 if [ "$ret" != "0" ]; then
1105 echo "got ref command failed unexpectedly" >&2
1106 test_done "$testroot" "$ret"
1107 return 1
1110 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1111 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1112 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1113 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1115 cmp -s $testroot/stdout $testroot/stdout.expected
1116 ret="$?"
1117 if [ "$ret" != "0" ]; then
1118 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1120 return 1
1123 got ref -l -r $testroot/repo-clone > $testroot/stdout
1124 if [ "$ret" != "0" ]; then
1125 echo "got ref command failed unexpectedly" >&2
1126 test_done "$testroot" "$ret"
1127 return 1
1130 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1131 cut -d ':' -f 2 | tr -d ' ')`
1132 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1133 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
1134 >> $testroot/stdout.expected
1135 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
1136 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
1137 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1138 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1139 >> $testroot/stdout.expected
1140 echo "refs/remotes/origin/bar: $commit_id4" \
1141 >> $testroot/stdout.expected
1142 echo "refs/remotes/origin/foo: $commit_id3" \
1143 >> $testroot/stdout.expected
1144 echo "refs/remotes/origin/master: $commit_id2" \
1145 >> $testroot/stdout.expected
1147 cmp -s $testroot/stdout $testroot/stdout.expected
1148 ret="$?"
1149 if [ "$ret" != "0" ]; then
1150 diff -u $testroot/stdout.expected $testroot/stdout
1151 test_done "$testroot" "$ret"
1152 return 1
1155 git_fsck "$testroot" "$testroot/repo-clone"
1156 ret="$?"
1157 test_done "$testroot" "$ret"
1160 test_send_to_empty_repo() {
1161 local testroot=`test_init send_to_empty_repo`
1162 local testurl=ssh://127.0.0.1/$testroot
1163 local commit_id=`git_show_head $testroot/repo`
1165 got init $testroot/repo2
1167 ret="$?"
1168 if [ "$ret" != "0" ]; then
1169 echo "got clone command failed unexpectedly" >&2
1170 test_done "$testroot" "$ret"
1171 return 1
1173 cat > $testroot/repo/.git/got.conf <<EOF
1174 remote "origin" {
1175 protocol ssh
1176 server 127.0.0.1
1177 repository "$testroot/repo2"
1179 EOF
1180 echo "modified alpha" > $testroot/repo/alpha
1181 git_commit $testroot/repo -m "modified alpha"
1182 local commit_id2=`git_show_head $testroot/repo`
1184 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1185 ret="$?"
1186 if [ "$ret" != "0" ]; then
1187 echo "got send command failed unexpectedly" >&2
1188 test_done "$testroot" "$ret"
1189 return 1
1192 echo -n > $testroot/stdout.expected
1193 cmp -s $testroot/stdout $testroot/stdout.expected
1194 ret="$?"
1195 if [ "$ret" != "0" ]; then
1196 diff -u $testroot/stdout.expected $testroot/stdout
1197 test_done "$testroot" "$ret"
1198 return 1
1201 # XXX Workaround: We cannot give the target for HEAD to 'got init'
1202 got ref -r $testroot/repo2 -s refs/heads/master HEAD
1204 got ref -l -r $testroot/repo > $testroot/stdout
1205 if [ "$ret" != "0" ]; then
1206 echo "got ref command failed unexpectedly" >&2
1207 test_done "$testroot" "$ret"
1208 return 1
1211 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1212 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1213 echo "refs/remotes/origin/master: $commit_id2" \
1214 >> $testroot/stdout.expected
1216 cmp -s $testroot/stdout $testroot/stdout.expected
1217 ret="$?"
1218 if [ "$ret" != "0" ]; then
1219 diff -u $testroot/stdout.expected $testroot/stdout
1220 test_done "$testroot" "$ret"
1221 return 1
1224 got ref -l -r $testroot/repo2 > $testroot/stdout
1225 if [ "$ret" != "0" ]; then
1226 echo "got ref command failed unexpectedly" >&2
1227 test_done "$testroot" "$ret"
1228 return 1
1231 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1232 echo "refs/heads/master: $commit_id2" >> $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 send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1243 ret="$?"
1244 if [ "$ret" != "0" ]; then
1245 echo "got send command failed unexpectedly" >&2
1246 test_done "$testroot" "$ret"
1247 return 1
1250 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1251 echo "Already up-to-date" >> $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 git_fsck "$testroot" "$testroot/repo2"
1261 ret="$?"
1262 test_done "$testroot" "$ret"
1265 test_send_and_fetch_config() {
1266 local testroot=`test_init send_fetch_conf`
1267 local testurl=ssh://127.0.0.1/$testroot
1268 local commit_id=`git_show_head $testroot/repo`
1270 got clone -q $testurl/repo $testroot/repo-clone
1271 ret="$?"
1272 if [ "$ret" != "0" ]; then
1273 echo "got clone command failed unexpectedly" >&2
1274 test_done "$testroot" "$ret"
1275 return 1
1278 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1279 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1280 | tr -d ' ' | cut -d: -f2`
1282 cp -R $testroot/repo-clone $testroot/repo-clone2
1283 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1284 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1285 | tr -d ' ' | cut -d: -f2`
1287 cat > $testroot/repo/.git/got.conf <<EOF
1288 remote "origin" {
1289 protocol ssh
1290 server 127.0.0.1
1291 send {
1292 repository "$testroot/repo-clone"
1294 fetch {
1295 repository "$testroot/repo-clone2"
1298 EOF
1299 got ref -l -r $testroot/repo > $testroot/stdout
1300 if [ "$ret" != "0" ]; then
1301 echo "got ref command failed unexpectedly" >&2
1302 test_done "$testroot" "$ret"
1303 return 1
1306 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1307 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1308 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1309 cmp -s $testroot/stdout $testroot/stdout.expected
1310 ret="$?"
1311 if [ "$ret" != "0" ]; then
1312 diff -u $testroot/stdout.expected $testroot/stdout
1313 test_done "$testroot" "$ret"
1314 return 1
1317 # fetch tag 2.0 from repo-clone2
1318 got fetch -q -r $testroot/repo > $testroot/stdout
1319 ret="$?"
1320 if [ "$ret" != "0" ]; then
1321 echo "got fetch command failed unexpectedly" >&2
1322 test_done "$testroot" "$ret"
1323 return 1
1326 got ref -l -r $testroot/repo > $testroot/stdout
1327 if [ "$ret" != "0" ]; then
1328 echo "got ref command failed unexpectedly" >&2
1329 test_done "$testroot" "$ret"
1330 return 1
1333 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1334 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1335 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1336 >> $testroot/stdout.expected
1337 echo "refs/remotes/origin/master: $commit_id" \
1338 >> $testroot/stdout.expected
1339 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1340 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1341 cmp -s $testroot/stdout $testroot/stdout.expected
1342 ret="$?"
1343 if [ "$ret" != "0" ]; then
1344 diff -u $testroot/stdout.expected $testroot/stdout
1345 test_done "$testroot" "$ret"
1346 return 1
1349 # send tag 1.0 to repo-clone
1350 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1351 ret="$?"
1352 if [ "$ret" != "0" ]; then
1353 echo "got send command failed unexpectedly" >&2
1354 test_done "$testroot" "$ret"
1355 return 1
1358 got ref -l -r $testroot/repo-clone > $testroot/stdout
1359 if [ "$ret" != "0" ]; then
1360 echo "got ref command failed unexpectedly" >&2
1361 test_done "$testroot" "$ret"
1362 return 1
1365 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1366 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1367 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1368 >> $testroot/stdout.expected
1369 echo "refs/remotes/origin/master: $commit_id" \
1370 >> $testroot/stdout.expected
1371 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1373 cmp -s $testroot/stdout $testroot/stdout.expected
1374 ret="$?"
1375 if [ "$ret" != "0" ]; then
1376 diff -u $testroot/stdout.expected $testroot/stdout
1377 test_done "$testroot" "$ret"
1378 return 1
1381 git_fsck "$testroot" "$testroot/repo-clone"
1382 ret="$?"
1383 test_done "$testroot" "$ret"
1386 test_send_config() {
1387 local testroot=`test_init send_fetch_conf`
1388 local testurl=ssh://127.0.0.1/$testroot
1389 local commit_id=`git_show_head $testroot/repo`
1391 got clone -q $testurl/repo $testroot/repo-clone
1392 ret="$?"
1393 if [ "$ret" != "0" ]; then
1394 echo "got clone command failed unexpectedly" >&2
1395 test_done "$testroot" "$ret"
1396 return 1
1399 cat > $testroot/repo/.git/got.conf <<EOF
1400 remote "origin" {
1401 protocol ssh
1402 server 127.0.0.1
1403 branch foo
1404 repository "$testroot/repo-clone"
1406 EOF
1407 got ref -l -r $testroot/repo-clone > $testroot/stdout
1408 if [ "$ret" != "0" ]; then
1409 echo "got ref command failed unexpectedly" >&2
1410 test_done "$testroot" "$ret"
1411 return 1
1414 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1415 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1416 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1417 >> $testroot/stdout.expected
1418 echo "refs/remotes/origin/master: $commit_id" \
1419 >> $testroot/stdout.expected
1421 cmp -s $testroot/stdout $testroot/stdout.expected
1422 ret="$?"
1423 if [ "$ret" != "0" ]; then
1424 diff -u $testroot/stdout.expected $testroot/stdout
1425 test_done "$testroot" "$ret"
1426 return 1
1429 got branch -r $testroot/repo foo
1431 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1432 ret="$?"
1433 if [ "$ret" != "0" ]; then
1434 echo "got send command failed unexpectedly" >&2
1435 test_done "$testroot" "$ret"
1436 return 1
1439 got ref -l -r $testroot/repo-clone > $testroot/stdout
1440 if [ "$ret" != "0" ]; then
1441 echo "got ref command failed unexpectedly" >&2
1442 test_done "$testroot" "$ret"
1443 return 1
1446 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1447 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1448 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1449 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1450 >> $testroot/stdout.expected
1451 echo "refs/remotes/origin/master: $commit_id" \
1452 >> $testroot/stdout.expected
1454 cmp -s $testroot/stdout $testroot/stdout.expected
1455 ret="$?"
1456 if [ "$ret" != "0" ]; then
1457 diff -u $testroot/stdout.expected $testroot/stdout
1458 test_done "$testroot" "$ret"
1459 return 1
1462 git_fsck "$testroot" "$testroot/repo-clone"
1463 ret="$?"
1464 test_done "$testroot" "$ret"
1467 test_parseargs "$@"
1468 run_test test_send_basic
1469 run_test test_send_rebase_required
1470 run_test test_send_rebase_required_overwrite
1471 run_test test_send_delete
1472 run_test test_send_clone_and_send
1473 run_test test_send_tags
1474 run_test test_send_tag_of_deleted_branch
1475 run_test test_send_new_branch
1476 run_test test_send_all_branches
1477 run_test test_send_to_empty_repo
1478 run_test test_send_and_fetch_config
1479 run_test test_send_config