Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_fetch_basic() {
20 local testroot=`test_init fetch_basic`
21 local testurl=ssh://127.0.0.1/$testroot
22 local commit_id=`git_show_head $testroot/repo`
24 got clone -q $testurl/repo $testroot/repo-clone
25 ret=$?
26 if [ $ret -ne 0 ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 echo "modified alpha" > $testroot/repo/alpha
33 git_commit $testroot/repo -m "modified alpha"
34 local commit_id2=`git_show_head $testroot/repo`
36 got ref -l -r $testroot/repo-clone > $testroot/stdout
37 ret=$?
38 if [ $ret -ne 0 ]; then
39 echo "got ref command failed unexpectedly" >&2
40 test_done "$testroot" "$ret"
41 return 1
42 fi
44 got fetch -q -r $testroot/repo-clone > $testroot/stdout \
45 2> $testroot/stderr
46 ret=$?
47 if [ $ret -ne 0 ]; then
48 echo "got fetch command failed unexpectedly" >&2
49 test_done "$testroot" "$ret"
50 return 1
51 fi
53 echo -n > $testroot/stdout.expected
55 cmp -s $testroot/stdout $testroot/stdout.expected
56 ret=$?
57 if [ $ret -ne 0 ]; then
58 diff -u $testroot/stdout.expected $testroot/stdout
59 test_done "$testroot" "$ret"
60 return 1
61 fi
63 got log -l0 -p -r $testroot/repo > $testroot/log-repo
64 ret=$?
65 if [ $ret -ne 0 ]; then
66 echo "got log command failed unexpectedly" >&2
67 test_done "$testroot" "$ret"
68 return 1
69 fi
70 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
71 ret=$?
72 if [ $ret -ne 0 ]; then
73 echo "got log command failed unexpectedly" >&2
74 test_done "$testroot" "$ret"
75 return 1
76 fi
77 cmp -s $testroot/log-repo $testroot/log-repo-clone
78 ret=$?
79 if [ $ret -ne 0 ]; then
80 echo "log -p output of cloned repository differs" >&2
81 test_done "$testroot" "$ret"
82 return 1
83 fi
85 got ref -l -r $testroot/repo > $testroot/stdout
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 echo "got ref command failed unexpectedly" >&2
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
94 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
96 cmp -s $testroot/stdout $testroot/stdout.expected
97 ret=$?
98 if [ $ret -ne 0 ]; then
99 diff -u $testroot/stdout.expected $testroot/stdout
100 test_done "$testroot" "$ret"
101 return 1
102 fi
104 got ref -l -r $testroot/repo-clone > $testroot/stdout
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 echo "got ref command failed unexpectedly" >&2
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
113 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
114 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
115 >> $testroot/stdout.expected
116 echo "refs/remotes/origin/master: $commit_id2" \
117 >> $testroot/stdout.expected
119 cmp -s $testroot/stdout $testroot/stdout.expected
120 ret=$?
121 if [ $ret -ne 0 ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 fi
124 test_done "$testroot" "$ret"
127 test_fetch_list() {
128 local testroot=`test_init fetch_list`
129 local testurl=ssh://127.0.0.1/$testroot
130 local commit_id=`git_show_head $testroot/repo`
132 got branch -r $testroot/repo -c $commit_id foo
133 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
134 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
136 got clone -q $testurl/repo $testroot/repo-clone
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 echo "got clone command failed unexpectedly" >&2
140 test_done "$testroot" "$ret"
141 return 1
142 fi
144 (cd $testroot/repo-clone && got fetch -q -l \
145 > $testroot/stdout 2>$testroot/stderr)
146 ret=$?
147 if [ $ret -ne 0 ]; then
148 echo "got fetch command failed unexpectedly" >&2
149 test_done "$testroot" "$ret"
150 return 1
151 fi
153 got ref -l -r $testroot/repo > $testroot/stdout.expected
155 cmp -s $testroot/stdout $testroot/stdout.expected
156 ret=$?
157 if [ $ret -ne 0 ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 fi
160 test_done "$testroot" "$ret"
163 test_fetch_branch() {
164 local testroot=`test_init fetch_branch`
165 local testurl=ssh://127.0.0.1/$testroot
166 local commit_id=`git_show_head $testroot/repo`
168 got clone -q $testurl/repo $testroot/repo-clone
169 ret=$?
170 if [ $ret -ne 0 ]; then
171 echo "got clone command failed unexpectedly" >&2
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 got branch -r $testroot/repo -c $commit_id foo
177 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
178 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
179 local tag_id=`got ref -r $testroot/repo -l \
180 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
182 echo "modified alpha on master" > $testroot/repo/alpha
183 git_commit $testroot/repo -m "modified alpha"
184 local commit_id2=`git_show_head $testroot/repo`
186 (cd $testroot/repo && git checkout -q foo)
187 echo "modified alpha on foo" > $testroot/repo/alpha
188 git_commit $testroot/repo -m "modified alpha"
189 local commit_id3=`git_show_head $testroot/repo`
191 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
192 ret=$?
193 if [ $ret -ne 0 ]; then
194 echo "got fetch command failed unexpectedly" >&2
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 echo -n > $testroot/stdout.expected
201 cmp -s $testroot/stdout $testroot/stdout.expected
202 ret=$?
203 if [ $ret -ne 0 ]; then
204 diff -u $testroot/stdout.expected $testroot/stdout
205 test_done "$testroot" "$ret"
206 return 1
207 fi
209 got ref -l -r $testroot/repo-clone > $testroot/stdout
211 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
212 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
213 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
214 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
215 >> $testroot/stdout.expected
216 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
217 # refs/remotes/origin/master is umodified because it wasn't fetched
218 echo "refs/remotes/origin/master: $commit_id" \
219 >> $testroot/stdout.expected
220 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
221 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
223 cmp -s $testroot/stdout $testroot/stdout.expected
224 ret=$?
225 if [ $ret -ne 0 ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
227 test_done "$testroot" "$ret"
228 return 1
229 fi
231 got fetch -q -r $testroot/repo-clone -b master > $testroot/stdout
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 echo "got fetch command failed unexpectedly" >&2
235 test_done "$testroot" "$ret"
236 return 1
237 fi
239 echo -n > $testroot/stdout.expected
241 cmp -s $testroot/stdout $testroot/stdout.expected
242 ret=$?
243 if [ $ret -ne 0 ]; then
244 diff -u $testroot/stdout.expected $testroot/stdout
245 test_done "$testroot" "$ret"
246 return 1
247 fi
249 got ref -l -r $testroot/repo-clone > $testroot/stdout
251 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
252 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
253 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
254 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
255 >> $testroot/stdout.expected
256 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
257 echo "refs/remotes/origin/master: $commit_id2" \
258 >> $testroot/stdout.expected
259 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
260 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
262 cmp -s $testroot/stdout $testroot/stdout.expected
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 echo "modified beta on foo" > $testroot/repo/beta
271 git_commit $testroot/repo -m "modified beta"
272 local commit_id4=`git_show_head $testroot/repo`
274 got checkout -b foo $testroot/repo-clone $testroot/wt > /dev/null
276 # fetch new commits on branch 'foo', implicitly obtaining the
277 # branch name from a work tree
278 (cd $testroot/wt && got fetch -q > $testroot/stdout)
280 echo -n > $testroot/stdout.expected
282 cmp -s $testroot/stdout $testroot/stdout.expected
283 ret=$?
284 if [ $ret -ne 0 ]; then
285 diff -u $testroot/stdout.expected $testroot/stdout
286 test_done "$testroot" "$ret"
287 return 1
288 fi
290 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
291 cut -d ':' -f 2 | tr -d ' ')`
293 got ref -l -r $testroot/repo-clone > $testroot/stdout
295 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
296 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
297 >> $testroot/stdout.expected
298 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
299 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
300 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
301 >> $testroot/stdout.expected
302 echo "refs/remotes/origin/foo: $commit_id4" >> $testroot/stdout.expected
303 echo "refs/remotes/origin/master: $commit_id2" \
304 >> $testroot/stdout.expected
305 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
306 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
308 cmp -s $testroot/stdout $testroot/stdout.expected
309 ret=$?
310 if [ $ret -ne 0 ]; then
311 diff -u $testroot/stdout.expected $testroot/stdout
312 fi
313 test_done "$testroot" "$ret"
316 test_fetch_all() {
317 local testroot=`test_init fetch_all`
318 local testurl=ssh://127.0.0.1/$testroot
319 local commit_id=`git_show_head $testroot/repo`
321 got clone -q $testurl/repo $testroot/repo-clone
322 ret=$?
323 if [ $ret -ne 0 ]; then
324 echo "got clone command failed unexpectedly" >&2
325 test_done "$testroot" "$ret"
326 return 1
327 fi
329 got branch -r $testroot/repo -c $commit_id foo
330 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
331 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
332 local tag_id=`got ref -r $testroot/repo -l \
333 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
335 got ref -l -r $testroot/repo-clone > $testroot/stdout
337 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
338 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
339 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
340 >> $testroot/stdout.expected
341 echo "refs/remotes/origin/master: $commit_id" \
342 >> $testroot/stdout.expected
343 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
345 cmp -s $testroot/stdout $testroot/stdout.expected
346 ret=$?
347 if [ $ret -ne 0 ]; then
348 diff -u $testroot/stdout.expected $testroot/stdout
349 test_done "$testroot" "$ret"
350 return 1
351 fi
353 got fetch -q -a -r $testroot/repo-clone
354 ret=$?
355 if [ $ret -ne 0 ]; then
356 echo "got fetch command failed unexpectedly" >&2
357 test_done "$testroot" "$ret"
358 return 1
359 fi
361 got ref -l -r $testroot/repo-clone > $testroot/stdout
363 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
364 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
365 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
366 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
367 >> $testroot/stdout.expected
368 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
369 echo "refs/remotes/origin/master: $commit_id" \
370 >> $testroot/stdout.expected
371 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
372 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
374 cmp -s $testroot/stdout $testroot/stdout.expected
375 ret=$?
376 if [ $ret -ne 0 ]; then
377 diff -u $testroot/stdout.expected $testroot/stdout
378 fi
379 test_done "$testroot" "$ret"
382 test_fetch_empty_packfile() {
383 local testroot=`test_init fetch_empty_packfile`
384 local testurl=ssh://127.0.0.1/$testroot
385 local commit_id=`git_show_head $testroot/repo`
387 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
388 local tag_id=`got ref -r $testroot/repo -l \
389 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
391 got clone -q $testurl/repo $testroot/repo-clone
392 ret=$?
393 if [ $ret -ne 0 ]; then
394 echo "got clone command failed unexpectedly" >&2
395 test_done "$testroot" "$ret"
396 return 1
397 fi
399 got branch -r $testroot/repo -c $commit_id foo
400 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
402 got ref -l -r $testroot/repo-clone > $testroot/stdout
404 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
405 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
406 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
407 >> $testroot/stdout.expected
408 echo "refs/remotes/origin/master: $commit_id" \
409 >> $testroot/stdout.expected
410 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
411 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
413 cmp -s $testroot/stdout $testroot/stdout.expected
414 ret=$?
415 if [ $ret -ne 0 ]; then
416 diff -u $testroot/stdout.expected $testroot/stdout
417 test_done "$testroot" "$ret"
418 return 1
419 fi
421 got fetch -q -a -r $testroot/repo-clone
422 ret=$?
423 if [ $ret -ne 0 ]; then
424 echo "got fetch command failed unexpectedly" >&2
425 test_done "$testroot" "$ret"
426 return 1
427 fi
429 got ref -l -r $testroot/repo-clone > $testroot/stdout
431 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
432 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
433 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
434 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
435 >> $testroot/stdout.expected
436 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
437 echo "refs/remotes/origin/master: $commit_id" \
438 >> $testroot/stdout.expected
439 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
440 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
442 cmp -s $testroot/stdout $testroot/stdout.expected
443 ret=$?
444 if [ $ret -ne 0 ]; then
445 diff -u $testroot/stdout.expected $testroot/stdout
446 fi
447 test_done "$testroot" "$ret"
450 test_fetch_delete_branch() {
451 local testroot=`test_init fetch_delete_branch`
452 local testurl=ssh://127.0.0.1/$testroot
453 local commit_id=`git_show_head $testroot/repo`
456 got branch -r $testroot/repo -c $commit_id foo
457 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
458 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
459 local tag_id=`got ref -r $testroot/repo -l \
460 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
462 got clone -a -q $testurl/repo $testroot/repo-clone
463 ret=$?
464 if [ $ret -ne 0 ]; then
465 echo "got clone command failed unexpectedly" >&2
466 test_done "$testroot" "$ret"
467 return 1
468 fi
470 got ref -l -r $testroot/repo-clone > $testroot/stdout
472 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
473 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
474 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
475 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
476 >> $testroot/stdout.expected
477 echo "refs/remotes/origin/foo: $commit_id" \
478 >> $testroot/stdout.expected
479 echo "refs/remotes/origin/master: $commit_id" \
480 >> $testroot/stdout.expected
481 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
482 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
484 cmp -s $testroot/stdout $testroot/stdout.expected
485 ret=$?
486 if [ $ret -ne 0 ]; then
487 diff -u $testroot/stdout.expected $testroot/stdout
488 test_done "$testroot" "$ret"
489 return 1
490 fi
492 got branch -r $testroot/repo -d foo >/dev/null
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_id" >> $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 test_done "$testroot" "$ret"
520 return 1
521 fi
523 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
524 ret=$?
525 if [ $ret -ne 0 ]; then
526 echo "got fetch command failed unexpectedly" >&2
527 test_done "$testroot" "$ret"
528 return 1
529 fi
531 echo -n > $testroot/stdout.expected
533 cmp -s $testroot/stdout $testroot/stdout.expected
534 ret=$?
535 if [ $ret -ne 0 ]; then
536 diff -u $testroot/stdout.expected $testroot/stdout
537 test_done "$testroot" "$ret"
538 return 1
539 fi
541 got ref -l -r $testroot/repo-clone > $testroot/stdout
543 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
544 # refs/heads/foo is now deleted
545 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
546 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
547 >> $testroot/stdout.expected
548 # refs/remotes/origin/foo is now deleted
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 fi
559 test_done "$testroot" "$ret"
563 test_fetch_delete_branch_mirror() {
564 local testroot=`test_init fetch_delete_branch_mirror`
565 local testurl=ssh://127.0.0.1/$testroot
566 local commit_id=`git_show_head $testroot/repo`
568 got branch -r $testroot/repo -c $commit_id foo
569 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
570 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
571 local tag_id=`got ref -r $testroot/repo -l \
572 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
574 got clone -a -m -q $testurl/repo $testroot/repo-clone
575 ret=$?
576 if [ $ret -ne 0 ]; then
577 echo "got clone command failed unexpectedly" >&2
578 test_done "$testroot" "$ret"
579 return 1
580 fi
582 got ref -l -r $testroot/repo-clone > $testroot/stdout
584 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
585 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
586 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
587 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
588 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
590 cmp -s $testroot/stdout $testroot/stdout.expected
591 ret=$?
592 if [ $ret -ne 0 ]; then
593 diff -u $testroot/stdout.expected $testroot/stdout
594 test_done "$testroot" "$ret"
595 return 1
596 fi
598 got branch -r $testroot/repo -d foo >/dev/null
600 got fetch -q -r $testroot/repo-clone
601 ret=$?
602 if [ $ret -ne 0 ]; then
603 echo "got fetch command failed unexpectedly" >&2
604 test_done "$testroot" "$ret"
605 return 1
606 fi
608 got ref -l -r $testroot/repo-clone > $testroot/stdout
610 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
611 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
612 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
613 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
614 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
616 cmp -s $testroot/stdout $testroot/stdout.expected
617 ret=$?
618 if [ $ret -ne 0 ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
625 ret=$?
626 if [ $ret -ne 0 ]; then
627 echo "got fetch command failed unexpectedly" >&2
628 test_done "$testroot" "$ret"
629 return 1
630 fi
632 echo -n > $testroot/stdout.expected
634 cmp -s $testroot/stdout $testroot/stdout.expected
635 ret=$?
636 if [ $ret -ne 0 ]; then
637 diff -u $testroot/stdout.expected $testroot/stdout
638 test_done "$testroot" "$ret"
639 return 1
640 fi
642 got ref -l -r $testroot/repo-clone > $testroot/stdout
644 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
645 # refs/heads/foo is now deleted
646 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
647 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
648 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
650 cmp -s $testroot/stdout $testroot/stdout.expected
651 ret=$?
652 if [ $ret -ne 0 ]; then
653 diff -u $testroot/stdout.expected $testroot/stdout
654 fi
655 test_done "$testroot" "$ret"
659 test_fetch_update_tag() {
660 local testroot=`test_init fetch_update_tag`
661 local testurl=ssh://127.0.0.1/$testroot
662 local commit_id=`git_show_head $testroot/repo`
665 got branch -r $testroot/repo -c $commit_id foo
666 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
667 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
668 local tag_id=`got ref -r $testroot/repo -l \
669 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
671 got clone -a -q $testurl/repo $testroot/repo-clone
672 ret=$?
673 if [ $ret -ne 0 ]; then
674 echo "got clone command failed unexpectedly" >&2
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 echo "modified alpha on master" > $testroot/repo/alpha
680 git_commit $testroot/repo -m "modified alpha"
681 local commit_id2=`git_show_head $testroot/repo`
683 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
684 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
685 local tag_id2=`got ref -r $testroot/repo -l \
686 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
688 got ref -l -r $testroot/repo-clone > $testroot/stdout
690 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
691 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
692 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
693 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
694 >> $testroot/stdout.expected
695 echo "refs/remotes/origin/foo: $commit_id" \
696 >> $testroot/stdout.expected
697 echo "refs/remotes/origin/master: $commit_id" \
698 >> $testroot/stdout.expected
699 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
700 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
702 cmp -s $testroot/stdout $testroot/stdout.expected
703 ret=$?
704 if [ $ret -ne 0 ]; then
705 diff -u $testroot/stdout.expected $testroot/stdout
706 test_done "$testroot" "$ret"
707 return 1
708 fi
710 got fetch -a -q -r $testroot/repo-clone
711 ret=$?
712 if [ $ret -ne 0 ]; then
713 echo "got fetch command failed unexpectedly" >&2
714 test_done "$testroot" "$ret"
715 return 1
716 fi
718 got ref -l -r $testroot/repo-clone > $testroot/stdout
720 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
721 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
722 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
723 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
724 >> $testroot/stdout.expected
725 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
726 echo "refs/remotes/origin/master: $commit_id2" \
727 >> $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 fetch -r $testroot/repo-clone 2> $testroot/stderr | \
740 tail -n 1 > $testroot/stdout
741 ret=$?
742 if [ $ret -ne 0 ]; then
743 echo "got fetch command failed unexpectedly" >&2
744 test_done "$testroot" "$ret"
745 return 1
746 fi
748 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
749 > $testroot/stdout.expected
751 cmp -s $testroot/stdout $testroot/stdout.expected
752 ret=$?
753 if [ $ret -ne 0 ]; then
754 diff -u $testroot/stdout.expected $testroot/stdout
755 test_done "$testroot" "$ret"
756 return 1
757 fi
759 got ref -l -r $testroot/repo-clone > $testroot/stdout
761 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
762 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
763 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
764 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
765 >> $testroot/stdout.expected
766 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
767 echo "refs/remotes/origin/master: $commit_id2" \
768 >> $testroot/stdout.expected
769 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
770 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
772 cmp -s $testroot/stdout $testroot/stdout.expected
773 ret=$?
774 if [ $ret -ne 0 ]; then
775 diff -u $testroot/stdout.expected $testroot/stdout
776 test_done "$testroot" "$ret"
777 return 1
778 fi
780 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
781 ret=$?
782 if [ $ret -ne 0 ]; then
783 echo "got fetch command failed unexpectedly" >&2
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 echo -n > $testroot/stdout.expected
790 cmp -s $testroot/stdout $testroot/stdout.expected
791 ret=$?
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/stdout.expected $testroot/stdout
794 test_done "$testroot" "$ret"
795 return 1
796 fi
798 got ref -l -r $testroot/repo-clone > $testroot/stdout
800 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
801 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
802 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
803 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
804 >> $testroot/stdout.expected
805 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
806 echo "refs/remotes/origin/master: $commit_id2" \
807 >> $testroot/stdout.expected
808 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
809 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
811 cmp -s $testroot/stdout $testroot/stdout.expected
812 ret=$?
813 if [ $ret -ne 0 ]; then
814 diff -u $testroot/stdout.expected $testroot/stdout
815 fi
816 test_done "$testroot" "$ret"
819 test_fetch_reference() {
820 local testroot=`test_init fetch_reference`
821 local testurl=ssh://127.0.0.1/$testroot
822 local commit_id=`git_show_head $testroot/repo`
824 got clone -q $testurl/repo $testroot/repo-clone
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 echo "got clone command failed unexpectedly" >&2
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 got branch -r $testroot/repo -c $commit_id foo
833 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
834 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
835 local tag_id=`got ref -r $testroot/repo -l \
836 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
838 echo "modified alpha on master" > $testroot/repo/alpha
839 git_commit $testroot/repo -m "modified alpha"
840 local commit_id2=`git_show_head $testroot/repo`
842 (cd $testroot/repo && git checkout -q foo)
843 echo "modified alpha on foo" > $testroot/repo/alpha
844 git_commit $testroot/repo -m "modified alpha"
845 local commit_id3=`git_show_head $testroot/repo`
846 (cd $testroot/repo && git checkout -q master)
848 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
849 > $testroot/stdout 2> $testroot/stderr
850 ret=$?
851 if [ $ret -eq 0 ]; then
852 echo "got fetch command succeeded unexpectedly" >&2
853 test_done "$testroot" "1"
854 return 1
855 fi
857 echo -n > $testroot/stdout.expected
859 cmp -s $testroot/stdout $testroot/stdout.expected
860 ret=$?
861 if [ $ret -ne 0 ]; then
862 diff -u $testroot/stdout.expected $testroot/stdout
863 test_done "$testroot" "$ret"
864 return 1
865 fi
867 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
868 > $testroot/stderr.expected
870 cmp -s $testroot/stderr $testroot/stderr.expected
871 ret=$?
872 if [ $ret -ne 0 ]; then
873 diff -u $testroot/stderr.expected $testroot/stderr
874 test_done "$testroot" "$ret"
875 return 1
876 fi
878 got fetch -q -r $testroot/repo-clone -R refs/hoo
879 ret=$?
880 if [ $ret -ne 0 ]; then
881 echo "got fetch command failed unexpectedly" >&2
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 got ref -l -r $testroot/repo-clone > $testroot/stdout
888 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
889 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
890 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
891 >> $testroot/stdout.expected
892 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
893 >> $testroot/stdout.expected
894 echo "refs/remotes/origin/master: $commit_id2" \
895 >> $testroot/stdout.expected
896 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
898 cmp -s $testroot/stdout $testroot/stdout.expected
899 ret=$?
900 if [ $ret -ne 0 ]; then
901 diff -u $testroot/stdout.expected $testroot/stdout
902 fi
903 test_done "$testroot" "$ret"
907 test_fetch_replace_symref() {
908 local testroot=`test_init fetch_replace_symref`
909 local testurl=ssh://127.0.0.1/$testroot
910 local commit_id=`git_show_head $testroot/repo`
912 got clone -m -q $testurl/repo $testroot/repo-clone
913 ret=$?
914 if [ $ret -ne 0 ]; then
915 echo "got clone command failed unexpectedly" >&2
916 test_done "$testroot" "$ret"
917 return 1
918 fi
920 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
921 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
923 got ref -l -r $testroot/repo-clone > $testroot/stdout
925 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
926 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
927 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
929 cmp -s $testroot/stdout $testroot/stdout.expected
930 ret=$?
931 if [ $ret -ne 0 ]; then
932 diff -u $testroot/stdout.expected $testroot/stdout
933 test_done "$testroot" "$ret"
934 return 1
935 fi
937 got fetch -r $testroot/repo-clone -R refs/hoo \
938 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
939 ret=$?
940 if [ $ret -ne 0 ]; then
941 echo "got fetch command failed unexpectedly" >&2
942 test_done "$testroot" "$ret"
943 return 1
944 fi
946 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
947 > $testroot/stdout.expected
949 cmp -s $testroot/stdout $testroot/stdout.expected
950 ret=$?
951 if [ $ret -ne 0 ]; then
952 diff -u $testroot/stdout.expected $testroot/stdout
953 test_done "$testroot" "$ret"
954 return 1
955 fi
957 got ref -l -r $testroot/repo-clone > $testroot/stdout
959 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
960 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
961 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
963 cmp -s $testroot/stdout $testroot/stdout.expected
964 ret=$?
965 if [ $ret -ne 0 ]; then
966 diff -u $testroot/stdout.expected $testroot/stdout
967 fi
968 test_done "$testroot" "$ret"
972 test_fetch_update_headref() {
973 local testroot=`test_init fetch_update_headref`
974 local testurl=ssh://127.0.0.1/$testroot
975 local commit_id=`git_show_head $testroot/repo`
977 got clone -q $testurl/repo $testroot/repo-clone
978 ret=$?
979 if [ $ret -ne 0 ]; then
980 echo "got clone command failed unexpectedly" >&2
981 test_done "$testroot" "$ret"
982 return 1
983 fi
985 got ref -l -r $testroot/repo-clone > $testroot/stdout
987 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
988 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
989 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
990 >> $testroot/stdout.expected
991 echo "refs/remotes/origin/master: $commit_id" \
992 >> $testroot/stdout.expected
994 cmp -s $testroot/stdout $testroot/stdout.expected
995 ret=$?
996 if [ $ret -ne 0 ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 test_done "$testroot" "$ret"
999 return 1
1002 got ref -r $testroot/repo -c refs/heads/master refs/heads/foo
1003 got ref -r $testroot/repo -s refs/heads/foo HEAD
1004 got ref -l -r $testroot/repo > $testroot/stdout
1006 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
1007 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1008 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1010 cmp -s $testroot/stdout $testroot/stdout.expected
1011 ret=$?
1012 if [ $ret -ne 0 ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1015 return 1
1018 got fetch -q -r $testroot/repo-clone
1020 got ref -l -r $testroot/repo-clone > $testroot/stdout
1022 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1023 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1024 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1025 >> $testroot/stdout.expected
1026 echo "refs/remotes/origin/master: $commit_id" \
1027 >> $testroot/stdout.expected
1029 cmp -s $testroot/stdout $testroot/stdout.expected
1030 ret=$?
1031 if [ $ret -ne 0 ]; then
1032 diff -u $testroot/stdout.expected $testroot/stdout
1033 test_done "$testroot" "$ret"
1034 return 1
1037 got fetch -q -r $testroot/repo-clone -a
1039 got ref -l -r $testroot/repo-clone > $testroot/stdout
1041 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1042 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1043 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1044 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
1045 >> $testroot/stdout.expected
1046 echo "refs/remotes/origin/foo: $commit_id" \
1047 >> $testroot/stdout.expected
1048 echo "refs/remotes/origin/master: $commit_id" \
1049 >> $testroot/stdout.expected
1051 cmp -s $testroot/stdout $testroot/stdout.expected
1052 ret=$?
1053 if [ $ret -ne 0 ]; then
1054 diff -u $testroot/stdout.expected $testroot/stdout
1056 test_done "$testroot" "$ret"
1059 test_fetch_headref_deleted_locally() {
1060 local testroot=`test_init fetch_headref_deleted_locally`
1061 local testurl=ssh://127.0.0.1/$testroot
1062 local commit_id=`git_show_head $testroot/repo`
1064 got clone -q $testurl/repo $testroot/repo-clone
1065 ret=$?
1066 if [ $ret -ne 0 ]; then
1067 echo "got clone command failed unexpectedly" >&2
1068 test_done "$testroot" "$ret"
1069 return 1
1072 got ref -l -r $testroot/repo-clone > $testroot/stdout
1074 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1075 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1076 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1077 >> $testroot/stdout.expected
1078 echo "refs/remotes/origin/master: $commit_id" \
1079 >> $testroot/stdout.expected
1081 cmp -s $testroot/stdout $testroot/stdout.expected
1082 ret=$?
1083 if [ $ret -ne 0 ]; then
1084 diff -u $testroot/stdout.expected $testroot/stdout
1085 test_done "$testroot" "$ret"
1086 return 1
1089 got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD > /dev/null
1091 got fetch -q -r $testroot/repo-clone
1092 ret=$?
1093 if [ $ret -ne 0 ]; then
1094 echo "got fetch command failed unexpectedly" >&2
1095 test_done "$testroot" "$ret"
1096 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 # refs/remotes/origin/HEAD has been restored:
1103 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1104 >> $testroot/stdout.expected
1105 echo "refs/remotes/origin/master: $commit_id" \
1106 >> $testroot/stdout.expected
1108 cmp -s $testroot/stdout $testroot/stdout.expected
1109 ret=$?
1110 if [ $ret -ne 0 ]; then
1111 diff -u $testroot/stdout.expected $testroot/stdout
1113 test_done "$testroot" "$ret"
1116 test_fetch_gotconfig_remote_repo() {
1117 local testroot=`test_init fetch_gotconfig_remote_repo`
1118 local testurl=ssh://127.0.0.1/$testroot
1119 local commit_id=`git_show_head $testroot/repo`
1121 got branch -r $testroot/repo -c $commit_id foo
1122 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1123 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
1125 got clone -q $testurl/repo $testroot/repo-clone
1126 ret=$?
1127 if [ $ret -ne 0 ]; then
1128 echo "got clone command failed unexpectedly" >&2
1129 test_done "$testroot" "$ret"
1130 return 1
1133 cat > $testroot/repo-clone/got.conf <<EOF
1134 remote "foobar" {
1135 protocol ssh
1136 server 127.0.0.1
1137 repository "$testroot/repo"
1140 remote "barbaz" {
1141 protocol ssh
1142 server 127.0.0.1
1143 repository "$testroot/does-not-exist"
1145 EOF
1146 echo "got: nonexistent: remote repository not found" \
1147 > $testroot/stderr.expected
1148 (cd $testroot/repo-clone && got fetch -q nonexistent \
1149 > $testroot/stdout 2> $testroot/stderr)
1150 ret=$?
1151 if [ $ret -eq 0 ]; then
1152 echo "got fetch command succeeded unexpectedly" >&2
1153 diff -u $testroot/stderr.expected $testroot/stderr
1154 test_done "$testroot" "1"
1155 return 1
1158 (cd $testroot/repo-clone && got fetch -q -l foobar \
1159 > $testroot/stdout)
1160 ret=$?
1161 if [ $ret -ne 0 ]; then
1162 echo "got fetch command failed unexpectedly" >&2
1163 test_done "$testroot" "$ret"
1164 return 1
1167 got ref -l -r $testroot/repo > $testroot/stdout.expected
1169 cmp -s $testroot/stdout $testroot/stdout.expected
1170 ret=$?
1171 if [ $ret -ne 0 ]; then
1172 diff -u $testroot/stdout.expected $testroot/stdout
1173 test_done "$testroot" "$ret"
1174 return 1
1177 got checkout $testroot/repo $testroot/wt > /dev/null
1179 cat > $testroot/wt/.got/got.conf <<EOF
1180 remote "barbaz" {
1181 protocol ssh
1182 server 127.0.0.1
1183 repository "$testroot/repo"
1185 EOF
1186 (cd $testroot/wt && got fetch -q -l barbaz > $testroot/stdout)
1187 ret=$?
1188 if [ $ret -ne 0 ]; then
1189 echo "got fetch command failed unexpectedly" >&2
1190 test_done "$testroot" "$ret"
1191 return 1
1194 got ref -l -r $testroot/repo > $testroot/stdout.expected
1196 cmp -s $testroot/stdout $testroot/stdout.expected
1197 ret=$?
1198 if [ $ret -ne 0 ]; then
1199 diff -u $testroot/stdout.expected $testroot/stdout
1200 test_done "$testroot" "$ret"
1201 return 1
1204 cat > $testroot/repo-clone/got.conf <<EOF
1205 remote "origin" {
1206 protocol ssh
1207 server 127.0.0.1
1208 repository "$testroot/repo"
1209 branch { "foo" }
1210 reference { "hoo/boo/zoo" }
1212 EOF
1213 (cd $testroot/repo-clone && got fetch -q > $testroot/stdout)
1215 local tag_id=`got ref -r $testroot/repo -l \
1216 | grep "^refs/tags/1.0" | tr -d ' ' | cut -d: -f2`
1217 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1218 echo "refs/heads/foo: $commit_id" >> $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/foo: $commit_id" \
1223 >> $testroot/stdout.expected
1224 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
1225 >> $testroot/stdout.expected
1226 echo "refs/remotes/origin/master: $commit_id" \
1227 >> $testroot/stdout.expected
1228 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1230 got ref -l -r $testroot/repo-clone > $testroot/stdout
1232 cmp -s $testroot/stdout $testroot/stdout.expected
1233 ret=$?
1234 if [ $ret -ne 0 ]; then
1235 diff -u $testroot/stdout.expected $testroot/stdout
1237 test_done "$testroot" "$ret"
1240 test_fetch_delete_remote_refs() {
1241 local testroot=`test_init fetch_delete_remote_refs`
1242 local testurl=ssh://127.0.0.1/$testroot
1243 local commit_id=`git_show_head $testroot/repo`
1245 got clone -q $testurl/repo $testroot/repo-clone
1246 ret=$?
1247 if [ $ret -ne 0 ]; then
1248 echo "got clone command failed unexpectedly" >&2
1249 test_done "$testroot" "$ret"
1250 return 1
1253 got ref -l -r $testroot/repo-clone > $testroot/stdout
1254 ret=$?
1255 if [ $ret -ne 0 ]; then
1256 echo "got ref command failed unexpectedly" >&2
1257 test_done "$testroot" "$ret"
1258 return 1
1261 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1262 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1263 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1264 >> $testroot/stdout.expected
1265 echo "refs/remotes/origin/master: $commit_id" \
1266 >> $testroot/stdout.expected
1268 cmp -s $testroot/stdout $testroot/stdout.expected
1269 ret=$?
1270 if [ $ret -ne 0 ]; then
1271 diff -u $testroot/stdout.expected $testroot/stdout
1272 test_done "$testroot" "$ret"
1273 return 1
1276 got fetch -q -r $testroot/repo-clone -X > $testroot/stdout \
1277 2> $testroot/stderr
1278 ret=$?
1279 if [ $ret -eq 0 ]; then
1280 echo "got fetch command succeeded unexpectedly" >&2
1281 test_done "$testroot" "$ret"
1282 return 1
1285 echo "got: -X option requires a remote name" > $testroot/stderr.expected
1286 cmp -s $testroot/stderr $testroot/stderr.expected
1287 ret=$?
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stderr.expected $testroot/stderr
1290 test_done "$testroot" "$ret"
1291 return 1
1294 got fetch -q -r $testroot/repo-clone -X origin > $testroot/stdout \
1295 2> $testroot/stderr
1296 ret=$?
1297 if [ $ret -ne 0 ]; then
1298 echo "got fetch command failed unexpectedly" >&2
1299 test_done "$testroot" "$ret"
1300 return 1
1303 echo -n "Deleted refs/remotes/origin/HEAD: " > $testroot/stdout.expected
1304 echo "refs/remotes/origin/master" >> $testroot/stdout.expected
1305 echo "Deleted refs/remotes/origin/master: $commit_id" \
1306 >> $testroot/stdout.expected
1308 cmp -s $testroot/stdout $testroot/stdout.expected
1309 ret=$?
1310 if [ $ret -ne 0 ]; then
1311 diff -u $testroot/stdout.expected $testroot/stdout
1312 test_done "$testroot" "$ret"
1313 return 1
1316 got ref -l -r $testroot/repo-clone > $testroot/stdout
1317 ret=$?
1318 if [ $ret -ne 0 ]; then
1319 echo "got ref command failed unexpectedly" >&2
1320 test_done "$testroot" "$ret"
1321 return 1
1324 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1325 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1327 cmp -s $testroot/stdout $testroot/stdout.expected
1328 ret=$?
1329 if [ $ret -ne 0 ]; then
1330 diff -u $testroot/stdout.expected $testroot/stdout
1332 test_done "$testroot" "$ret"
1336 test_parseargs "$@"
1337 run_test test_fetch_basic
1338 run_test test_fetch_list
1339 run_test test_fetch_branch
1340 run_test test_fetch_all
1341 run_test test_fetch_empty_packfile
1342 run_test test_fetch_delete_branch
1343 run_test test_fetch_delete_branch_mirror
1344 run_test test_fetch_update_tag
1345 run_test test_fetch_reference
1346 run_test test_fetch_replace_symref
1347 run_test test_fetch_update_headref
1348 run_test test_fetch_headref_deleted_locally
1349 run_test test_fetch_gotconfig_remote_repo
1350 run_test test_fetch_delete_remote_refs