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 git_commit $testroot/repo -m "modified alpha"
44 local commit_id2=`git_show_head $testroot/repo`
46 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
47 ret="$?"
48 if [ "$ret" != "0" ]; then
49 echo "got send command failed unexpectedly" >&2
50 test_done "$testroot" "$ret"
51 return 1
52 fi
54 echo -n > $testroot/stdout.expected
55 cmp -s $testroot/stdout $testroot/stdout.expected
56 ret="$?"
57 if [ "$ret" != "0" ]; then
58 diff -u $testroot/stdout.expected $testroot/stdout
59 test_done "$testroot" "$ret"
60 return 1
61 fi
63 got ref -l -r $testroot/repo > $testroot/stdout
64 if [ "$ret" != "0" ]; then
65 echo "got ref command failed unexpectedly" >&2
66 test_done "$testroot" "$ret"
67 return 1
68 fi
70 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
71 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
72 echo "refs/remotes/origin/master: $commit_id2" \
73 >> $testroot/stdout.expected
74 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
76 cmp -s $testroot/stdout $testroot/stdout.expected
77 ret="$?"
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 got ref -l -r $testroot/repo-clone > $testroot/stdout
85 if [ "$ret" != "0" ]; then
86 echo "got ref command failed unexpectedly" >&2
87 test_done "$testroot" "$ret"
88 return 1
89 fi
91 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
92 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
93 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
94 >> $testroot/stdout.expected
95 echo "refs/remotes/origin/master: $commit_id" \
96 >> $testroot/stdout.expected
98 cmp -s $testroot/stdout $testroot/stdout.expected
99 ret="$?"
100 if [ "$ret" != "0" ]; then
101 diff -u $testroot/stdout.expected $testroot/stdout
102 test_done "$testroot" "$ret"
103 return 1
104 fi
106 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
107 ret="$?"
108 if [ "$ret" != "0" ]; then
109 echo "got send command failed unexpectedly" >&2
110 test_done "$testroot" "$ret"
111 return 1
112 fi
114 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
115 echo "Already up-to-date" >> $testroot/stdout.expected
116 cmp -s $testroot/stdout $testroot/stdout.expected
117 ret="$?"
118 if [ "$ret" != "0" ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 fi
121 test_done "$testroot" "$ret"
124 test_send_rebase_required() {
125 local testroot=`test_init send_rebase_required`
126 local testurl=ssh://127.0.0.1/$testroot
127 local commit_id=`git_show_head $testroot/repo`
129 got clone -q $testurl/repo $testroot/repo-clone
130 ret="$?"
131 if [ "$ret" != "0" ]; then
132 echo "got clone command failed unexpectedly" >&2
133 test_done "$testroot" "$ret"
134 return 1
135 fi
136 cat > $testroot/repo/.git/got.conf <<EOF
137 remote "origin" {
138 protocol ssh
139 server 127.0.0.1
140 repository "$testroot/repo-clone"
142 EOF
143 echo "modified alpha" > $testroot/repo/alpha
144 git_commit $testroot/repo -m "modified alpha"
145 local commit_id2=`git_show_head $testroot/repo`
147 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
148 echo "modified alpha, too" > $testroot/wt-clone/alpha
149 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
151 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
152 ret="$?"
153 if [ "$ret" = "0" ]; then
154 echo "got send command succeeded unexpectedly" >&2
155 test_done "$testroot" "$ret"
156 return 1
157 fi
159 echo -n > $testroot/stdout.expected
160 cmp -s $testroot/stdout $testroot/stdout.expected
161 ret="$?"
162 if [ "$ret" != "0" ]; then
163 diff -u $testroot/stdout.expected $testroot/stdout
164 test_done "$testroot" "$ret"
165 return 1
166 fi
168 echo "got: refs/heads/master: fetch and rebase required" \
169 > $testroot/stderr.expected
170 cmp -s $testroot/stderr $testroot/stderr.expected
171 ret="$?"
172 if [ "$ret" != "0" ]; then
173 diff -u $testroot/stderr.expected $testroot/stderr
174 fi
175 test_done "$testroot" "$ret"
178 test_send_rebase_required_overwrite() {
179 local testroot=`test_init send_rebase_required_overwrite`
180 local testurl=ssh://127.0.0.1/$testroot
181 local commit_id=`git_show_head $testroot/repo`
183 got clone -q $testurl/repo $testroot/repo-clone
184 ret="$?"
185 if [ "$ret" != "0" ]; then
186 echo "got clone command failed unexpectedly" >&2
187 test_done "$testroot" "$ret"
188 return 1
189 fi
190 cat > $testroot/repo/.git/got.conf <<EOF
191 remote "foobar" {
192 protocol ssh
193 server 127.0.0.1
194 repository "$testroot/repo-clone"
196 EOF
197 echo "modified alpha" > $testroot/repo/alpha
198 git_commit $testroot/repo -m "modified alpha"
199 local commit_id2=`git_show_head $testroot/repo`
201 got checkout $testroot/repo-clone $testroot/wt-clone >/dev/null
202 echo "modified alpha, too" > $testroot/wt-clone/alpha
203 (cd $testroot/wt-clone && got commit -m 'change alpha' >/dev/null)
204 local commit_id3=`git_show_head $testroot/repo-clone`
206 # non-default remote requires an explicit argument
207 got send -q -r $testroot/repo -f > $testroot/stdout \
208 2> $testroot/stderr
209 ret="$?"
210 if [ "$ret" = "0" ]; then
211 echo "got send command succeeded unexpectedly" >&2
212 test_done "$testroot" "$ret"
213 return 1
214 fi
215 echo "got: origin: remote repository not found" \
216 > $testroot/stderr.expected
217 cmp -s $testroot/stderr $testroot/stderr.expected
218 ret="$?"
219 if [ "$ret" != "0" ]; then
220 diff -u $testroot/stderr.expected $testroot/stderr
221 test_done "$testroot" "$ret"
222 return 1
223 fi
225 got send -q -r $testroot/repo -f foobar > $testroot/stdout \
226 2> $testroot/stderr
227 ret="$?"
228 if [ "$ret" != "0" ]; then
229 echo "got send command failed unexpectedly" >&2
230 test_done "$testroot" "$ret"
231 return 1
232 fi
234 echo -n > $testroot/stdout.expected
235 cmp -s $testroot/stdout $testroot/stdout.expected
236 ret="$?"
237 if [ "$ret" != "0" ]; then
238 diff -u $testroot/stdout.expected $testroot/stdout
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 got ref -l -r $testroot/repo > $testroot/stdout
244 if [ "$ret" != "0" ]; then
245 echo "got ref command failed unexpectedly" >&2
246 test_done "$testroot" "$ret"
247 return 1
248 fi
250 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
251 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
252 echo "refs/remotes/foobar/master: $commit_id2" \
253 >> $testroot/stdout.expected
255 cmp -s $testroot/stdout $testroot/stdout.expected
256 ret="$?"
257 if [ "$ret" != "0" ]; then
258 diff -u $testroot/stdout.expected $testroot/stdout
259 test_done "$testroot" "$ret"
260 return 1
261 fi
263 got ref -l -r $testroot/repo-clone > $testroot/stdout
264 if [ "$ret" != "0" ]; then
265 echo "got ref command failed unexpectedly" >&2
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 wt_uuid=`(cd $testroot/wt-clone && got info | grep 'UUID:' | \
271 cut -d ':' -f 2 | tr -d ' ')`
272 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
273 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
274 >> $testroot/stdout.expected
275 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
276 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
277 >> $testroot/stdout.expected
278 echo "refs/remotes/origin/master: $commit_id" \
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 fi
286 test_done "$testroot" "$ret"
289 test_send_delete() {
290 local testroot=`test_init send_delete`
291 local testurl=ssh://127.0.0.1/$testroot
292 local commit_id=`git_show_head $testroot/repo`
294 # branch1 exists in both repositories
295 got branch -r $testroot/repo branch1
297 got clone -a -q $testurl/repo $testroot/repo-clone
298 ret="$?"
299 if [ "$ret" != "0" ]; then
300 echo "got clone command failed unexpectedly" >&2
301 test_done "$testroot" "$ret"
302 return 1
303 fi
304 cat > $testroot/repo/.git/got.conf <<EOF
305 remote "origin" {
306 protocol ssh
307 server 127.0.0.1
308 repository "$testroot/repo-clone"
310 EOF
311 # branch2 exists only in the remote repository
312 got branch -r $testroot/repo-clone branch2
314 got ref -l -r $testroot/repo-clone > $testroot/stdout
315 if [ "$ret" != "0" ]; then
316 echo "got ref command failed unexpectedly" >&2
317 test_done "$testroot" "$ret"
318 return 1
319 fi
321 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
322 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
323 echo "refs/heads/branch2: $commit_id" >> $testroot/stdout.expected
324 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
326 # Sending changes for a branch and deleting it at the same
327 # time is not allowed.
328 got send -q -r $testroot/repo -d branch1 -b branch1 \
329 > $testroot/stdout 2> $testroot/stderr
330 ret="$?"
331 if [ "$ret" = "0" ]; then
332 echo "got send command succeeded unexpectedly" >&2
333 test_done "$testroot" "$ret"
334 return 1
335 fi
336 echo -n "got: changes on refs/heads/branch1 will be sent to server" \
337 > $testroot/stderr.expected
338 echo ": reference cannot be deleted" >> $testroot/stderr.expected
339 cmp -s $testroot/stderr $testroot/stderr.expected
340 ret="$?"
341 if [ "$ret" != "0" ]; then
342 diff -u $testroot/stderr.expected $testroot/stderr
343 test_done "$testroot" "$ret"
344 return 1
345 fi
347 got send -q -r $testroot/repo -d refs/heads/branch1 origin \
348 > $testroot/stdout 2> $testroot/stderr
349 ret="$?"
350 if [ "$ret" != "0" ]; then
351 echo "got send command failed unexpectedly" >&2
352 test_done "$testroot" "$ret"
353 return 1
354 fi
356 got send -r $testroot/repo -d refs/heads/branch2 origin \
357 > $testroot/stdout 2>$testroot/stderr
358 ret="$?"
359 if [ "$ret" != "0" ]; then
360 echo "got send command failed unexpectedly" >&2
361 test_done "$testroot" "$ret"
362 return 1
363 fi
365 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
366 echo "Server has deleted refs/heads/branch2" \
367 >> $testroot/stdout.expected
369 cmp -s $testroot/stdout $testroot/stdout.expected
370 ret="$?"
371 if [ "$ret" != "0" ]; then
372 diff -u $testroot/stdout.expected $testroot/stdout
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 # branchX exists in neither repository
378 got send -q -r $testroot/repo -d refs/heads/branchX origin \
379 > $testroot/stdout 2> $testroot/stderr
380 ret="$?"
381 if [ "$ret" = "0" ]; then
382 echo "got send command succeeded unexpectedly" >&2
383 test_done "$testroot" "$ret"
384 return 1
385 fi
386 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
387 > $testroot/stderr.expected
388 echo "repository: no such reference found" >> $testroot/stderr.expected
389 echo "got: no such reference found" >> $testroot/stderr.expected
390 cmp -s $testroot/stderr $testroot/stderr.expected
391 ret="$?"
392 if [ "$ret" != "0" ]; then
393 diff -u $testroot/stderr.expected $testroot/stderr
394 test_done "$testroot" "$ret"
395 return 1
396 fi
398 # References outside of refs/heads/ cannot be deleted with 'got send'.
399 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
400 > $testroot/stdout 2> $testroot/stderr
401 ret="$?"
402 if [ "$ret" = "0" ]; then
403 echo "got send command succeeded unexpectedly" >&2
404 test_done "$testroot" "$ret"
405 return 1
406 fi
407 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
408 > $testroot/stderr.expected
409 echo "in remote repository: no such reference found" \
410 >> $testroot/stderr.expected
411 echo "got: no such reference found" >> $testroot/stderr.expected
412 cmp -s $testroot/stderr $testroot/stderr.expected
413 ret="$?"
414 if [ "$ret" != "0" ]; then
415 diff -u $testroot/stderr.expected $testroot/stderr
416 test_done "$testroot" "$ret"
417 return 1
418 fi
420 got ref -l -r $testroot/repo > $testroot/stdout
421 if [ "$ret" != "0" ]; then
422 echo "got ref command failed unexpectedly" >&2
423 test_done "$testroot" "$ret"
424 return 1
425 fi
427 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
428 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
429 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
431 cmp -s $testroot/stdout $testroot/stdout.expected
432 ret="$?"
433 if [ "$ret" != "0" ]; then
434 diff -u $testroot/stdout.expected $testroot/stdout
435 test_done "$testroot" "$ret"
436 return 1
437 fi
439 got ref -l -r $testroot/repo-clone > $testroot/stdout
440 if [ "$ret" != "0" ]; then
441 echo "got ref command failed unexpectedly" >&2
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
447 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
448 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
449 >> $testroot/stdout.expected
450 echo "refs/remotes/origin/branch1: $commit_id" \
451 >> $testroot/stdout.expected
452 echo "refs/remotes/origin/master: $commit_id" \
453 >> $testroot/stdout.expected
455 cmp -s $testroot/stdout $testroot/stdout.expected
456 ret="$?"
457 if [ "$ret" != "0" ]; then
458 diff -u $testroot/stdout.expected $testroot/stdout
459 fi
460 test_done "$testroot" "$ret"
463 test_send_clone_and_send() {
464 local testroot=`test_init send_clone_and_send`
465 local testurl=ssh://127.0.0.1/$testroot
466 local commit_id=`git_show_head $testroot/repo`
468 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
470 got clone -q $testurl/repo $testroot/repo-clone
471 ret="$?"
472 if [ "$ret" != "0" ]; then
473 echo "got clone command failed unexpectedly" >&2
474 test_done "$testroot" "$ret"
475 return 1
476 fi
478 got checkout $testroot/repo-clone $testroot/wt >/dev/null
479 echo "modified alpha" > $testroot/wt/alpha
480 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
481 local commit_id2=`git_show_head $testroot/repo-clone`
483 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
484 ret="$?"
485 if [ "$ret" != "0" ]; then
486 echo "got send command failed unexpectedly" >&2
487 test_done "$testroot" "$ret"
488 return 1
489 fi
491 echo -n > $testroot/stdout.expected
492 cmp -s $testroot/stdout $testroot/stdout.expected
493 ret="$?"
494 if [ "$ret" != "0" ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
496 test_done "$testroot" "$ret"
497 return 1
498 fi
500 got ref -l -r $testroot/repo > $testroot/stdout
501 if [ "$ret" != "0" ]; then
502 echo "got ref command failed unexpectedly" >&2
503 test_done "$testroot" "$ret"
504 return 1
505 fi
507 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
508 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
510 cmp -s $testroot/stdout $testroot/stdout.expected
511 ret="$?"
512 if [ "$ret" != "0" ]; then
513 diff -u $testroot/stdout.expected $testroot/stdout
514 test_done "$testroot" "$ret"
515 return 1
516 fi
518 got ref -l -r $testroot/repo-clone > $testroot/stdout
519 if [ "$ret" != "0" ]; then
520 echo "got ref command failed unexpectedly" >&2
521 test_done "$testroot" "$ret"
522 return 1
523 fi
525 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
526 cut -d ':' -f 2 | tr -d ' ')`
527 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
528 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
529 >> $testroot/stdout.expected
530 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
531 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
532 >> $testroot/stdout.expected
533 echo "refs/remotes/origin/master: $commit_id2" \
534 >> $testroot/stdout.expected
536 cmp -s $testroot/stdout $testroot/stdout.expected
537 ret="$?"
538 if [ "$ret" != "0" ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 fi
541 test_done "$testroot" "$ret"
544 test_send_tags() {
545 local testroot=`test_init send_tags`
546 local testurl=ssh://127.0.0.1/$testroot
547 local commit_id=`git_show_head $testroot/repo`
549 got clone -q $testurl/repo $testroot/repo-clone
550 ret="$?"
551 if [ "$ret" != "0" ]; then
552 echo "got clone command failed unexpectedly" >&2
553 test_done "$testroot" "$ret"
554 return 1
555 fi
556 cat > $testroot/repo/.git/got.conf <<EOF
557 remote "origin" {
558 protocol ssh
559 server 127.0.0.1
560 repository "$testroot/repo-clone"
562 EOF
563 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
564 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
565 | tr -d ' ' | cut -d: -f2`
567 echo "modified alpha" > $testroot/repo/alpha
568 git_commit $testroot/repo -m "modified alpha"
569 local commit_id2=`git_show_head $testroot/repo`
571 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
572 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
573 | tr -d ' ' | cut -d: -f2`
575 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
576 ret="$?"
577 if [ "$ret" != "0" ]; then
578 echo "got send command failed unexpectedly" >&2
579 test_done "$testroot" "$ret"
580 return 1
581 fi
583 echo -n > $testroot/stdout.expected
584 cmp -s $testroot/stdout $testroot/stdout.expected
585 ret="$?"
586 if [ "$ret" != "0" ]; then
587 diff -u $testroot/stdout.expected $testroot/stdout
588 test_done "$testroot" "$ret"
589 return 1
590 fi
592 got ref -l -r $testroot/repo > $testroot/stdout
593 if [ "$ret" != "0" ]; then
594 echo "got ref command failed unexpectedly" >&2
595 test_done "$testroot" "$ret"
596 return 1
597 fi
599 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
600 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
601 echo "refs/remotes/origin/master: $commit_id2" \
602 >> $testroot/stdout.expected
603 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
604 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
606 cmp -s $testroot/stdout $testroot/stdout.expected
607 ret="$?"
608 if [ "$ret" != "0" ]; then
609 diff -u $testroot/stdout.expected $testroot/stdout
610 test_done "$testroot" "$ret"
611 return 1
612 fi
614 got ref -l -r $testroot/repo-clone > $testroot/stdout
615 if [ "$ret" != "0" ]; then
616 echo "got ref command failed unexpectedly" >&2
617 test_done "$testroot" "$ret"
618 return 1
619 fi
621 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
622 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
623 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
624 >> $testroot/stdout.expected
625 echo "refs/remotes/origin/master: $commit_id" \
626 >> $testroot/stdout.expected
627 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
628 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
630 cmp -s $testroot/stdout $testroot/stdout.expected
631 ret="$?"
632 if [ "$ret" != "0" ]; then
633 diff -u $testroot/stdout.expected $testroot/stdout
634 test_done "$testroot" "$ret"
635 return 1
636 fi
638 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
639 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
640 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
641 cmp -s $testroot/stdout $testroot/stdout.expected
642 ret="$?"
643 if [ "$ret" != "0" ]; then
644 diff -u $testroot/stdout.expected $testroot/stdout
645 test_done "$testroot" "$ret"
646 return 1
647 fi
649 # Overwriting an existing tag 'got send -f'.
650 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
651 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
652 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
653 | tr -d ' ' | cut -d: -f2`
655 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
656 2> $testroot/stderr
657 ret="$?"
658 if [ "$ret" = "0" ]; then
659 echo "got send command succeeded unexpectedly" >&2
660 test_done "$testroot" "$ret"
661 return 1
662 fi
664 echo "got: refs/tags/1.0: tag already exists on server" \
665 > $testroot/stderr.expected
666 cmp -s $testroot/stderr $testroot/stderr.expected
667 ret="$?"
668 if [ "$ret" != "0" ]; then
669 diff -u $testroot/stderr.expected $testroot/stderr
670 test_done "$testroot" "$ret"
671 return 1
672 fi
674 # attempting the same with -T should fail, too
675 got send -q -r $testroot/repo -T > $testroot/stdout \
676 2> $testroot/stderr
677 ret="$?"
678 if [ "$ret" = "0" ]; then
679 echo "got send command succeeded unexpectedly" >&2
680 test_done "$testroot" "$ret"
681 return 1
682 fi
684 echo "got: refs/tags/1.0: tag already exists on server" \
685 > $testroot/stderr.expected
686 cmp -s $testroot/stderr $testroot/stderr.expected
687 ret="$?"
688 if [ "$ret" != "0" ]; then
689 diff -u $testroot/stderr.expected $testroot/stderr
690 test_done "$testroot" "$ret"
691 return 1
692 fi
694 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
695 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
696 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
697 cmp -s $testroot/stdout $testroot/stdout.expected
698 ret="$?"
699 if [ "$ret" != "0" ]; then
700 diff -u $testroot/stdout.expected $testroot/stdout
701 test_done "$testroot" "$ret"
702 return 1
703 fi
705 # overwrite the 1.0 tag only
706 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
707 2> $testroot/stderr
708 ret="$?"
709 if [ "$ret" != "0" ]; then
710 echo "got send command failed unexpectedly" >&2
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
716 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
717 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
718 cmp -s $testroot/stdout $testroot/stdout.expected
719 ret="$?"
720 if [ "$ret" != "0" ]; then
721 diff -u $testroot/stdout.expected $testroot/stdout
722 fi
723 test_done "$testroot" "$ret"
726 test_send_new_branch() {
727 local testroot=`test_init send_new_branch`
728 local testurl=ssh://127.0.0.1/$testroot
729 local commit_id=`git_show_head $testroot/repo`
731 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
733 got clone -q $testurl/repo $testroot/repo-clone
734 ret="$?"
735 if [ "$ret" != "0" ]; then
736 echo "got clone command failed unexpectedly" >&2
737 test_done "$testroot" "$ret"
738 return 1
739 fi
741 got branch -r $testroot/repo-clone foo >/dev/null
742 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
743 echo "modified alpha" > $testroot/wt/alpha
744 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
745 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
747 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
748 ret="$?"
749 if [ "$ret" != "0" ]; then
750 echo "got send command failed unexpectedly" >&2
751 test_done "$testroot" "$ret"
752 return 1
753 fi
755 echo -n > $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 got ref -l -r $testroot/repo > $testroot/stdout
765 if [ "$ret" != "0" ]; then
766 echo "got ref command failed unexpectedly" >&2
767 test_done "$testroot" "$ret"
768 return 1
769 fi
771 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
772 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
773 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
775 cmp -s $testroot/stdout $testroot/stdout.expected
776 ret="$?"
777 if [ "$ret" != "0" ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
779 test_done "$testroot" "$ret"
780 return 1
781 fi
783 got ref -l -r $testroot/repo-clone > $testroot/stdout
784 if [ "$ret" != "0" ]; then
785 echo "got ref command failed unexpectedly" >&2
786 test_done "$testroot" "$ret"
787 return 1
788 fi
790 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
791 cut -d ':' -f 2 | tr -d ' ')`
792 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
793 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
794 >> $testroot/stdout.expected
795 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
796 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
797 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
798 >> $testroot/stdout.expected
799 echo "refs/remotes/origin/foo: $commit_id2" \
800 >> $testroot/stdout.expected
801 echo "refs/remotes/origin/master: $commit_id" \
802 >> $testroot/stdout.expected
804 cmp -s $testroot/stdout $testroot/stdout.expected
805 ret="$?"
806 if [ "$ret" != "0" ]; then
807 diff -u $testroot/stdout.expected $testroot/stdout
808 fi
809 test_done "$testroot" "$ret"
812 test_send_all_branches() {
813 local testroot=`test_init send_all_branches`
814 local testurl=ssh://127.0.0.1/$testroot
815 local commit_id=`git_show_head $testroot/repo`
817 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
819 got clone -q $testurl/repo $testroot/repo-clone
820 ret="$?"
821 if [ "$ret" != "0" ]; then
822 echo "got clone command failed unexpectedly" >&2
823 test_done "$testroot" "$ret"
824 return 1
825 fi
827 got checkout $testroot/repo-clone $testroot/wt >/dev/null
828 echo "modified alpha" > $testroot/wt/alpha
829 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
830 local commit_id2=`git_show_head $testroot/repo-clone`
832 got branch -r $testroot/repo-clone foo >/dev/null
833 (cd $testroot/wt && got update -b foo >/dev/null)
834 echo "modified beta on new branch foo" > $testroot/wt/beta
835 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
836 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
838 got branch -r $testroot/repo-clone bar >/dev/null
839 (cd $testroot/wt && got update -b bar >/dev/null)
840 echo "modified beta again on new branch bar" > $testroot/wt/beta
841 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
842 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
844 got ref -l -r $testroot/repo-clone > $testroot/stdout
845 if [ "$ret" != "0" ]; then
846 echo "got ref command failed unexpectedly" >&2
847 test_done "$testroot" "$ret"
848 return 1
849 fi
851 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
852 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
853 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
854 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
856 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
857 2> $testroot/stderr
858 ret="$?"
859 if [ "$ret" = "0" ]; then
860 echo "got send command succeeded unexpectedly" >&2
861 test_done "$testroot" "$ret"
862 return 1
863 fi
864 echo "got: -a and -b options are mutually exclusive" \
865 > $testroot/stderr.expected
866 cmp -s $testroot/stderr $testroot/stderr.expected
867 ret="$?"
868 if [ "$ret" != "0" ]; then
869 diff -u $testroot/stderr.expected $testroot/stderr
870 test_done "$testroot" "$ret"
871 return 1
872 fi
874 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
875 2> $testroot/stderr
876 ret="$?"
877 if [ "$ret" != "0" ]; then
878 echo "got send command failed unexpectedly" >&2
879 test_done "$testroot" "$ret"
880 return 1
881 fi
883 echo -n > $testroot/stdout.expected
884 cmp -s $testroot/stdout $testroot/stdout.expected
885 ret="$?"
886 if [ "$ret" != "0" ]; then
887 diff -u $testroot/stdout.expected $testroot/stdout
888 test_done "$testroot" "$ret"
889 return 1
890 fi
892 got ref -l -r $testroot/repo > $testroot/stdout
893 if [ "$ret" != "0" ]; then
894 echo "got ref command failed unexpectedly" >&2
895 test_done "$testroot" "$ret"
896 return 1
897 fi
899 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
900 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
901 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
902 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
904 cmp -s $testroot/stdout $testroot/stdout.expected
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 test_done "$testroot" "$ret"
909 return 1
910 fi
912 got ref -l -r $testroot/repo-clone > $testroot/stdout
913 if [ "$ret" != "0" ]; then
914 echo "got ref command failed unexpectedly" >&2
915 test_done "$testroot" "$ret"
916 return 1
917 fi
919 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
920 cut -d ':' -f 2 | tr -d ' ')`
921 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
922 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
923 >> $testroot/stdout.expected
924 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
925 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
926 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
927 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
928 >> $testroot/stdout.expected
929 echo "refs/remotes/origin/bar: $commit_id4" \
930 >> $testroot/stdout.expected
931 echo "refs/remotes/origin/foo: $commit_id3" \
932 >> $testroot/stdout.expected
933 echo "refs/remotes/origin/master: $commit_id2" \
934 >> $testroot/stdout.expected
936 cmp -s $testroot/stdout $testroot/stdout.expected
937 ret="$?"
938 if [ "$ret" != "0" ]; then
939 diff -u $testroot/stdout.expected $testroot/stdout
940 fi
941 test_done "$testroot" "$ret"
944 test_send_to_empty_repo() {
945 local testroot=`test_init send_to_empty_repo`
946 local testurl=ssh://127.0.0.1/$testroot
947 local commit_id=`git_show_head $testroot/repo`
949 got init $testroot/repo2
951 ret="$?"
952 if [ "$ret" != "0" ]; then
953 echo "got clone command failed unexpectedly" >&2
954 test_done "$testroot" "$ret"
955 return 1
956 fi
957 cat > $testroot/repo/.git/got.conf <<EOF
958 remote "origin" {
959 protocol ssh
960 server 127.0.0.1
961 repository "$testroot/repo2"
963 EOF
964 echo "modified alpha" > $testroot/repo/alpha
965 git_commit $testroot/repo -m "modified alpha"
966 local commit_id2=`git_show_head $testroot/repo`
968 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
969 ret="$?"
970 if [ "$ret" != "0" ]; then
971 echo "got send command failed unexpectedly" >&2
972 test_done "$testroot" "$ret"
973 return 1
974 fi
976 echo -n > $testroot/stdout.expected
977 cmp -s $testroot/stdout $testroot/stdout.expected
978 ret="$?"
979 if [ "$ret" != "0" ]; then
980 diff -u $testroot/stdout.expected $testroot/stdout
981 test_done "$testroot" "$ret"
982 return 1
983 fi
985 # XXX Workaround: We cannot give the target for HEAD to 'got init'
986 got ref -r $testroot/repo2 -s refs/heads/master HEAD
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/master: $commit_id2" >> $testroot/stdout.expected
997 echo "refs/remotes/origin/master: $commit_id2" \
998 >> $testroot/stdout.expected
1000 cmp -s $testroot/stdout $testroot/stdout.expected
1001 ret="$?"
1002 if [ "$ret" != "0" ]; then
1003 diff -u $testroot/stdout.expected $testroot/stdout
1004 test_done "$testroot" "$ret"
1005 return 1
1008 got ref -l -r $testroot/repo2 > $testroot/stdout
1009 if [ "$ret" != "0" ]; then
1010 echo "got ref command failed unexpectedly" >&2
1011 test_done "$testroot" "$ret"
1012 return 1
1015 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1016 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1018 cmp -s $testroot/stdout $testroot/stdout.expected
1019 ret="$?"
1020 if [ "$ret" != "0" ]; then
1021 diff -u $testroot/stdout.expected $testroot/stdout
1022 test_done "$testroot" "$ret"
1023 return 1
1026 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1027 ret="$?"
1028 if [ "$ret" != "0" ]; then
1029 echo "got send command failed unexpectedly" >&2
1030 test_done "$testroot" "$ret"
1031 return 1
1034 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1035 echo "Already up-to-date" >> $testroot/stdout.expected
1036 cmp -s $testroot/stdout $testroot/stdout.expected
1037 ret="$?"
1038 if [ "$ret" != "0" ]; then
1039 diff -u $testroot/stdout.expected $testroot/stdout
1041 test_done "$testroot" "$ret"
1044 test_send_and_fetch_config() {
1045 local testroot=`test_init send_fetch_conf`
1046 local testurl=ssh://127.0.0.1/$testroot
1047 local commit_id=`git_show_head $testroot/repo`
1049 got clone -q $testurl/repo $testroot/repo-clone
1050 ret="$?"
1051 if [ "$ret" != "0" ]; then
1052 echo "got clone command failed unexpectedly" >&2
1053 test_done "$testroot" "$ret"
1054 return 1
1057 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
1058 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
1059 | tr -d ' ' | cut -d: -f2`
1061 cp -R $testroot/repo-clone $testroot/repo-clone2
1062 got tag -r $testroot/repo-clone2 -m '2.0' 2.0 >/dev/null
1063 tag_id2=`got ref -r $testroot/repo-clone2 -l | grep "^refs/tags/2.0" \
1064 | tr -d ' ' | cut -d: -f2`
1066 cat > $testroot/repo/.git/got.conf <<EOF
1067 remote "origin" {
1068 protocol ssh
1069 server 127.0.0.1
1070 send {
1071 repository "$testroot/repo-clone"
1073 fetch {
1074 repository "$testroot/repo-clone2"
1077 EOF
1078 got ref -l -r $testroot/repo > $testroot/stdout
1079 if [ "$ret" != "0" ]; then
1080 echo "got ref command failed unexpectedly" >&2
1081 test_done "$testroot" "$ret"
1082 return 1
1085 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1086 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1087 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1088 cmp -s $testroot/stdout $testroot/stdout.expected
1089 ret="$?"
1090 if [ "$ret" != "0" ]; then
1091 diff -u $testroot/stdout.expected $testroot/stdout
1092 test_done "$testroot" "$ret"
1093 return 1
1096 # fetch tag 2.0 from repo-clone2
1097 got fetch -q -r $testroot/repo > $testroot/stdout
1098 ret="$?"
1099 if [ "$ret" != "0" ]; then
1100 echo "got fetch command failed unexpectedly" >&2
1101 test_done "$testroot" "$ret"
1102 return 1
1105 got ref -l -r $testroot/repo > $testroot/stdout
1106 if [ "$ret" != "0" ]; then
1107 echo "got ref command failed unexpectedly" >&2
1108 test_done "$testroot" "$ret"
1109 return 1
1112 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1113 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1114 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1115 >> $testroot/stdout.expected
1116 echo "refs/remotes/origin/master: $commit_id" \
1117 >> $testroot/stdout.expected
1118 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1119 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
1120 cmp -s $testroot/stdout $testroot/stdout.expected
1121 ret="$?"
1122 if [ "$ret" != "0" ]; then
1123 diff -u $testroot/stdout.expected $testroot/stdout
1124 test_done "$testroot" "$ret"
1125 return 1
1128 # send tag 1.0 to repo-clone
1129 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout
1130 ret="$?"
1131 if [ "$ret" != "0" ]; then
1132 echo "got send command failed unexpectedly" >&2
1133 test_done "$testroot" "$ret"
1134 return 1
1137 got ref -l -r $testroot/repo-clone > $testroot/stdout
1138 if [ "$ret" != "0" ]; then
1139 echo "got ref command failed unexpectedly" >&2
1140 test_done "$testroot" "$ret"
1141 return 1
1144 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1145 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1146 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1147 >> $testroot/stdout.expected
1148 echo "refs/remotes/origin/master: $commit_id" \
1149 >> $testroot/stdout.expected
1150 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1152 cmp -s $testroot/stdout $testroot/stdout.expected
1153 ret="$?"
1154 if [ "$ret" != "0" ]; then
1155 diff -u $testroot/stdout.expected $testroot/stdout
1158 test_done "$testroot" "$ret"
1161 test_parseargs "$@"
1162 run_test test_send_basic
1163 run_test test_send_rebase_required
1164 run_test test_send_rebase_required_overwrite
1165 run_test test_send_delete
1166 run_test test_send_clone_and_send
1167 run_test test_send_tags
1168 run_test test_send_new_branch
1169 run_test test_send_all_branches
1170 run_test test_send_to_empty_repo
1171 run_test test_send_and_fetch_config