Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2020 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_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
25 ret=$?
26 if [ $ret -ne 0 ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
29 return 1
30 fi
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 ret=$?
38 if [ $ret -ne 0 ]; then
39 echo "got ref command failed unexpectedly" >&2
40 test_done "$testroot" "$ret"
41 return 1
42 fi
44 got fetch -q -r $testroot/repo-clone > $testroot/stdout \
45 2> $testroot/stderr
46 ret=$?
47 if [ $ret -ne 0 ]; then
48 echo "got fetch command failed unexpectedly" >&2
49 test_done "$testroot" "$ret"
50 return 1
51 fi
53 echo -n > $testroot/stdout.expected
55 cmp -s $testroot/stdout $testroot/stdout.expected
56 ret=$?
57 if [ $ret -ne 0 ]; then
58 diff -u $testroot/stdout.expected $testroot/stdout
59 test_done "$testroot" "$ret"
60 return 1
61 fi
63 got log -l0 -p -r $testroot/repo > $testroot/log-repo
64 ret=$?
65 if [ $ret -ne 0 ]; then
66 echo "got log command failed unexpectedly" >&2
67 test_done "$testroot" "$ret"
68 return 1
69 fi
70 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
71 ret=$?
72 if [ $ret -ne 0 ]; then
73 echo "got log command failed unexpectedly" >&2
74 test_done "$testroot" "$ret"
75 return 1
76 fi
77 cmp -s $testroot/log-repo $testroot/log-repo-clone
78 ret=$?
79 if [ $ret -ne 0 ]; then
80 echo "log -p output of cloned repository differs" >&2
81 test_done "$testroot" "$ret"
82 return 1
83 fi
85 got ref -l -r $testroot/repo > $testroot/stdout
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 echo "got ref command failed unexpectedly" >&2
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
94 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
96 cmp -s $testroot/stdout $testroot/stdout.expected
97 ret=$?
98 if [ $ret -ne 0 ]; then
99 diff -u $testroot/stdout.expected $testroot/stdout
100 test_done "$testroot" "$ret"
101 return 1
102 fi
104 got ref -l -r $testroot/repo-clone > $testroot/stdout
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 echo "got ref command failed unexpectedly" >&2
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
113 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
114 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
115 >> $testroot/stdout.expected
116 echo "refs/remotes/origin/master: $commit_id2" \
117 >> $testroot/stdout.expected
119 cmp -s $testroot/stdout $testroot/stdout.expected
120 ret=$?
121 if [ $ret -ne 0 ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 fi
124 test_done "$testroot" "$ret"
127 test_fetch_list() {
128 local testroot=`test_init fetch_list`
129 local testurl=ssh://127.0.0.1/$testroot
130 local commit_id=`git_show_head $testroot/repo`
132 got branch -r $testroot/repo -c $commit_id foo
133 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
134 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
136 got clone -q $testurl/repo $testroot/repo-clone
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 echo "got clone command failed unexpectedly" >&2
140 test_done "$testroot" "$ret"
141 return 1
142 fi
144 (cd $testroot/repo-clone && got fetch -q -l \
145 > $testroot/stdout 2>$testroot/stderr)
146 ret=$?
147 if [ $ret -ne 0 ]; then
148 echo "got fetch command failed unexpectedly" >&2
149 test_done "$testroot" "$ret"
150 return 1
151 fi
153 got ref -l -r $testroot/repo > $testroot/stdout.expected
155 cmp -s $testroot/stdout $testroot/stdout.expected
156 ret=$?
157 if [ $ret -ne 0 ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 fi
160 test_done "$testroot" "$ret"
163 test_fetch_branch() {
164 local testroot=`test_init fetch_branch`
165 local testurl=ssh://127.0.0.1/$testroot
166 local commit_id=`git_show_head $testroot/repo`
168 got clone -q $testurl/repo $testroot/repo-clone
169 ret=$?
170 if [ $ret -ne 0 ]; then
171 echo "got clone command failed unexpectedly" >&2
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 got branch -r $testroot/repo -c $commit_id foo
177 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
178 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
179 local tag_id=`got ref -r $testroot/repo -l \
180 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
182 echo "modified alpha on master" > $testroot/repo/alpha
183 git_commit $testroot/repo -m "modified alpha"
184 local commit_id2=`git_show_head $testroot/repo`
186 (cd $testroot/repo && git checkout -q foo)
187 echo "modified alpha on foo" > $testroot/repo/alpha
188 git_commit $testroot/repo -m "modified alpha"
189 local commit_id3=`git_show_head $testroot/repo`
191 # foo is now the default HEAD branch in $testroot/repo
192 # but got.conf still says to fetch "master"
193 got fetch -q -r $testroot/repo-clone > $testroot/stdout
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 echo "got fetch command failed unexpectedly" >&2
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 echo -n > $testroot/stdout.expected
203 cmp -s $testroot/stdout $testroot/stdout.expected
204 ret=$?
205 if [ $ret -ne 0 ]; then
206 diff -u $testroot/stdout.expected $testroot/stdout
207 test_done "$testroot" "$ret"
208 return 1
209 fi
211 got ref -l -r $testroot/repo-clone > $testroot/stdout
213 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
214 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
215 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
216 >> $testroot/stdout.expected
217 echo "refs/remotes/origin/master: $commit_id2" \
218 >> $testroot/stdout.expected
219 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
220 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
222 cmp -s $testroot/stdout $testroot/stdout.expected
223 ret=$?
224 if [ $ret -ne 0 ]; then
225 diff -u $testroot/stdout.expected $testroot/stdout
226 test_done "$testroot" "$ret"
227 return 1
228 fi
230 # fetch branch foo via command-line switch
231 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 echo "got fetch command failed unexpectedly" >&2
235 test_done "$testroot" "$ret"
236 return 1
237 fi
239 echo -n > $testroot/stdout.expected
241 cmp -s $testroot/stdout $testroot/stdout.expected
242 ret=$?
243 if [ $ret -ne 0 ]; then
244 diff -u $testroot/stdout.expected $testroot/stdout
245 test_done "$testroot" "$ret"
246 return 1
247 fi
249 got ref -l -r $testroot/repo-clone > $testroot/stdout
251 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
252 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
253 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
254 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
255 >> $testroot/stdout.expected
256 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
257 echo "refs/remotes/origin/master: $commit_id2" \
258 >> $testroot/stdout.expected
259 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
260 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
262 cmp -s $testroot/stdout $testroot/stdout.expected
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 # got.conf tells us to fetch the 'master' branch by default
271 got fetch -q -r $testroot/repo-clone > $testroot/stdout
272 ret=$?
273 if [ $ret -ne 0 ]; then
274 echo "got fetch command failed unexpectedly" >&2
275 test_done "$testroot" "$ret"
276 return 1
277 fi
279 echo -n > $testroot/stdout.expected
281 cmp -s $testroot/stdout $testroot/stdout.expected
282 ret=$?
283 if [ $ret -ne 0 ]; then
284 diff -u $testroot/stdout.expected $testroot/stdout
285 test_done "$testroot" "$ret"
286 return 1
287 fi
289 got ref -l -r $testroot/repo-clone > $testroot/stdout
291 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
292 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
293 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
294 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
295 >> $testroot/stdout.expected
296 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
297 echo "refs/remotes/origin/master: $commit_id2" \
298 >> $testroot/stdout.expected
299 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
300 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
302 cmp -s $testroot/stdout $testroot/stdout.expected
303 ret=$?
304 if [ $ret -ne 0 ]; then
305 diff -u $testroot/stdout.expected $testroot/stdout
306 test_done "$testroot" "$ret"
307 return 1
308 fi
310 echo "modified beta on foo" > $testroot/repo/beta
311 git_commit $testroot/repo -m "modified beta"
312 local commit_id4=`git_show_head $testroot/repo`
314 # set the default HEAD branch back to master
315 (cd $testroot/repo && git checkout -q master)
317 got checkout -b foo $testroot/repo-clone $testroot/wt > /dev/null
319 # fetch new commits on branch 'foo', implicitly obtaining the
320 # branch name from a work tree
321 (cd $testroot/wt && got fetch -q > $testroot/stdout)
323 echo -n > $testroot/stdout.expected
325 cmp -s $testroot/stdout $testroot/stdout.expected
326 ret=$?
327 if [ $ret -ne 0 ]; then
328 diff -u $testroot/stdout.expected $testroot/stdout
329 test_done "$testroot" "$ret"
330 return 1
331 fi
333 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
334 cut -d ':' -f 2 | tr -d ' ')`
336 got ref -l -r $testroot/repo-clone > $testroot/stdout
338 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
339 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
340 >> $testroot/stdout.expected
341 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
342 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
343 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
344 >> $testroot/stdout.expected
345 echo "refs/remotes/origin/foo: $commit_id4" >> $testroot/stdout.expected
346 echo "refs/remotes/origin/master: $commit_id2" \
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
352 ret=$?
353 if [ $ret -ne 0 ]; then
354 diff -u $testroot/stdout.expected $testroot/stdout
355 test_done "$testroot" "$ret"
356 return 1
357 fi
359 # remove default branch information from got.conf
360 sed -i -e "/branch {/d" $testroot/repo-clone/got.conf
362 # make another change on 'foo' and fetch it without got.conf
363 (cd $testroot/repo && git checkout -q foo)
364 echo "modified beta on foo agan" > $testroot/repo/beta
365 git_commit $testroot/repo -m "modified beta"
366 local commit_id5=`git_show_head $testroot/repo`
367 (cd $testroot/repo && git checkout -q master)
369 # fetch new commits on branch 'foo', implicitly obtaining the
370 # branch name from a work tree
371 (cd $testroot/wt && got fetch -q > $testroot/stdout)
373 echo -n > $testroot/stdout.expected
375 cmp -s $testroot/stdout $testroot/stdout.expected
376 ret=$?
377 if [ $ret -ne 0 ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
384 cut -d ':' -f 2 | tr -d ' ')`
386 got ref -l -r $testroot/repo-clone > $testroot/stdout
388 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
389 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
390 >> $testroot/stdout.expected
391 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
392 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
393 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
394 >> $testroot/stdout.expected
395 echo "refs/remotes/origin/foo: $commit_id5" >> $testroot/stdout.expected
396 echo "refs/remotes/origin/master: $commit_id2" \
397 >> $testroot/stdout.expected
398 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
399 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
401 cmp -s $testroot/stdout $testroot/stdout.expected
402 ret=$?
403 if [ $ret -ne 0 ]; then
404 diff -u $testroot/stdout.expected $testroot/stdout
405 fi
406 test_done "$testroot" "$ret"
409 test_fetch_all() {
410 local testroot=`test_init fetch_all`
411 local testurl=ssh://127.0.0.1/$testroot
412 local commit_id=`git_show_head $testroot/repo`
414 got clone -q $testurl/repo $testroot/repo-clone
415 ret=$?
416 if [ $ret -ne 0 ]; then
417 echo "got clone command failed unexpectedly" >&2
418 test_done "$testroot" "$ret"
419 return 1
420 fi
422 got branch -r $testroot/repo -c $commit_id foo
423 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
424 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
425 local tag_id=`got ref -r $testroot/repo -l \
426 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
428 got ref -l -r $testroot/repo-clone > $testroot/stdout
430 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
431 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
432 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
433 >> $testroot/stdout.expected
434 echo "refs/remotes/origin/master: $commit_id" \
435 >> $testroot/stdout.expected
436 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
438 cmp -s $testroot/stdout $testroot/stdout.expected
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 got fetch -q -a -r $testroot/repo-clone
447 ret=$?
448 if [ $ret -ne 0 ]; then
449 echo "got fetch command failed unexpectedly" >&2
450 test_done "$testroot" "$ret"
451 return 1
452 fi
454 got ref -l -r $testroot/repo-clone > $testroot/stdout
456 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
457 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
458 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
459 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
460 >> $testroot/stdout.expected
461 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
462 echo "refs/remotes/origin/master: $commit_id" \
463 >> $testroot/stdout.expected
464 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
465 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
467 cmp -s $testroot/stdout $testroot/stdout.expected
468 ret=$?
469 if [ $ret -ne 0 ]; then
470 diff -u $testroot/stdout.expected $testroot/stdout
471 fi
472 test_done "$testroot" "$ret"
475 test_fetch_empty_packfile() {
476 local testroot=`test_init fetch_empty_packfile`
477 local testurl=ssh://127.0.0.1/$testroot
478 local commit_id=`git_show_head $testroot/repo`
480 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
481 local tag_id=`got ref -r $testroot/repo -l \
482 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
484 got clone -q $testurl/repo $testroot/repo-clone
485 ret=$?
486 if [ $ret -ne 0 ]; then
487 echo "got clone command failed unexpectedly" >&2
488 test_done "$testroot" "$ret"
489 return 1
490 fi
492 got branch -r $testroot/repo -c $commit_id foo
493 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
495 got ref -l -r $testroot/repo-clone > $testroot/stdout
497 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
498 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
499 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
500 >> $testroot/stdout.expected
501 echo "refs/remotes/origin/master: $commit_id" \
502 >> $testroot/stdout.expected
503 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
504 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
506 cmp -s $testroot/stdout $testroot/stdout.expected
507 ret=$?
508 if [ $ret -ne 0 ]; then
509 diff -u $testroot/stdout.expected $testroot/stdout
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 got fetch -q -a -r $testroot/repo-clone
515 ret=$?
516 if [ $ret -ne 0 ]; then
517 echo "got fetch command failed unexpectedly" >&2
518 test_done "$testroot" "$ret"
519 return 1
520 fi
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/HEAD: refs/remotes/origin/master" \
528 >> $testroot/stdout.expected
529 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
530 echo "refs/remotes/origin/master: $commit_id" \
531 >> $testroot/stdout.expected
532 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
533 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
535 cmp -s $testroot/stdout $testroot/stdout.expected
536 ret=$?
537 if [ $ret -ne 0 ]; then
538 diff -u $testroot/stdout.expected $testroot/stdout
539 fi
540 test_done "$testroot" "$ret"
543 test_fetch_delete_branch() {
544 local testroot=`test_init fetch_delete_branch`
545 local testurl=ssh://127.0.0.1/$testroot
546 local commit_id=`git_show_head $testroot/repo`
549 got branch -r $testroot/repo -c $commit_id foo
550 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
551 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
552 local tag_id=`got ref -r $testroot/repo -l \
553 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
555 got clone -a -q $testurl/repo $testroot/repo-clone
556 ret=$?
557 if [ $ret -ne 0 ]; then
558 echo "got clone command failed unexpectedly" >&2
559 test_done "$testroot" "$ret"
560 return 1
561 fi
563 got ref -l -r $testroot/repo-clone > $testroot/stdout
565 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
566 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
567 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
568 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
569 >> $testroot/stdout.expected
570 echo "refs/remotes/origin/foo: $commit_id" \
571 >> $testroot/stdout.expected
572 echo "refs/remotes/origin/master: $commit_id" \
573 >> $testroot/stdout.expected
574 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
575 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
577 cmp -s $testroot/stdout $testroot/stdout.expected
578 ret=$?
579 if [ $ret -ne 0 ]; then
580 diff -u $testroot/stdout.expected $testroot/stdout
581 test_done "$testroot" "$ret"
582 return 1
583 fi
585 got branch -r $testroot/repo -d foo >/dev/null
587 got fetch -q -r $testroot/repo-clone
588 ret=$?
589 if [ $ret -ne 0 ]; then
590 echo "got fetch command failed unexpectedly" >&2
591 test_done "$testroot" "$ret"
592 return 1
593 fi
595 got ref -l -r $testroot/repo-clone > $testroot/stdout
597 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
598 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
599 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
600 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
601 >> $testroot/stdout.expected
602 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
603 echo "refs/remotes/origin/master: $commit_id" \
604 >> $testroot/stdout.expected
605 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
606 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
608 cmp -s $testroot/stdout $testroot/stdout.expected
609 ret=$?
610 if [ $ret -ne 0 ]; then
611 diff -u $testroot/stdout.expected $testroot/stdout
612 test_done "$testroot" "$ret"
613 return 1
614 fi
616 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
617 ret=$?
618 if [ $ret -ne 0 ]; then
619 echo "got fetch command failed unexpectedly" >&2
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo -n > $testroot/stdout.expected
626 cmp -s $testroot/stdout $testroot/stdout.expected
627 ret=$?
628 if [ $ret -ne 0 ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
631 return 1
632 fi
634 got ref -l -r $testroot/repo-clone > $testroot/stdout
636 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
637 # refs/heads/foo is now deleted
638 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
639 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
640 >> $testroot/stdout.expected
641 # refs/remotes/origin/foo is now deleted
642 echo "refs/remotes/origin/master: $commit_id" \
643 >> $testroot/stdout.expected
644 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
645 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
647 cmp -s $testroot/stdout $testroot/stdout.expected
648 ret=$?
649 if [ $ret -ne 0 ]; then
650 diff -u $testroot/stdout.expected $testroot/stdout
651 fi
652 test_done "$testroot" "$ret"
656 test_fetch_delete_branch_mirror() {
657 local testroot=`test_init fetch_delete_branch_mirror`
658 local testurl=ssh://127.0.0.1/$testroot
659 local commit_id=`git_show_head $testroot/repo`
661 got branch -r $testroot/repo -c $commit_id foo
662 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
663 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
664 local tag_id=`got ref -r $testroot/repo -l \
665 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
667 got clone -a -m -q $testurl/repo $testroot/repo-clone
668 ret=$?
669 if [ $ret -ne 0 ]; then
670 echo "got clone command failed unexpectedly" >&2
671 test_done "$testroot" "$ret"
672 return 1
673 fi
675 got ref -l -r $testroot/repo-clone > $testroot/stdout
677 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
678 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
679 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
680 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
681 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
683 cmp -s $testroot/stdout $testroot/stdout.expected
684 ret=$?
685 if [ $ret -ne 0 ]; then
686 diff -u $testroot/stdout.expected $testroot/stdout
687 test_done "$testroot" "$ret"
688 return 1
689 fi
691 got branch -r $testroot/repo -d foo >/dev/null
693 got fetch -q -r $testroot/repo-clone
694 ret=$?
695 if [ $ret -ne 0 ]; then
696 echo "got fetch command failed unexpectedly" >&2
697 test_done "$testroot" "$ret"
698 return 1
699 fi
701 got ref -l -r $testroot/repo-clone > $testroot/stdout
703 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
704 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
705 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
706 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
707 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
709 cmp -s $testroot/stdout $testroot/stdout.expected
710 ret=$?
711 if [ $ret -ne 0 ]; then
712 diff -u $testroot/stdout.expected $testroot/stdout
713 test_done "$testroot" "$ret"
714 return 1
715 fi
717 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
718 ret=$?
719 if [ $ret -ne 0 ]; then
720 echo "got fetch command failed unexpectedly" >&2
721 test_done "$testroot" "$ret"
722 return 1
723 fi
725 echo -n > $testroot/stdout.expected
727 cmp -s $testroot/stdout $testroot/stdout.expected
728 ret=$?
729 if [ $ret -ne 0 ]; then
730 diff -u $testroot/stdout.expected $testroot/stdout
731 test_done "$testroot" "$ret"
732 return 1
733 fi
735 got ref -l -r $testroot/repo-clone > $testroot/stdout
737 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
738 # refs/heads/foo is now deleted
739 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
740 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
741 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
743 cmp -s $testroot/stdout $testroot/stdout.expected
744 ret=$?
745 if [ $ret -ne 0 ]; then
746 diff -u $testroot/stdout.expected $testroot/stdout
747 fi
748 test_done "$testroot" "$ret"
752 test_fetch_update_tag() {
753 local testroot=`test_init fetch_update_tag`
754 local testurl=ssh://127.0.0.1/$testroot
755 local commit_id=`git_show_head $testroot/repo`
758 got branch -r $testroot/repo -c $commit_id foo
759 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
760 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
761 local tag_id=`got ref -r $testroot/repo -l \
762 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
764 got clone -a -q $testurl/repo $testroot/repo-clone
765 ret=$?
766 if [ $ret -ne 0 ]; then
767 echo "got clone command failed unexpectedly" >&2
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 echo "modified alpha on master" > $testroot/repo/alpha
773 git_commit $testroot/repo -m "modified alpha"
774 local commit_id2=`git_show_head $testroot/repo`
776 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
777 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
778 local tag_id2=`got ref -r $testroot/repo -l \
779 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
781 got ref -l -r $testroot/repo-clone > $testroot/stdout
783 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
784 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
785 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
786 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
787 >> $testroot/stdout.expected
788 echo "refs/remotes/origin/foo: $commit_id" \
789 >> $testroot/stdout.expected
790 echo "refs/remotes/origin/master: $commit_id" \
791 >> $testroot/stdout.expected
792 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
793 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
795 cmp -s $testroot/stdout $testroot/stdout.expected
796 ret=$?
797 if [ $ret -ne 0 ]; then
798 diff -u $testroot/stdout.expected $testroot/stdout
799 test_done "$testroot" "$ret"
800 return 1
801 fi
803 got fetch -a -q -r $testroot/repo-clone
804 ret=$?
805 if [ $ret -ne 0 ]; then
806 echo "got fetch command failed unexpectedly" >&2
807 test_done "$testroot" "$ret"
808 return 1
809 fi
811 got ref -l -r $testroot/repo-clone > $testroot/stdout
813 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
814 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
815 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
816 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
817 >> $testroot/stdout.expected
818 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
819 echo "refs/remotes/origin/master: $commit_id2" \
820 >> $testroot/stdout.expected
821 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
822 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
824 cmp -s $testroot/stdout $testroot/stdout.expected
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/stdout.expected $testroot/stdout
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
833 tail -n 1 > $testroot/stdout
834 ret=$?
835 if [ $ret -ne 0 ]; then
836 echo "got fetch command failed unexpectedly" >&2
837 test_done "$testroot" "$ret"
838 return 1
839 fi
841 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
842 > $testroot/stdout.expected
844 cmp -s $testroot/stdout $testroot/stdout.expected
845 ret=$?
846 if [ $ret -ne 0 ]; then
847 diff -u $testroot/stdout.expected $testroot/stdout
848 test_done "$testroot" "$ret"
849 return 1
850 fi
852 got ref -l -r $testroot/repo-clone > $testroot/stdout
854 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
855 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
856 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
857 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
858 >> $testroot/stdout.expected
859 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
860 echo "refs/remotes/origin/master: $commit_id2" \
861 >> $testroot/stdout.expected
862 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
863 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
865 cmp -s $testroot/stdout $testroot/stdout.expected
866 ret=$?
867 if [ $ret -ne 0 ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
874 ret=$?
875 if [ $ret -ne 0 ]; then
876 echo "got fetch command failed unexpectedly" >&2
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 echo -n > $testroot/stdout.expected
883 cmp -s $testroot/stdout $testroot/stdout.expected
884 ret=$?
885 if [ $ret -ne 0 ]; then
886 diff -u $testroot/stdout.expected $testroot/stdout
887 test_done "$testroot" "$ret"
888 return 1
889 fi
891 got ref -l -r $testroot/repo-clone > $testroot/stdout
893 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
894 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
895 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
896 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
897 >> $testroot/stdout.expected
898 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
899 echo "refs/remotes/origin/master: $commit_id2" \
900 >> $testroot/stdout.expected
901 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
902 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
904 cmp -s $testroot/stdout $testroot/stdout.expected
905 ret=$?
906 if [ $ret -ne 0 ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 fi
909 test_done "$testroot" "$ret"
912 test_fetch_reference() {
913 local testroot=`test_init fetch_reference`
914 local testurl=ssh://127.0.0.1/$testroot
915 local commit_id=`git_show_head $testroot/repo`
917 got clone -q $testurl/repo $testroot/repo-clone
918 ret=$?
919 if [ $ret -ne 0 ]; then
920 echo "got clone command failed unexpectedly" >&2
921 test_done "$testroot" "$ret"
922 return 1
923 fi
925 got branch -r $testroot/repo -c $commit_id foo
926 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
927 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
928 local tag_id=`got ref -r $testroot/repo -l \
929 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
931 echo "modified alpha on master" > $testroot/repo/alpha
932 git_commit $testroot/repo -m "modified alpha"
933 local commit_id2=`git_show_head $testroot/repo`
935 (cd $testroot/repo && git checkout -q foo)
936 echo "modified alpha on foo" > $testroot/repo/alpha
937 git_commit $testroot/repo -m "modified alpha"
938 local commit_id3=`git_show_head $testroot/repo`
939 (cd $testroot/repo && git checkout -q master)
941 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
942 > $testroot/stdout 2> $testroot/stderr
943 ret=$?
944 if [ $ret -eq 0 ]; then
945 echo "got fetch command succeeded unexpectedly" >&2
946 test_done "$testroot" "1"
947 return 1
948 fi
950 echo -n > $testroot/stdout.expected
952 cmp -s $testroot/stdout $testroot/stdout.expected
953 ret=$?
954 if [ $ret -ne 0 ]; then
955 diff -u $testroot/stdout.expected $testroot/stdout
956 test_done "$testroot" "$ret"
957 return 1
958 fi
960 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
961 > $testroot/stderr.expected
963 cmp -s $testroot/stderr $testroot/stderr.expected
964 ret=$?
965 if [ $ret -ne 0 ]; then
966 diff -u $testroot/stderr.expected $testroot/stderr
967 test_done "$testroot" "$ret"
968 return 1
969 fi
971 got fetch -q -r $testroot/repo-clone -R refs/hoo
972 ret=$?
973 if [ $ret -ne 0 ]; then
974 echo "got fetch command failed unexpectedly" >&2
975 test_done "$testroot" "$ret"
976 return 1
977 fi
979 got ref -l -r $testroot/repo-clone > $testroot/stdout
981 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
982 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
983 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
984 >> $testroot/stdout.expected
985 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
986 >> $testroot/stdout.expected
987 echo "refs/remotes/origin/master: $commit_id2" \
988 >> $testroot/stdout.expected
989 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
991 cmp -s $testroot/stdout $testroot/stdout.expected
992 ret=$?
993 if [ $ret -ne 0 ]; then
994 diff -u $testroot/stdout.expected $testroot/stdout
995 fi
996 test_done "$testroot" "$ret"
1000 test_fetch_replace_symref() {
1001 local testroot=`test_init fetch_replace_symref`
1002 local testurl=ssh://127.0.0.1/$testroot
1003 local commit_id=`git_show_head $testroot/repo`
1005 got clone -m -q $testurl/repo $testroot/repo-clone
1006 ret=$?
1007 if [ $ret -ne 0 ]; then
1008 echo "got clone command failed unexpectedly" >&2
1009 test_done "$testroot" "$ret"
1010 return 1
1013 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1014 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
1016 got ref -l -r $testroot/repo-clone > $testroot/stdout
1018 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1019 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1020 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
1022 cmp -s $testroot/stdout $testroot/stdout.expected
1023 ret=$?
1024 if [ $ret -ne 0 ]; then
1025 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1027 return 1
1030 got fetch -r $testroot/repo-clone -R refs/hoo \
1031 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
1032 ret=$?
1033 if [ $ret -ne 0 ]; then
1034 echo "got fetch command failed unexpectedly" >&2
1035 test_done "$testroot" "$ret"
1036 return 1
1039 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
1040 > $testroot/stdout.expected
1042 cmp -s $testroot/stdout $testroot/stdout.expected
1043 ret=$?
1044 if [ $ret -ne 0 ]; then
1045 diff -u $testroot/stdout.expected $testroot/stdout
1046 test_done "$testroot" "$ret"
1047 return 1
1050 got ref -l -r $testroot/repo-clone > $testroot/stdout
1052 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1053 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1054 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
1056 cmp -s $testroot/stdout $testroot/stdout.expected
1057 ret=$?
1058 if [ $ret -ne 0 ]; then
1059 diff -u $testroot/stdout.expected $testroot/stdout
1061 test_done "$testroot" "$ret"
1065 test_fetch_update_headref() {
1066 local testroot=`test_init fetch_update_headref`
1067 local testurl=ssh://127.0.0.1/$testroot
1068 local commit_id=`git_show_head $testroot/repo`
1070 got clone -q $testurl/repo $testroot/repo-clone
1071 ret=$?
1072 if [ $ret -ne 0 ]; then
1073 echo "got clone command failed unexpectedly" >&2
1074 test_done "$testroot" "$ret"
1075 return 1
1078 got ref -l -r $testroot/repo-clone > $testroot/stdout
1080 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1081 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1082 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1083 >> $testroot/stdout.expected
1084 echo "refs/remotes/origin/master: $commit_id" \
1085 >> $testroot/stdout.expected
1087 cmp -s $testroot/stdout $testroot/stdout.expected
1088 ret=$?
1089 if [ $ret -ne 0 ]; then
1090 diff -u $testroot/stdout.expected $testroot/stdout
1091 test_done "$testroot" "$ret"
1092 return 1
1095 got ref -r $testroot/repo -c refs/heads/master refs/heads/foo
1096 got ref -r $testroot/repo -s refs/heads/foo HEAD
1097 got ref -l -r $testroot/repo > $testroot/stdout
1099 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
1100 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1101 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1103 cmp -s $testroot/stdout $testroot/stdout.expected
1104 ret=$?
1105 if [ $ret -ne 0 ]; then
1106 diff -u $testroot/stdout.expected $testroot/stdout
1107 test_done "$testroot" "$ret"
1108 return 1
1111 got fetch -q -r $testroot/repo-clone
1113 got ref -l -r $testroot/repo-clone > $testroot/stdout
1115 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1116 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1117 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1118 >> $testroot/stdout.expected
1119 echo "refs/remotes/origin/master: $commit_id" \
1120 >> $testroot/stdout.expected
1122 cmp -s $testroot/stdout $testroot/stdout.expected
1123 ret=$?
1124 if [ $ret -ne 0 ]; then
1125 diff -u $testroot/stdout.expected $testroot/stdout
1126 test_done "$testroot" "$ret"
1127 return 1
1130 got fetch -q -r $testroot/repo-clone -a
1132 got ref -l -r $testroot/repo-clone > $testroot/stdout
1134 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1135 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1136 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1137 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
1138 >> $testroot/stdout.expected
1139 echo "refs/remotes/origin/foo: $commit_id" \
1140 >> $testroot/stdout.expected
1141 echo "refs/remotes/origin/master: $commit_id" \
1142 >> $testroot/stdout.expected
1144 cmp -s $testroot/stdout $testroot/stdout.expected
1145 ret=$?
1146 if [ $ret -ne 0 ]; then
1147 diff -u $testroot/stdout.expected $testroot/stdout
1149 test_done "$testroot" "$ret"
1152 test_fetch_headref_deleted_locally() {
1153 local testroot=`test_init fetch_headref_deleted_locally`
1154 local testurl=ssh://127.0.0.1/$testroot
1155 local commit_id=`git_show_head $testroot/repo`
1157 got clone -q $testurl/repo $testroot/repo-clone
1158 ret=$?
1159 if [ $ret -ne 0 ]; then
1160 echo "got clone command failed unexpectedly" >&2
1161 test_done "$testroot" "$ret"
1162 return 1
1165 got ref -l -r $testroot/repo-clone > $testroot/stdout
1167 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1168 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1169 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1170 >> $testroot/stdout.expected
1171 echo "refs/remotes/origin/master: $commit_id" \
1172 >> $testroot/stdout.expected
1174 cmp -s $testroot/stdout $testroot/stdout.expected
1175 ret=$?
1176 if [ $ret -ne 0 ]; then
1177 diff -u $testroot/stdout.expected $testroot/stdout
1178 test_done "$testroot" "$ret"
1179 return 1
1182 got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD > /dev/null
1184 got fetch -q -r $testroot/repo-clone
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 echo "got fetch command failed unexpectedly" >&2
1188 test_done "$testroot" "$ret"
1189 return 1
1191 got ref -l -r $testroot/repo-clone > $testroot/stdout
1193 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1194 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1195 # refs/remotes/origin/HEAD has been restored:
1196 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1197 >> $testroot/stdout.expected
1198 echo "refs/remotes/origin/master: $commit_id" \
1199 >> $testroot/stdout.expected
1201 cmp -s $testroot/stdout $testroot/stdout.expected
1202 ret=$?
1203 if [ $ret -ne 0 ]; then
1204 diff -u $testroot/stdout.expected $testroot/stdout
1206 test_done "$testroot" "$ret"
1209 test_fetch_gotconfig_remote_repo() {
1210 local testroot=`test_init fetch_gotconfig_remote_repo`
1211 local testurl=ssh://127.0.0.1/$testroot
1212 local commit_id=`git_show_head $testroot/repo`
1214 got branch -r $testroot/repo -c $commit_id foo
1215 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1216 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
1218 got clone -q $testurl/repo $testroot/repo-clone
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 echo "got clone command failed unexpectedly" >&2
1222 test_done "$testroot" "$ret"
1223 return 1
1226 cat > $testroot/repo-clone/got.conf <<EOF
1227 remote "foobar" {
1228 protocol ssh
1229 server 127.0.0.1
1230 repository "$testroot/repo"
1233 remote "barbaz" {
1234 protocol ssh
1235 server 127.0.0.1
1236 repository "$testroot/does-not-exist"
1238 EOF
1239 echo "got: nonexistent: remote repository not found" \
1240 > $testroot/stderr.expected
1241 (cd $testroot/repo-clone && got fetch -q nonexistent \
1242 > $testroot/stdout 2> $testroot/stderr)
1243 ret=$?
1244 if [ $ret -eq 0 ]; then
1245 echo "got fetch command succeeded unexpectedly" >&2
1246 diff -u $testroot/stderr.expected $testroot/stderr
1247 test_done "$testroot" "1"
1248 return 1
1251 (cd $testroot/repo-clone && got fetch -q -l foobar \
1252 > $testroot/stdout)
1253 ret=$?
1254 if [ $ret -ne 0 ]; then
1255 echo "got fetch command failed unexpectedly" >&2
1256 test_done "$testroot" "$ret"
1257 return 1
1260 got ref -l -r $testroot/repo > $testroot/stdout.expected
1262 cmp -s $testroot/stdout $testroot/stdout.expected
1263 ret=$?
1264 if [ $ret -ne 0 ]; then
1265 diff -u $testroot/stdout.expected $testroot/stdout
1266 test_done "$testroot" "$ret"
1267 return 1
1270 got checkout $testroot/repo $testroot/wt > /dev/null
1272 cat > $testroot/wt/.got/got.conf <<EOF
1273 remote "barbaz" {
1274 protocol ssh
1275 server 127.0.0.1
1276 repository "$testroot/repo"
1278 EOF
1279 (cd $testroot/wt && got fetch -q -l barbaz > $testroot/stdout)
1280 ret=$?
1281 if [ $ret -ne 0 ]; then
1282 echo "got fetch command failed unexpectedly" >&2
1283 test_done "$testroot" "$ret"
1284 return 1
1287 got ref -l -r $testroot/repo > $testroot/stdout.expected
1289 cmp -s $testroot/stdout $testroot/stdout.expected
1290 ret=$?
1291 if [ $ret -ne 0 ]; then
1292 diff -u $testroot/stdout.expected $testroot/stdout
1293 test_done "$testroot" "$ret"
1294 return 1
1297 cat > $testroot/repo-clone/got.conf <<EOF
1298 remote "origin" {
1299 protocol ssh
1300 server 127.0.0.1
1301 repository "$testroot/repo"
1302 branch { "foo" }
1303 reference { "hoo/boo/zoo" }
1305 EOF
1306 (cd $testroot/repo-clone && got fetch -q > $testroot/stdout)
1308 local tag_id=`got ref -r $testroot/repo -l \
1309 | grep "^refs/tags/1.0" | tr -d ' ' | cut -d: -f2`
1310 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1311 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1312 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1313 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1314 >> $testroot/stdout.expected
1315 echo "refs/remotes/origin/foo: $commit_id" \
1316 >> $testroot/stdout.expected
1317 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
1318 >> $testroot/stdout.expected
1319 echo "refs/remotes/origin/master: $commit_id" \
1320 >> $testroot/stdout.expected
1321 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1323 got ref -l -r $testroot/repo-clone > $testroot/stdout
1325 cmp -s $testroot/stdout $testroot/stdout.expected
1326 ret=$?
1327 if [ $ret -ne 0 ]; then
1328 diff -u $testroot/stdout.expected $testroot/stdout
1330 test_done "$testroot" "$ret"
1333 test_fetch_delete_remote_refs() {
1334 local testroot=`test_init fetch_delete_remote_refs`
1335 local testurl=ssh://127.0.0.1/$testroot
1336 local commit_id=`git_show_head $testroot/repo`
1338 got clone -q $testurl/repo $testroot/repo-clone
1339 ret=$?
1340 if [ $ret -ne 0 ]; then
1341 echo "got clone command failed unexpectedly" >&2
1342 test_done "$testroot" "$ret"
1343 return 1
1346 got ref -l -r $testroot/repo-clone > $testroot/stdout
1347 ret=$?
1348 if [ $ret -ne 0 ]; then
1349 echo "got ref command failed unexpectedly" >&2
1350 test_done "$testroot" "$ret"
1351 return 1
1354 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1355 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1356 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1357 >> $testroot/stdout.expected
1358 echo "refs/remotes/origin/master: $commit_id" \
1359 >> $testroot/stdout.expected
1361 cmp -s $testroot/stdout $testroot/stdout.expected
1362 ret=$?
1363 if [ $ret -ne 0 ]; then
1364 diff -u $testroot/stdout.expected $testroot/stdout
1365 test_done "$testroot" "$ret"
1366 return 1
1369 got fetch -q -r $testroot/repo-clone -X > $testroot/stdout \
1370 2> $testroot/stderr
1371 ret=$?
1372 if [ $ret -eq 0 ]; then
1373 echo "got fetch command succeeded unexpectedly" >&2
1374 test_done "$testroot" "$ret"
1375 return 1
1378 echo "got: -X option requires a remote name" > $testroot/stderr.expected
1379 cmp -s $testroot/stderr $testroot/stderr.expected
1380 ret=$?
1381 if [ $ret -ne 0 ]; then
1382 diff -u $testroot/stderr.expected $testroot/stderr
1383 test_done "$testroot" "$ret"
1384 return 1
1387 got fetch -q -r $testroot/repo-clone -X origin > $testroot/stdout \
1388 2> $testroot/stderr
1389 ret=$?
1390 if [ $ret -ne 0 ]; then
1391 echo "got fetch command failed unexpectedly" >&2
1392 test_done "$testroot" "$ret"
1393 return 1
1396 echo -n "Deleted refs/remotes/origin/HEAD: " > $testroot/stdout.expected
1397 echo "refs/remotes/origin/master" >> $testroot/stdout.expected
1398 echo "Deleted refs/remotes/origin/master: $commit_id" \
1399 >> $testroot/stdout.expected
1401 cmp -s $testroot/stdout $testroot/stdout.expected
1402 ret=$?
1403 if [ $ret -ne 0 ]; then
1404 diff -u $testroot/stdout.expected $testroot/stdout
1405 test_done "$testroot" "$ret"
1406 return 1
1409 got ref -l -r $testroot/repo-clone > $testroot/stdout
1410 ret=$?
1411 if [ $ret -ne 0 ]; then
1412 echo "got ref command failed unexpectedly" >&2
1413 test_done "$testroot" "$ret"
1414 return 1
1417 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1418 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1420 cmp -s $testroot/stdout $testroot/stdout.expected
1421 ret=$?
1422 if [ $ret -ne 0 ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1425 test_done "$testroot" "$ret"
1429 test_parseargs "$@"
1430 run_test test_fetch_basic
1431 run_test test_fetch_list
1432 run_test test_fetch_branch
1433 run_test test_fetch_all
1434 run_test test_fetch_empty_packfile
1435 run_test test_fetch_delete_branch
1436 run_test test_fetch_delete_branch_mirror
1437 run_test test_fetch_update_tag
1438 run_test test_fetch_reference
1439 run_test test_fetch_replace_symref
1440 run_test test_fetch_update_headref
1441 run_test test_fetch_headref_deleted_locally
1442 run_test test_fetch_gotconfig_remote_repo
1443 run_test test_fetch_delete_remote_refs