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_gitconfig_remote_repo() {
1385 local testroot=`test_init fetch_gotconfig_remote_repo`
1386 local testurl=ssh://127.0.0.1/$testroot
1387 local commit_id=`git_show_head $testroot/repo`
1389 make_single_file_repo $testroot/alternate-repo foo
1390 local alt_commit_id=`git_show_head $testroot/alternate-repo`
1392 cat >> $testroot/repo/.git/config <<EOF
1393 [remote "hasnourl"]
1394 unrelated = setting
1395 [remote "alt"]
1396 url = $testurl/alternate-repo
1397 [remote "another"]
1398 url = $testurl/some-other-repo
1399 EOF
1401 # unset in a subshell to avoid affecting our environment
1402 (unset GOT_IGNORE_GITCONFIG && cd $testroot/repo && got fetch -q alt)
1403 ret=$?
1404 if [ $ret -ne 0 ]; then
1405 echo "got fetch command failed unexpectedly" >&2
1406 test_done "$testroot" "$ret"
1407 return 1
1410 got ref -l -r $testroot/repo > $testroot/stdout
1412 cat > $testroot/stdout.expected <<-EOF
1413 HEAD: refs/heads/master
1414 refs/heads/master: $commit_id
1415 refs/remotes/alt/HEAD: refs/remotes/alt/master
1416 refs/remotes/alt/master: $alt_commit_id
1417 EOF
1419 cmp -s $testroot/stdout $testroot/stdout.expected
1420 ret=$?
1421 if [ $ret -ne 0 ]; then
1422 diff -u $testroot/stdout.expected $testroot/stdout
1424 test_done "$testroot" "$ret"
1427 test_fetch_delete_remote_refs() {
1428 local testroot=`test_init fetch_delete_remote_refs`
1429 local testurl=ssh://127.0.0.1/$testroot
1430 local commit_id=`git_show_head $testroot/repo`
1432 got clone -q $testurl/repo $testroot/repo-clone
1433 ret=$?
1434 if [ $ret -ne 0 ]; then
1435 echo "got clone command failed unexpectedly" >&2
1436 test_done "$testroot" "$ret"
1437 return 1
1440 got ref -l -r $testroot/repo-clone > $testroot/stdout
1441 ret=$?
1442 if [ $ret -ne 0 ]; then
1443 echo "got ref command failed unexpectedly" >&2
1444 test_done "$testroot" "$ret"
1445 return 1
1448 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1449 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1450 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1451 >> $testroot/stdout.expected
1452 echo "refs/remotes/origin/master: $commit_id" \
1453 >> $testroot/stdout.expected
1455 cmp -s $testroot/stdout $testroot/stdout.expected
1456 ret=$?
1457 if [ $ret -ne 0 ]; then
1458 diff -u $testroot/stdout.expected $testroot/stdout
1459 test_done "$testroot" "$ret"
1460 return 1
1463 got fetch -q -r $testroot/repo-clone -X > $testroot/stdout \
1464 2> $testroot/stderr
1465 ret=$?
1466 if [ $ret -eq 0 ]; then
1467 echo "got fetch command succeeded unexpectedly" >&2
1468 test_done "$testroot" "1"
1469 return 1
1472 echo "got: -X option requires a remote name" > $testroot/stderr.expected
1473 cmp -s $testroot/stderr $testroot/stderr.expected
1474 ret=$?
1475 if [ $ret -ne 0 ]; then
1476 diff -u $testroot/stderr.expected $testroot/stderr
1477 test_done "$testroot" "$ret"
1478 return 1
1481 got fetch -q -r $testroot/repo-clone -X origin > $testroot/stdout \
1482 2> $testroot/stderr
1483 ret=$?
1484 if [ $ret -ne 0 ]; then
1485 echo "got fetch command failed unexpectedly" >&2
1486 test_done "$testroot" "$ret"
1487 return 1
1490 echo -n "Deleted refs/remotes/origin/HEAD: " > $testroot/stdout.expected
1491 echo "refs/remotes/origin/master" >> $testroot/stdout.expected
1492 echo "Deleted refs/remotes/origin/master: $commit_id" \
1493 >> $testroot/stdout.expected
1495 cmp -s $testroot/stdout $testroot/stdout.expected
1496 ret=$?
1497 if [ $ret -ne 0 ]; then
1498 diff -u $testroot/stdout.expected $testroot/stdout
1499 test_done "$testroot" "$ret"
1500 return 1
1503 got ref -l -r $testroot/repo-clone > $testroot/stdout
1504 ret=$?
1505 if [ $ret -ne 0 ]; then
1506 echo "got ref command failed unexpectedly" >&2
1507 test_done "$testroot" "$ret"
1508 return 1
1511 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1512 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1514 cmp -s $testroot/stdout $testroot/stdout.expected
1515 ret=$?
1516 if [ $ret -ne 0 ]; then
1517 diff -u $testroot/stdout.expected $testroot/stdout
1519 test_done "$testroot" "$ret"
1522 test_fetch_honor_wt_conf_bflag() {
1523 local testroot=`test_init fetch_honor_wt_conf_bflag`
1524 local testurl=ssh://127.0.0.1/$testroot
1526 # server will have 'boo', 'hoo', and 'master'
1527 echo "modified alpha on master" > $testroot/repo/alpha
1528 git_commit $testroot/repo -m "modified alpha"
1529 local commit_id=`git_show_head $testroot/repo`
1531 got branch -r $testroot/repo -c $commit_id boo
1532 git -C $testroot/repo checkout -q boo
1533 echo "modified beta on boo" > $testroot/repo/beta
1534 git_commit $testroot/repo -m "modified beta"
1535 local commit_id2=`git_show_head $testroot/repo`
1537 got branch -r $testroot/repo -c $commit_id2 hoo
1538 git -C $testroot/repo checkout -q hoo
1539 echo "modified delta on hoo" > $testroot/repo/gamma/delta
1540 git_commit $testroot/repo -m "modified delta"
1541 local commit_id3=`git_show_head $testroot/repo`
1543 git -C $testroot/repo checkout -q master
1544 got clone -q $testurl/repo $testroot/repo-clone
1545 ret=$?
1546 if [ $ret -ne 0 ]; then
1547 echo "got clone command failed unexpectedly" >&2
1548 test_done "$testroot" "$ret"
1549 return 1
1552 # only clone will have foo and bar
1553 got branch -r $testroot/repo-clone -c $commit_id foo
1554 got branch -r $testroot/repo-clone -c $commit_id bar
1556 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1557 ret=$?
1558 if [ $ret -ne 0 ]; then
1559 echo "got fetch command failed unexpectedly" >&2
1560 test_done "$testroot" "$ret"
1561 return 1
1564 echo -n > $testroot/stdout.expected
1566 cmp -s $testroot/stdout $testroot/stdout.expected
1567 ret=$?
1568 if [ $ret -ne 0 ]; then
1569 diff -u $testroot/stdout.expected $testroot/stdout
1570 test_done "$testroot" "$ret"
1571 return 1
1574 got ref -l -r $testroot/repo-clone > $testroot/stdout
1576 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1577 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1578 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1579 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1580 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1581 >> $testroot/stdout.expected
1582 echo "refs/remotes/origin/master: $commit_id" \
1583 >> $testroot/stdout.expected
1585 cmp -s $testroot/stdout $testroot/stdout.expected
1586 ret=$?
1587 if [ $ret -ne 0 ]; then
1588 diff -u $testroot/stdout.expected $testroot/stdout
1589 test_done "$testroot" "$ret"
1590 return 1
1593 git -C $testroot/repo checkout -q boo
1594 # clone has remote/origin/HEAD symref with "master" as its target
1595 # but the repo has changed HEAD to "boo", so we should fetch "boo"
1596 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1597 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1598 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1599 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1600 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1601 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1602 >> $testroot/stdout.expected
1603 echo "refs/remotes/origin/boo: $commit_id2" \
1604 >> $testroot/stdout.expected
1605 echo "refs/remotes/origin/master: $commit_id" \
1606 >> $testroot/stdout.expected
1608 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1609 ret=$?
1610 if [ $ret -ne 0 ]; then
1611 echo "got fetch command failed unexpectedly" >&2
1612 test_done "$testroot" "$ret"
1613 return 1
1616 got ref -l -r $testroot/repo-clone > $testroot/stdout
1618 cmp -s $testroot/stdout $testroot/stdout.expected
1619 ret=$?
1620 if [ $ret -ne 0 ]; then
1621 diff -u $testroot/stdout.expected $testroot/stdout
1622 test_done "$testroot" "$ret"
1623 return 1
1626 # from repo: fetch -b hoo
1627 got fetch -q -r $testroot/repo-clone -b hoo > $testroot/stdout
1628 ret=$?
1629 if [ $ret -ne 0 ]; then
1630 echo "got fetch command failed unexpectedly" >&2
1631 test_done "$testroot" "$ret"
1632 return 1
1635 echo -n > $testroot/stdout.expected
1637 cmp -s $testroot/stdout $testroot/stdout.expected
1638 ret=$?
1639 if [ $ret -ne 0 ]; then
1640 diff -u $testroot/stdout.expected $testroot/stdout
1641 test_done "$testroot" "$ret"
1642 return 1
1645 got ref -l -r $testroot/repo-clone > $testroot/stdout
1647 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1648 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1649 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1650 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1651 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1652 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1653 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1654 >> $testroot/stdout.expected
1655 echo "refs/remotes/origin/boo: $commit_id2" \
1656 >> $testroot/stdout.expected
1657 echo "refs/remotes/origin/hoo: $commit_id3" \
1658 >> $testroot/stdout.expected
1659 echo "refs/remotes/origin/master: $commit_id" \
1660 >> $testroot/stdout.expected
1662 cmp -s $testroot/stdout $testroot/stdout.expected
1663 ret=$?
1664 if [ $ret -ne 0 ]; then
1665 diff -u $testroot/stdout.expected $testroot/stdout
1666 test_done "$testroot" "$ret"
1667 return 1
1670 # from repo: fetch -b foo which doesn't exist on the server but
1671 # do not fallback to repo HEAD "boo" because we used the -b flag
1672 got fetch -r $testroot/repo-clone -b foo > $testroot/stdout \
1673 2> $testroot/stderr
1675 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \
1676 > $testroot/stdout.expected
1677 echo "got-fetch-pack: branch \"foo\" not found on server" \
1678 > $testroot/stderr.expected
1679 echo "got: could not find any branches to fetch" \
1680 >> $testroot/stderr.expected
1682 cmp -s $testroot/stdout $testroot/stdout.expected
1683 ret=$?
1684 if [ $ret -ne 0 ]; then
1685 diff -u $testroot/stdout.expected $testroot/stdout
1686 test_done "$testroot" "$ret"
1687 return 1
1690 cmp -s $testroot/stderr $testroot/stderr.expected
1691 ret=$?
1692 if [ $ret -ne 0 ]; then
1693 diff -u $testroot/stderr.expected $testroot/stderr
1694 test_done "$testroot" "$ret"
1695 return 1
1698 # from repo: fetch got.conf branch which doesn't exist, so fallback
1699 # to repo HEAD "boo"
1700 # change default branch in got.conf from "master" to "foo"
1701 ed -s $testroot/repo-clone/got.conf <<-EOF
1702 ,s/master/foo/
1704 EOF
1706 got fetch -q -r $testroot/repo-clone > $testroot/stdout
1707 ret=$?
1708 if [ $ret -ne 0 ]; then
1709 echo "got fetch command failed unexpectedly" >&2
1710 test_done "$testroot" "$ret"
1711 return 1
1714 echo -n > $testroot/stdout.expected
1716 cmp -s $testroot/stdout $testroot/stdout.expected
1717 ret=$?
1718 if [ $ret -ne 0 ]; then
1719 diff -u $testroot/stdout.expected $testroot/stdout
1720 test_done "$testroot" "$ret"
1721 return 1
1724 got ref -l -r $testroot/repo-clone > $testroot/stdout
1726 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1727 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1728 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1729 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1730 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1731 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1732 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1733 >> $testroot/stdout.expected
1734 echo "refs/remotes/origin/boo: $commit_id2" \
1735 >> $testroot/stdout.expected
1736 echo "refs/remotes/origin/hoo: $commit_id3" \
1737 >> $testroot/stdout.expected
1738 echo "refs/remotes/origin/master: $commit_id" \
1739 >> $testroot/stdout.expected
1741 cmp -s $testroot/stdout $testroot/stdout.expected
1742 ret=$?
1743 if [ $ret -ne 0 ]; then
1744 diff -u $testroot/stdout.expected $testroot/stdout
1745 test_done "$testroot" "$ret"
1746 return 1
1749 # from wt: fetch got.conf "foo", which doesn't exist on the server,
1750 # and implicit wt branch "boo", not repo HEAD "master"
1751 echo "modified delta on boo" > $testroot/repo/gamma/delta
1752 git_commit $testroot/repo -m "modified delta"
1753 local commit_id4=`git_show_head $testroot/repo`
1755 git -C $testroot/repo checkout -q master
1757 got checkout -b boo $testroot/repo-clone $testroot/wt > /dev/null
1758 (cd $testroot/wt && got fetch -q > $testroot/stdout)
1760 echo -n > $testroot/stdout.expected
1762 cmp -s $testroot/stdout $testroot/stdout.expected
1763 ret=$?
1764 if [ $ret -ne 0 ]; then
1765 diff -u $testroot/stdout.expected $testroot/stdout
1766 test_done "$testroot" "$ret"
1767 return 1
1770 local wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
1771 cut -d ':' -f 2 | tr -d ' ')`
1773 got ref -l -r $testroot/repo-clone > $testroot/stdout
1775 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1776 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1777 >> $testroot/stdout.expected
1778 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1779 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1780 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1781 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1782 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1783 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1784 >> $testroot/stdout.expected
1785 echo "refs/remotes/origin/boo: $commit_id4" \
1786 >> $testroot/stdout.expected
1787 echo "refs/remotes/origin/hoo: $commit_id3" \
1788 >> $testroot/stdout.expected
1789 echo "refs/remotes/origin/master: $commit_id" \
1790 >> $testroot/stdout.expected
1792 cmp -s $testroot/stdout $testroot/stdout.expected
1793 ret=$?
1794 if [ $ret -ne 0 ]; then
1795 diff -u $testroot/stdout.expected $testroot/stdout
1796 test_done "$testroot" "$ret"
1797 return 1
1800 # from wt: fetch got.conf "master", wt "boo", and the repo's new HEAD
1801 # "hoo" as it no longer matches our remote HEAD symref target "master"
1802 ed -s $testroot/repo-clone/got.conf <<-EOF
1803 ,s/foo/master/
1805 EOF
1806 echo "modified delta on master" > $testroot/repo/gamma/delta
1807 git_commit $testroot/repo -m "modified delta on master"
1808 local commit_id5=`git_show_head $testroot/repo`
1810 git -C $testroot/repo checkout -q boo
1811 echo "modified alpha on boo" > $testroot/repo/alpha
1812 git_commit $testroot/repo -m "modified alpha on boo"
1813 local commit_id6=`git_show_head $testroot/repo`
1815 git -C $testroot/repo checkout -q hoo
1816 echo "modified beta on hoo" > $testroot/repo/beta
1817 git_commit $testroot/repo -m "modified beta on hoo"
1818 local commit_id7=`git_show_head $testroot/repo`
1820 (cd $testroot/wt && got fetch -q > $testroot/stdout)
1822 echo -n > $testroot/stdout.expected
1824 cmp -s $testroot/stdout $testroot/stdout.expected
1825 ret=$?
1826 if [ $ret -ne 0 ]; then
1827 diff -u $testroot/stdout.expected $testroot/stdout
1828 test_done "$testroot" "$ret"
1829 return 1
1832 got ref -l -r $testroot/repo-clone > $testroot/stdout
1834 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1835 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1836 >> $testroot/stdout.expected
1837 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1838 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1839 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1840 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1841 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1842 echo "refs/remotes/origin/HEAD: refs/remotes/origin/hoo" \
1843 >> $testroot/stdout.expected
1844 echo "refs/remotes/origin/boo: $commit_id6" \
1845 >> $testroot/stdout.expected
1846 echo "refs/remotes/origin/hoo: $commit_id7" \
1847 >> $testroot/stdout.expected
1848 echo "refs/remotes/origin/master: $commit_id5" \
1849 >> $testroot/stdout.expected
1851 cmp -s $testroot/stdout $testroot/stdout.expected
1852 ret=$?
1853 if [ $ret -ne 0 ]; then
1854 diff -u $testroot/stdout.expected $testroot/stdout
1855 test_done "$testroot" "$ret"
1856 return 1
1859 # from wt: fetch -b hoo not got.conf "master" or wt "boo" or
1860 # repo HEAD "boo"
1861 git -C $testroot/repo checkout -q boo
1862 echo "modified alpha again on boo" > $testroot/repo/alpha
1863 git_commit $testroot/repo -m "modified alpha again on boo"
1864 local commit_id8=`git_show_head $testroot/repo`
1866 (cd $testroot/wt && got fetch -q -b hoo > $testroot/stdout)
1868 echo -n > $testroot/stdout.expected
1870 cmp -s $testroot/stdout $testroot/stdout.expected
1871 ret=$?
1872 if [ $ret -ne 0 ]; then
1873 diff -u $testroot/stdout.expected $testroot/stdout
1874 test_done "$testroot" "$ret"
1875 return 1
1878 got ref -l -r $testroot/repo-clone > $testroot/stdout
1880 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1881 echo "refs/got/worktree/base-$wt_uuid: $commit_id2" \
1882 >> $testroot/stdout.expected
1883 echo "refs/heads/bar: $commit_id" >> $testroot/stdout.expected
1884 echo "refs/heads/boo: $commit_id2" >> $testroot/stdout.expected
1885 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1886 echo "refs/heads/hoo: $commit_id3" >> $testroot/stdout.expected
1887 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1888 echo "refs/remotes/origin/HEAD: refs/remotes/origin/boo" \
1889 >> $testroot/stdout.expected
1890 echo "refs/remotes/origin/boo: $commit_id6" \
1891 >> $testroot/stdout.expected
1892 echo "refs/remotes/origin/hoo: $commit_id7" \
1893 >> $testroot/stdout.expected
1894 echo "refs/remotes/origin/master: $commit_id5" \
1895 >> $testroot/stdout.expected
1897 cmp -s $testroot/stdout $testroot/stdout.expected
1898 ret=$?
1899 if [ $ret -ne 0 ]; then
1900 diff -u $testroot/stdout.expected $testroot/stdout
1901 test_done "$testroot" "$ret"
1902 return 1
1905 # from wt: fetch -b bar that doesn't exist on the server but
1906 # do not fetch got.conf "master" or wt "boo" or repo HEAD "boo"
1907 (cd $testroot/wt && got fetch -b bar > $testroot/stdout \
1908 2> $testroot/stderr)
1910 echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \
1911 > $testroot/stdout.expected
1912 echo "got-fetch-pack: branch \"bar\" not found on server" \
1913 > $testroot/stderr.expected
1914 echo "got: could not find any branches to fetch" \
1915 >> $testroot/stderr.expected
1917 cmp -s $testroot/stderr $testroot/stderr.expected
1918 ret=$?
1919 if [ $ret -ne 0 ]; then
1920 diff -u $testroot/stderr.expected $testroot/stderr
1921 test_done "$testroot" "$ret"
1922 return 1
1925 cmp -s $testroot/stdout $testroot/stdout.expected
1926 ret=$?
1927 if [ $ret -ne 0 ]; then
1928 diff -u $testroot/stdout.expected $testroot/stdout
1930 test_done "$testroot" "$ret"
1933 test_fetch_from_out_of_date_remote() {
1934 local testroot=`test_init fetch_from_out_of_date_remote`
1935 local testurl=ssh://127.0.0.1/$testroot
1936 local commit_id=`git_show_head $testroot/repo`
1938 got clone -q $testurl/repo $testroot/repo-clone
1939 ret=$?
1940 if [ $ret -ne 0 ]; then
1941 echo "got clone command failed unexpectedly" >&2
1942 test_done "$testroot" "$ret"
1943 return 1
1946 echo "modified alpha" > $testroot/repo/alpha
1947 git_commit $testroot/repo -m "modified alpha"
1948 local commit_id2=`git_show_head $testroot/repo`
1950 got clone -q $testurl/repo $testroot/repo-clone2 \
1951 > $testroot/stdout 2> $testroot/stderr
1952 ret=$?
1953 if [ $ret -ne 0 ]; then
1954 echo "got clone command failed unexpectedly" >&2
1955 test_done "$testroot" "$ret"
1956 return 1
1959 got ref -l -r $testroot/repo-clone2 > $testroot/stdout
1960 ret=$?
1961 if [ $ret -ne 0 ]; then
1962 echo "got ref command failed unexpectedly" >&2
1963 test_done "$testroot" "$ret"
1964 return 1
1967 cat > $testroot/stdout.expected <<EOF
1968 HEAD: refs/heads/master
1969 refs/heads/master: $commit_id2
1970 refs/remotes/origin/HEAD: refs/remotes/origin/master
1971 refs/remotes/origin/master: $commit_id2
1972 EOF
1973 cmp -s $testroot/stdout $testroot/stdout.expected
1974 ret=$?
1975 if [ $ret -ne 0 ]; then
1976 diff -u $testroot/stdout.expected $testroot/stdout
1977 test_done "$testroot" "$ret"
1978 return 1
1981 cat >> $testroot/repo-clone2/got.conf <<EOF
1982 remote "other" {
1983 server "127.0.0.1"
1984 protocol ssh
1985 repository "$testroot/repo-clone"
1986 branch { "master" }
1988 EOF
1989 got fetch -q -r $testroot/repo-clone2 other \
1990 > $testroot/stdout 2> $testroot/stderr
1991 ret=$?
1992 if [ $ret -ne 0 ]; then
1993 echo "got fetch command failed unexpectedly" >&2
1994 test_done "$testroot" "$ret"
1995 return 1
1998 got ref -l -r $testroot/repo-clone2 > $testroot/stdout
1999 ret=$?
2000 if [ $ret -ne 0 ]; then
2001 echo "got ref command failed unexpectedly" >&2
2002 test_done "$testroot" "$ret"
2003 return 1
2006 cat > $testroot/stdout.expected <<EOF
2007 HEAD: refs/heads/master
2008 refs/heads/master: $commit_id2
2009 refs/remotes/origin/HEAD: refs/remotes/origin/master
2010 refs/remotes/origin/master: $commit_id2
2011 refs/remotes/other/HEAD: refs/remotes/other/master
2012 refs/remotes/other/master: $commit_id
2013 EOF
2014 cmp -s $testroot/stdout $testroot/stdout.expected
2015 ret=$?
2016 if [ $ret -ne 0 ]; then
2017 diff -u $testroot/stdout.expected $testroot/stdout
2019 test_done "$testroot" "$ret"
2023 test_parseargs "$@"
2024 run_test test_fetch_basic
2025 run_test test_fetch_list
2026 run_test test_fetch_branch
2027 run_test test_fetch_all
2028 run_test test_fetch_empty_packfile
2029 run_test test_fetch_delete_branch
2030 run_test test_fetch_delete_branch_mirror
2031 run_test test_fetch_update_tag
2032 run_test test_fetch_reference
2033 run_test test_fetch_replace_symref
2034 run_test test_fetch_update_headref
2035 run_test test_fetch_headref_deleted_locally
2036 run_test test_fetch_gotconfig_remote_repo
2037 run_test test_fetch_gitconfig_remote_repo
2038 run_test test_fetch_delete_remote_refs
2039 run_test test_fetch_honor_wt_conf_bflag
2040 run_test test_fetch_from_out_of_date_remote