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 git -C $testroot/repo 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 git -C $testroot/repo 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 git -C $testroot/repo 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 git -C $testroot/repo 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 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
437 cmp -s $testroot/stdout $testroot/stdout.expected
438 ret=$?
439 if [ $ret -ne 0 ]; then
440 diff -u $testroot/stdout.expected $testroot/stdout
441 test_done "$testroot" "$ret"
442 return 1
443 fi
445 got branch -r $testroot/repo -c $commit_id foo
446 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
447 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
448 local tag_id=`got ref -r $testroot/repo -l \
449 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
451 got fetch -q -a -r $testroot/repo-clone
452 ret=$?
453 if [ $ret -ne 0 ]; then
454 echo "got fetch command failed unexpectedly" >&2
455 test_done "$testroot" "$ret"
456 return 1
457 fi
459 got ref -l -r $testroot/repo-clone > $testroot/stdout
461 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
462 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
463 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
464 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
465 >> $testroot/stdout.expected
466 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
467 echo "refs/remotes/origin/master: $commit_id" \
468 >> $testroot/stdout.expected
469 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
470 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
472 cmp -s $testroot/stdout $testroot/stdout.expected
473 ret=$?
474 if [ $ret -ne 0 ]; then
475 diff -u $testroot/stdout.expected $testroot/stdout
476 fi
478 git -C $testroot/repo checkout -q foo
479 echo "modified beta on foo" > $testroot/repo/beta
480 git_commit $testroot/repo -m "modified beta"
481 local commit_id2=`git_show_head $testroot/repo`
483 # set the default HEAD branch back to master
484 git -C $testroot/repo checkout -q master
486 # remove default branch from got.conf, fetch all branches
487 ed -s $testroot/repo-clone/got.conf <<-EOF
488 /branch {/c
489 fetch_all_branches yes
492 EOF
494 got fetch -q -r $testroot/repo-clone
495 ret=$?
496 if [ $ret -ne 0 ]; then
497 echo "got fetch command failed unexpectedly" >&2
498 test_done "$testroot" "$ret"
499 return 1
500 fi
502 got ref -l -r $testroot/repo-clone > $testroot/stdout
504 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
505 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
506 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
507 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
508 >> $testroot/stdout.expected
509 echo "refs/remotes/origin/foo: $commit_id2" >> $testroot/stdout.expected
510 echo "refs/remotes/origin/master: $commit_id" \
511 >> $testroot/stdout.expected
512 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
513 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
515 cmp -s $testroot/stdout $testroot/stdout.expected
516 ret=$?
517 if [ $ret -ne 0 ]; then
518 diff -u $testroot/stdout.expected $testroot/stdout
519 fi
520 test_done "$testroot" "$ret"
523 test_fetch_empty_packfile() {
524 local testroot=`test_init fetch_empty_packfile`
525 local testurl=ssh://127.0.0.1/$testroot
526 local commit_id=`git_show_head $testroot/repo`
528 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
529 local tag_id=`got ref -r $testroot/repo -l \
530 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
532 got clone -q $testurl/repo $testroot/repo-clone
533 ret=$?
534 if [ $ret -ne 0 ]; then
535 echo "got clone command failed unexpectedly" >&2
536 test_done "$testroot" "$ret"
537 return 1
538 fi
540 got branch -r $testroot/repo -c $commit_id foo
541 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
543 got ref -l -r $testroot/repo-clone > $testroot/stdout
545 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
546 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
547 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
548 >> $testroot/stdout.expected
549 echo "refs/remotes/origin/master: $commit_id" \
550 >> $testroot/stdout.expected
551 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
552 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
554 cmp -s $testroot/stdout $testroot/stdout.expected
555 ret=$?
556 if [ $ret -ne 0 ]; then
557 diff -u $testroot/stdout.expected $testroot/stdout
558 test_done "$testroot" "$ret"
559 return 1
560 fi
562 got fetch -q -a -r $testroot/repo-clone
563 ret=$?
564 if [ $ret -ne 0 ]; then
565 echo "got fetch command failed unexpectedly" >&2
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 got ref -l -r $testroot/repo-clone > $testroot/stdout
572 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
573 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
574 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
575 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
576 >> $testroot/stdout.expected
577 echo "refs/remotes/origin/foo: $commit_id" >> $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 fi
588 test_done "$testroot" "$ret"
591 test_fetch_delete_branch() {
592 local testroot=`test_init fetch_delete_branch`
593 local testurl=ssh://127.0.0.1/$testroot
594 local commit_id=`git_show_head $testroot/repo`
597 got branch -r $testroot/repo -c $commit_id foo
598 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
599 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
600 local tag_id=`got ref -r $testroot/repo -l \
601 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
603 got clone -a -q $testurl/repo $testroot/repo-clone
604 ret=$?
605 if [ $ret -ne 0 ]; then
606 echo "got clone command failed unexpectedly" >&2
607 test_done "$testroot" "$ret"
608 return 1
609 fi
611 got ref -l -r $testroot/repo-clone > $testroot/stdout
613 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
614 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
615 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
616 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
617 >> $testroot/stdout.expected
618 echo "refs/remotes/origin/foo: $commit_id" \
619 >> $testroot/stdout.expected
620 echo "refs/remotes/origin/master: $commit_id" \
621 >> $testroot/stdout.expected
622 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
623 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
625 cmp -s $testroot/stdout $testroot/stdout.expected
626 ret=$?
627 if [ $ret -ne 0 ]; then
628 diff -u $testroot/stdout.expected $testroot/stdout
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 got branch -r $testroot/repo -d foo >/dev/null
635 got fetch -q -r $testroot/repo-clone
636 ret=$?
637 if [ $ret -ne 0 ]; then
638 echo "got fetch command failed unexpectedly" >&2
639 test_done "$testroot" "$ret"
640 return 1
641 fi
643 got ref -l -r $testroot/repo-clone > $testroot/stdout
645 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
646 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
647 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
648 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
649 >> $testroot/stdout.expected
650 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
651 echo "refs/remotes/origin/master: $commit_id" \
652 >> $testroot/stdout.expected
653 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
654 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
656 cmp -s $testroot/stdout $testroot/stdout.expected
657 ret=$?
658 if [ $ret -ne 0 ]; then
659 diff -u $testroot/stdout.expected $testroot/stdout
660 test_done "$testroot" "$ret"
661 return 1
662 fi
664 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
665 ret=$?
666 if [ $ret -ne 0 ]; then
667 echo "got fetch command failed unexpectedly" >&2
668 test_done "$testroot" "$ret"
669 return 1
670 fi
672 echo -n > $testroot/stdout.expected
674 cmp -s $testroot/stdout $testroot/stdout.expected
675 ret=$?
676 if [ $ret -ne 0 ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 got ref -l -r $testroot/repo-clone > $testroot/stdout
684 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
685 # refs/heads/foo is now deleted
686 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
687 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
688 >> $testroot/stdout.expected
689 # refs/remotes/origin/foo is now deleted
690 echo "refs/remotes/origin/master: $commit_id" \
691 >> $testroot/stdout.expected
692 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
693 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
695 cmp -s $testroot/stdout $testroot/stdout.expected
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 fi
700 test_done "$testroot" "$ret"
704 test_fetch_delete_branch_mirror() {
705 local testroot=`test_init fetch_delete_branch_mirror`
706 local testurl=ssh://127.0.0.1/$testroot
707 local commit_id=`git_show_head $testroot/repo`
709 got branch -r $testroot/repo -c $commit_id foo
710 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
711 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
712 local tag_id=`got ref -r $testroot/repo -l \
713 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
715 got clone -a -m -q $testurl/repo $testroot/repo-clone
716 ret=$?
717 if [ $ret -ne 0 ]; then
718 echo "got clone command failed unexpectedly" >&2
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 got ref -l -r $testroot/repo-clone > $testroot/stdout
725 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
726 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
727 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
728 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
729 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
731 cmp -s $testroot/stdout $testroot/stdout.expected
732 ret=$?
733 if [ $ret -ne 0 ]; then
734 diff -u $testroot/stdout.expected $testroot/stdout
735 test_done "$testroot" "$ret"
736 return 1
737 fi
739 got branch -r $testroot/repo -d foo >/dev/null
741 got fetch -q -r $testroot/repo-clone
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 echo "got fetch command failed unexpectedly" >&2
745 test_done "$testroot" "$ret"
746 return 1
747 fi
749 got ref -l -r $testroot/repo-clone > $testroot/stdout
751 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
752 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
753 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
754 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
755 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
757 cmp -s $testroot/stdout $testroot/stdout.expected
758 ret=$?
759 if [ $ret -ne 0 ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 test_done "$testroot" "$ret"
762 return 1
763 fi
765 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
766 ret=$?
767 if [ $ret -ne 0 ]; then
768 echo "got fetch command failed unexpectedly" >&2
769 test_done "$testroot" "$ret"
770 return 1
771 fi
773 echo -n > $testroot/stdout.expected
775 cmp -s $testroot/stdout $testroot/stdout.expected
776 ret=$?
777 if [ $ret -ne 0 ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
779 test_done "$testroot" "$ret"
780 return 1
781 fi
783 got ref -l -r $testroot/repo-clone > $testroot/stdout
785 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
786 # refs/heads/foo is now deleted
787 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
788 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
789 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
791 cmp -s $testroot/stdout $testroot/stdout.expected
792 ret=$?
793 if [ $ret -ne 0 ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
795 fi
796 test_done "$testroot" "$ret"
800 test_fetch_update_tag() {
801 local testroot=`test_init fetch_update_tag`
802 local testurl=ssh://127.0.0.1/$testroot
803 local commit_id=`git_show_head $testroot/repo`
806 got branch -r $testroot/repo -c $commit_id foo
807 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
808 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
809 local tag_id=`got ref -r $testroot/repo -l \
810 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
812 got clone -a -q $testurl/repo $testroot/repo-clone
813 ret=$?
814 if [ $ret -ne 0 ]; then
815 echo "got clone command failed unexpectedly" >&2
816 test_done "$testroot" "$ret"
817 return 1
818 fi
820 echo "modified alpha on master" > $testroot/repo/alpha
821 git_commit $testroot/repo -m "modified alpha"
822 local commit_id2=`git_show_head $testroot/repo`
824 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
825 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
826 local tag_id2=`got ref -r $testroot/repo -l \
827 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
829 got ref -l -r $testroot/repo-clone > $testroot/stdout
831 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
832 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
833 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
834 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
835 >> $testroot/stdout.expected
836 echo "refs/remotes/origin/foo: $commit_id" \
837 >> $testroot/stdout.expected
838 echo "refs/remotes/origin/master: $commit_id" \
839 >> $testroot/stdout.expected
840 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
841 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
843 cmp -s $testroot/stdout $testroot/stdout.expected
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 test_done "$testroot" "$ret"
848 return 1
849 fi
851 got fetch -a -q -r $testroot/repo-clone
852 ret=$?
853 if [ $ret -ne 0 ]; then
854 echo "got fetch command failed unexpectedly" >&2
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 got ref -l -r $testroot/repo-clone > $testroot/stdout
861 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
862 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
863 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
864 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
865 >> $testroot/stdout.expected
866 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
867 echo "refs/remotes/origin/master: $commit_id2" \
868 >> $testroot/stdout.expected
869 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
870 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
872 cmp -s $testroot/stdout $testroot/stdout.expected
873 ret=$?
874 if [ $ret -ne 0 ]; then
875 diff -u $testroot/stdout.expected $testroot/stdout
876 test_done "$testroot" "$ret"
877 return 1
878 fi
880 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
881 tail -n 1 > $testroot/stdout
882 ret=$?
883 if [ $ret -ne 0 ]; then
884 echo "got fetch command failed unexpectedly" >&2
885 test_done "$testroot" "$ret"
886 return 1
887 fi
889 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
890 > $testroot/stdout.expected
892 cmp -s $testroot/stdout $testroot/stdout.expected
893 ret=$?
894 if [ $ret -ne 0 ]; then
895 diff -u $testroot/stdout.expected $testroot/stdout
896 test_done "$testroot" "$ret"
897 return 1
898 fi
900 got ref -l -r $testroot/repo-clone > $testroot/stdout
902 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
903 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
904 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
905 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
906 >> $testroot/stdout.expected
907 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
908 echo "refs/remotes/origin/master: $commit_id2" \
909 >> $testroot/stdout.expected
910 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
911 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
913 cmp -s $testroot/stdout $testroot/stdout.expected
914 ret=$?
915 if [ $ret -ne 0 ]; then
916 diff -u $testroot/stdout.expected $testroot/stdout
917 test_done "$testroot" "$ret"
918 return 1
919 fi
921 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
922 ret=$?
923 if [ $ret -ne 0 ]; then
924 echo "got fetch command failed unexpectedly" >&2
925 test_done "$testroot" "$ret"
926 return 1
927 fi
929 echo -n > $testroot/stdout.expected
931 cmp -s $testroot/stdout $testroot/stdout.expected
932 ret=$?
933 if [ $ret -ne 0 ]; then
934 diff -u $testroot/stdout.expected $testroot/stdout
935 test_done "$testroot" "$ret"
936 return 1
937 fi
939 got ref -l -r $testroot/repo-clone > $testroot/stdout
941 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
942 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
943 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
944 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
945 >> $testroot/stdout.expected
946 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
947 echo "refs/remotes/origin/master: $commit_id2" \
948 >> $testroot/stdout.expected
949 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
950 echo "refs/tags/1.0: $tag_id2" >> $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 fi
957 test_done "$testroot" "$ret"
960 test_fetch_reference() {
961 local testroot=`test_init fetch_reference`
962 local testurl=ssh://127.0.0.1/$testroot
963 local commit_id=`git_show_head $testroot/repo`
965 got clone -q $testurl/repo $testroot/repo-clone
966 ret=$?
967 if [ $ret -ne 0 ]; then
968 echo "got clone command failed unexpectedly" >&2
969 test_done "$testroot" "$ret"
970 return 1
971 fi
973 got branch -r $testroot/repo -c $commit_id foo
974 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
975 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
976 local tag_id=`got ref -r $testroot/repo -l \
977 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
979 echo "modified alpha on master" > $testroot/repo/alpha
980 git_commit $testroot/repo -m "modified alpha"
981 local commit_id2=`git_show_head $testroot/repo`
983 git -C $testroot/repo checkout -q foo
984 echo "modified alpha on foo" > $testroot/repo/alpha
985 git_commit $testroot/repo -m "modified alpha"
986 local commit_id3=`git_show_head $testroot/repo`
987 git -C $testroot/repo checkout -q master
989 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
990 > $testroot/stdout 2> $testroot/stderr
991 ret=$?
992 if [ $ret -eq 0 ]; then
993 echo "got fetch command succeeded unexpectedly" >&2
994 test_done "$testroot" "1"
995 return 1
996 fi
998 echo -n > $testroot/stdout.expected
1000 cmp -s $testroot/stdout $testroot/stdout.expected
1001 ret=$?
1002 if [ $ret -ne 0 ]; then
1003 diff -u $testroot/stdout.expected $testroot/stdout
1004 test_done "$testroot" "$ret"
1005 return 1
1008 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
1009 > $testroot/stderr.expected
1011 cmp -s $testroot/stderr $testroot/stderr.expected
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 diff -u $testroot/stderr.expected $testroot/stderr
1015 test_done "$testroot" "$ret"
1016 return 1
1019 got fetch -q -r $testroot/repo-clone -R refs/hoo
1020 ret=$?
1021 if [ $ret -ne 0 ]; then
1022 echo "got fetch command failed unexpectedly" >&2
1023 test_done "$testroot" "$ret"
1024 return 1
1027 got ref -l -r $testroot/repo-clone > $testroot/stdout
1029 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1030 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1031 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1032 >> $testroot/stdout.expected
1033 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
1034 >> $testroot/stdout.expected
1035 echo "refs/remotes/origin/master: $commit_id2" \
1036 >> $testroot/stdout.expected
1037 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1039 cmp -s $testroot/stdout $testroot/stdout.expected
1040 ret=$?
1041 if [ $ret -ne 0 ]; then
1042 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1048 test_fetch_replace_symref() {
1049 local testroot=`test_init fetch_replace_symref`
1050 local testurl=ssh://127.0.0.1/$testroot
1051 local commit_id=`git_show_head $testroot/repo`
1053 got clone -m -q $testurl/repo $testroot/repo-clone
1054 ret=$?
1055 if [ $ret -ne 0 ]; then
1056 echo "got clone command failed unexpectedly" >&2
1057 test_done "$testroot" "$ret"
1058 return 1
1061 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1062 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
1064 got ref -l -r $testroot/repo-clone > $testroot/stdout
1066 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1067 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1068 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
1070 cmp -s $testroot/stdout $testroot/stdout.expected
1071 ret=$?
1072 if [ $ret -ne 0 ]; then
1073 diff -u $testroot/stdout.expected $testroot/stdout
1074 test_done "$testroot" "$ret"
1075 return 1
1078 got fetch -r $testroot/repo-clone -R refs/hoo \
1079 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
1080 ret=$?
1081 if [ $ret -ne 0 ]; then
1082 echo "got fetch command failed unexpectedly" >&2
1083 test_done "$testroot" "$ret"
1084 return 1
1087 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
1088 > $testroot/stdout.expected
1090 cmp -s $testroot/stdout $testroot/stdout.expected
1091 ret=$?
1092 if [ $ret -ne 0 ]; then
1093 diff -u $testroot/stdout.expected $testroot/stdout
1094 test_done "$testroot" "$ret"
1095 return 1
1098 got ref -l -r $testroot/repo-clone > $testroot/stdout
1100 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1101 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1102 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
1104 cmp -s $testroot/stdout $testroot/stdout.expected
1105 ret=$?
1106 if [ $ret -ne 0 ]; then
1107 diff -u $testroot/stdout.expected $testroot/stdout
1109 test_done "$testroot" "$ret"
1113 test_fetch_update_headref() {
1114 local testroot=`test_init fetch_update_headref`
1115 local testurl=ssh://127.0.0.1/$testroot
1116 local commit_id=`git_show_head $testroot/repo`
1118 got clone -q $testurl/repo $testroot/repo-clone
1119 ret=$?
1120 if [ $ret -ne 0 ]; then
1121 echo "got clone command failed unexpectedly" >&2
1122 test_done "$testroot" "$ret"
1123 return 1
1126 got ref -l -r $testroot/repo-clone > $testroot/stdout
1128 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1129 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1130 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1131 >> $testroot/stdout.expected
1132 echo "refs/remotes/origin/master: $commit_id" \
1133 >> $testroot/stdout.expected
1135 cmp -s $testroot/stdout $testroot/stdout.expected
1136 ret=$?
1137 if [ $ret -ne 0 ]; then
1138 diff -u $testroot/stdout.expected $testroot/stdout
1139 test_done "$testroot" "$ret"
1140 return 1
1143 got ref -r $testroot/repo -c refs/heads/master refs/heads/foo
1144 got ref -r $testroot/repo -s refs/heads/foo HEAD
1145 got ref -l -r $testroot/repo > $testroot/stdout
1147 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
1148 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1149 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1151 cmp -s $testroot/stdout $testroot/stdout.expected
1152 ret=$?
1153 if [ $ret -ne 0 ]; then
1154 diff -u $testroot/stdout.expected $testroot/stdout
1155 test_done "$testroot" "$ret"
1156 return 1
1159 got fetch -q -r $testroot/repo-clone
1161 got ref -l -r $testroot/repo-clone > $testroot/stdout
1163 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1164 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1165 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1166 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
1167 >> $testroot/stdout.expected
1168 echo "refs/remotes/origin/foo: $commit_id" \
1169 >> $testroot/stdout.expected
1170 echo "refs/remotes/origin/master: $commit_id" \
1171 >> $testroot/stdout.expected
1173 cmp -s $testroot/stdout $testroot/stdout.expected
1174 ret=$?
1175 if [ $ret -ne 0 ]; then
1176 diff -u $testroot/stdout.expected $testroot/stdout
1177 test_done "$testroot" "$ret"
1178 return 1
1181 got fetch -q -r $testroot/repo-clone -a
1183 got ref -l -r $testroot/repo-clone > $testroot/stdout
1185 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1186 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1187 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1188 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
1189 >> $testroot/stdout.expected
1190 echo "refs/remotes/origin/foo: $commit_id" \
1191 >> $testroot/stdout.expected
1192 echo "refs/remotes/origin/master: $commit_id" \
1193 >> $testroot/stdout.expected
1195 cmp -s $testroot/stdout $testroot/stdout.expected
1196 ret=$?
1197 if [ $ret -ne 0 ]; then
1198 diff -u $testroot/stdout.expected $testroot/stdout
1200 test_done "$testroot" "$ret"
1203 test_fetch_headref_deleted_locally() {
1204 local testroot=`test_init fetch_headref_deleted_locally`
1205 local testurl=ssh://127.0.0.1/$testroot
1206 local commit_id=`git_show_head $testroot/repo`
1208 got clone -q $testurl/repo $testroot/repo-clone
1209 ret=$?
1210 if [ $ret -ne 0 ]; then
1211 echo "got clone command failed unexpectedly" >&2
1212 test_done "$testroot" "$ret"
1213 return 1
1216 got ref -l -r $testroot/repo-clone > $testroot/stdout
1218 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1219 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1220 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1221 >> $testroot/stdout.expected
1222 echo "refs/remotes/origin/master: $commit_id" \
1223 >> $testroot/stdout.expected
1225 cmp -s $testroot/stdout $testroot/stdout.expected
1226 ret=$?
1227 if [ $ret -ne 0 ]; then
1228 diff -u $testroot/stdout.expected $testroot/stdout
1229 test_done "$testroot" "$ret"
1230 return 1
1233 got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD > /dev/null
1235 got fetch -q -r $testroot/repo-clone
1236 ret=$?
1237 if [ $ret -ne 0 ]; then
1238 echo "got fetch command failed unexpectedly" >&2
1239 test_done "$testroot" "$ret"
1240 return 1
1242 got ref -l -r $testroot/repo-clone > $testroot/stdout
1244 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1245 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1246 # refs/remotes/origin/HEAD has been restored:
1247 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1248 >> $testroot/stdout.expected
1249 echo "refs/remotes/origin/master: $commit_id" \
1250 >> $testroot/stdout.expected
1252 cmp -s $testroot/stdout $testroot/stdout.expected
1253 ret=$?
1254 if [ $ret -ne 0 ]; then
1255 diff -u $testroot/stdout.expected $testroot/stdout
1257 test_done "$testroot" "$ret"
1260 test_fetch_gotconfig_remote_repo() {
1261 local testroot=`test_init fetch_gotconfig_remote_repo`
1262 local testurl=ssh://127.0.0.1/$testroot
1263 local commit_id=`git_show_head $testroot/repo`
1265 got branch -r $testroot/repo -c $commit_id foo
1266 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1267 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
1269 got clone -q $testurl/repo $testroot/repo-clone
1270 ret=$?
1271 if [ $ret -ne 0 ]; then
1272 echo "got clone command failed unexpectedly" >&2
1273 test_done "$testroot" "$ret"
1274 return 1
1277 cat > $testroot/repo-clone/got.conf <<EOF
1278 remote "foobar" {
1279 protocol ssh
1280 server 127.0.0.1
1281 repository "$testroot/repo"
1284 remote "barbaz" {
1285 protocol ssh
1286 server 127.0.0.1
1287 repository "$testroot/does-not-exist"
1289 EOF
1290 echo "got: nonexistent: remote repository not found" \
1291 > $testroot/stderr.expected
1292 (cd $testroot/repo-clone && got fetch -q nonexistent \
1293 > $testroot/stdout 2> $testroot/stderr)
1294 ret=$?
1295 if [ $ret -eq 0 ]; then
1296 echo "got fetch command succeeded unexpectedly" >&2
1297 diff -u $testroot/stderr.expected $testroot/stderr
1298 test_done "$testroot" "1"
1299 return 1
1302 (cd $testroot/repo-clone && got fetch -q -l foobar \
1303 > $testroot/stdout)
1304 ret=$?
1305 if [ $ret -ne 0 ]; then
1306 echo "got fetch command failed unexpectedly" >&2
1307 test_done "$testroot" "$ret"
1308 return 1
1311 got ref -l -r $testroot/repo > $testroot/stdout.expected
1313 cmp -s $testroot/stdout $testroot/stdout.expected
1314 ret=$?
1315 if [ $ret -ne 0 ]; then
1316 diff -u $testroot/stdout.expected $testroot/stdout
1317 test_done "$testroot" "$ret"
1318 return 1
1321 got checkout $testroot/repo $testroot/wt > /dev/null
1323 cat > $testroot/wt/.got/got.conf <<EOF
1324 remote "barbaz" {
1325 protocol ssh
1326 server 127.0.0.1
1327 repository "$testroot/repo"
1329 EOF
1330 (cd $testroot/wt && got fetch -q -l barbaz > $testroot/stdout)
1331 ret=$?
1332 if [ $ret -ne 0 ]; then
1333 echo "got fetch command failed unexpectedly" >&2
1334 test_done "$testroot" "$ret"
1335 return 1
1338 got ref -l -r $testroot/repo > $testroot/stdout.expected
1340 cmp -s $testroot/stdout $testroot/stdout.expected
1341 ret=$?
1342 if [ $ret -ne 0 ]; then
1343 diff -u $testroot/stdout.expected $testroot/stdout
1344 test_done "$testroot" "$ret"
1345 return 1
1348 cat > $testroot/repo-clone/got.conf <<EOF
1349 remote "origin" {
1350 protocol ssh
1351 server 127.0.0.1
1352 repository "$testroot/repo"
1353 branch { "foo" }
1354 reference { "hoo/boo/zoo" }
1356 EOF
1357 (cd $testroot/repo-clone && got fetch -q > $testroot/stdout)
1359 local tag_id=`got ref -r $testroot/repo -l \
1360 | grep "^refs/tags/1.0" | tr -d ' ' | cut -d: -f2`
1361 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1362 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1363 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1364 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1365 >> $testroot/stdout.expected
1366 echo "refs/remotes/origin/foo: $commit_id" \
1367 >> $testroot/stdout.expected
1368 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
1369 >> $testroot/stdout.expected
1370 echo "refs/remotes/origin/master: $commit_id" \
1371 >> $testroot/stdout.expected
1372 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1374 got ref -l -r $testroot/repo-clone > $testroot/stdout
1376 cmp -s $testroot/stdout $testroot/stdout.expected
1377 ret=$?
1378 if [ $ret -ne 0 ]; then
1379 diff -u $testroot/stdout.expected $testroot/stdout
1381 test_done "$testroot" "$ret"
1384 test_fetch_delete_remote_refs() {
1385 local testroot=`test_init fetch_delete_remote_refs`
1386 local testurl=ssh://127.0.0.1/$testroot
1387 local commit_id=`git_show_head $testroot/repo`
1389 got clone -q $testurl/repo $testroot/repo-clone
1390 ret=$?
1391 if [ $ret -ne 0 ]; then
1392 echo "got clone command failed unexpectedly" >&2
1393 test_done "$testroot" "$ret"
1394 return 1
1397 got ref -l -r $testroot/repo-clone > $testroot/stdout
1398 ret=$?
1399 if [ $ret -ne 0 ]; then
1400 echo "got ref command failed unexpectedly" >&2
1401 test_done "$testroot" "$ret"
1402 return 1
1405 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1406 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1407 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1408 >> $testroot/stdout.expected
1409 echo "refs/remotes/origin/master: $commit_id" \
1410 >> $testroot/stdout.expected
1412 cmp -s $testroot/stdout $testroot/stdout.expected
1413 ret=$?
1414 if [ $ret -ne 0 ]; then
1415 diff -u $testroot/stdout.expected $testroot/stdout
1416 test_done "$testroot" "$ret"
1417 return 1
1420 got fetch -q -r $testroot/repo-clone -X > $testroot/stdout \
1421 2> $testroot/stderr
1422 ret=$?
1423 if [ $ret -eq 0 ]; then
1424 echo "got fetch command succeeded unexpectedly" >&2
1425 test_done "$testroot" "1"
1426 return 1
1429 echo "got: -X option requires a remote name" > $testroot/stderr.expected
1430 cmp -s $testroot/stderr $testroot/stderr.expected
1431 ret=$?
1432 if [ $ret -ne 0 ]; then
1433 diff -u $testroot/stderr.expected $testroot/stderr
1434 test_done "$testroot" "$ret"
1435 return 1
1438 got fetch -q -r $testroot/repo-clone -X origin > $testroot/stdout \
1439 2> $testroot/stderr
1440 ret=$?
1441 if [ $ret -ne 0 ]; then
1442 echo "got fetch command failed unexpectedly" >&2
1443 test_done "$testroot" "$ret"
1444 return 1
1447 echo -n "Deleted refs/remotes/origin/HEAD: " > $testroot/stdout.expected
1448 echo "refs/remotes/origin/master" >> $testroot/stdout.expected
1449 echo "Deleted refs/remotes/origin/master: $commit_id" \
1450 >> $testroot/stdout.expected
1452 cmp -s $testroot/stdout $testroot/stdout.expected
1453 ret=$?
1454 if [ $ret -ne 0 ]; then
1455 diff -u $testroot/stdout.expected $testroot/stdout
1456 test_done "$testroot" "$ret"
1457 return 1
1460 got ref -l -r $testroot/repo-clone > $testroot/stdout
1461 ret=$?
1462 if [ $ret -ne 0 ]; then
1463 echo "got ref command failed unexpectedly" >&2
1464 test_done "$testroot" "$ret"
1465 return 1
1468 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1469 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1471 cmp -s $testroot/stdout $testroot/stdout.expected
1472 ret=$?
1473 if [ $ret -ne 0 ]; then
1474 diff -u $testroot/stdout.expected $testroot/stdout
1476 test_done "$testroot" "$ret"
1479 test_fetch_honor_wt_conf_bflag() {
1480 local testroot=`test_init fetch_honor_wt_conf_bflag`
1481 local testurl=ssh://127.0.0.1/$testroot
1483 # server will have 'boo', 'hoo', and 'master'
1484 echo "modified alpha on master" > $testroot/repo/alpha
1485 git_commit $testroot/repo -m "modified alpha"
1486 local commit_id=`git_show_head $testroot/repo`
1488 got branch -r $testroot/repo -c $commit_id boo
1489 git -C $testroot/repo checkout -q boo
1490 echo "modified beta on boo" > $testroot/repo/beta
1491 git_commit $testroot/repo -m "modified beta"
1492 local commit_id2=`git_show_head $testroot/repo`
1494 got branch -r $testroot/repo -c $commit_id2 hoo
1495 git -C $testroot/repo checkout -q hoo
1496 echo "modified delta on hoo" > $testroot/repo/gamma/delta
1497 git_commit $testroot/repo -m "modified delta"
1498 local commit_id3=`git_show_head $testroot/repo`
1500 git -C $testroot/repo checkout -q master
1501 got clone -q $testurl/repo $testroot/repo-clone
1502 ret=$?
1503 if [ $ret -ne 0 ]; then
1504 echo "got clone command failed unexpectedly" >&2
1505 test_done "$testroot" "$ret"
1506 return 1
1509 # only clone will have foo and bar
1510 got branch -r $testroot/repo-clone -c $commit_id foo
1511 got branch -r $testroot/repo-clone -c $commit_id bar
1513 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1514 ret=$?
1515 if [ $ret -ne 0 ]; then
1516 echo "got fetch command failed unexpectedly" >&2
1517 test_done "$testroot" "$ret"
1518 return 1
1521 echo -n > $testroot/stdout.expected
1523 cmp -s $testroot/stdout $testroot/stdout.expected
1524 ret=$?
1525 if [ $ret -ne 0 ]; then
1526 diff -u $testroot/stdout.expected $testroot/stdout
1527 test_done "$testroot" "$ret"
1528 return 1
1531 got ref -l -r $testroot/repo-clone > $testroot/stdout
1533 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1534 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1535 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1536 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1537 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1538 >> $testroot/stdout.expected
1539 echo "refs/remotes/origin/master: $commit_id" \
1540 >> $testroot/stdout.expected
1542 cmp -s $testroot/stdout $testroot/stdout.expected
1543 ret=$?
1544 if [ $ret -ne 0 ]; then
1545 diff -u $testroot/stdout.expected $testroot/stdout
1546 test_done "$testroot" "$ret"
1547 return 1
1550 git -C $testroot/repo checkout -q boo
1551 # clone has remote/origin/HEAD symref with "master" as its target
1552 # but the repo has changed HEAD to "boo", so we should fetch "boo"
1553 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1554 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1555 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1556 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1557 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1558 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1559 >> $testroot/stdout.expected
1560 echo "refs/remotes/origin/boo: $commit_id2" \
1561 >> $testroot/stdout.expected
1562 echo "refs/remotes/origin/master: $commit_id" \
1563 >> $testroot/stdout.expected
1565 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1566 ret=$?
1567 if [ $ret -ne 0 ]; then
1568 echo "got fetch command failed unexpectedly" >&2
1569 test_done "$testroot" "$ret"
1570 return 1
1573 got ref -l -r $testroot/repo-clone > $testroot/stdout
1575 cmp -s $testroot/stdout $testroot/stdout.expected
1576 ret=$?
1577 if [ $ret -ne 0 ]; then
1578 diff -u $testroot/stdout.expected $testroot/stdout
1579 test_done "$testroot" "$ret"
1580 return 1
1583 # from repo: fetch -b hoo
1584 got fetch -q -r $testroot/repo-clone -b hoo > $testroot/stdout
1585 ret=$?
1586 if [ $ret -ne 0 ]; then
1587 echo "got fetch command failed unexpectedly" >&2
1588 test_done "$testroot" "$ret"
1589 return 1
1592 echo -n > $testroot/stdout.expected
1594 cmp -s $testroot/stdout $testroot/stdout.expected
1595 ret=$?
1596 if [ $ret -ne 0 ]; then
1597 diff -u $testroot/stdout.expected $testroot/stdout
1598 test_done "$testroot" "$ret"
1599 return 1
1602 got ref -l -r $testroot/repo-clone > $testroot/stdout
1604 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1605 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1606 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1607 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1608 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1609 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1610 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1611 >> $testroot/stdout.expected
1612 echo "refs/remotes/origin/boo: $commit_id2" \
1613 >> $testroot/stdout.expected
1614 echo "refs/remotes/origin/hoo: $commit_id3" \
1615 >> $testroot/stdout.expected
1616 echo "refs/remotes/origin/master: $commit_id" \
1617 >> $testroot/stdout.expected
1619 cmp -s $testroot/stdout $testroot/stdout.expected
1620 ret=$?
1621 if [ $ret -ne 0 ]; then
1622 diff -u $testroot/stdout.expected $testroot/stdout
1623 test_done "$testroot" "$ret"
1624 return 1
1627 # from repo: fetch -b foo which doesn't exist on the server but
1628 # do not fallback to repo HEAD "boo" because we used the -b flag
1629 got fetch -r $testroot/repo-clone -b foo > $testroot/stdout \
1630 2> $testroot/stderr
1632 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \
1633 > $testroot/stdout.expected
1634 echo "got-fetch-pack: branch \"foo\" not found on server" \
1635 > $testroot/stderr.expected
1636 echo "got: could not find any branches to fetch" \
1637 >> $testroot/stderr.expected
1639 cmp -s $testroot/stdout $testroot/stdout.expected
1640 ret=$?
1641 if [ $ret -ne 0 ]; then
1642 diff -u $testroot/stdout.expected $testroot/stdout
1643 test_done "$testroot" "$ret"
1644 return 1
1647 cmp -s $testroot/stderr $testroot/stderr.expected
1648 ret=$?
1649 if [ $ret -ne 0 ]; then
1650 diff -u $testroot/stderr.expected $testroot/stderr
1651 test_done "$testroot" "$ret"
1652 return 1
1655 # from repo: fetch got.conf branch which doesn't exist, so fallback
1656 # to repo HEAD "boo"
1657 # change default branch in got.conf from "master" to "foo"
1658 ed -s $testroot/repo-clone/got.conf <<-EOF
1659 ,s/master/foo/
1661 EOF
1663 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1664 ret=$?
1665 if [ $ret -ne 0 ]; then
1666 echo "got fetch command failed unexpectedly" >&2
1667 test_done "$testroot" "$ret"
1668 return 1
1671 echo -n > $testroot/stdout.expected
1673 cmp -s $testroot/stdout $testroot/stdout.expected
1674 ret=$?
1675 if [ $ret -ne 0 ]; then
1676 diff -u $testroot/stdout.expected $testroot/stdout
1677 test_done "$testroot" "$ret"
1678 return 1
1681 got ref -l -r $testroot/repo-clone > $testroot/stdout
1683 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1684 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1685 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1686 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1687 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1688 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1689 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1690 >> $testroot/stdout.expected
1691 echo "refs/remotes/origin/boo: $commit_id2" \
1692 >> $testroot/stdout.expected
1693 echo "refs/remotes/origin/hoo: $commit_id3" \
1694 >> $testroot/stdout.expected
1695 echo "refs/remotes/origin/master: $commit_id" \
1696 >> $testroot/stdout.expected
1698 cmp -s $testroot/stdout $testroot/stdout.expected
1699 ret=$?
1700 if [ $ret -ne 0 ]; then
1701 diff -u $testroot/stdout.expected $testroot/stdout
1702 test_done "$testroot" "$ret"
1703 return 1
1706 # from wt: fetch got.conf "foo", which doesn't exist on the server,
1707 # and implicit wt branch "boo", not repo HEAD "master"
1708 echo "modified delta on boo" > $testroot/repo/gamma/delta
1709 git_commit $testroot/repo -m "modified delta"
1710 local commit_id4=`git_show_head $testroot/repo`
1712 git -C $testroot/repo checkout -q master
1714 got checkout -b boo $testroot/repo-clone $testroot/wt > /dev/null
1715 (cd $testroot/wt && got fetch -q > $testroot/stdout)
1717 echo -n > $testroot/stdout.expected
1719 cmp -s $testroot/stdout $testroot/stdout.expected
1720 ret=$?
1721 if [ $ret -ne 0 ]; then
1722 diff -u $testroot/stdout.expected $testroot/stdout
1723 test_done "$testroot" "$ret"
1724 return 1
1727 local wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1728 cut -d ':' -f 2 | tr -d ' ')`
1730 got ref -l -r $testroot/repo-clone > $testroot/stdout
1732 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1733 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1734 >> $testroot/stdout.expected
1735 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1736 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1737 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1738 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1739 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1740 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1741 >> $testroot/stdout.expected
1742 echo "refs/remotes/origin/boo: $commit_id4" \
1743 >> $testroot/stdout.expected
1744 echo "refs/remotes/origin/hoo: $commit_id3" \
1745 >> $testroot/stdout.expected
1746 echo "refs/remotes/origin/master: $commit_id" \
1747 >> $testroot/stdout.expected
1749 cmp -s $testroot/stdout $testroot/stdout.expected
1750 ret=$?
1751 if [ $ret -ne 0 ]; then
1752 diff -u $testroot/stdout.expected $testroot/stdout
1753 test_done "$testroot" "$ret"
1754 return 1
1757 # from wt: fetch got.conf "master", wt "boo", and the repo's new HEAD
1758 # "hoo" as it no longer matches our remote HEAD symref target "master"
1759 ed -s $testroot/repo-clone/got.conf <<-EOF
1760 ,s/foo/master/
1762 EOF
1763 echo "modified delta on master" > $testroot/repo/gamma/delta
1764 git_commit $testroot/repo -m "modified delta on master"
1765 local commit_id5=`git_show_head $testroot/repo`
1767 git -C $testroot/repo checkout -q boo
1768 echo "modified alpha on boo" > $testroot/repo/alpha
1769 git_commit $testroot/repo -m "modified alpha on boo"
1770 local commit_id6=`git_show_head $testroot/repo`
1772 git -C $testroot/repo checkout -q hoo
1773 echo "modified beta on hoo" > $testroot/repo/beta
1774 git_commit $testroot/repo -m "modified beta on hoo"
1775 local commit_id7=`git_show_head $testroot/repo`
1777 (cd $testroot/wt && got fetch -q > $testroot/stdout)
1779 echo -n > $testroot/stdout.expected
1781 cmp -s $testroot/stdout $testroot/stdout.expected
1782 ret=$?
1783 if [ $ret -ne 0 ]; then
1784 diff -u $testroot/stdout.expected $testroot/stdout
1785 test_done "$testroot" "$ret"
1786 return 1
1789 got ref -l -r $testroot/repo-clone > $testroot/stdout
1791 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1792 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1793 >> $testroot/stdout.expected
1794 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1795 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1796 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1797 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1798 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1799 echo "refs/remotes/origin/HEAD: refs/remotes/origin/hoo" \
1800 >> $testroot/stdout.expected
1801 echo "refs/remotes/origin/boo: $commit_id6" \
1802 >> $testroot/stdout.expected
1803 echo "refs/remotes/origin/hoo: $commit_id7" \
1804 >> $testroot/stdout.expected
1805 echo "refs/remotes/origin/master: $commit_id5" \
1806 >> $testroot/stdout.expected
1808 cmp -s $testroot/stdout $testroot/stdout.expected
1809 ret=$?
1810 if [ $ret -ne 0 ]; then
1811 diff -u $testroot/stdout.expected $testroot/stdout
1812 test_done "$testroot" "$ret"
1813 return 1
1816 # from wt: fetch -b hoo not got.conf "master" or wt "boo" or
1817 # repo HEAD "boo"
1818 git -C $testroot/repo checkout -q boo
1819 echo "modified alpha again on boo" > $testroot/repo/alpha
1820 git_commit $testroot/repo -m "modified alpha again on boo"
1821 local commit_id8=`git_show_head $testroot/repo`
1823 (cd $testroot/wt && got fetch -q -b hoo > $testroot/stdout)
1825 echo -n > $testroot/stdout.expected
1827 cmp -s $testroot/stdout $testroot/stdout.expected
1828 ret=$?
1829 if [ $ret -ne 0 ]; then
1830 diff -u $testroot/stdout.expected $testroot/stdout
1831 test_done "$testroot" "$ret"
1832 return 1
1835 got ref -l -r $testroot/repo-clone > $testroot/stdout
1837 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1838 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1839 >> $testroot/stdout.expected
1840 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1841 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1842 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1843 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1844 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1845 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1846 >> $testroot/stdout.expected
1847 echo "refs/remotes/origin/boo: $commit_id6" \
1848 >> $testroot/stdout.expected
1849 echo "refs/remotes/origin/hoo: $commit_id7" \
1850 >> $testroot/stdout.expected
1851 echo "refs/remotes/origin/master: $commit_id5" \
1852 >> $testroot/stdout.expected
1854 cmp -s $testroot/stdout $testroot/stdout.expected
1855 ret=$?
1856 if [ $ret -ne 0 ]; then
1857 diff -u $testroot/stdout.expected $testroot/stdout
1858 test_done "$testroot" "$ret"
1859 return 1
1862 # from wt: fetch -b bar that doesn't exist on the server but
1863 # do not fetch got.conf "master" or wt "boo" or repo HEAD "boo"
1864 (cd $testroot/wt && got fetch -b bar > $testroot/stdout \
1865 2> $testroot/stderr)
1867 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \
1868 > $testroot/stdout.expected
1869 echo "got-fetch-pack: branch \"bar\" not found on server" \
1870 > $testroot/stderr.expected
1871 echo "got: could not find any branches to fetch" \
1872 >> $testroot/stderr.expected
1874 cmp -s $testroot/stderr $testroot/stderr.expected
1875 ret=$?
1876 if [ $ret -ne 0 ]; then
1877 diff -u $testroot/stderr.expected $testroot/stderr
1878 test_done "$testroot" "$ret"
1879 return 1
1882 cmp -s $testroot/stdout $testroot/stdout.expected
1883 ret=$?
1884 if [ $ret -ne 0 ]; then
1885 diff -u $testroot/stdout.expected $testroot/stdout
1887 test_done "$testroot" "$ret"
1890 test_fetch_from_out_of_date_remote() {
1891 local testroot=`test_init fetch_from_out_of_date_remote`
1892 local testurl=ssh://127.0.0.1/$testroot
1893 local commit_id=`git_show_head $testroot/repo`
1895 got clone -q $testurl/repo $testroot/repo-clone
1896 ret=$?
1897 if [ $ret -ne 0 ]; then
1898 echo "got clone command failed unexpectedly" >&2
1899 test_done "$testroot" "$ret"
1900 return 1
1903 echo "modified alpha" > $testroot/repo/alpha
1904 git_commit $testroot/repo -m "modified alpha"
1905 local commit_id2=`git_show_head $testroot/repo`
1907 got clone -q $testurl/repo $testroot/repo-clone2 \
1908 > $testroot/stdout 2> $testroot/stderr
1909 ret=$?
1910 if [ $ret -ne 0 ]; then
1911 echo "got clone command failed unexpectedly" >&2
1912 test_done "$testroot" "$ret"
1913 return 1
1916 got ref -l -r $testroot/repo-clone2 > $testroot/stdout
1917 ret=$?
1918 if [ $ret -ne 0 ]; then
1919 echo "got ref command failed unexpectedly" >&2
1920 test_done "$testroot" "$ret"
1921 return 1
1924 cat > $testroot/stdout.expected <<EOF
1925 HEAD: refs/heads/master
1926 refs/heads/master: $commit_id2
1927 refs/remotes/origin/HEAD: refs/remotes/origin/master
1928 refs/remotes/origin/master: $commit_id2
1929 EOF
1930 cmp -s $testroot/stdout $testroot/stdout.expected
1931 ret=$?
1932 if [ $ret -ne 0 ]; then
1933 diff -u $testroot/stdout.expected $testroot/stdout
1934 test_done "$testroot" "$ret"
1935 return 1
1938 cat >> $testroot/repo-clone2/got.conf <<EOF
1939 remote "other" {
1940 server "127.0.0.1"
1941 protocol ssh
1942 repository "$testroot/repo-clone"
1943 branch { "master" }
1945 EOF
1946 got fetch -q -r $testroot/repo-clone2 other \
1947 > $testroot/stdout 2> $testroot/stderr
1948 ret=$?
1949 if [ $ret -ne 0 ]; then
1950 echo "got fetch command failed unexpectedly" >&2
1951 test_done "$testroot" "$ret"
1952 return 1
1955 got ref -l -r $testroot/repo-clone2 > $testroot/stdout
1956 ret=$?
1957 if [ $ret -ne 0 ]; then
1958 echo "got ref command failed unexpectedly" >&2
1959 test_done "$testroot" "$ret"
1960 return 1
1963 cat > $testroot/stdout.expected <<EOF
1964 HEAD: refs/heads/master
1965 refs/heads/master: $commit_id2
1966 refs/remotes/origin/HEAD: refs/remotes/origin/master
1967 refs/remotes/origin/master: $commit_id2
1968 refs/remotes/other/HEAD: refs/remotes/other/master
1969 refs/remotes/other/master: $commit_id
1970 EOF
1971 cmp -s $testroot/stdout $testroot/stdout.expected
1972 ret=$?
1973 if [ $ret -ne 0 ]; then
1974 diff -u $testroot/stdout.expected $testroot/stdout
1976 test_done "$testroot" "$ret"
1980 test_parseargs "$@"
1981 run_test test_fetch_basic
1982 run_test test_fetch_list
1983 run_test test_fetch_branch
1984 run_test test_fetch_all
1985 run_test test_fetch_empty_packfile
1986 run_test test_fetch_delete_branch
1987 run_test test_fetch_delete_branch_mirror
1988 run_test test_fetch_update_tag
1989 run_test test_fetch_reference
1990 run_test test_fetch_replace_symref
1991 run_test test_fetch_update_headref
1992 run_test test_fetch_headref_deleted_locally
1993 run_test test_fetch_gotconfig_remote_repo
1994 run_test test_fetch_delete_remote_refs
1995 run_test test_fetch_honor_wt_conf_bflag
1996 run_test test_fetch_from_out_of_date_remote