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/master: $commit_id2" \
110 >> $testroot/stdout.expected
112 cmp -s $testroot/stdout $testroot/stdout.expected
114 if [ "$ret" != "0" ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
117 test_done "$testroot" "$ret"
120 function test_fetch_list {
121 local testroot=`test_init fetch_list`
122 local testurl=ssh://127.0.0.1/$testroot
123 local commit_id=`git_show_head $testroot/repo`
125 got branch -r $testroot/repo -c $commit_id foo
126 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
127 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
129 got clone -q $testurl/repo $testroot/repo-clone
131 if [ "$ret" != "0" ]; then
132 echo "got clone command failed unexpectedly" >&2
133 test_done "$testroot" "$ret"
137 (cd $testroot/repo-clone && got fetch -l \
138 > $testroot/stdout 2>$testroot/stderr)
140 if [ "$ret" != "0" ]; then
141 echo "got fetch command failed unexpectedly" >&2
142 test_done "$testroot" "$ret"
146 echo "Connected to \"origin\" 127.0.0.1" > $testroot/stdout.expected
147 got ref -l -r $testroot/repo >> $testroot/stdout.expected
149 cmp -s $testroot/stdout $testroot/stdout.expected
151 if [ "$ret" != "0" ]; then
152 diff -u $testroot/stdout.expected $testroot/stdout
154 test_done "$testroot" "$ret"
157 function test_fetch_branch {
158 local testroot=`test_init fetch_branch`
159 local testurl=ssh://127.0.0.1/$testroot
160 local commit_id=`git_show_head $testroot/repo`
162 got clone -q $testurl/repo $testroot/repo-clone
164 if [ "$ret" != "0" ]; then
165 echo "got clone command failed unexpectedly" >&2
166 test_done "$testroot" "$ret"
170 got branch -r $testroot/repo -c $commit_id foo
171 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
172 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
173 local tag_id=`got ref -r $testroot/repo -l \
174 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
176 echo "modified alpha on master" > $testroot/repo/alpha
177 git_commit $testroot/repo -m "modified alpha"
178 local commit_id2=`git_show_head $testroot/repo`
180 (cd $testroot/repo && git checkout -q foo)
181 echo "modified alpha on foo" > $testroot/repo/alpha
182 git_commit $testroot/repo -m "modified alpha"
183 local commit_id3=`git_show_head $testroot/repo`
185 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
187 if [ "$ret" != "0" ]; then
188 echo "got fetch command failed unexpectedly" >&2
189 test_done "$testroot" "$ret"
193 echo -n > $testroot/stdout.expected
195 cmp -s $testroot/stdout $testroot/stdout.expected
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
203 got ref -l -r $testroot/repo-clone > $testroot/stdout
205 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
206 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
207 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
208 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
209 # refs/remotes/origin/master is umodified because it wasn't fetched
210 echo "refs/remotes/origin/master: $commit_id" \
211 >> $testroot/stdout.expected
212 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
213 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
215 cmp -s $testroot/stdout $testroot/stdout.expected
217 if [ "$ret" != "0" ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 test_done "$testroot" "$ret"
223 got fetch -q -r $testroot/repo-clone -b master > $testroot/stdout
225 if [ "$ret" != "0" ]; then
226 echo "got fetch command failed unexpectedly" >&2
227 test_done "$testroot" "$ret"
231 echo -n > $testroot/stdout.expected
233 cmp -s $testroot/stdout $testroot/stdout.expected
235 if [ "$ret" != "0" ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
237 test_done "$testroot" "$ret"
241 got ref -l -r $testroot/repo-clone > $testroot/stdout
243 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
244 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
245 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
246 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
247 echo "refs/remotes/origin/master: $commit_id2" \
248 >> $testroot/stdout.expected
249 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
250 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
252 cmp -s $testroot/stdout $testroot/stdout.expected
254 if [ "$ret" != "0" ]; then
255 diff -u $testroot/stdout.expected $testroot/stdout
257 test_done "$testroot" "$ret"
260 function test_fetch_all {
261 local testroot=`test_init fetch_all`
262 local testurl=ssh://127.0.0.1/$testroot
263 local commit_id=`git_show_head $testroot/repo`
265 got clone -q $testurl/repo $testroot/repo-clone
267 if [ "$ret" != "0" ]; then
268 echo "got clone command failed unexpectedly" >&2
269 test_done "$testroot" "$ret"
273 got branch -r $testroot/repo -c $commit_id foo
274 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
275 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
276 local tag_id=`got ref -r $testroot/repo -l \
277 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
279 got ref -l -r $testroot/repo-clone > $testroot/stdout
281 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
282 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
283 echo "refs/remotes/origin/master: $commit_id" \
284 >> $testroot/stdout.expected
285 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
287 cmp -s $testroot/stdout $testroot/stdout.expected
289 if [ "$ret" != "0" ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 test_done "$testroot" "$ret"
295 got fetch -q -a -r $testroot/repo-clone
297 if [ "$ret" != "0" ]; then
298 echo "got fetch command failed unexpectedly" >&2
299 test_done "$testroot" "$ret"
303 got ref -l -r $testroot/repo-clone > $testroot/stdout
305 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
306 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
307 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
308 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
309 echo "refs/remotes/origin/master: $commit_id" \
310 >> $testroot/stdout.expected
311 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
312 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
314 cmp -s $testroot/stdout $testroot/stdout.expected
316 if [ "$ret" != "0" ]; then
317 diff -u $testroot/stdout.expected $testroot/stdout
319 test_done "$testroot" "$ret"
322 function test_fetch_empty_packfile {
323 local testroot=`test_init fetch_empty_packfile`
324 local testurl=ssh://127.0.0.1/$testroot
325 local commit_id=`git_show_head $testroot/repo`
327 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
328 local tag_id=`got ref -r $testroot/repo -l \
329 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
331 got clone -q $testurl/repo $testroot/repo-clone
333 if [ "$ret" != "0" ]; then
334 echo "got clone command failed unexpectedly" >&2
335 test_done "$testroot" "$ret"
339 got branch -r $testroot/repo -c $commit_id foo
340 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
342 got ref -l -r $testroot/repo-clone > $testroot/stdout
344 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
345 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
346 echo "refs/remotes/origin/master: $commit_id" \
347 >> $testroot/stdout.expected
348 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
349 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
351 cmp -s $testroot/stdout $testroot/stdout.expected
353 if [ "$ret" != "0" ]; then
354 diff -u $testroot/stdout.expected $testroot/stdout
355 test_done "$testroot" "$ret"
359 got fetch -q -a -r $testroot/repo-clone
361 if [ "$ret" != "0" ]; then
362 echo "got fetch command failed unexpectedly" >&2
363 test_done "$testroot" "$ret"
367 got ref -l -r $testroot/repo-clone > $testroot/stdout
369 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
370 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
371 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
372 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
373 echo "refs/remotes/origin/master: $commit_id" \
374 >> $testroot/stdout.expected
375 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
376 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
378 cmp -s $testroot/stdout $testroot/stdout.expected
380 if [ "$ret" != "0" ]; then
381 diff -u $testroot/stdout.expected $testroot/stdout
383 test_done "$testroot" "$ret"
386 function test_fetch_delete_branch {
387 local testroot=`test_init fetch_delete_branch`
388 local testurl=ssh://127.0.0.1/$testroot
389 local commit_id=`git_show_head $testroot/repo`
392 got branch -r $testroot/repo -c $commit_id foo
393 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
394 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
395 local tag_id=`got ref -r $testroot/repo -l \
396 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
398 got clone -a -q $testurl/repo $testroot/repo-clone
400 if [ "$ret" != "0" ]; then
401 echo "got clone command failed unexpectedly" >&2
402 test_done "$testroot" "$ret"
406 got ref -l -r $testroot/repo-clone > $testroot/stdout
408 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
409 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
410 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
411 echo "refs/remotes/origin/foo: $commit_id" \
412 >> $testroot/stdout.expected
413 echo "refs/remotes/origin/master: $commit_id" \
414 >> $testroot/stdout.expected
415 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
416 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
418 cmp -s $testroot/stdout $testroot/stdout.expected
420 if [ "$ret" != "0" ]; then
421 diff -u $testroot/stdout.expected $testroot/stdout
422 test_done "$testroot" "$ret"
426 got branch -r $testroot/repo -d foo
428 got fetch -q -r $testroot/repo-clone
430 if [ "$ret" != "0" ]; then
431 echo "got fetch command failed unexpectedly" >&2
432 test_done "$testroot" "$ret"
436 got ref -l -r $testroot/repo-clone > $testroot/stdout
438 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
439 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
440 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
441 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
442 echo "refs/remotes/origin/master: $commit_id" \
443 >> $testroot/stdout.expected
444 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
445 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
447 cmp -s $testroot/stdout $testroot/stdout.expected
449 if [ "$ret" != "0" ]; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" "$ret"
455 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
457 if [ "$ret" != "0" ]; then
458 echo "got fetch command failed unexpectedly" >&2
459 test_done "$testroot" "$ret"
463 echo -n > $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 ref -l -r $testroot/repo-clone > $testroot/stdout
475 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
476 # refs/heads/foo is now deleted
477 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
478 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
479 echo "refs/remotes/origin/master: $commit_id" \
480 >> $testroot/stdout.expected
481 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
482 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
484 cmp -s $testroot/stdout $testroot/stdout.expected
486 if [ "$ret" != "0" ]; then
487 diff -u $testroot/stdout.expected $testroot/stdout
489 test_done "$testroot" "$ret"
493 function test_fetch_update_tag {
494 local testroot=`test_init fetch_update_tag`
495 local testurl=ssh://127.0.0.1/$testroot
496 local commit_id=`git_show_head $testroot/repo`
499 got branch -r $testroot/repo -c $commit_id foo
500 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
501 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
502 local tag_id=`got ref -r $testroot/repo -l \
503 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
505 got clone -a -q $testurl/repo $testroot/repo-clone
507 if [ "$ret" != "0" ]; then
508 echo "got clone command failed unexpectedly" >&2
509 test_done "$testroot" "$ret"
513 echo "modified alpha on master" > $testroot/repo/alpha
514 git_commit $testroot/repo -m "modified alpha"
515 local commit_id2=`git_show_head $testroot/repo`
517 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
518 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
519 local tag_id2=`got ref -r $testroot/repo -l \
520 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
522 got ref -l -r $testroot/repo-clone > $testroot/stdout
524 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
525 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
526 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
527 echo "refs/remotes/origin/foo: $commit_id" \
528 >> $testroot/stdout.expected
529 echo "refs/remotes/origin/master: $commit_id" \
530 >> $testroot/stdout.expected
531 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
532 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
534 cmp -s $testroot/stdout $testroot/stdout.expected
536 if [ "$ret" != "0" ]; then
537 diff -u $testroot/stdout.expected $testroot/stdout
538 test_done "$testroot" "$ret"
542 got fetch -q -r $testroot/repo-clone
544 if [ "$ret" != "0" ]; then
545 echo "got fetch command failed unexpectedly" >&2
546 test_done "$testroot" "$ret"
550 got ref -l -r $testroot/repo-clone > $testroot/stdout
552 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
553 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
554 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
555 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
556 echo "refs/remotes/origin/master: $commit_id2" \
557 >> $testroot/stdout.expected
558 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
559 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
561 cmp -s $testroot/stdout $testroot/stdout.expected
563 if [ "$ret" != "0" ]; then
564 diff -u $testroot/stdout.expected $testroot/stdout
565 test_done "$testroot" "$ret"
569 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
570 tail -n 1 > $testroot/stdout
572 if [ "$ret" != "0" ]; then
573 echo "got fetch command failed unexpectedly" >&2
574 test_done "$testroot" "$ret"
578 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
579 > $testroot/stdout.expected
581 cmp -s $testroot/stdout $testroot/stdout.expected
583 if [ "$ret" != "0" ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 test_done "$testroot" "$ret"
589 got ref -l -r $testroot/repo-clone > $testroot/stdout
591 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
592 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
593 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
594 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
595 echo "refs/remotes/origin/master: $commit_id2" \
596 >> $testroot/stdout.expected
597 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
598 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
600 cmp -s $testroot/stdout $testroot/stdout.expected
602 if [ "$ret" != "0" ]; then
603 diff -u $testroot/stdout.expected $testroot/stdout
604 test_done "$testroot" "$ret"
608 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
610 if [ "$ret" != "0" ]; then
611 echo "got fetch command failed unexpectedly" >&2
612 test_done "$testroot" "$ret"
616 echo -n > $testroot/stdout.expected
618 cmp -s $testroot/stdout $testroot/stdout.expected
620 if [ "$ret" != "0" ]; then
621 diff -u $testroot/stdout.expected $testroot/stdout
622 test_done "$testroot" "$ret"
626 got ref -l -r $testroot/repo-clone > $testroot/stdout
628 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
629 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
630 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
631 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
632 echo "refs/remotes/origin/master: $commit_id2" \
633 >> $testroot/stdout.expected
634 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
635 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
637 cmp -s $testroot/stdout $testroot/stdout.expected
639 if [ "$ret" != "0" ]; then
640 diff -u $testroot/stdout.expected $testroot/stdout
642 test_done "$testroot" "$ret"
645 function test_fetch_reference {
646 local testroot=`test_init fetch_reference`
647 local testurl=ssh://127.0.0.1/$testroot
648 local commit_id=`git_show_head $testroot/repo`
650 got clone -q $testurl/repo $testroot/repo-clone
652 if [ "$ret" != "0" ]; then
653 echo "got clone command failed unexpectedly" >&2
654 test_done "$testroot" "$ret"
658 got branch -r $testroot/repo -c $commit_id foo
659 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
660 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
661 local tag_id=`got ref -r $testroot/repo -l \
662 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
664 echo "modified alpha on master" > $testroot/repo/alpha
665 git_commit $testroot/repo -m "modified alpha"
666 local commit_id2=`git_show_head $testroot/repo`
668 (cd $testroot/repo && git checkout -q foo)
669 echo "modified alpha on foo" > $testroot/repo/alpha
670 git_commit $testroot/repo -m "modified alpha"
671 local commit_id3=`git_show_head $testroot/repo`
672 (cd $testroot/repo && git checkout -q master)
674 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
675 > $testroot/stdout 2> $testroot/stderr
677 if [ "$ret" == "0" ]; then
678 echo "got fetch command succeeded unexpectedly" >&2
679 test_done "$testroot" "1"
683 echo -n > $testroot/stdout.expected
685 cmp -s $testroot/stdout $testroot/stdout.expected
687 if [ "$ret" != "0" ]; then
688 diff -u $testroot/stdout.expected $testroot/stdout
689 test_done "$testroot" "$ret"
693 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
694 > $testroot/stderr.expected
696 cmp -s $testroot/stderr $testroot/stderr.expected
698 if [ "$ret" != "0" ]; then
699 diff -u $testroot/stderr.expected $testroot/stderr
700 test_done "$testroot" "$ret"
704 got fetch -q -r $testroot/repo-clone -R refs/hoo
706 if [ "$ret" != "0" ]; then
707 echo "got fetch command failed unexpectedly" >&2
708 test_done "$testroot" "$ret"
712 got ref -l -r $testroot/repo-clone > $testroot/stdout
714 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
715 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
716 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
717 >> $testroot/stdout.expected
718 echo "refs/remotes/origin/master: $commit_id2" \
719 >> $testroot/stdout.expected
720 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
722 cmp -s $testroot/stdout $testroot/stdout.expected
724 if [ "$ret" != "0" ]; then
725 diff -u $testroot/stdout.expected $testroot/stdout
727 test_done "$testroot" "$ret"
731 function test_fetch_replace_symref {
732 local testroot=`test_init fetch_replace_symref`
733 local testurl=ssh://127.0.0.1/$testroot
734 local commit_id=`git_show_head $testroot/repo`
736 got clone -m -q $testurl/repo $testroot/repo-clone
738 if [ "$ret" != "0" ]; then
739 echo "got clone command failed unexpectedly" >&2
740 test_done "$testroot" "$ret"
744 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
745 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
747 got ref -l -r $testroot/repo-clone > $testroot/stdout
749 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
750 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
751 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
753 cmp -s $testroot/stdout $testroot/stdout.expected
755 if [ "$ret" != "0" ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
761 got fetch -r $testroot/repo-clone -R refs/hoo \
762 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
764 if [ "$ret" != "0" ]; then
765 echo "got fetch command failed unexpectedly" >&2
766 test_done "$testroot" "$ret"
770 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
771 > $testroot/stdout.expected
773 cmp -s $testroot/stdout $testroot/stdout.expected
775 if [ "$ret" != "0" ]; then
776 diff -u $testroot/stdout.expected $testroot/stdout
777 test_done "$testroot" "$ret"
781 got ref -l -r $testroot/repo-clone > $testroot/stdout
783 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
784 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
785 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
787 cmp -s $testroot/stdout $testroot/stdout.expected
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stdout.expected $testroot/stdout
792 test_done "$testroot" "$ret"
796 run_test test_fetch_basic
797 run_test test_fetch_list
798 run_test test_fetch_branch
799 run_test test_fetch_all
800 run_test test_fetch_empty_packfile
801 run_test test_fetch_delete_branch
802 run_test test_fetch_update_tag
803 run_test test_fetch_reference
804 run_test test_fetch_replace_symref