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.raw 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
364 tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
366 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
367 echo -n "packing 0 references; 0 objects; deltify: 0%; " \
368 >> $testroot/stdout.expected
369 echo "uploading pack: 32B 100%" >> $testroot/stdout.expected
370 echo "Server has deleted refs/heads/branch2" \
371 >> $testroot/stdout.expected
373 cmp -s $testroot/stdout $testroot/stdout.expected
374 ret="$?"
375 if [ "$ret" != "0" ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
378 return 1
379 fi
381 # branchX exists in neither repository
382 got send -q -r $testroot/repo -d refs/heads/branchX origin \
383 > $testroot/stdout 2> $testroot/stderr
384 ret="$?"
385 if [ "$ret" = "0" ]; then
386 echo "got send command succeeded unexpectedly" >&2
387 test_done "$testroot" "$ret"
388 return 1
389 fi
390 echo -n "got-send-pack: refs/heads/branchX does not exist in remote " \
391 > $testroot/stderr.expected
392 echo "repository: no such reference found" >> $testroot/stderr.expected
393 echo "got: no such reference found" >> $testroot/stderr.expected
394 cmp -s $testroot/stderr $testroot/stderr.expected
395 ret="$?"
396 if [ "$ret" != "0" ]; then
397 diff -u $testroot/stderr.expected $testroot/stderr
398 test_done "$testroot" "$ret"
399 return 1
400 fi
402 # References outside of refs/heads/ cannot be deleted with 'got send'.
403 got send -q -r $testroot/repo -d refs/tags/1.0 origin \
404 > $testroot/stdout 2> $testroot/stderr
405 ret="$?"
406 if [ "$ret" = "0" ]; then
407 echo "got send command succeeded unexpectedly" >&2
408 test_done "$testroot" "$ret"
409 return 1
410 fi
411 echo -n "got-send-pack: refs/heads/refs/tags/1.0 does not exist " \
412 > $testroot/stderr.expected
413 echo "in remote repository: no such reference found" \
414 >> $testroot/stderr.expected
415 echo "got: no such reference found" >> $testroot/stderr.expected
416 cmp -s $testroot/stderr $testroot/stderr.expected
417 ret="$?"
418 if [ "$ret" != "0" ]; then
419 diff -u $testroot/stderr.expected $testroot/stderr
420 test_done "$testroot" "$ret"
421 return 1
422 fi
424 got ref -l -r $testroot/repo > $testroot/stdout
425 if [ "$ret" != "0" ]; then
426 echo "got ref command failed unexpectedly" >&2
427 test_done "$testroot" "$ret"
428 return 1
429 fi
431 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
432 echo "refs/heads/branch1: $commit_id" >> $testroot/stdout.expected
433 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
435 cmp -s $testroot/stdout $testroot/stdout.expected
436 ret="$?"
437 if [ "$ret" != "0" ]; then
438 diff -u $testroot/stdout.expected $testroot/stdout
439 test_done "$testroot" "$ret"
440 return 1
441 fi
443 got ref -l -r $testroot/repo-clone > $testroot/stdout
444 if [ "$ret" != "0" ]; then
445 echo "got ref command failed unexpectedly" >&2
446 test_done "$testroot" "$ret"
447 return 1
448 fi
450 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
451 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
452 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
453 >> $testroot/stdout.expected
454 echo "refs/remotes/origin/branch1: $commit_id" \
455 >> $testroot/stdout.expected
456 echo "refs/remotes/origin/master: $commit_id" \
457 >> $testroot/stdout.expected
459 cmp -s $testroot/stdout $testroot/stdout.expected
460 ret="$?"
461 if [ "$ret" != "0" ]; then
462 diff -u $testroot/stdout.expected $testroot/stdout
463 fi
464 test_done "$testroot" "$ret"
467 test_send_clone_and_send() {
468 local testroot=`test_init send_clone_and_send`
469 local testurl=ssh://127.0.0.1/$testroot
470 local commit_id=`git_show_head $testroot/repo`
472 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
474 got clone -q $testurl/repo $testroot/repo-clone
475 ret="$?"
476 if [ "$ret" != "0" ]; then
477 echo "got clone command failed unexpectedly" >&2
478 test_done "$testroot" "$ret"
479 return 1
480 fi
482 got checkout $testroot/repo-clone $testroot/wt >/dev/null
483 echo "modified alpha" > $testroot/wt/alpha
484 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
485 local commit_id2=`git_show_head $testroot/repo-clone`
487 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
488 ret="$?"
489 if [ "$ret" != "0" ]; then
490 echo "got send command failed unexpectedly" >&2
491 test_done "$testroot" "$ret"
492 return 1
493 fi
495 echo -n > $testroot/stdout.expected
496 cmp -s $testroot/stdout $testroot/stdout.expected
497 ret="$?"
498 if [ "$ret" != "0" ]; then
499 diff -u $testroot/stdout.expected $testroot/stdout
500 test_done "$testroot" "$ret"
501 return 1
502 fi
504 got ref -l -r $testroot/repo > $testroot/stdout
505 if [ "$ret" != "0" ]; then
506 echo "got ref command failed unexpectedly" >&2
507 test_done "$testroot" "$ret"
508 return 1
509 fi
511 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
512 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
514 cmp -s $testroot/stdout $testroot/stdout.expected
515 ret="$?"
516 if [ "$ret" != "0" ]; then
517 diff -u $testroot/stdout.expected $testroot/stdout
518 test_done "$testroot" "$ret"
519 return 1
520 fi
522 got ref -l -r $testroot/repo-clone > $testroot/stdout
523 if [ "$ret" != "0" ]; then
524 echo "got ref command failed unexpectedly" >&2
525 test_done "$testroot" "$ret"
526 return 1
527 fi
529 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
530 cut -d ':' -f 2 | tr -d ' ')`
531 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
532 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
533 >> $testroot/stdout.expected
534 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
535 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
536 >> $testroot/stdout.expected
537 echo "refs/remotes/origin/master: $commit_id2" \
538 >> $testroot/stdout.expected
540 cmp -s $testroot/stdout $testroot/stdout.expected
541 ret="$?"
542 if [ "$ret" != "0" ]; then
543 diff -u $testroot/stdout.expected $testroot/stdout
544 fi
545 test_done "$testroot" "$ret"
548 test_send_tags() {
549 local testroot=`test_init send_tags`
550 local testurl=ssh://127.0.0.1/$testroot
551 local commit_id=`git_show_head $testroot/repo`
553 got clone -q $testurl/repo $testroot/repo-clone
554 ret="$?"
555 if [ "$ret" != "0" ]; then
556 echo "got clone command failed unexpectedly" >&2
557 test_done "$testroot" "$ret"
558 return 1
559 fi
560 cat > $testroot/repo/.git/got.conf <<EOF
561 remote "origin" {
562 protocol ssh
563 server 127.0.0.1
564 repository "$testroot/repo-clone"
566 EOF
567 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
568 tag_id=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
569 | tr -d ' ' | cut -d: -f2`
571 echo "modified alpha" > $testroot/repo/alpha
572 git_commit $testroot/repo -m "modified alpha"
573 local commit_id2=`git_show_head $testroot/repo`
575 got tag -r $testroot/repo -m '2.0' 2.0 >/dev/null
576 tag_id2=`got ref -r $testroot/repo -l | grep "^refs/tags/2.0" \
577 | tr -d ' ' | cut -d: -f2`
579 got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
580 ret="$?"
581 if [ "$ret" != "0" ]; then
582 echo "got send command failed unexpectedly" >&2
583 test_done "$testroot" "$ret"
584 return 1
585 fi
587 echo -n > $testroot/stdout.expected
588 cmp -s $testroot/stdout $testroot/stdout.expected
589 ret="$?"
590 if [ "$ret" != "0" ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 got ref -l -r $testroot/repo > $testroot/stdout
597 if [ "$ret" != "0" ]; then
598 echo "got ref command failed unexpectedly" >&2
599 test_done "$testroot" "$ret"
600 return 1
601 fi
603 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
604 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
605 echo "refs/remotes/origin/master: $commit_id2" \
606 >> $testroot/stdout.expected
607 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
608 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
610 cmp -s $testroot/stdout $testroot/stdout.expected
611 ret="$?"
612 if [ "$ret" != "0" ]; then
613 diff -u $testroot/stdout.expected $testroot/stdout
614 test_done "$testroot" "$ret"
615 return 1
616 fi
618 got ref -l -r $testroot/repo-clone > $testroot/stdout
619 if [ "$ret" != "0" ]; then
620 echo "got ref command failed unexpectedly" >&2
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
626 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
627 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
628 >> $testroot/stdout.expected
629 echo "refs/remotes/origin/master: $commit_id" \
630 >> $testroot/stdout.expected
631 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
632 echo "refs/tags/2.0: $tag_id2" >> $testroot/stdout.expected
634 cmp -s $testroot/stdout $testroot/stdout.expected
635 ret="$?"
636 if [ "$ret" != "0" ]; then
637 diff -u $testroot/stdout.expected $testroot/stdout
638 test_done "$testroot" "$ret"
639 return 1
640 fi
642 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
643 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
644 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
645 cmp -s $testroot/stdout $testroot/stdout.expected
646 ret="$?"
647 if [ "$ret" != "0" ]; then
648 diff -u $testroot/stdout.expected $testroot/stdout
649 test_done "$testroot" "$ret"
650 return 1
651 fi
653 # Overwriting an existing tag 'got send -f'.
654 got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
655 got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null
656 tag_id3=`got ref -r $testroot/repo -l | grep "^refs/tags/1.0" \
657 | tr -d ' ' | cut -d: -f2`
659 got send -q -r $testroot/repo -t 1.0 > $testroot/stdout \
660 2> $testroot/stderr
661 ret="$?"
662 if [ "$ret" = "0" ]; then
663 echo "got send command succeeded unexpectedly" >&2
664 test_done "$testroot" "$ret"
665 return 1
666 fi
668 echo "got: refs/tags/1.0: tag already exists on server" \
669 > $testroot/stderr.expected
670 cmp -s $testroot/stderr $testroot/stderr.expected
671 ret="$?"
672 if [ "$ret" != "0" ]; then
673 diff -u $testroot/stderr.expected $testroot/stderr
674 test_done "$testroot" "$ret"
675 return 1
676 fi
678 # attempting the same with -T should fail, too
679 got send -q -r $testroot/repo -T > $testroot/stdout \
680 2> $testroot/stderr
681 ret="$?"
682 if [ "$ret" = "0" ]; then
683 echo "got send command succeeded unexpectedly" >&2
684 test_done "$testroot" "$ret"
685 return 1
686 fi
688 echo "got: refs/tags/1.0: tag already exists on server" \
689 > $testroot/stderr.expected
690 cmp -s $testroot/stderr $testroot/stderr.expected
691 ret="$?"
692 if [ "$ret" != "0" ]; then
693 diff -u $testroot/stderr.expected $testroot/stderr
694 test_done "$testroot" "$ret"
695 return 1
696 fi
698 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
699 echo "tag 1.0 $tag_id" > $testroot/stdout.expected
700 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
701 cmp -s $testroot/stdout $testroot/stdout.expected
702 ret="$?"
703 if [ "$ret" != "0" ]; then
704 diff -u $testroot/stdout.expected $testroot/stdout
705 test_done "$testroot" "$ret"
706 return 1
707 fi
709 # overwrite the 1.0 tag only
710 got send -q -r $testroot/repo -t 1.0 -f > $testroot/stdout \
711 2> $testroot/stderr
712 ret="$?"
713 if [ "$ret" != "0" ]; then
714 echo "got send command failed unexpectedly" >&2
715 test_done "$testroot" "$ret"
716 return 1
717 fi
719 got tag -l -r $testroot/repo-clone | grep ^tag | sort > $testroot/stdout
720 echo "tag 1.0 $tag_id3" > $testroot/stdout.expected
721 echo "tag 2.0 $tag_id2" >> $testroot/stdout.expected
722 cmp -s $testroot/stdout $testroot/stdout.expected
723 ret="$?"
724 if [ "$ret" != "0" ]; then
725 diff -u $testroot/stdout.expected $testroot/stdout
726 fi
727 test_done "$testroot" "$ret"
730 test_send_new_branch() {
731 local testroot=`test_init send_new_branch`
732 local testurl=ssh://127.0.0.1/$testroot
733 local commit_id=`git_show_head $testroot/repo`
735 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
737 got clone -q $testurl/repo $testroot/repo-clone
738 ret="$?"
739 if [ "$ret" != "0" ]; then
740 echo "got clone command failed unexpectedly" >&2
741 test_done "$testroot" "$ret"
742 return 1
743 fi
745 got branch -r $testroot/repo-clone foo >/dev/null
746 got checkout -b foo $testroot/repo-clone $testroot/wt >/dev/null
747 echo "modified alpha" > $testroot/wt/alpha
748 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
749 local commit_id2=`git_show_branch_head $testroot/repo-clone foo`
751 (cd $testroot/wt && got send -q > $testroot/stdout 2> $testroot/stderr)
752 ret="$?"
753 if [ "$ret" != "0" ]; then
754 echo "got send command failed unexpectedly" >&2
755 test_done "$testroot" "$ret"
756 return 1
757 fi
759 echo -n > $testroot/stdout.expected
760 cmp -s $testroot/stdout $testroot/stdout.expected
761 ret="$?"
762 if [ "$ret" != "0" ]; then
763 diff -u $testroot/stdout.expected $testroot/stdout
764 test_done "$testroot" "$ret"
765 return 1
766 fi
768 got ref -l -r $testroot/repo > $testroot/stdout
769 if [ "$ret" != "0" ]; then
770 echo "got ref command failed unexpectedly" >&2
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
776 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
777 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
779 cmp -s $testroot/stdout $testroot/stdout.expected
780 ret="$?"
781 if [ "$ret" != "0" ]; then
782 diff -u $testroot/stdout.expected $testroot/stdout
783 test_done "$testroot" "$ret"
784 return 1
785 fi
787 got ref -l -r $testroot/repo-clone > $testroot/stdout
788 if [ "$ret" != "0" ]; then
789 echo "got ref command failed unexpectedly" >&2
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
795 cut -d ':' -f 2 | tr -d ' ')`
796 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
797 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
798 >> $testroot/stdout.expected
799 echo "refs/heads/foo: $commit_id2" >> $testroot/stdout.expected
800 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
801 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
802 >> $testroot/stdout.expected
803 echo "refs/remotes/origin/foo: $commit_id2" \
804 >> $testroot/stdout.expected
805 echo "refs/remotes/origin/master: $commit_id" \
806 >> $testroot/stdout.expected
808 cmp -s $testroot/stdout $testroot/stdout.expected
809 ret="$?"
810 if [ "$ret" != "0" ]; then
811 diff -u $testroot/stdout.expected $testroot/stdout
812 fi
813 test_done "$testroot" "$ret"
816 test_send_all_branches() {
817 local testroot=`test_init send_all_branches`
818 local testurl=ssh://127.0.0.1/$testroot
819 local commit_id=`git_show_head $testroot/repo`
821 (cd $testroot/repo && git config receive.denyCurrentBranch ignore)
823 got clone -q $testurl/repo $testroot/repo-clone
824 ret="$?"
825 if [ "$ret" != "0" ]; then
826 echo "got clone command failed unexpectedly" >&2
827 test_done "$testroot" "$ret"
828 return 1
829 fi
831 got checkout $testroot/repo-clone $testroot/wt >/dev/null
832 echo "modified alpha" > $testroot/wt/alpha
833 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
834 local commit_id2=`git_show_head $testroot/repo-clone`
836 got branch -r $testroot/repo-clone foo >/dev/null
837 (cd $testroot/wt && got update -b foo >/dev/null)
838 echo "modified beta on new branch foo" > $testroot/wt/beta
839 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
840 local commit_id3=`git_show_branch_head $testroot/repo-clone foo`
842 got branch -r $testroot/repo-clone bar >/dev/null
843 (cd $testroot/wt && got update -b bar >/dev/null)
844 echo "modified beta again on new branch bar" > $testroot/wt/beta
845 (cd $testroot/wt && got commit -m "modified beta" >/dev/null)
846 local commit_id4=`git_show_branch_head $testroot/repo-clone bar`
848 got ref -l -r $testroot/repo-clone > $testroot/stdout
849 if [ "$ret" != "0" ]; then
850 echo "got ref command failed unexpectedly" >&2
851 test_done "$testroot" "$ret"
852 return 1
853 fi
855 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
856 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
857 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
858 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
860 got send -a -q -r $testroot/repo-clone -b master > $testroot/stdout \
861 2> $testroot/stderr
862 ret="$?"
863 if [ "$ret" = "0" ]; then
864 echo "got send command succeeded unexpectedly" >&2
865 test_done "$testroot" "$ret"
866 return 1
867 fi
868 echo "got: -a and -b options are mutually exclusive" \
869 > $testroot/stderr.expected
870 cmp -s $testroot/stderr $testroot/stderr.expected
871 ret="$?"
872 if [ "$ret" != "0" ]; then
873 diff -u $testroot/stderr.expected $testroot/stderr
874 test_done "$testroot" "$ret"
875 return 1
876 fi
878 got send -a -q -r $testroot/repo-clone > $testroot/stdout \
879 2> $testroot/stderr
880 ret="$?"
881 if [ "$ret" != "0" ]; then
882 echo "got send command failed unexpectedly" >&2
883 test_done "$testroot" "$ret"
884 return 1
885 fi
887 echo -n > $testroot/stdout.expected
888 cmp -s $testroot/stdout $testroot/stdout.expected
889 ret="$?"
890 if [ "$ret" != "0" ]; then
891 diff -u $testroot/stdout.expected $testroot/stdout
892 test_done "$testroot" "$ret"
893 return 1
894 fi
896 got ref -l -r $testroot/repo > $testroot/stdout
897 if [ "$ret" != "0" ]; then
898 echo "got ref command failed unexpectedly" >&2
899 test_done "$testroot" "$ret"
900 return 1
901 fi
903 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
904 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
905 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
906 echo "refs/heads/master: $commit_id2" >> $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 ref -l -r $testroot/repo-clone > $testroot/stdout
917 if [ "$ret" != "0" ]; then
918 echo "got ref command failed unexpectedly" >&2
919 test_done "$testroot" "$ret"
920 return 1
921 fi
923 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
924 cut -d ':' -f 2 | tr -d ' ')`
925 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
926 echo "refs/got/worktree/base-$wt_uuid: $commit_id4" \
927 >> $testroot/stdout.expected
928 echo "refs/heads/bar: $commit_id4" >> $testroot/stdout.expected
929 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
930 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
931 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
932 >> $testroot/stdout.expected
933 echo "refs/remotes/origin/bar: $commit_id4" \
934 >> $testroot/stdout.expected
935 echo "refs/remotes/origin/foo: $commit_id3" \
936 >> $testroot/stdout.expected
937 echo "refs/remotes/origin/master: $commit_id2" \
938 >> $testroot/stdout.expected
940 cmp -s $testroot/stdout $testroot/stdout.expected
941 ret="$?"
942 if [ "$ret" != "0" ]; then
943 diff -u $testroot/stdout.expected $testroot/stdout
944 fi
945 test_done "$testroot" "$ret"
948 test_send_to_empty_repo() {
949 local testroot=`test_init send_to_empty_repo`
950 local testurl=ssh://127.0.0.1/$testroot
951 local commit_id=`git_show_head $testroot/repo`
953 got init $testroot/repo2
955 ret="$?"
956 if [ "$ret" != "0" ]; then
957 echo "got clone command failed unexpectedly" >&2
958 test_done "$testroot" "$ret"
959 return 1
960 fi
961 cat > $testroot/repo/.git/got.conf <<EOF
962 remote "origin" {
963 protocol ssh
964 server 127.0.0.1
965 repository "$testroot/repo2"
967 EOF
968 echo "modified alpha" > $testroot/repo/alpha
969 git_commit $testroot/repo -m "modified alpha"
970 local commit_id2=`git_show_head $testroot/repo`
972 got send -q -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
973 ret="$?"
974 if [ "$ret" != "0" ]; then
975 echo "got send command failed unexpectedly" >&2
976 test_done "$testroot" "$ret"
977 return 1
978 fi
980 echo -n > $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 # XXX Workaround: We cannot give the target for HEAD to 'got init'
990 got ref -r $testroot/repo2 -s refs/heads/master HEAD
992 got ref -l -r $testroot/repo > $testroot/stdout
993 if [ "$ret" != "0" ]; then
994 echo "got ref command failed unexpectedly" >&2
995 test_done "$testroot" "$ret"
996 return 1
997 fi
999 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1000 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1001 echo "refs/remotes/origin/master: $commit_id2" \
1002 >> $testroot/stdout.expected
1004 cmp -s $testroot/stdout $testroot/stdout.expected
1005 ret="$?"
1006 if [ "$ret" != "0" ]; then
1007 diff -u $testroot/stdout.expected $testroot/stdout
1008 test_done "$testroot" "$ret"
1009 return 1
1012 got ref -l -r $testroot/repo2 > $testroot/stdout
1013 if [ "$ret" != "0" ]; then
1014 echo "got ref command failed unexpectedly" >&2
1015 test_done "$testroot" "$ret"
1016 return 1
1019 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1020 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
1022 cmp -s $testroot/stdout $testroot/stdout.expected
1023 ret="$?"
1024 if [ "$ret" != "0" ]; then
1025 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1027 return 1
1030 got send -r $testroot/repo > $testroot/stdout 2> $testroot/stderr
1031 ret="$?"
1032 if [ "$ret" != "0" ]; then
1033 echo "got send command failed unexpectedly" >&2
1034 test_done "$testroot" "$ret"
1035 return 1
1038 echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
1039 echo "Already up-to-date" >> $testroot/stdout.expected
1040 cmp -s $testroot/stdout $testroot/stdout.expected
1041 ret="$?"
1042 if [ "$ret" != "0" ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1045 test_done "$testroot" "$ret"
1049 test_parseargs "$@"
1050 run_test test_send_basic
1051 run_test test_send_rebase_required
1052 run_test test_send_rebase_required_overwrite
1053 run_test test_send_delete
1054 run_test test_send_clone_and_send
1055 run_test test_send_tags
1056 run_test test_send_new_branch
1057 run_test test_send_all_branches
1058 run_test test_send_to_empty_repo