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 and should be
192 # fetched as the clone's remote HEAD symref target no longer matches
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/foo: $commit_id3" >> $testroot/stdout.expected
215 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
216 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
217 >> $testroot/stdout.expected
218 echo "refs/remotes/origin/foo: $commit_id3" \
219 >> $testroot/stdout.expected
220 echo "refs/remotes/origin/master: $commit_id2" \
221 >> $testroot/stdout.expected
222 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
223 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
225 cmp -s $testroot/stdout $testroot/stdout.expected
226 ret=$?
227 if [ $ret -ne 0 ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
229 test_done "$testroot" "$ret"
230 return 1
231 fi
233 # fetch branch foo via command-line switch
234 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
235 ret=$?
236 if [ $ret -ne 0 ]; then
237 echo "got fetch command failed unexpectedly" >&2
238 test_done "$testroot" "$ret"
239 return 1
240 fi
242 echo -n > $testroot/stdout.expected
244 cmp -s $testroot/stdout $testroot/stdout.expected
245 ret=$?
246 if [ $ret -ne 0 ]; then
247 diff -u $testroot/stdout.expected $testroot/stdout
248 test_done "$testroot" "$ret"
249 return 1
250 fi
252 got ref -l -r $testroot/repo-clone > $testroot/stdout
254 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
255 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
256 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
257 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
258 >> $testroot/stdout.expected
259 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
260 echo "refs/remotes/origin/master: $commit_id2" \
261 >> $testroot/stdout.expected
262 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
263 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
265 cmp -s $testroot/stdout $testroot/stdout.expected
266 ret=$?
267 if [ $ret -ne 0 ]; then
268 diff -u $testroot/stdout.expected $testroot/stdout
269 test_done "$testroot" "$ret"
270 return 1
271 fi
273 # got.conf tells us to fetch the 'master' branch by default
274 got fetch -q -r $testroot/repo-clone > $testroot/stdout
275 ret=$?
276 if [ $ret -ne 0 ]; then
277 echo "got fetch command failed unexpectedly" >&2
278 test_done "$testroot" "$ret"
279 return 1
280 fi
282 echo -n > $testroot/stdout.expected
284 cmp -s $testroot/stdout $testroot/stdout.expected
285 ret=$?
286 if [ $ret -ne 0 ]; then
287 diff -u $testroot/stdout.expected $testroot/stdout
288 test_done "$testroot" "$ret"
289 return 1
290 fi
292 got ref -l -r $testroot/repo-clone > $testroot/stdout
294 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
295 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
296 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
297 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
298 >> $testroot/stdout.expected
299 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
300 echo "refs/remotes/origin/master: $commit_id2" \
301 >> $testroot/stdout.expected
302 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
303 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
305 cmp -s $testroot/stdout $testroot/stdout.expected
306 ret=$?
307 if [ $ret -ne 0 ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
310 return 1
311 fi
313 echo "modified beta on foo" > $testroot/repo/beta
314 git_commit $testroot/repo -m "modified beta"
315 local commit_id4=`git_show_head $testroot/repo`
317 # set the default HEAD branch back to master
318 (cd $testroot/repo && git checkout -q master)
320 got checkout -b foo $testroot/repo-clone $testroot/wt > /dev/null
322 # fetch new commits on branch 'foo', implicitly obtaining the
323 # branch name from a work tree
324 (cd $testroot/wt && got fetch -q > $testroot/stdout)
326 echo -n > $testroot/stdout.expected
328 cmp -s $testroot/stdout $testroot/stdout.expected
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
333 return 1
334 fi
336 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
337 cut -d ':' -f 2 | tr -d ' ')`
339 got ref -l -r $testroot/repo-clone > $testroot/stdout
341 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
342 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
343 >> $testroot/stdout.expected
344 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
345 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
346 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
347 >> $testroot/stdout.expected
348 echo "refs/remotes/origin/foo: $commit_id4" >> $testroot/stdout.expected
349 echo "refs/remotes/origin/master: $commit_id2" \
350 >> $testroot/stdout.expected
351 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
352 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
354 cmp -s $testroot/stdout $testroot/stdout.expected
355 ret=$?
356 if [ $ret -ne 0 ]; then
357 diff -u $testroot/stdout.expected $testroot/stdout
358 test_done "$testroot" "$ret"
359 return 1
360 fi
362 # remove default branch information from got.conf
363 ed -s $testroot/repo-clone/got.conf <<-EOF
364 g/branch {/d
366 EOF
368 # make another change on 'foo' and fetch it without got.conf
369 (cd $testroot/repo && git checkout -q foo)
370 echo "modified beta on foo agan" > $testroot/repo/beta
371 git_commit $testroot/repo -m "modified beta"
372 local commit_id5=`git_show_head $testroot/repo`
373 (cd $testroot/repo && git checkout -q master)
375 # fetch new commits on branch 'foo', implicitly obtaining the
376 # branch name from a work tree
377 (cd $testroot/wt && got fetch -q > $testroot/stdout)
379 echo -n > $testroot/stdout.expected
381 cmp -s $testroot/stdout $testroot/stdout.expected
382 ret=$?
383 if [ $ret -ne 0 ]; then
384 diff -u $testroot/stdout.expected $testroot/stdout
385 test_done "$testroot" "$ret"
386 return 1
387 fi
389 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
390 cut -d ':' -f 2 | tr -d ' ')`
392 got ref -l -r $testroot/repo-clone > $testroot/stdout
394 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
395 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
396 >> $testroot/stdout.expected
397 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
398 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
399 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
400 >> $testroot/stdout.expected
401 echo "refs/remotes/origin/foo: $commit_id5" >> $testroot/stdout.expected
402 echo "refs/remotes/origin/master: $commit_id2" \
403 >> $testroot/stdout.expected
404 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
405 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
407 cmp -s $testroot/stdout $testroot/stdout.expected
408 ret=$?
409 if [ $ret -ne 0 ]; then
410 diff -u $testroot/stdout.expected $testroot/stdout
411 fi
412 test_done "$testroot" "$ret"
415 test_fetch_all() {
416 local testroot=`test_init fetch_all`
417 local testurl=ssh://127.0.0.1/$testroot
418 local commit_id=`git_show_head $testroot/repo`
420 got clone -q $testurl/repo $testroot/repo-clone
421 ret=$?
422 if [ $ret -ne 0 ]; then
423 echo "got clone command failed unexpectedly" >&2
424 test_done "$testroot" "$ret"
425 return 1
426 fi
428 got branch -r $testroot/repo -c $commit_id foo
429 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
430 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
431 local tag_id=`got ref -r $testroot/repo -l \
432 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
434 got ref -l -r $testroot/repo-clone > $testroot/stdout
436 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
437 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
438 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
439 >> $testroot/stdout.expected
440 echo "refs/remotes/origin/master: $commit_id" \
441 >> $testroot/stdout.expected
442 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
444 cmp -s $testroot/stdout $testroot/stdout.expected
445 ret=$?
446 if [ $ret -ne 0 ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 got fetch -q -a -r $testroot/repo-clone
453 ret=$?
454 if [ $ret -ne 0 ]; then
455 echo "got fetch command failed unexpectedly" >&2
456 test_done "$testroot" "$ret"
457 return 1
458 fi
460 got ref -l -r $testroot/repo-clone > $testroot/stdout
462 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
463 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
464 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
465 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
466 >> $testroot/stdout.expected
467 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
468 echo "refs/remotes/origin/master: $commit_id" \
469 >> $testroot/stdout.expected
470 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
471 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
473 cmp -s $testroot/stdout $testroot/stdout.expected
474 ret=$?
475 if [ $ret -ne 0 ]; then
476 diff -u $testroot/stdout.expected $testroot/stdout
477 fi
478 test_done "$testroot" "$ret"
481 test_fetch_empty_packfile() {
482 local testroot=`test_init fetch_empty_packfile`
483 local testurl=ssh://127.0.0.1/$testroot
484 local commit_id=`git_show_head $testroot/repo`
486 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
487 local tag_id=`got ref -r $testroot/repo -l \
488 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
490 got clone -q $testurl/repo $testroot/repo-clone
491 ret=$?
492 if [ $ret -ne 0 ]; then
493 echo "got clone command failed unexpectedly" >&2
494 test_done "$testroot" "$ret"
495 return 1
496 fi
498 got branch -r $testroot/repo -c $commit_id foo
499 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
501 got ref -l -r $testroot/repo-clone > $testroot/stdout
503 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
504 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
505 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
506 >> $testroot/stdout.expected
507 echo "refs/remotes/origin/master: $commit_id" \
508 >> $testroot/stdout.expected
509 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
510 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
512 cmp -s $testroot/stdout $testroot/stdout.expected
513 ret=$?
514 if [ $ret -ne 0 ]; then
515 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 got fetch -q -a -r $testroot/repo-clone
521 ret=$?
522 if [ $ret -ne 0 ]; then
523 echo "got fetch command failed unexpectedly" >&2
524 test_done "$testroot" "$ret"
525 return 1
526 fi
528 got ref -l -r $testroot/repo-clone > $testroot/stdout
530 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
531 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
532 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
533 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
534 >> $testroot/stdout.expected
535 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
536 echo "refs/remotes/origin/master: $commit_id" \
537 >> $testroot/stdout.expected
538 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
539 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
541 cmp -s $testroot/stdout $testroot/stdout.expected
542 ret=$?
543 if [ $ret -ne 0 ]; then
544 diff -u $testroot/stdout.expected $testroot/stdout
545 fi
546 test_done "$testroot" "$ret"
549 test_fetch_delete_branch() {
550 local testroot=`test_init fetch_delete_branch`
551 local testurl=ssh://127.0.0.1/$testroot
552 local commit_id=`git_show_head $testroot/repo`
555 got branch -r $testroot/repo -c $commit_id foo
556 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
557 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
558 local tag_id=`got ref -r $testroot/repo -l \
559 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
561 got clone -a -q $testurl/repo $testroot/repo-clone
562 ret=$?
563 if [ $ret -ne 0 ]; then
564 echo "got clone command failed unexpectedly" >&2
565 test_done "$testroot" "$ret"
566 return 1
567 fi
569 got ref -l -r $testroot/repo-clone > $testroot/stdout
571 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
572 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
573 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
574 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
575 >> $testroot/stdout.expected
576 echo "refs/remotes/origin/foo: $commit_id" \
577 >> $testroot/stdout.expected
578 echo "refs/remotes/origin/master: $commit_id" \
579 >> $testroot/stdout.expected
580 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
581 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
583 cmp -s $testroot/stdout $testroot/stdout.expected
584 ret=$?
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
588 return 1
589 fi
591 got branch -r $testroot/repo -d foo >/dev/null
593 got fetch -q -r $testroot/repo-clone
594 ret=$?
595 if [ $ret -ne 0 ]; then
596 echo "got fetch command failed unexpectedly" >&2
597 test_done "$testroot" "$ret"
598 return 1
599 fi
601 got ref -l -r $testroot/repo-clone > $testroot/stdout
603 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
604 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
605 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
606 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
607 >> $testroot/stdout.expected
608 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
609 echo "refs/remotes/origin/master: $commit_id" \
610 >> $testroot/stdout.expected
611 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
612 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
614 cmp -s $testroot/stdout $testroot/stdout.expected
615 ret=$?
616 if [ $ret -ne 0 ]; then
617 diff -u $testroot/stdout.expected $testroot/stdout
618 test_done "$testroot" "$ret"
619 return 1
620 fi
622 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
623 ret=$?
624 if [ $ret -ne 0 ]; then
625 echo "got fetch command failed unexpectedly" >&2
626 test_done "$testroot" "$ret"
627 return 1
628 fi
630 echo -n > $testroot/stdout.expected
632 cmp -s $testroot/stdout $testroot/stdout.expected
633 ret=$?
634 if [ $ret -ne 0 ]; then
635 diff -u $testroot/stdout.expected $testroot/stdout
636 test_done "$testroot" "$ret"
637 return 1
638 fi
640 got ref -l -r $testroot/repo-clone > $testroot/stdout
642 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
643 # refs/heads/foo is now deleted
644 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
645 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
646 >> $testroot/stdout.expected
647 # refs/remotes/origin/foo is now deleted
648 echo "refs/remotes/origin/master: $commit_id" \
649 >> $testroot/stdout.expected
650 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
651 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
653 cmp -s $testroot/stdout $testroot/stdout.expected
654 ret=$?
655 if [ $ret -ne 0 ]; then
656 diff -u $testroot/stdout.expected $testroot/stdout
657 fi
658 test_done "$testroot" "$ret"
662 test_fetch_delete_branch_mirror() {
663 local testroot=`test_init fetch_delete_branch_mirror`
664 local testurl=ssh://127.0.0.1/$testroot
665 local commit_id=`git_show_head $testroot/repo`
667 got branch -r $testroot/repo -c $commit_id foo
668 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
669 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
670 local tag_id=`got ref -r $testroot/repo -l \
671 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
673 got clone -a -m -q $testurl/repo $testroot/repo-clone
674 ret=$?
675 if [ $ret -ne 0 ]; then
676 echo "got clone command failed unexpectedly" >&2
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 got ref -l -r $testroot/repo-clone > $testroot/stdout
683 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
684 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
685 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
686 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
687 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
689 cmp -s $testroot/stdout $testroot/stdout.expected
690 ret=$?
691 if [ $ret -ne 0 ]; then
692 diff -u $testroot/stdout.expected $testroot/stdout
693 test_done "$testroot" "$ret"
694 return 1
695 fi
697 got branch -r $testroot/repo -d foo >/dev/null
699 got fetch -q -r $testroot/repo-clone
700 ret=$?
701 if [ $ret -ne 0 ]; then
702 echo "got fetch command failed unexpectedly" >&2
703 test_done "$testroot" "$ret"
704 return 1
705 fi
707 got ref -l -r $testroot/repo-clone > $testroot/stdout
709 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
710 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
711 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
712 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
713 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
715 cmp -s $testroot/stdout $testroot/stdout.expected
716 ret=$?
717 if [ $ret -ne 0 ]; then
718 diff -u $testroot/stdout.expected $testroot/stdout
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
724 ret=$?
725 if [ $ret -ne 0 ]; then
726 echo "got fetch command failed unexpectedly" >&2
727 test_done "$testroot" "$ret"
728 return 1
729 fi
731 echo -n > $testroot/stdout.expected
733 cmp -s $testroot/stdout $testroot/stdout.expected
734 ret=$?
735 if [ $ret -ne 0 ]; then
736 diff -u $testroot/stdout.expected $testroot/stdout
737 test_done "$testroot" "$ret"
738 return 1
739 fi
741 got ref -l -r $testroot/repo-clone > $testroot/stdout
743 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
744 # refs/heads/foo is now deleted
745 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
746 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
747 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
749 cmp -s $testroot/stdout $testroot/stdout.expected
750 ret=$?
751 if [ $ret -ne 0 ]; then
752 diff -u $testroot/stdout.expected $testroot/stdout
753 fi
754 test_done "$testroot" "$ret"
758 test_fetch_update_tag() {
759 local testroot=`test_init fetch_update_tag`
760 local testurl=ssh://127.0.0.1/$testroot
761 local commit_id=`git_show_head $testroot/repo`
764 got branch -r $testroot/repo -c $commit_id foo
765 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
766 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
767 local tag_id=`got ref -r $testroot/repo -l \
768 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
770 got clone -a -q $testurl/repo $testroot/repo-clone
771 ret=$?
772 if [ $ret -ne 0 ]; then
773 echo "got clone command failed unexpectedly" >&2
774 test_done "$testroot" "$ret"
775 return 1
776 fi
778 echo "modified alpha on master" > $testroot/repo/alpha
779 git_commit $testroot/repo -m "modified alpha"
780 local commit_id2=`git_show_head $testroot/repo`
782 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
783 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
784 local tag_id2=`got ref -r $testroot/repo -l \
785 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
787 got ref -l -r $testroot/repo-clone > $testroot/stdout
789 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
790 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
791 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
792 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
793 >> $testroot/stdout.expected
794 echo "refs/remotes/origin/foo: $commit_id" \
795 >> $testroot/stdout.expected
796 echo "refs/remotes/origin/master: $commit_id" \
797 >> $testroot/stdout.expected
798 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
799 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
801 cmp -s $testroot/stdout $testroot/stdout.expected
802 ret=$?
803 if [ $ret -ne 0 ]; then
804 diff -u $testroot/stdout.expected $testroot/stdout
805 test_done "$testroot" "$ret"
806 return 1
807 fi
809 got fetch -a -q -r $testroot/repo-clone
810 ret=$?
811 if [ $ret -ne 0 ]; then
812 echo "got fetch command failed unexpectedly" >&2
813 test_done "$testroot" "$ret"
814 return 1
815 fi
817 got ref -l -r $testroot/repo-clone > $testroot/stdout
819 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
820 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
821 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
822 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
823 >> $testroot/stdout.expected
824 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
825 echo "refs/remotes/origin/master: $commit_id2" \
826 >> $testroot/stdout.expected
827 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
828 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
830 cmp -s $testroot/stdout $testroot/stdout.expected
831 ret=$?
832 if [ $ret -ne 0 ]; then
833 diff -u $testroot/stdout.expected $testroot/stdout
834 test_done "$testroot" "$ret"
835 return 1
836 fi
838 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
839 tail -n 1 > $testroot/stdout
840 ret=$?
841 if [ $ret -ne 0 ]; then
842 echo "got fetch command failed unexpectedly" >&2
843 test_done "$testroot" "$ret"
844 return 1
845 fi
847 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
848 > $testroot/stdout.expected
850 cmp -s $testroot/stdout $testroot/stdout.expected
851 ret=$?
852 if [ $ret -ne 0 ]; then
853 diff -u $testroot/stdout.expected $testroot/stdout
854 test_done "$testroot" "$ret"
855 return 1
856 fi
858 got ref -l -r $testroot/repo-clone > $testroot/stdout
860 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
861 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
862 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
863 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
864 >> $testroot/stdout.expected
865 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
866 echo "refs/remotes/origin/master: $commit_id2" \
867 >> $testroot/stdout.expected
868 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
869 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
871 cmp -s $testroot/stdout $testroot/stdout.expected
872 ret=$?
873 if [ $ret -ne 0 ]; then
874 diff -u $testroot/stdout.expected $testroot/stdout
875 test_done "$testroot" "$ret"
876 return 1
877 fi
879 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
880 ret=$?
881 if [ $ret -ne 0 ]; then
882 echo "got fetch command failed unexpectedly" >&2
883 test_done "$testroot" "$ret"
884 return 1
885 fi
887 echo -n > $testroot/stdout.expected
889 cmp -s $testroot/stdout $testroot/stdout.expected
890 ret=$?
891 if [ $ret -ne 0 ]; then
892 diff -u $testroot/stdout.expected $testroot/stdout
893 test_done "$testroot" "$ret"
894 return 1
895 fi
897 got ref -l -r $testroot/repo-clone > $testroot/stdout
899 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
900 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
901 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
902 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
903 >> $testroot/stdout.expected
904 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
905 echo "refs/remotes/origin/master: $commit_id2" \
906 >> $testroot/stdout.expected
907 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
908 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
910 cmp -s $testroot/stdout $testroot/stdout.expected
911 ret=$?
912 if [ $ret -ne 0 ]; then
913 diff -u $testroot/stdout.expected $testroot/stdout
914 fi
915 test_done "$testroot" "$ret"
918 test_fetch_reference() {
919 local testroot=`test_init fetch_reference`
920 local testurl=ssh://127.0.0.1/$testroot
921 local commit_id=`git_show_head $testroot/repo`
923 got clone -q $testurl/repo $testroot/repo-clone
924 ret=$?
925 if [ $ret -ne 0 ]; then
926 echo "got clone command failed unexpectedly" >&2
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 got branch -r $testroot/repo -c $commit_id foo
932 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
933 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
934 local tag_id=`got ref -r $testroot/repo -l \
935 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
937 echo "modified alpha on master" > $testroot/repo/alpha
938 git_commit $testroot/repo -m "modified alpha"
939 local commit_id2=`git_show_head $testroot/repo`
941 (cd $testroot/repo && git checkout -q foo)
942 echo "modified alpha on foo" > $testroot/repo/alpha
943 git_commit $testroot/repo -m "modified alpha"
944 local commit_id3=`git_show_head $testroot/repo`
945 (cd $testroot/repo && git checkout -q master)
947 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
948 > $testroot/stdout 2> $testroot/stderr
949 ret=$?
950 if [ $ret -eq 0 ]; then
951 echo "got fetch command succeeded unexpectedly" >&2
952 test_done "$testroot" "1"
953 return 1
954 fi
956 echo -n > $testroot/stdout.expected
958 cmp -s $testroot/stdout $testroot/stdout.expected
959 ret=$?
960 if [ $ret -ne 0 ]; then
961 diff -u $testroot/stdout.expected $testroot/stdout
962 test_done "$testroot" "$ret"
963 return 1
964 fi
966 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
967 > $testroot/stderr.expected
969 cmp -s $testroot/stderr $testroot/stderr.expected
970 ret=$?
971 if [ $ret -ne 0 ]; then
972 diff -u $testroot/stderr.expected $testroot/stderr
973 test_done "$testroot" "$ret"
974 return 1
975 fi
977 got fetch -q -r $testroot/repo-clone -R refs/hoo
978 ret=$?
979 if [ $ret -ne 0 ]; then
980 echo "got fetch command failed unexpectedly" >&2
981 test_done "$testroot" "$ret"
982 return 1
983 fi
985 got ref -l -r $testroot/repo-clone > $testroot/stdout
987 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
988 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
989 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
990 >> $testroot/stdout.expected
991 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
992 >> $testroot/stdout.expected
993 echo "refs/remotes/origin/master: $commit_id2" \
994 >> $testroot/stdout.expected
995 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
997 cmp -s $testroot/stdout $testroot/stdout.expected
998 ret=$?
999 if [ $ret -ne 0 ]; then
1000 diff -u $testroot/stdout.expected $testroot/stdout
1002 test_done "$testroot" "$ret"
1006 test_fetch_replace_symref() {
1007 local testroot=`test_init fetch_replace_symref`
1008 local testurl=ssh://127.0.0.1/$testroot
1009 local commit_id=`git_show_head $testroot/repo`
1011 got clone -m -q $testurl/repo $testroot/repo-clone
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 echo "got clone command failed unexpectedly" >&2
1015 test_done "$testroot" "$ret"
1016 return 1
1019 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1020 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
1022 got ref -l -r $testroot/repo-clone > $testroot/stdout
1024 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1025 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1026 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
1028 cmp -s $testroot/stdout $testroot/stdout.expected
1029 ret=$?
1030 if [ $ret -ne 0 ]; then
1031 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1033 return 1
1036 got fetch -r $testroot/repo-clone -R refs/hoo \
1037 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
1038 ret=$?
1039 if [ $ret -ne 0 ]; then
1040 echo "got fetch command failed unexpectedly" >&2
1041 test_done "$testroot" "$ret"
1042 return 1
1045 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
1046 > $testroot/stdout.expected
1048 cmp -s $testroot/stdout $testroot/stdout.expected
1049 ret=$?
1050 if [ $ret -ne 0 ]; then
1051 diff -u $testroot/stdout.expected $testroot/stdout
1052 test_done "$testroot" "$ret"
1053 return 1
1056 got ref -l -r $testroot/repo-clone > $testroot/stdout
1058 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1059 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1060 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
1062 cmp -s $testroot/stdout $testroot/stdout.expected
1063 ret=$?
1064 if [ $ret -ne 0 ]; then
1065 diff -u $testroot/stdout.expected $testroot/stdout
1067 test_done "$testroot" "$ret"
1071 test_fetch_update_headref() {
1072 local testroot=`test_init fetch_update_headref`
1073 local testurl=ssh://127.0.0.1/$testroot
1074 local commit_id=`git_show_head $testroot/repo`
1076 got clone -q $testurl/repo $testroot/repo-clone
1077 ret=$?
1078 if [ $ret -ne 0 ]; then
1079 echo "got clone command failed unexpectedly" >&2
1080 test_done "$testroot" "$ret"
1081 return 1
1084 got ref -l -r $testroot/repo-clone > $testroot/stdout
1086 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1087 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1088 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1089 >> $testroot/stdout.expected
1090 echo "refs/remotes/origin/master: $commit_id" \
1091 >> $testroot/stdout.expected
1093 cmp -s $testroot/stdout $testroot/stdout.expected
1094 ret=$?
1095 if [ $ret -ne 0 ]; then
1096 diff -u $testroot/stdout.expected $testroot/stdout
1097 test_done "$testroot" "$ret"
1098 return 1
1101 got ref -r $testroot/repo -c refs/heads/master refs/heads/foo
1102 got ref -r $testroot/repo -s refs/heads/foo HEAD
1103 got ref -l -r $testroot/repo > $testroot/stdout
1105 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
1106 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1107 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1109 cmp -s $testroot/stdout $testroot/stdout.expected
1110 ret=$?
1111 if [ $ret -ne 0 ]; then
1112 diff -u $testroot/stdout.expected $testroot/stdout
1113 test_done "$testroot" "$ret"
1114 return 1
1117 got fetch -q -r $testroot/repo-clone
1119 got ref -l -r $testroot/repo-clone > $testroot/stdout
1121 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1122 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1123 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1124 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
1125 >> $testroot/stdout.expected
1126 echo "refs/remotes/origin/foo: $commit_id" \
1127 >> $testroot/stdout.expected
1128 echo "refs/remotes/origin/master: $commit_id" \
1129 >> $testroot/stdout.expected
1131 cmp -s $testroot/stdout $testroot/stdout.expected
1132 ret=$?
1133 if [ $ret -ne 0 ]; then
1134 diff -u $testroot/stdout.expected $testroot/stdout
1135 test_done "$testroot" "$ret"
1136 return 1
1139 got fetch -q -r $testroot/repo-clone -a
1141 got ref -l -r $testroot/repo-clone > $testroot/stdout
1143 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1144 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1145 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1146 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
1147 >> $testroot/stdout.expected
1148 echo "refs/remotes/origin/foo: $commit_id" \
1149 >> $testroot/stdout.expected
1150 echo "refs/remotes/origin/master: $commit_id" \
1151 >> $testroot/stdout.expected
1153 cmp -s $testroot/stdout $testroot/stdout.expected
1154 ret=$?
1155 if [ $ret -ne 0 ]; then
1156 diff -u $testroot/stdout.expected $testroot/stdout
1158 test_done "$testroot" "$ret"
1161 test_fetch_headref_deleted_locally() {
1162 local testroot=`test_init fetch_headref_deleted_locally`
1163 local testurl=ssh://127.0.0.1/$testroot
1164 local commit_id=`git_show_head $testroot/repo`
1166 got clone -q $testurl/repo $testroot/repo-clone
1167 ret=$?
1168 if [ $ret -ne 0 ]; then
1169 echo "got clone command failed unexpectedly" >&2
1170 test_done "$testroot" "$ret"
1171 return 1
1174 got ref -l -r $testroot/repo-clone > $testroot/stdout
1176 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1177 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1178 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1179 >> $testroot/stdout.expected
1180 echo "refs/remotes/origin/master: $commit_id" \
1181 >> $testroot/stdout.expected
1183 cmp -s $testroot/stdout $testroot/stdout.expected
1184 ret=$?
1185 if [ $ret -ne 0 ]; then
1186 diff -u $testroot/stdout.expected $testroot/stdout
1187 test_done "$testroot" "$ret"
1188 return 1
1191 got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD > /dev/null
1193 got fetch -q -r $testroot/repo-clone
1194 ret=$?
1195 if [ $ret -ne 0 ]; then
1196 echo "got fetch command failed unexpectedly" >&2
1197 test_done "$testroot" "$ret"
1198 return 1
1200 got ref -l -r $testroot/repo-clone > $testroot/stdout
1202 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1203 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1204 # refs/remotes/origin/HEAD has been restored:
1205 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1206 >> $testroot/stdout.expected
1207 echo "refs/remotes/origin/master: $commit_id" \
1208 >> $testroot/stdout.expected
1210 cmp -s $testroot/stdout $testroot/stdout.expected
1211 ret=$?
1212 if [ $ret -ne 0 ]; then
1213 diff -u $testroot/stdout.expected $testroot/stdout
1215 test_done "$testroot" "$ret"
1218 test_fetch_gotconfig_remote_repo() {
1219 local testroot=`test_init fetch_gotconfig_remote_repo`
1220 local testurl=ssh://127.0.0.1/$testroot
1221 local commit_id=`git_show_head $testroot/repo`
1223 got branch -r $testroot/repo -c $commit_id foo
1224 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1225 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
1227 got clone -q $testurl/repo $testroot/repo-clone
1228 ret=$?
1229 if [ $ret -ne 0 ]; then
1230 echo "got clone command failed unexpectedly" >&2
1231 test_done "$testroot" "$ret"
1232 return 1
1235 cat > $testroot/repo-clone/got.conf <<EOF
1236 remote "foobar" {
1237 protocol ssh
1238 server 127.0.0.1
1239 repository "$testroot/repo"
1242 remote "barbaz" {
1243 protocol ssh
1244 server 127.0.0.1
1245 repository "$testroot/does-not-exist"
1247 EOF
1248 echo "got: nonexistent: remote repository not found" \
1249 > $testroot/stderr.expected
1250 (cd $testroot/repo-clone && got fetch -q nonexistent \
1251 > $testroot/stdout 2> $testroot/stderr)
1252 ret=$?
1253 if [ $ret -eq 0 ]; then
1254 echo "got fetch command succeeded unexpectedly" >&2
1255 diff -u $testroot/stderr.expected $testroot/stderr
1256 test_done "$testroot" "1"
1257 return 1
1260 (cd $testroot/repo-clone && got fetch -q -l foobar \
1261 > $testroot/stdout)
1262 ret=$?
1263 if [ $ret -ne 0 ]; then
1264 echo "got fetch command failed unexpectedly" >&2
1265 test_done "$testroot" "$ret"
1266 return 1
1269 got ref -l -r $testroot/repo > $testroot/stdout.expected
1271 cmp -s $testroot/stdout $testroot/stdout.expected
1272 ret=$?
1273 if [ $ret -ne 0 ]; then
1274 diff -u $testroot/stdout.expected $testroot/stdout
1275 test_done "$testroot" "$ret"
1276 return 1
1279 got checkout $testroot/repo $testroot/wt > /dev/null
1281 cat > $testroot/wt/.got/got.conf <<EOF
1282 remote "barbaz" {
1283 protocol ssh
1284 server 127.0.0.1
1285 repository "$testroot/repo"
1287 EOF
1288 (cd $testroot/wt && got fetch -q -l barbaz > $testroot/stdout)
1289 ret=$?
1290 if [ $ret -ne 0 ]; then
1291 echo "got fetch command failed unexpectedly" >&2
1292 test_done "$testroot" "$ret"
1293 return 1
1296 got ref -l -r $testroot/repo > $testroot/stdout.expected
1298 cmp -s $testroot/stdout $testroot/stdout.expected
1299 ret=$?
1300 if [ $ret -ne 0 ]; then
1301 diff -u $testroot/stdout.expected $testroot/stdout
1302 test_done "$testroot" "$ret"
1303 return 1
1306 cat > $testroot/repo-clone/got.conf <<EOF
1307 remote "origin" {
1308 protocol ssh
1309 server 127.0.0.1
1310 repository "$testroot/repo"
1311 branch { "foo" }
1312 reference { "hoo/boo/zoo" }
1314 EOF
1315 (cd $testroot/repo-clone && got fetch -q > $testroot/stdout)
1317 local tag_id=`got ref -r $testroot/repo -l \
1318 | grep "^refs/tags/1.0" | tr -d ' ' | cut -d: -f2`
1319 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1320 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1321 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1322 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1323 >> $testroot/stdout.expected
1324 echo "refs/remotes/origin/foo: $commit_id" \
1325 >> $testroot/stdout.expected
1326 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
1327 >> $testroot/stdout.expected
1328 echo "refs/remotes/origin/master: $commit_id" \
1329 >> $testroot/stdout.expected
1330 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1332 got ref -l -r $testroot/repo-clone > $testroot/stdout
1334 cmp -s $testroot/stdout $testroot/stdout.expected
1335 ret=$?
1336 if [ $ret -ne 0 ]; then
1337 diff -u $testroot/stdout.expected $testroot/stdout
1339 test_done "$testroot" "$ret"
1342 test_fetch_delete_remote_refs() {
1343 local testroot=`test_init fetch_delete_remote_refs`
1344 local testurl=ssh://127.0.0.1/$testroot
1345 local commit_id=`git_show_head $testroot/repo`
1347 got clone -q $testurl/repo $testroot/repo-clone
1348 ret=$?
1349 if [ $ret -ne 0 ]; then
1350 echo "got clone command failed unexpectedly" >&2
1351 test_done "$testroot" "$ret"
1352 return 1
1355 got ref -l -r $testroot/repo-clone > $testroot/stdout
1356 ret=$?
1357 if [ $ret -ne 0 ]; then
1358 echo "got ref command failed unexpectedly" >&2
1359 test_done "$testroot" "$ret"
1360 return 1
1363 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1364 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1365 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1366 >> $testroot/stdout.expected
1367 echo "refs/remotes/origin/master: $commit_id" \
1368 >> $testroot/stdout.expected
1370 cmp -s $testroot/stdout $testroot/stdout.expected
1371 ret=$?
1372 if [ $ret -ne 0 ]; then
1373 diff -u $testroot/stdout.expected $testroot/stdout
1374 test_done "$testroot" "$ret"
1375 return 1
1378 got fetch -q -r $testroot/repo-clone -X > $testroot/stdout \
1379 2> $testroot/stderr
1380 ret=$?
1381 if [ $ret -eq 0 ]; then
1382 echo "got fetch command succeeded unexpectedly" >&2
1383 test_done "$testroot" "$ret"
1384 return 1
1387 echo "got: -X option requires a remote name" > $testroot/stderr.expected
1388 cmp -s $testroot/stderr $testroot/stderr.expected
1389 ret=$?
1390 if [ $ret -ne 0 ]; then
1391 diff -u $testroot/stderr.expected $testroot/stderr
1392 test_done "$testroot" "$ret"
1393 return 1
1396 got fetch -q -r $testroot/repo-clone -X origin > $testroot/stdout \
1397 2> $testroot/stderr
1398 ret=$?
1399 if [ $ret -ne 0 ]; then
1400 echo "got fetch command failed unexpectedly" >&2
1401 test_done "$testroot" "$ret"
1402 return 1
1405 echo -n "Deleted refs/remotes/origin/HEAD: " > $testroot/stdout.expected
1406 echo "refs/remotes/origin/master" >> $testroot/stdout.expected
1407 echo "Deleted refs/remotes/origin/master: $commit_id" \
1408 >> $testroot/stdout.expected
1410 cmp -s $testroot/stdout $testroot/stdout.expected
1411 ret=$?
1412 if [ $ret -ne 0 ]; then
1413 diff -u $testroot/stdout.expected $testroot/stdout
1414 test_done "$testroot" "$ret"
1415 return 1
1418 got ref -l -r $testroot/repo-clone > $testroot/stdout
1419 ret=$?
1420 if [ $ret -ne 0 ]; then
1421 echo "got ref command failed unexpectedly" >&2
1422 test_done "$testroot" "$ret"
1423 return 1
1426 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1427 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1429 cmp -s $testroot/stdout $testroot/stdout.expected
1430 ret=$?
1431 if [ $ret -ne 0 ]; then
1432 diff -u $testroot/stdout.expected $testroot/stdout
1434 test_done "$testroot" "$ret"
1437 test_fetch_honor_wt_conf_bflag() {
1438 local testroot=`test_init fetch_honor_wt_conf_bflag`
1439 local testurl=ssh://127.0.0.1/$testroot
1441 # server will have 'boo', 'hoo', and 'master'
1442 echo "modified alpha on master" > $testroot/repo/alpha
1443 git_commit $testroot/repo -m "modified alpha"
1444 local commit_id=`git_show_head $testroot/repo`
1446 got branch -r $testroot/repo -c $commit_id boo
1447 (cd $testroot/repo && git checkout -q boo)
1448 echo "modified beta on boo" > $testroot/repo/beta
1449 git_commit $testroot/repo -m "modified beta"
1450 local commit_id2=`git_show_head $testroot/repo`
1452 got branch -r $testroot/repo -c $commit_id2 hoo
1453 (cd $testroot/repo && git checkout -q hoo)
1454 echo "modified delta on hoo" > $testroot/repo/gamma/delta
1455 git_commit $testroot/repo -m "modified delta"
1456 local commit_id3=`git_show_head $testroot/repo`
1458 (cd $testroot/repo && git checkout -q master)
1459 got clone -q $testurl/repo $testroot/repo-clone
1460 ret=$?
1461 if [ $ret -ne 0 ]; then
1462 echo "got clone command failed unexpectedly" >&2
1463 test_done "$testroot" "$ret"
1464 return 1
1467 # only clone will have foo and bar
1468 got branch -r $testroot/repo-clone -c $commit_id foo
1469 got branch -r $testroot/repo-clone -c $commit_id bar
1471 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1472 ret=$?
1473 if [ $ret -ne 0 ]; then
1474 echo "got fetch command failed unexpectedly" >&2
1475 test_done "$testroot" "$ret"
1476 return 1
1479 echo -n > $testroot/stdout.expected
1481 cmp -s $testroot/stdout $testroot/stdout.expected
1482 ret=$?
1483 if [ $ret -ne 0 ]; then
1484 diff -u $testroot/stdout.expected $testroot/stdout
1485 test_done "$testroot" "$ret"
1486 return 1
1489 got ref -l -r $testroot/repo-clone > $testroot/stdout
1491 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1492 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1493 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1494 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1495 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1496 >> $testroot/stdout.expected
1497 echo "refs/remotes/origin/master: $commit_id" \
1498 >> $testroot/stdout.expected
1500 cmp -s $testroot/stdout $testroot/stdout.expected
1501 ret=$?
1502 if [ $ret -ne 0 ]; then
1503 diff -u $testroot/stdout.expected $testroot/stdout
1504 test_done "$testroot" "$ret"
1505 return 1
1508 (cd $testroot/repo && git checkout -q boo)
1509 # clone has remote/origin/HEAD symref with "master" as its target
1510 # but the repo has changed HEAD to "boo", so we should fetch "boo"
1511 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1512 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1513 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1514 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1515 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1516 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1517 >> $testroot/stdout.expected
1518 echo "refs/remotes/origin/boo: $commit_id2" \
1519 >> $testroot/stdout.expected
1520 echo "refs/remotes/origin/master: $commit_id" \
1521 >> $testroot/stdout.expected
1523 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1524 ret=$?
1525 if [ $ret -ne 0 ]; then
1526 echo "got fetch command failed unexpectedly" >&2
1527 test_done "$testroot" "$ret"
1528 return 1
1531 got ref -l -r $testroot/repo-clone > $testroot/stdout
1533 cmp -s $testroot/stdout $testroot/stdout.expected
1534 ret=$?
1535 if [ $ret -ne 0 ]; then
1536 diff -u $testroot/stdout.expected $testroot/stdout
1537 test_done "$testroot" "$ret"
1538 return 1
1541 # from repo: fetch -b hoo
1542 got fetch -q -r $testroot/repo-clone -b hoo > $testroot/stdout
1543 ret=$?
1544 if [ $ret -ne 0 ]; then
1545 echo "got fetch command failed unexpectedly" >&2
1546 test_done "$testroot" "$ret"
1547 return 1
1550 echo -n > $testroot/stdout.expected
1552 cmp -s $testroot/stdout $testroot/stdout.expected
1553 ret=$?
1554 if [ $ret -ne 0 ]; then
1555 diff -u $testroot/stdout.expected $testroot/stdout
1556 test_done "$testroot" "$ret"
1557 return 1
1560 got ref -l -r $testroot/repo-clone > $testroot/stdout
1562 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1563 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1564 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1565 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1566 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1567 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1568 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1569 >> $testroot/stdout.expected
1570 echo "refs/remotes/origin/boo: $commit_id2" \
1571 >> $testroot/stdout.expected
1572 echo "refs/remotes/origin/hoo: $commit_id3" \
1573 >> $testroot/stdout.expected
1574 echo "refs/remotes/origin/master: $commit_id" \
1575 >> $testroot/stdout.expected
1577 cmp -s $testroot/stdout $testroot/stdout.expected
1578 ret=$?
1579 if [ $ret -ne 0 ]; then
1580 diff -u $testroot/stdout.expected $testroot/stdout
1581 test_done "$testroot" "$ret"
1582 return 1
1585 # from repo: fetch -b foo which doesn't exist on the server but
1586 # do not fallback to repo HEAD "boo" because we used the -b flag
1587 got fetch -r $testroot/repo-clone -b foo > $testroot/stdout \
1588 2> $testroot/stderr
1590 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \
1591 > $testroot/stdout.expected
1592 echo "got-fetch-pack: branch \"foo\" not found on server" \
1593 > $testroot/stderr.expected
1594 echo "got: could not find any branches to fetch" \
1595 >> $testroot/stderr.expected
1597 cmp -s $testroot/stdout $testroot/stdout.expected
1598 ret=$?
1599 if [ $ret -ne 0 ]; then
1600 diff -u $testroot/stdout.expected $testroot/stdout
1601 test_done "$testroot" "$ret"
1602 return 1
1605 cmp -s $testroot/stderr $testroot/stderr.expected
1606 ret=$?
1607 if [ $ret -ne 0 ]; then
1608 diff -u $testroot/stderr.expected $testroot/stderr
1609 test_done "$testroot" "$ret"
1610 return 1
1613 # from repo: fetch got.conf branch which doesn't exist, so fallback
1614 # to repo HEAD "boo"
1615 # change default branch in got.conf from "master" to "foo"
1616 ed -s $testroot/repo-clone/got.conf <<-EOF
1617 ,s/master/foo/
1619 EOF
1621 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1622 ret=$?
1623 if [ $ret -ne 0 ]; then
1624 echo "got fetch command failed unexpectedly" >&2
1625 test_done "$testroot" "$ret"
1626 return 1
1629 echo -n > $testroot/stdout.expected
1631 cmp -s $testroot/stdout $testroot/stdout.expected
1632 ret=$?
1633 if [ $ret -ne 0 ]; then
1634 diff -u $testroot/stdout.expected $testroot/stdout
1635 test_done "$testroot" "$ret"
1636 return 1
1639 got ref -l -r $testroot/repo-clone > $testroot/stdout
1641 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1642 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1643 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1644 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1645 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1646 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1647 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1648 >> $testroot/stdout.expected
1649 echo "refs/remotes/origin/boo: $commit_id2" \
1650 >> $testroot/stdout.expected
1651 echo "refs/remotes/origin/hoo: $commit_id3" \
1652 >> $testroot/stdout.expected
1653 echo "refs/remotes/origin/master: $commit_id" \
1654 >> $testroot/stdout.expected
1656 cmp -s $testroot/stdout $testroot/stdout.expected
1657 ret=$?
1658 if [ $ret -ne 0 ]; then
1659 diff -u $testroot/stdout.expected $testroot/stdout
1660 test_done "$testroot" "$ret"
1661 return 1
1664 # from wt: fetch got.conf "foo", which doesn't exist on the server,
1665 # and implicit wt branch "boo", not repo HEAD "master"
1666 echo "modified delta on boo" > $testroot/repo/gamma/delta
1667 git_commit $testroot/repo -m "modified delta"
1668 local commit_id4=`git_show_head $testroot/repo`
1670 (cd $testroot/repo && git checkout -q master)
1672 got checkout -b boo $testroot/repo-clone $testroot/wt > /dev/null
1673 (cd $testroot/wt && got fetch -q > $testroot/stdout)
1675 echo -n > $testroot/stdout.expected
1677 cmp -s $testroot/stdout $testroot/stdout.expected
1678 ret=$?
1679 if [ $ret -ne 0 ]; then
1680 diff -u $testroot/stdout.expected $testroot/stdout
1681 test_done "$testroot" "$ret"
1682 return 1
1685 local wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1686 cut -d ':' -f 2 | tr -d ' ')`
1688 got ref -l -r $testroot/repo-clone > $testroot/stdout
1690 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1691 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1692 >> $testroot/stdout.expected
1693 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1694 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1695 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1696 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1697 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1698 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1699 >> $testroot/stdout.expected
1700 echo "refs/remotes/origin/boo: $commit_id4" \
1701 >> $testroot/stdout.expected
1702 echo "refs/remotes/origin/hoo: $commit_id3" \
1703 >> $testroot/stdout.expected
1704 echo "refs/remotes/origin/master: $commit_id" \
1705 >> $testroot/stdout.expected
1707 cmp -s $testroot/stdout $testroot/stdout.expected
1708 ret=$?
1709 if [ $ret -ne 0 ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1711 test_done "$testroot" "$ret"
1712 return 1
1715 # from wt: fetch got.conf "master", wt "boo", and the repo's new HEAD
1716 # "hoo" as it no longer matches our remote HEAD symref target "master"
1717 ed -s $testroot/repo-clone/got.conf <<-EOF
1718 ,s/foo/master/
1720 EOF
1721 echo "modified delta on master" > $testroot/repo/gamma/delta
1722 git_commit $testroot/repo -m "modified delta on master"
1723 local commit_id5=`git_show_head $testroot/repo`
1725 (cd $testroot/repo && git checkout -q boo)
1726 echo "modified alpha on boo" > $testroot/repo/alpha
1727 git_commit $testroot/repo -m "modified alpha on boo"
1728 local commit_id6=`git_show_head $testroot/repo`
1730 (cd $testroot/repo && git checkout -q hoo)
1731 echo "modified beta on hoo" > $testroot/repo/beta
1732 git_commit $testroot/repo -m "modified beta on hoo"
1733 local commit_id7=`git_show_head $testroot/repo`
1735 (cd $testroot/wt && got fetch -q > $testroot/stdout)
1737 echo -n > $testroot/stdout.expected
1739 cmp -s $testroot/stdout $testroot/stdout.expected
1740 ret=$?
1741 if [ $ret -ne 0 ]; then
1742 diff -u $testroot/stdout.expected $testroot/stdout
1743 test_done "$testroot" "$ret"
1744 return 1
1747 got ref -l -r $testroot/repo-clone > $testroot/stdout
1749 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1750 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1751 >> $testroot/stdout.expected
1752 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1753 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1754 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1755 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1756 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1757 echo "refs/remotes/origin/HEAD: refs/remotes/origin/hoo" \
1758 >> $testroot/stdout.expected
1759 echo "refs/remotes/origin/boo: $commit_id6" \
1760 >> $testroot/stdout.expected
1761 echo "refs/remotes/origin/hoo: $commit_id7" \
1762 >> $testroot/stdout.expected
1763 echo "refs/remotes/origin/master: $commit_id5" \
1764 >> $testroot/stdout.expected
1766 cmp -s $testroot/stdout $testroot/stdout.expected
1767 ret=$?
1768 if [ $ret -ne 0 ]; then
1769 diff -u $testroot/stdout.expected $testroot/stdout
1770 test_done "$testroot" "$ret"
1771 return 1
1774 # from wt: fetch -b hoo not got.conf "master" or wt "boo" or
1775 # repo HEAD "boo"
1776 (cd $testroot/repo && git checkout -q boo)
1777 echo "modified alpha again on boo" > $testroot/repo/alpha
1778 git_commit $testroot/repo -m "modified alpha again on boo"
1779 local commit_id8=`git_show_head $testroot/repo`
1781 (cd $testroot/wt && got fetch -q -b hoo > $testroot/stdout)
1783 echo -n > $testroot/stdout.expected
1785 cmp -s $testroot/stdout $testroot/stdout.expected
1786 ret=$?
1787 if [ $ret -ne 0 ]; then
1788 diff -u $testroot/stdout.expected $testroot/stdout
1789 test_done "$testroot" "$ret"
1790 return 1
1793 got ref -l -r $testroot/repo-clone > $testroot/stdout
1795 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1796 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1797 >> $testroot/stdout.expected
1798 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1799 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1800 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1801 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1802 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1803 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1804 >> $testroot/stdout.expected
1805 echo "refs/remotes/origin/boo: $commit_id6" \
1806 >> $testroot/stdout.expected
1807 echo "refs/remotes/origin/hoo: $commit_id7" \
1808 >> $testroot/stdout.expected
1809 echo "refs/remotes/origin/master: $commit_id5" \
1810 >> $testroot/stdout.expected
1812 cmp -s $testroot/stdout $testroot/stdout.expected
1813 ret=$?
1814 if [ $ret -ne 0 ]; then
1815 diff -u $testroot/stdout.expected $testroot/stdout
1816 test_done "$testroot" "$ret"
1817 return 1
1820 # from wt: fetch -b bar that doesn't exist on the server but
1821 # do not fetch got.conf "master" or wt "boo" or repo HEAD "boo"
1822 (cd $testroot/wt && got fetch -b bar > $testroot/stdout \
1823 2> $testroot/stderr)
1825 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \
1826 > $testroot/stdout.expected
1827 echo "got-fetch-pack: branch \"bar\" not found on server" \
1828 > $testroot/stderr.expected
1829 echo "got: could not find any branches to fetch" \
1830 >> $testroot/stderr.expected
1832 cmp -s $testroot/stderr $testroot/stderr.expected
1833 ret=$?
1834 if [ $ret -ne 0 ]; then
1835 diff -u $testroot/stderr.expected $testroot/stderr
1836 test_done "$testroot" "$ret"
1837 return 1
1840 cmp -s $testroot/stdout $testroot/stdout.expected
1841 ret=$?
1842 if [ $ret -ne 0 ]; then
1843 diff -u $testroot/stdout.expected $testroot/stdout
1845 test_done "$testroot" "$ret"
1848 test_fetch_from_out_of_date_remote() {
1849 local testroot=`test_init fetch_from_out_of_date_remote`
1850 local testurl=ssh://127.0.0.1/$testroot
1851 local commit_id=`git_show_head $testroot/repo`
1853 got clone -q $testurl/repo $testroot/repo-clone
1854 ret=$?
1855 if [ $ret -ne 0 ]; then
1856 echo "got clone command failed unexpectedly" >&2
1857 test_done "$testroot" "$ret"
1858 return 1
1861 echo "modified alpha" > $testroot/repo/alpha
1862 git_commit $testroot/repo -m "modified alpha"
1863 local commit_id2=`git_show_head $testroot/repo`
1865 got clone -q $testurl/repo $testroot/repo-clone2 \
1866 > $testroot/stdout 2> $testroot/stderr
1867 ret=$?
1868 if [ $ret -ne 0 ]; then
1869 echo "got clone command failed unexpectedly" >&2
1870 test_done "$testroot" "$ret"
1871 return 1
1874 got ref -l -r $testroot/repo-clone2 > $testroot/stdout
1875 ret=$?
1876 if [ $ret -ne 0 ]; then
1877 echo "got ref command failed unexpectedly" >&2
1878 test_done "$testroot" "$ret"
1879 return 1
1882 cat > $testroot/stdout.expected <<EOF
1883 HEAD: refs/heads/master
1884 refs/heads/master: $commit_id2
1885 refs/remotes/origin/HEAD: refs/remotes/origin/master
1886 refs/remotes/origin/master: $commit_id2
1887 EOF
1888 cmp -s $testroot/stdout $testroot/stdout.expected
1889 ret=$?
1890 if [ $ret -ne 0 ]; then
1891 diff -u $testroot/stdout.expected $testroot/stdout
1892 test_done "$testroot" "$ret"
1893 return 1
1896 cat >> $testroot/repo-clone2/got.conf <<EOF
1897 remote "other" {
1898 server "127.0.0.1"
1899 protocol ssh
1900 repository "$testroot/repo-clone"
1901 branch { "master" }
1903 EOF
1904 got fetch -q -r $testroot/repo-clone2 other \
1905 > $testroot/stdout 2> $testroot/stderr
1906 ret=$?
1907 if [ $ret -ne 0 ]; then
1908 echo "got fetch command failed unexpectedly" >&2
1909 test_done "$testroot" "$ret"
1910 return 1
1913 got ref -l -r $testroot/repo-clone2 > $testroot/stdout
1914 ret=$?
1915 if [ $ret -ne 0 ]; then
1916 echo "got ref command failed unexpectedly" >&2
1917 test_done "$testroot" "$ret"
1918 return 1
1921 cat > $testroot/stdout.expected <<EOF
1922 HEAD: refs/heads/master
1923 refs/heads/master: $commit_id2
1924 refs/remotes/origin/HEAD: refs/remotes/origin/master
1925 refs/remotes/origin/master: $commit_id2
1926 refs/remotes/other/HEAD: refs/remotes/other/master
1927 refs/remotes/other/master: $commit_id
1928 EOF
1929 cmp -s $testroot/stdout $testroot/stdout.expected
1930 ret=$?
1931 if [ $ret -ne 0 ]; then
1932 diff -u $testroot/stdout.expected $testroot/stdout
1934 test_done "$testroot" "$ret"
1938 test_parseargs "$@"
1939 run_test test_fetch_basic
1940 run_test test_fetch_list
1941 run_test test_fetch_branch
1942 run_test test_fetch_all
1943 run_test test_fetch_empty_packfile
1944 run_test test_fetch_delete_branch
1945 run_test test_fetch_delete_branch_mirror
1946 run_test test_fetch_update_tag
1947 run_test test_fetch_reference
1948 run_test test_fetch_replace_symref
1949 run_test test_fetch_update_headref
1950 run_test test_fetch_headref_deleted_locally
1951 run_test test_fetch_gotconfig_remote_repo
1952 run_test test_fetch_delete_remote_refs
1953 run_test test_fetch_honor_wt_conf_bflag
1954 run_test test_fetch_from_out_of_date_remote