3 # Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
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.
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.
19 function test_fetch_basic {
20 local testroot=`test_init fetch_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
26 if [ "$ret" != "0" ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
32 echo "modified alpha" > $testroot/repo/alpha
33 git_commit $testroot/repo -m "modified alpha"
34 local commit_id2=`git_show_head $testroot/repo`
36 got ref -l -r $testroot/repo-clone > $testroot/stdout
37 if [ "$ret" != "0" ]; then
38 echo "got ref command failed unexpectedly" >&2
39 test_done "$testroot" "$ret"
43 got fetch -q -r $testroot/repo-clone > $testroot/stdout \
46 if [ "$ret" != "0" ]; then
47 echo "got fetch command failed unexpectedly" >&2
48 test_done "$testroot" "$ret"
52 echo -n > $testroot/stdout.expected
54 cmp -s $testroot/stdout $testroot/stdout.expected
56 if [ "$ret" != "0" ]; then
57 diff -u $testroot/stdout.expected $testroot/stdout
58 test_done "$testroot" "$ret"
62 got log -l0 -p -r $testroot/repo > $testroot/log-repo
63 if [ "$ret" != "0" ]; then
64 echo "got log command failed unexpectedly" >&2
65 test_done "$testroot" "$ret"
68 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
69 if [ "$ret" != "0" ]; then
70 echo "got log command failed unexpectedly" >&2
71 test_done "$testroot" "$ret"
74 cmp -s $testroot/log-repo $testroot/log-repo-clone
76 if [ "$ret" != "0" ]; then
77 echo "log -p output of cloned repository differs" >&2
78 test_done "$testroot" "$ret"
82 got ref -l -r $testroot/repo > $testroot/stdout
83 if [ "$ret" != "0" ]; then
84 echo "got ref command failed unexpectedly" >&2
85 test_done "$testroot" "$ret"
89 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
90 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
92 cmp -s $testroot/stdout $testroot/stdout.expected
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/stdout.expected $testroot/stdout
96 test_done "$testroot" "$ret"
100 got ref -l -r $testroot/repo-clone > $testroot/stdout
101 if [ "$ret" != "0" ]; then
102 echo "got ref command failed unexpectedly" >&2
103 test_done "$testroot" "$ret"
107 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
108 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
109 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
110 >> $testroot/stdout.expected
111 echo "refs/remotes/origin/master: $commit_id2" \
112 >> $testroot/stdout.expected
114 cmp -s $testroot/stdout $testroot/stdout.expected
116 if [ "$ret" != "0" ]; then
117 diff -u $testroot/stdout.expected $testroot/stdout
119 test_done "$testroot" "$ret"
122 function test_fetch_list {
123 local testroot=`test_init fetch_list`
124 local testurl=ssh://127.0.0.1/$testroot
125 local commit_id=`git_show_head $testroot/repo`
127 got branch -r $testroot/repo -c $commit_id foo
128 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
129 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
131 got clone -q $testurl/repo $testroot/repo-clone
133 if [ "$ret" != "0" ]; then
134 echo "got clone command failed unexpectedly" >&2
135 test_done "$testroot" "$ret"
139 (cd $testroot/repo-clone && got fetch -l \
140 > $testroot/stdout 2>$testroot/stderr)
142 if [ "$ret" != "0" ]; then
143 echo "got fetch command failed unexpectedly" >&2
144 test_done "$testroot" "$ret"
148 echo "Connected to \"origin\" 127.0.0.1" > $testroot/stdout.expected
149 got ref -l -r $testroot/repo >> $testroot/stdout.expected
151 cmp -s $testroot/stdout $testroot/stdout.expected
153 if [ "$ret" != "0" ]; then
154 diff -u $testroot/stdout.expected $testroot/stdout
156 test_done "$testroot" "$ret"
159 function test_fetch_branch {
160 local testroot=`test_init fetch_branch`
161 local testurl=ssh://127.0.0.1/$testroot
162 local commit_id=`git_show_head $testroot/repo`
164 got clone -q $testurl/repo $testroot/repo-clone
166 if [ "$ret" != "0" ]; then
167 echo "got clone command failed unexpectedly" >&2
168 test_done "$testroot" "$ret"
172 got branch -r $testroot/repo -c $commit_id foo
173 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
174 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
175 local tag_id=`got ref -r $testroot/repo -l \
176 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
178 echo "modified alpha on master" > $testroot/repo/alpha
179 git_commit $testroot/repo -m "modified alpha"
180 local commit_id2=`git_show_head $testroot/repo`
182 (cd $testroot/repo && git checkout -q foo)
183 echo "modified alpha on foo" > $testroot/repo/alpha
184 git_commit $testroot/repo -m "modified alpha"
185 local commit_id3=`git_show_head $testroot/repo`
187 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
189 if [ "$ret" != "0" ]; then
190 echo "got fetch command failed unexpectedly" >&2
191 test_done "$testroot" "$ret"
195 echo -n > $testroot/stdout.expected
197 cmp -s $testroot/stdout $testroot/stdout.expected
199 if [ "$ret" != "0" ]; then
200 diff -u $testroot/stdout.expected $testroot/stdout
201 test_done "$testroot" "$ret"
205 got ref -l -r $testroot/repo-clone > $testroot/stdout
207 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
208 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
209 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
210 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
211 >> $testroot/stdout.expected
212 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
213 # refs/remotes/origin/master is umodified because it wasn't fetched
214 echo "refs/remotes/origin/master: $commit_id" \
215 >> $testroot/stdout.expected
216 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
217 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
219 cmp -s $testroot/stdout $testroot/stdout.expected
221 if [ "$ret" != "0" ]; then
222 diff -u $testroot/stdout.expected $testroot/stdout
223 test_done "$testroot" "$ret"
227 got fetch -q -r $testroot/repo-clone -b master > $testroot/stdout
229 if [ "$ret" != "0" ]; then
230 echo "got fetch command failed unexpectedly" >&2
231 test_done "$testroot" "$ret"
235 echo -n > $testroot/stdout.expected
237 cmp -s $testroot/stdout $testroot/stdout.expected
239 if [ "$ret" != "0" ]; then
240 diff -u $testroot/stdout.expected $testroot/stdout
241 test_done "$testroot" "$ret"
245 got ref -l -r $testroot/repo-clone > $testroot/stdout
247 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
248 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
249 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
250 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
251 >> $testroot/stdout.expected
252 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
253 echo "refs/remotes/origin/master: $commit_id2" \
254 >> $testroot/stdout.expected
255 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
256 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
258 cmp -s $testroot/stdout $testroot/stdout.expected
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
263 test_done "$testroot" "$ret"
266 function test_fetch_all {
267 local testroot=`test_init fetch_all`
268 local testurl=ssh://127.0.0.1/$testroot
269 local commit_id=`git_show_head $testroot/repo`
271 got clone -q $testurl/repo $testroot/repo-clone
273 if [ "$ret" != "0" ]; then
274 echo "got clone command failed unexpectedly" >&2
275 test_done "$testroot" "$ret"
279 got branch -r $testroot/repo -c $commit_id foo
280 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
281 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
282 local tag_id=`got ref -r $testroot/repo -l \
283 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
285 got ref -l -r $testroot/repo-clone > $testroot/stdout
287 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
288 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
289 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
290 >> $testroot/stdout.expected
291 echo "refs/remotes/origin/master: $commit_id" \
292 >> $testroot/stdout.expected
293 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
295 cmp -s $testroot/stdout $testroot/stdout.expected
297 if [ "$ret" != "0" ]; then
298 diff -u $testroot/stdout.expected $testroot/stdout
299 test_done "$testroot" "$ret"
303 got fetch -q -a -r $testroot/repo-clone
305 if [ "$ret" != "0" ]; then
306 echo "got fetch command failed unexpectedly" >&2
307 test_done "$testroot" "$ret"
311 got ref -l -r $testroot/repo-clone > $testroot/stdout
313 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
314 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
315 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
316 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
317 >> $testroot/stdout.expected
318 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
319 echo "refs/remotes/origin/master: $commit_id" \
320 >> $testroot/stdout.expected
321 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
322 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
324 cmp -s $testroot/stdout $testroot/stdout.expected
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
329 test_done "$testroot" "$ret"
332 function test_fetch_empty_packfile {
333 local testroot=`test_init fetch_empty_packfile`
334 local testurl=ssh://127.0.0.1/$testroot
335 local commit_id=`git_show_head $testroot/repo`
337 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
338 local tag_id=`got ref -r $testroot/repo -l \
339 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
341 got clone -q $testurl/repo $testroot/repo-clone
343 if [ "$ret" != "0" ]; then
344 echo "got clone command failed unexpectedly" >&2
345 test_done "$testroot" "$ret"
349 got branch -r $testroot/repo -c $commit_id foo
350 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
352 got ref -l -r $testroot/repo-clone > $testroot/stdout
354 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
355 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
356 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
357 >> $testroot/stdout.expected
358 echo "refs/remotes/origin/master: $commit_id" \
359 >> $testroot/stdout.expected
360 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
361 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
363 cmp -s $testroot/stdout $testroot/stdout.expected
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/stdout.expected $testroot/stdout
367 test_done "$testroot" "$ret"
371 got fetch -q -a -r $testroot/repo-clone
373 if [ "$ret" != "0" ]; then
374 echo "got fetch command failed unexpectedly" >&2
375 test_done "$testroot" "$ret"
379 got ref -l -r $testroot/repo-clone > $testroot/stdout
381 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
382 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
383 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
384 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
385 >> $testroot/stdout.expected
386 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
387 echo "refs/remotes/origin/master: $commit_id" \
388 >> $testroot/stdout.expected
389 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
390 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
392 cmp -s $testroot/stdout $testroot/stdout.expected
394 if [ "$ret" != "0" ]; then
395 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
400 function test_fetch_delete_branch {
401 local testroot=`test_init fetch_delete_branch`
402 local testurl=ssh://127.0.0.1/$testroot
403 local commit_id=`git_show_head $testroot/repo`
406 got branch -r $testroot/repo -c $commit_id foo
407 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
408 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
409 local tag_id=`got ref -r $testroot/repo -l \
410 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
412 got clone -a -q $testurl/repo $testroot/repo-clone
414 if [ "$ret" != "0" ]; then
415 echo "got clone command failed unexpectedly" >&2
416 test_done "$testroot" "$ret"
420 got ref -l -r $testroot/repo-clone > $testroot/stdout
422 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
423 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
424 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
425 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
426 >> $testroot/stdout.expected
427 echo "refs/remotes/origin/foo: $commit_id" \
428 >> $testroot/stdout.expected
429 echo "refs/remotes/origin/master: $commit_id" \
430 >> $testroot/stdout.expected
431 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
432 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
434 cmp -s $testroot/stdout $testroot/stdout.expected
436 if [ "$ret" != "0" ]; then
437 diff -u $testroot/stdout.expected $testroot/stdout
438 test_done "$testroot" "$ret"
442 got branch -r $testroot/repo -d foo
444 got fetch -q -r $testroot/repo-clone
446 if [ "$ret" != "0" ]; then
447 echo "got fetch command failed unexpectedly" >&2
448 test_done "$testroot" "$ret"
452 got ref -l -r $testroot/repo-clone > $testroot/stdout
454 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
455 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
456 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
457 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
458 >> $testroot/stdout.expected
459 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
460 echo "refs/remotes/origin/master: $commit_id" \
461 >> $testroot/stdout.expected
462 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
463 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
465 cmp -s $testroot/stdout $testroot/stdout.expected
467 if [ "$ret" != "0" ]; then
468 diff -u $testroot/stdout.expected $testroot/stdout
469 test_done "$testroot" "$ret"
473 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
475 if [ "$ret" != "0" ]; then
476 echo "got fetch command failed unexpectedly" >&2
477 test_done "$testroot" "$ret"
481 echo -n > $testroot/stdout.expected
483 cmp -s $testroot/stdout $testroot/stdout.expected
485 if [ "$ret" != "0" ]; then
486 diff -u $testroot/stdout.expected $testroot/stdout
487 test_done "$testroot" "$ret"
491 got ref -l -r $testroot/repo-clone > $testroot/stdout
493 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
494 # refs/heads/foo is now deleted
495 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
496 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
497 >> $testroot/stdout.expected
498 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
499 echo "refs/remotes/origin/master: $commit_id" \
500 >> $testroot/stdout.expected
501 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
502 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
504 cmp -s $testroot/stdout $testroot/stdout.expected
506 if [ "$ret" != "0" ]; then
507 diff -u $testroot/stdout.expected $testroot/stdout
509 test_done "$testroot" "$ret"
513 function test_fetch_update_tag {
514 local testroot=`test_init fetch_update_tag`
515 local testurl=ssh://127.0.0.1/$testroot
516 local commit_id=`git_show_head $testroot/repo`
519 got branch -r $testroot/repo -c $commit_id foo
520 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
521 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
522 local tag_id=`got ref -r $testroot/repo -l \
523 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
525 got clone -a -q $testurl/repo $testroot/repo-clone
527 if [ "$ret" != "0" ]; then
528 echo "got clone command failed unexpectedly" >&2
529 test_done "$testroot" "$ret"
533 echo "modified alpha on master" > $testroot/repo/alpha
534 git_commit $testroot/repo -m "modified alpha"
535 local commit_id2=`git_show_head $testroot/repo`
537 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
538 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
539 local tag_id2=`got ref -r $testroot/repo -l \
540 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
542 got ref -l -r $testroot/repo-clone > $testroot/stdout
544 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
545 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
546 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
547 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
548 >> $testroot/stdout.expected
549 echo "refs/remotes/origin/foo: $commit_id" \
550 >> $testroot/stdout.expected
551 echo "refs/remotes/origin/master: $commit_id" \
552 >> $testroot/stdout.expected
553 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
554 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
556 cmp -s $testroot/stdout $testroot/stdout.expected
558 if [ "$ret" != "0" ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
564 got fetch -q -r $testroot/repo-clone
566 if [ "$ret" != "0" ]; then
567 echo "got fetch command failed unexpectedly" >&2
568 test_done "$testroot" "$ret"
572 got ref -l -r $testroot/repo-clone > $testroot/stdout
574 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
575 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
576 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
577 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
578 >> $testroot/stdout.expected
579 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
580 echo "refs/remotes/origin/master: $commit_id2" \
581 >> $testroot/stdout.expected
582 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
583 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
585 cmp -s $testroot/stdout $testroot/stdout.expected
587 if [ "$ret" != "0" ]; then
588 diff -u $testroot/stdout.expected $testroot/stdout
589 test_done "$testroot" "$ret"
593 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
594 tail -n 1 > $testroot/stdout
596 if [ "$ret" != "0" ]; then
597 echo "got fetch command failed unexpectedly" >&2
598 test_done "$testroot" "$ret"
602 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
603 > $testroot/stdout.expected
605 cmp -s $testroot/stdout $testroot/stdout.expected
607 if [ "$ret" != "0" ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
613 got ref -l -r $testroot/repo-clone > $testroot/stdout
615 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
616 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
617 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
618 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
619 >> $testroot/stdout.expected
620 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
621 echo "refs/remotes/origin/master: $commit_id2" \
622 >> $testroot/stdout.expected
623 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
624 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
626 cmp -s $testroot/stdout $testroot/stdout.expected
628 if [ "$ret" != "0" ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
634 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
636 if [ "$ret" != "0" ]; then
637 echo "got fetch command failed unexpectedly" >&2
638 test_done "$testroot" "$ret"
642 echo -n > $testroot/stdout.expected
644 cmp -s $testroot/stdout $testroot/stdout.expected
646 if [ "$ret" != "0" ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 test_done "$testroot" "$ret"
652 got ref -l -r $testroot/repo-clone > $testroot/stdout
654 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
655 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
656 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
657 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
658 >> $testroot/stdout.expected
659 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
660 echo "refs/remotes/origin/master: $commit_id2" \
661 >> $testroot/stdout.expected
662 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
663 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
665 cmp -s $testroot/stdout $testroot/stdout.expected
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
670 test_done "$testroot" "$ret"
673 function test_fetch_reference {
674 local testroot=`test_init fetch_reference`
675 local testurl=ssh://127.0.0.1/$testroot
676 local commit_id=`git_show_head $testroot/repo`
678 got clone -q $testurl/repo $testroot/repo-clone
680 if [ "$ret" != "0" ]; then
681 echo "got clone command failed unexpectedly" >&2
682 test_done "$testroot" "$ret"
686 got branch -r $testroot/repo -c $commit_id foo
687 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
688 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
689 local tag_id=`got ref -r $testroot/repo -l \
690 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
692 echo "modified alpha on master" > $testroot/repo/alpha
693 git_commit $testroot/repo -m "modified alpha"
694 local commit_id2=`git_show_head $testroot/repo`
696 (cd $testroot/repo && git checkout -q foo)
697 echo "modified alpha on foo" > $testroot/repo/alpha
698 git_commit $testroot/repo -m "modified alpha"
699 local commit_id3=`git_show_head $testroot/repo`
700 (cd $testroot/repo && git checkout -q master)
702 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
703 > $testroot/stdout 2> $testroot/stderr
705 if [ "$ret" == "0" ]; then
706 echo "got fetch command succeeded unexpectedly" >&2
707 test_done "$testroot" "1"
711 echo -n > $testroot/stdout.expected
713 cmp -s $testroot/stdout $testroot/stdout.expected
715 if [ "$ret" != "0" ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 test_done "$testroot" "$ret"
721 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
722 > $testroot/stderr.expected
724 cmp -s $testroot/stderr $testroot/stderr.expected
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/stderr.expected $testroot/stderr
728 test_done "$testroot" "$ret"
732 got fetch -q -r $testroot/repo-clone -R refs/hoo
734 if [ "$ret" != "0" ]; then
735 echo "got fetch command failed unexpectedly" >&2
736 test_done "$testroot" "$ret"
740 got ref -l -r $testroot/repo-clone > $testroot/stdout
742 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
743 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
744 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
745 >> $testroot/stdout.expected
746 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
747 >> $testroot/stdout.expected
748 echo "refs/remotes/origin/master: $commit_id2" \
749 >> $testroot/stdout.expected
750 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
752 cmp -s $testroot/stdout $testroot/stdout.expected
754 if [ "$ret" != "0" ]; then
755 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
761 function test_fetch_replace_symref {
762 local testroot=`test_init fetch_replace_symref`
763 local testurl=ssh://127.0.0.1/$testroot
764 local commit_id=`git_show_head $testroot/repo`
766 got clone -m -q $testurl/repo $testroot/repo-clone
768 if [ "$ret" != "0" ]; then
769 echo "got clone command failed unexpectedly" >&2
770 test_done "$testroot" "$ret"
774 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
775 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
777 got ref -l -r $testroot/repo-clone > $testroot/stdout
779 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
780 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
781 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
783 cmp -s $testroot/stdout $testroot/stdout.expected
785 if [ "$ret" != "0" ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done "$testroot" "$ret"
791 got fetch -r $testroot/repo-clone -R refs/hoo \
792 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
794 if [ "$ret" != "0" ]; then
795 echo "got fetch command failed unexpectedly" >&2
796 test_done "$testroot" "$ret"
800 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
801 > $testroot/stdout.expected
803 cmp -s $testroot/stdout $testroot/stdout.expected
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/stdout.expected $testroot/stdout
807 test_done "$testroot" "$ret"
811 got ref -l -r $testroot/repo-clone > $testroot/stdout
813 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
814 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
815 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
817 cmp -s $testroot/stdout $testroot/stdout.expected
819 if [ "$ret" != "0" ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
822 test_done "$testroot" "$ret"
826 run_test test_fetch_basic
827 run_test test_fetch_list
828 run_test test_fetch_branch
829 run_test test_fetch_all
830 run_test test_fetch_empty_packfile
831 run_test test_fetch_delete_branch
832 run_test test_fetch_update_tag
833 run_test test_fetch_reference
834 run_test test_fetch_replace_symref