Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2020 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_fetch_basic() {
20 local testroot=`test_init fetch_basic`
21 local testurl=ssh://127.0.0.1/$testroot
22 local commit_id=`git_show_head $testroot/repo`
24 got clone -q $testurl/repo $testroot/repo-clone
25 ret=$?
26 if [ $ret -ne 0 ]; then
27 echo "got clone command failed unexpectedly" >&2
28 test_done "$testroot" "$ret"
29 return 1
30 fi
32 echo "modified alpha" > $testroot/repo/alpha
33 git_commit $testroot/repo -m "modified alpha"
34 local commit_id2=`git_show_head $testroot/repo`
36 got ref -l -r $testroot/repo-clone > $testroot/stdout
37 ret=$?
38 if [ $ret -ne 0 ]; then
39 echo "got ref command failed unexpectedly" >&2
40 test_done "$testroot" "$ret"
41 return 1
42 fi
44 got fetch -q -r $testroot/repo-clone > $testroot/stdout \
45 2> $testroot/stderr
46 ret=$?
47 if [ $ret -ne 0 ]; then
48 echo "got fetch command failed unexpectedly" >&2
49 test_done "$testroot" "$ret"
50 return 1
51 fi
53 echo -n > $testroot/stdout.expected
55 cmp -s $testroot/stdout $testroot/stdout.expected
56 ret=$?
57 if [ $ret -ne 0 ]; then
58 diff -u $testroot/stdout.expected $testroot/stdout
59 test_done "$testroot" "$ret"
60 return 1
61 fi
63 got log -l0 -p -r $testroot/repo > $testroot/log-repo
64 ret=$?
65 if [ $ret -ne 0 ]; then
66 echo "got log command failed unexpectedly" >&2
67 test_done "$testroot" "$ret"
68 return 1
69 fi
70 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
71 ret=$?
72 if [ $ret -ne 0 ]; then
73 echo "got log command failed unexpectedly" >&2
74 test_done "$testroot" "$ret"
75 return 1
76 fi
77 cmp -s $testroot/log-repo $testroot/log-repo-clone
78 ret=$?
79 if [ $ret -ne 0 ]; then
80 echo "log -p output of cloned repository differs" >&2
81 test_done "$testroot" "$ret"
82 return 1
83 fi
85 got ref -l -r $testroot/repo > $testroot/stdout
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 echo "got ref command failed unexpectedly" >&2
89 test_done "$testroot" "$ret"
90 return 1
91 fi
93 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
94 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
96 cmp -s $testroot/stdout $testroot/stdout.expected
97 ret=$?
98 if [ $ret -ne 0 ]; then
99 diff -u $testroot/stdout.expected $testroot/stdout
100 test_done "$testroot" "$ret"
101 return 1
102 fi
104 got ref -l -r $testroot/repo-clone > $testroot/stdout
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 echo "got ref command failed unexpectedly" >&2
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
113 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
114 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
115 >> $testroot/stdout.expected
116 echo "refs/remotes/origin/master: $commit_id2" \
117 >> $testroot/stdout.expected
119 cmp -s $testroot/stdout $testroot/stdout.expected
120 ret=$?
121 if [ $ret -ne 0 ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 fi
124 test_done "$testroot" "$ret"
127 test_fetch_list() {
128 local testroot=`test_init fetch_list`
129 local testurl=ssh://127.0.0.1/$testroot
130 local commit_id=`git_show_head $testroot/repo`
132 got branch -r $testroot/repo -c $commit_id foo
133 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
134 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
136 got clone -q $testurl/repo $testroot/repo-clone
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 echo "got clone command failed unexpectedly" >&2
140 test_done "$testroot" "$ret"
141 return 1
142 fi
144 (cd $testroot/repo-clone && got fetch -q -l \
145 > $testroot/stdout 2>$testroot/stderr)
146 ret=$?
147 if [ $ret -ne 0 ]; then
148 echo "got fetch command failed unexpectedly" >&2
149 test_done "$testroot" "$ret"
150 return 1
151 fi
153 got ref -l -r $testroot/repo > $testroot/stdout.expected
155 cmp -s $testroot/stdout $testroot/stdout.expected
156 ret=$?
157 if [ $ret -ne 0 ]; then
158 diff -u $testroot/stdout.expected $testroot/stdout
159 fi
160 test_done "$testroot" "$ret"
163 test_fetch_branch() {
164 local testroot=`test_init fetch_branch`
165 local testurl=ssh://127.0.0.1/$testroot
166 local commit_id=`git_show_head $testroot/repo`
168 got clone -q $testurl/repo $testroot/repo-clone
169 ret=$?
170 if [ $ret -ne 0 ]; then
171 echo "got clone command failed unexpectedly" >&2
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 got branch -r $testroot/repo -c $commit_id foo
177 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
178 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
179 local tag_id=`got ref -r $testroot/repo -l \
180 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
182 echo "modified alpha on master" > $testroot/repo/alpha
183 git_commit $testroot/repo -m "modified alpha"
184 local commit_id2=`git_show_head $testroot/repo`
186 (cd $testroot/repo && git checkout -q foo)
187 echo "modified alpha on foo" > $testroot/repo/alpha
188 git_commit $testroot/repo -m "modified alpha"
189 local commit_id3=`git_show_head $testroot/repo`
191 # foo is now the default HEAD branch in $testroot/repo
192 # but got.conf still says to fetch "master"
193 got fetch -q -r $testroot/repo-clone -b foo > $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" >> $testroot/stdout.expected
219 # refs/remotes/origin/master is umodified because it wasn't fetched
220 echo "refs/remotes/origin/master: $commit_id" \
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 # got.conf tells us to fetch the 'master' branch by default
234 got fetch -q -r $testroot/repo-clone > $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 echo "modified beta on foo" > $testroot/repo/beta
274 git_commit $testroot/repo -m "modified beta"
275 local commit_id4=`git_show_head $testroot/repo`
277 # set the default HEAD branch back to master
278 (cd $testroot/repo && git checkout -q master)
280 got checkout -b foo $testroot/repo-clone $testroot/wt > /dev/null
282 # fetch new commits on branch 'foo', implicitly obtaining the
283 # branch name from a work tree
284 (cd $testroot/wt && got fetch -q > $testroot/stdout)
286 echo -n > $testroot/stdout.expected
288 cmp -s $testroot/stdout $testroot/stdout.expected
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 diff -u $testroot/stdout.expected $testroot/stdout
292 test_done "$testroot" "$ret"
293 return 1
294 fi
296 wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
297 cut -d ':' -f 2 | tr -d ' ')`
299 got ref -l -r $testroot/repo-clone > $testroot/stdout
301 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
302 echo "refs/got/worktree/base-$wt_uuid: $commit_id3" \
303 >> $testroot/stdout.expected
304 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
305 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
306 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
307 >> $testroot/stdout.expected
308 echo "refs/remotes/origin/foo: $commit_id4" >> $testroot/stdout.expected
309 echo "refs/remotes/origin/master: $commit_id2" \
310 >> $testroot/stdout.expected
311 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
312 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
314 cmp -s $testroot/stdout $testroot/stdout.expected
315 ret=$?
316 if [ $ret -ne 0 ]; then
317 diff -u $testroot/stdout.expected $testroot/stdout
318 fi
319 test_done "$testroot" "$ret"
322 test_fetch_all() {
323 local testroot=`test_init fetch_all`
324 local testurl=ssh://127.0.0.1/$testroot
325 local commit_id=`git_show_head $testroot/repo`
327 got clone -q $testurl/repo $testroot/repo-clone
328 ret=$?
329 if [ $ret -ne 0 ]; then
330 echo "got clone command failed unexpectedly" >&2
331 test_done "$testroot" "$ret"
332 return 1
333 fi
335 got branch -r $testroot/repo -c $commit_id foo
336 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
337 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
338 local tag_id=`got ref -r $testroot/repo -l \
339 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
341 got ref -l -r $testroot/repo-clone > $testroot/stdout
343 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
344 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
345 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
346 >> $testroot/stdout.expected
347 echo "refs/remotes/origin/master: $commit_id" \
348 >> $testroot/stdout.expected
349 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
351 cmp -s $testroot/stdout $testroot/stdout.expected
352 ret=$?
353 if [ $ret -ne 0 ]; then
354 diff -u $testroot/stdout.expected $testroot/stdout
355 test_done "$testroot" "$ret"
356 return 1
357 fi
359 got fetch -q -a -r $testroot/repo-clone
360 ret=$?
361 if [ $ret -ne 0 ]; then
362 echo "got fetch command failed unexpectedly" >&2
363 test_done "$testroot" "$ret"
364 return 1
365 fi
367 got ref -l -r $testroot/repo-clone > $testroot/stdout
369 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
370 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
371 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
372 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
373 >> $testroot/stdout.expected
374 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
375 echo "refs/remotes/origin/master: $commit_id" \
376 >> $testroot/stdout.expected
377 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
378 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
380 cmp -s $testroot/stdout $testroot/stdout.expected
381 ret=$?
382 if [ $ret -ne 0 ]; then
383 diff -u $testroot/stdout.expected $testroot/stdout
384 fi
385 test_done "$testroot" "$ret"
388 test_fetch_empty_packfile() {
389 local testroot=`test_init fetch_empty_packfile`
390 local testurl=ssh://127.0.0.1/$testroot
391 local commit_id=`git_show_head $testroot/repo`
393 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
394 local tag_id=`got ref -r $testroot/repo -l \
395 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
397 got clone -q $testurl/repo $testroot/repo-clone
398 ret=$?
399 if [ $ret -ne 0 ]; then
400 echo "got clone command failed unexpectedly" >&2
401 test_done "$testroot" "$ret"
402 return 1
403 fi
405 got branch -r $testroot/repo -c $commit_id foo
406 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
408 got ref -l -r $testroot/repo-clone > $testroot/stdout
410 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
411 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
412 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
413 >> $testroot/stdout.expected
414 echo "refs/remotes/origin/master: $commit_id" \
415 >> $testroot/stdout.expected
416 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
417 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
419 cmp -s $testroot/stdout $testroot/stdout.expected
420 ret=$?
421 if [ $ret -ne 0 ]; then
422 diff -u $testroot/stdout.expected $testroot/stdout
423 test_done "$testroot" "$ret"
424 return 1
425 fi
427 got fetch -q -a -r $testroot/repo-clone
428 ret=$?
429 if [ $ret -ne 0 ]; then
430 echo "got fetch command failed unexpectedly" >&2
431 test_done "$testroot" "$ret"
432 return 1
433 fi
435 got ref -l -r $testroot/repo-clone > $testroot/stdout
437 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
438 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
439 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
440 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
441 >> $testroot/stdout.expected
442 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
443 echo "refs/remotes/origin/master: $commit_id" \
444 >> $testroot/stdout.expected
445 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
446 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
448 cmp -s $testroot/stdout $testroot/stdout.expected
449 ret=$?
450 if [ $ret -ne 0 ]; then
451 diff -u $testroot/stdout.expected $testroot/stdout
452 fi
453 test_done "$testroot" "$ret"
456 test_fetch_delete_branch() {
457 local testroot=`test_init fetch_delete_branch`
458 local testurl=ssh://127.0.0.1/$testroot
459 local commit_id=`git_show_head $testroot/repo`
462 got branch -r $testroot/repo -c $commit_id foo
463 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
464 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
465 local tag_id=`got ref -r $testroot/repo -l \
466 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
468 got clone -a -q $testurl/repo $testroot/repo-clone
469 ret=$?
470 if [ $ret -ne 0 ]; then
471 echo "got clone command failed unexpectedly" >&2
472 test_done "$testroot" "$ret"
473 return 1
474 fi
476 got ref -l -r $testroot/repo-clone > $testroot/stdout
478 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
479 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
480 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
481 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
482 >> $testroot/stdout.expected
483 echo "refs/remotes/origin/foo: $commit_id" \
484 >> $testroot/stdout.expected
485 echo "refs/remotes/origin/master: $commit_id" \
486 >> $testroot/stdout.expected
487 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
488 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
490 cmp -s $testroot/stdout $testroot/stdout.expected
491 ret=$?
492 if [ $ret -ne 0 ]; then
493 diff -u $testroot/stdout.expected $testroot/stdout
494 test_done "$testroot" "$ret"
495 return 1
496 fi
498 got branch -r $testroot/repo -d foo >/dev/null
500 got fetch -q -r $testroot/repo-clone
501 ret=$?
502 if [ $ret -ne 0 ]; then
503 echo "got fetch command failed unexpectedly" >&2
504 test_done "$testroot" "$ret"
505 return 1
506 fi
508 got ref -l -r $testroot/repo-clone > $testroot/stdout
510 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
511 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
512 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
513 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
514 >> $testroot/stdout.expected
515 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
516 echo "refs/remotes/origin/master: $commit_id" \
517 >> $testroot/stdout.expected
518 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
519 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
521 cmp -s $testroot/stdout $testroot/stdout.expected
522 ret=$?
523 if [ $ret -ne 0 ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 test_done "$testroot" "$ret"
526 return 1
527 fi
529 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
530 ret=$?
531 if [ $ret -ne 0 ]; then
532 echo "got fetch command failed unexpectedly" >&2
533 test_done "$testroot" "$ret"
534 return 1
535 fi
537 echo -n > $testroot/stdout.expected
539 cmp -s $testroot/stdout $testroot/stdout.expected
540 ret=$?
541 if [ $ret -ne 0 ]; then
542 diff -u $testroot/stdout.expected $testroot/stdout
543 test_done "$testroot" "$ret"
544 return 1
545 fi
547 got ref -l -r $testroot/repo-clone > $testroot/stdout
549 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
550 # refs/heads/foo is now deleted
551 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
552 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
553 >> $testroot/stdout.expected
554 # refs/remotes/origin/foo is now deleted
555 echo "refs/remotes/origin/master: $commit_id" \
556 >> $testroot/stdout.expected
557 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
558 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
560 cmp -s $testroot/stdout $testroot/stdout.expected
561 ret=$?
562 if [ $ret -ne 0 ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 fi
565 test_done "$testroot" "$ret"
569 test_fetch_delete_branch_mirror() {
570 local testroot=`test_init fetch_delete_branch_mirror`
571 local testurl=ssh://127.0.0.1/$testroot
572 local commit_id=`git_show_head $testroot/repo`
574 got branch -r $testroot/repo -c $commit_id foo
575 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
576 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
577 local tag_id=`got ref -r $testroot/repo -l \
578 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
580 got clone -a -m -q $testurl/repo $testroot/repo-clone
581 ret=$?
582 if [ $ret -ne 0 ]; then
583 echo "got clone command failed unexpectedly" >&2
584 test_done "$testroot" "$ret"
585 return 1
586 fi
588 got ref -l -r $testroot/repo-clone > $testroot/stdout
590 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
591 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
592 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
593 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
594 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
596 cmp -s $testroot/stdout $testroot/stdout.expected
597 ret=$?
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 test_done "$testroot" "$ret"
601 return 1
602 fi
604 got branch -r $testroot/repo -d foo >/dev/null
606 got fetch -q -r $testroot/repo-clone
607 ret=$?
608 if [ $ret -ne 0 ]; then
609 echo "got fetch command failed unexpectedly" >&2
610 test_done "$testroot" "$ret"
611 return 1
612 fi
614 got ref -l -r $testroot/repo-clone > $testroot/stdout
616 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
617 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
618 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
619 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
620 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
622 cmp -s $testroot/stdout $testroot/stdout.expected
623 ret=$?
624 if [ $ret -ne 0 ]; then
625 diff -u $testroot/stdout.expected $testroot/stdout
626 test_done "$testroot" "$ret"
627 return 1
628 fi
630 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
631 ret=$?
632 if [ $ret -ne 0 ]; then
633 echo "got fetch command failed unexpectedly" >&2
634 test_done "$testroot" "$ret"
635 return 1
636 fi
638 echo -n > $testroot/stdout.expected
640 cmp -s $testroot/stdout $testroot/stdout.expected
641 ret=$?
642 if [ $ret -ne 0 ]; then
643 diff -u $testroot/stdout.expected $testroot/stdout
644 test_done "$testroot" "$ret"
645 return 1
646 fi
648 got ref -l -r $testroot/repo-clone > $testroot/stdout
650 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
651 # refs/heads/foo is now deleted
652 echo "refs/heads/master: $commit_id" >> $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 fi
661 test_done "$testroot" "$ret"
665 test_fetch_update_tag() {
666 local testroot=`test_init fetch_update_tag`
667 local testurl=ssh://127.0.0.1/$testroot
668 local commit_id=`git_show_head $testroot/repo`
671 got branch -r $testroot/repo -c $commit_id foo
672 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
673 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
674 local tag_id=`got ref -r $testroot/repo -l \
675 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
677 got clone -a -q $testurl/repo $testroot/repo-clone
678 ret=$?
679 if [ $ret -ne 0 ]; then
680 echo "got clone command failed unexpectedly" >&2
681 test_done "$testroot" "$ret"
682 return 1
683 fi
685 echo "modified alpha on master" > $testroot/repo/alpha
686 git_commit $testroot/repo -m "modified alpha"
687 local commit_id2=`git_show_head $testroot/repo`
689 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
690 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
691 local tag_id2=`got ref -r $testroot/repo -l \
692 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
694 got ref -l -r $testroot/repo-clone > $testroot/stdout
696 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
697 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
698 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
699 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
700 >> $testroot/stdout.expected
701 echo "refs/remotes/origin/foo: $commit_id" \
702 >> $testroot/stdout.expected
703 echo "refs/remotes/origin/master: $commit_id" \
704 >> $testroot/stdout.expected
705 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
706 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
708 cmp -s $testroot/stdout $testroot/stdout.expected
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
712 test_done "$testroot" "$ret"
713 return 1
714 fi
716 got fetch -a -q -r $testroot/repo-clone
717 ret=$?
718 if [ $ret -ne 0 ]; then
719 echo "got fetch command failed unexpectedly" >&2
720 test_done "$testroot" "$ret"
721 return 1
722 fi
724 got ref -l -r $testroot/repo-clone > $testroot/stdout
726 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
727 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
728 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
729 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
730 >> $testroot/stdout.expected
731 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
732 echo "refs/remotes/origin/master: $commit_id2" \
733 >> $testroot/stdout.expected
734 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
735 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
737 cmp -s $testroot/stdout $testroot/stdout.expected
738 ret=$?
739 if [ $ret -ne 0 ]; then
740 diff -u $testroot/stdout.expected $testroot/stdout
741 test_done "$testroot" "$ret"
742 return 1
743 fi
745 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
746 tail -n 1 > $testroot/stdout
747 ret=$?
748 if [ $ret -ne 0 ]; then
749 echo "got fetch command failed unexpectedly" >&2
750 test_done "$testroot" "$ret"
751 return 1
752 fi
754 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
755 > $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 ref -l -r $testroot/repo-clone > $testroot/stdout
767 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
768 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
769 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
770 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
771 >> $testroot/stdout.expected
772 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
773 echo "refs/remotes/origin/master: $commit_id2" \
774 >> $testroot/stdout.expected
775 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
776 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
778 cmp -s $testroot/stdout $testroot/stdout.expected
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stdout.expected $testroot/stdout
782 test_done "$testroot" "$ret"
783 return 1
784 fi
786 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
787 ret=$?
788 if [ $ret -ne 0 ]; then
789 echo "got fetch command failed unexpectedly" >&2
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 echo -n > $testroot/stdout.expected
796 cmp -s $testroot/stdout $testroot/stdout.expected
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 diff -u $testroot/stdout.expected $testroot/stdout
800 test_done "$testroot" "$ret"
801 return 1
802 fi
804 got ref -l -r $testroot/repo-clone > $testroot/stdout
806 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
807 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
808 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
809 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
810 >> $testroot/stdout.expected
811 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
812 echo "refs/remotes/origin/master: $commit_id2" \
813 >> $testroot/stdout.expected
814 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
815 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
817 cmp -s $testroot/stdout $testroot/stdout.expected
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 fi
822 test_done "$testroot" "$ret"
825 test_fetch_reference() {
826 local testroot=`test_init fetch_reference`
827 local testurl=ssh://127.0.0.1/$testroot
828 local commit_id=`git_show_head $testroot/repo`
830 got clone -q $testurl/repo $testroot/repo-clone
831 ret=$?
832 if [ $ret -ne 0 ]; then
833 echo "got clone command failed unexpectedly" >&2
834 test_done "$testroot" "$ret"
835 return 1
836 fi
838 got branch -r $testroot/repo -c $commit_id foo
839 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
840 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
841 local tag_id=`got ref -r $testroot/repo -l \
842 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
844 echo "modified alpha on master" > $testroot/repo/alpha
845 git_commit $testroot/repo -m "modified alpha"
846 local commit_id2=`git_show_head $testroot/repo`
848 (cd $testroot/repo && git checkout -q foo)
849 echo "modified alpha on foo" > $testroot/repo/alpha
850 git_commit $testroot/repo -m "modified alpha"
851 local commit_id3=`git_show_head $testroot/repo`
852 (cd $testroot/repo && git checkout -q master)
854 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
855 > $testroot/stdout 2> $testroot/stderr
856 ret=$?
857 if [ $ret -eq 0 ]; then
858 echo "got fetch command succeeded unexpectedly" >&2
859 test_done "$testroot" "1"
860 return 1
861 fi
863 echo -n > $testroot/stdout.expected
865 cmp -s $testroot/stdout $testroot/stdout.expected
866 ret=$?
867 if [ $ret -ne 0 ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
874 > $testroot/stderr.expected
876 cmp -s $testroot/stderr $testroot/stderr.expected
877 ret=$?
878 if [ $ret -ne 0 ]; then
879 diff -u $testroot/stderr.expected $testroot/stderr
880 test_done "$testroot" "$ret"
881 return 1
882 fi
884 got fetch -q -r $testroot/repo-clone -R refs/hoo
885 ret=$?
886 if [ $ret -ne 0 ]; then
887 echo "got fetch command failed unexpectedly" >&2
888 test_done "$testroot" "$ret"
889 return 1
890 fi
892 got ref -l -r $testroot/repo-clone > $testroot/stdout
894 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
895 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
896 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
897 >> $testroot/stdout.expected
898 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
899 >> $testroot/stdout.expected
900 echo "refs/remotes/origin/master: $commit_id2" \
901 >> $testroot/stdout.expected
902 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
904 cmp -s $testroot/stdout $testroot/stdout.expected
905 ret=$?
906 if [ $ret -ne 0 ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 fi
909 test_done "$testroot" "$ret"
913 test_fetch_replace_symref() {
914 local testroot=`test_init fetch_replace_symref`
915 local testurl=ssh://127.0.0.1/$testroot
916 local commit_id=`git_show_head $testroot/repo`
918 got clone -m -q $testurl/repo $testroot/repo-clone
919 ret=$?
920 if [ $ret -ne 0 ]; then
921 echo "got clone command failed unexpectedly" >&2
922 test_done "$testroot" "$ret"
923 return 1
924 fi
926 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
927 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
929 got ref -l -r $testroot/repo-clone > $testroot/stdout
931 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
932 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
933 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
935 cmp -s $testroot/stdout $testroot/stdout.expected
936 ret=$?
937 if [ $ret -ne 0 ]; then
938 diff -u $testroot/stdout.expected $testroot/stdout
939 test_done "$testroot" "$ret"
940 return 1
941 fi
943 got fetch -r $testroot/repo-clone -R refs/hoo \
944 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
945 ret=$?
946 if [ $ret -ne 0 ]; then
947 echo "got fetch command failed unexpectedly" >&2
948 test_done "$testroot" "$ret"
949 return 1
950 fi
952 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
953 > $testroot/stdout.expected
955 cmp -s $testroot/stdout $testroot/stdout.expected
956 ret=$?
957 if [ $ret -ne 0 ]; then
958 diff -u $testroot/stdout.expected $testroot/stdout
959 test_done "$testroot" "$ret"
960 return 1
961 fi
963 got ref -l -r $testroot/repo-clone > $testroot/stdout
965 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
966 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
967 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
969 cmp -s $testroot/stdout $testroot/stdout.expected
970 ret=$?
971 if [ $ret -ne 0 ]; then
972 diff -u $testroot/stdout.expected $testroot/stdout
973 fi
974 test_done "$testroot" "$ret"
978 test_fetch_update_headref() {
979 local testroot=`test_init fetch_update_headref`
980 local testurl=ssh://127.0.0.1/$testroot
981 local commit_id=`git_show_head $testroot/repo`
983 got clone -q $testurl/repo $testroot/repo-clone
984 ret=$?
985 if [ $ret -ne 0 ]; then
986 echo "got clone command failed unexpectedly" >&2
987 test_done "$testroot" "$ret"
988 return 1
989 fi
991 got ref -l -r $testroot/repo-clone > $testroot/stdout
993 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
994 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
995 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
996 >> $testroot/stdout.expected
997 echo "refs/remotes/origin/master: $commit_id" \
998 >> $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 got ref -r $testroot/repo -c refs/heads/master refs/heads/foo
1009 got ref -r $testroot/repo -s refs/heads/foo HEAD
1010 got ref -l -r $testroot/repo > $testroot/stdout
1012 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
1013 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1014 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1016 cmp -s $testroot/stdout $testroot/stdout.expected
1017 ret=$?
1018 if [ $ret -ne 0 ]; then
1019 diff -u $testroot/stdout.expected $testroot/stdout
1020 test_done "$testroot" "$ret"
1021 return 1
1024 got fetch -q -r $testroot/repo-clone
1026 got ref -l -r $testroot/repo-clone > $testroot/stdout
1028 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1029 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1030 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1031 >> $testroot/stdout.expected
1032 echo "refs/remotes/origin/master: $commit_id" \
1033 >> $testroot/stdout.expected
1035 cmp -s $testroot/stdout $testroot/stdout.expected
1036 ret=$?
1037 if [ $ret -ne 0 ]; then
1038 diff -u $testroot/stdout.expected $testroot/stdout
1039 test_done "$testroot" "$ret"
1040 return 1
1043 got fetch -q -r $testroot/repo-clone -a
1045 got ref -l -r $testroot/repo-clone > $testroot/stdout
1047 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1048 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1049 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1050 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
1051 >> $testroot/stdout.expected
1052 echo "refs/remotes/origin/foo: $commit_id" \
1053 >> $testroot/stdout.expected
1054 echo "refs/remotes/origin/master: $commit_id" \
1055 >> $testroot/stdout.expected
1057 cmp -s $testroot/stdout $testroot/stdout.expected
1058 ret=$?
1059 if [ $ret -ne 0 ]; then
1060 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1065 test_fetch_headref_deleted_locally() {
1066 local testroot=`test_init fetch_headref_deleted_locally`
1067 local testurl=ssh://127.0.0.1/$testroot
1068 local commit_id=`git_show_head $testroot/repo`
1070 got clone -q $testurl/repo $testroot/repo-clone
1071 ret=$?
1072 if [ $ret -ne 0 ]; then
1073 echo "got clone command failed unexpectedly" >&2
1074 test_done "$testroot" "$ret"
1075 return 1
1078 got ref -l -r $testroot/repo-clone > $testroot/stdout
1080 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1081 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1082 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1083 >> $testroot/stdout.expected
1084 echo "refs/remotes/origin/master: $commit_id" \
1085 >> $testroot/stdout.expected
1087 cmp -s $testroot/stdout $testroot/stdout.expected
1088 ret=$?
1089 if [ $ret -ne 0 ]; then
1090 diff -u $testroot/stdout.expected $testroot/stdout
1091 test_done "$testroot" "$ret"
1092 return 1
1095 got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD > /dev/null
1097 got fetch -q -r $testroot/repo-clone
1098 ret=$?
1099 if [ $ret -ne 0 ]; then
1100 echo "got fetch command failed unexpectedly" >&2
1101 test_done "$testroot" "$ret"
1102 return 1
1104 got ref -l -r $testroot/repo-clone > $testroot/stdout
1106 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1107 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1108 # refs/remotes/origin/HEAD has been restored:
1109 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1110 >> $testroot/stdout.expected
1111 echo "refs/remotes/origin/master: $commit_id" \
1112 >> $testroot/stdout.expected
1114 cmp -s $testroot/stdout $testroot/stdout.expected
1115 ret=$?
1116 if [ $ret -ne 0 ]; then
1117 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1122 test_fetch_gotconfig_remote_repo() {
1123 local testroot=`test_init fetch_gotconfig_remote_repo`
1124 local testurl=ssh://127.0.0.1/$testroot
1125 local commit_id=`git_show_head $testroot/repo`
1127 got branch -r $testroot/repo -c $commit_id foo
1128 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
1129 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
1131 got clone -q $testurl/repo $testroot/repo-clone
1132 ret=$?
1133 if [ $ret -ne 0 ]; then
1134 echo "got clone command failed unexpectedly" >&2
1135 test_done "$testroot" "$ret"
1136 return 1
1139 cat > $testroot/repo-clone/got.conf <<EOF
1140 remote "foobar" {
1141 protocol ssh
1142 server 127.0.0.1
1143 repository "$testroot/repo"
1146 remote "barbaz" {
1147 protocol ssh
1148 server 127.0.0.1
1149 repository "$testroot/does-not-exist"
1151 EOF
1152 echo "got: nonexistent: remote repository not found" \
1153 > $testroot/stderr.expected
1154 (cd $testroot/repo-clone && got fetch -q nonexistent \
1155 > $testroot/stdout 2> $testroot/stderr)
1156 ret=$?
1157 if [ $ret -eq 0 ]; then
1158 echo "got fetch command succeeded unexpectedly" >&2
1159 diff -u $testroot/stderr.expected $testroot/stderr
1160 test_done "$testroot" "1"
1161 return 1
1164 (cd $testroot/repo-clone && got fetch -q -l foobar \
1165 > $testroot/stdout)
1166 ret=$?
1167 if [ $ret -ne 0 ]; then
1168 echo "got fetch command failed unexpectedly" >&2
1169 test_done "$testroot" "$ret"
1170 return 1
1173 got ref -l -r $testroot/repo > $testroot/stdout.expected
1175 cmp -s $testroot/stdout $testroot/stdout.expected
1176 ret=$?
1177 if [ $ret -ne 0 ]; then
1178 diff -u $testroot/stdout.expected $testroot/stdout
1179 test_done "$testroot" "$ret"
1180 return 1
1183 got checkout $testroot/repo $testroot/wt > /dev/null
1185 cat > $testroot/wt/.got/got.conf <<EOF
1186 remote "barbaz" {
1187 protocol ssh
1188 server 127.0.0.1
1189 repository "$testroot/repo"
1191 EOF
1192 (cd $testroot/wt && got fetch -q -l barbaz > $testroot/stdout)
1193 ret=$?
1194 if [ $ret -ne 0 ]; then
1195 echo "got fetch command failed unexpectedly" >&2
1196 test_done "$testroot" "$ret"
1197 return 1
1200 got ref -l -r $testroot/repo > $testroot/stdout.expected
1202 cmp -s $testroot/stdout $testroot/stdout.expected
1203 ret=$?
1204 if [ $ret -ne 0 ]; then
1205 diff -u $testroot/stdout.expected $testroot/stdout
1206 test_done "$testroot" "$ret"
1207 return 1
1210 cat > $testroot/repo-clone/got.conf <<EOF
1211 remote "origin" {
1212 protocol ssh
1213 server 127.0.0.1
1214 repository "$testroot/repo"
1215 branch { "foo" }
1216 reference { "hoo/boo/zoo" }
1218 EOF
1219 (cd $testroot/repo-clone && got fetch -q > $testroot/stdout)
1221 local tag_id=`got ref -r $testroot/repo -l \
1222 | grep "^refs/tags/1.0" | tr -d ' ' | cut -d: -f2`
1223 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1224 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1225 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1226 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1227 >> $testroot/stdout.expected
1228 echo "refs/remotes/origin/foo: $commit_id" \
1229 >> $testroot/stdout.expected
1230 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
1231 >> $testroot/stdout.expected
1232 echo "refs/remotes/origin/master: $commit_id" \
1233 >> $testroot/stdout.expected
1234 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1236 got ref -l -r $testroot/repo-clone > $testroot/stdout
1238 cmp -s $testroot/stdout $testroot/stdout.expected
1239 ret=$?
1240 if [ $ret -ne 0 ]; then
1241 diff -u $testroot/stdout.expected $testroot/stdout
1243 test_done "$testroot" "$ret"
1246 test_fetch_delete_remote_refs() {
1247 local testroot=`test_init fetch_delete_remote_refs`
1248 local testurl=ssh://127.0.0.1/$testroot
1249 local commit_id=`git_show_head $testroot/repo`
1251 got clone -q $testurl/repo $testroot/repo-clone
1252 ret=$?
1253 if [ $ret -ne 0 ]; then
1254 echo "got clone command failed unexpectedly" >&2
1255 test_done "$testroot" "$ret"
1256 return 1
1259 got ref -l -r $testroot/repo-clone > $testroot/stdout
1260 ret=$?
1261 if [ $ret -ne 0 ]; then
1262 echo "got ref command failed unexpectedly" >&2
1263 test_done "$testroot" "$ret"
1264 return 1
1267 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1268 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1269 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1270 >> $testroot/stdout.expected
1271 echo "refs/remotes/origin/master: $commit_id" \
1272 >> $testroot/stdout.expected
1274 cmp -s $testroot/stdout $testroot/stdout.expected
1275 ret=$?
1276 if [ $ret -ne 0 ]; then
1277 diff -u $testroot/stdout.expected $testroot/stdout
1278 test_done "$testroot" "$ret"
1279 return 1
1282 got fetch -q -r $testroot/repo-clone -X > $testroot/stdout \
1283 2> $testroot/stderr
1284 ret=$?
1285 if [ $ret -eq 0 ]; then
1286 echo "got fetch command succeeded unexpectedly" >&2
1287 test_done "$testroot" "$ret"
1288 return 1
1291 echo "got: -X option requires a remote name" > $testroot/stderr.expected
1292 cmp -s $testroot/stderr $testroot/stderr.expected
1293 ret=$?
1294 if [ $ret -ne 0 ]; then
1295 diff -u $testroot/stderr.expected $testroot/stderr
1296 test_done "$testroot" "$ret"
1297 return 1
1300 got fetch -q -r $testroot/repo-clone -X origin > $testroot/stdout \
1301 2> $testroot/stderr
1302 ret=$?
1303 if [ $ret -ne 0 ]; then
1304 echo "got fetch command failed unexpectedly" >&2
1305 test_done "$testroot" "$ret"
1306 return 1
1309 echo -n "Deleted refs/remotes/origin/HEAD: " > $testroot/stdout.expected
1310 echo "refs/remotes/origin/master" >> $testroot/stdout.expected
1311 echo "Deleted refs/remotes/origin/master: $commit_id" \
1312 >> $testroot/stdout.expected
1314 cmp -s $testroot/stdout $testroot/stdout.expected
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 diff -u $testroot/stdout.expected $testroot/stdout
1318 test_done "$testroot" "$ret"
1319 return 1
1322 got ref -l -r $testroot/repo-clone > $testroot/stdout
1323 ret=$?
1324 if [ $ret -ne 0 ]; then
1325 echo "got ref command failed unexpectedly" >&2
1326 test_done "$testroot" "$ret"
1327 return 1
1330 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1331 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1333 cmp -s $testroot/stdout $testroot/stdout.expected
1334 ret=$?
1335 if [ $ret -ne 0 ]; then
1336 diff -u $testroot/stdout.expected $testroot/stdout
1338 test_done "$testroot" "$ret"
1342 test_parseargs "$@"
1343 run_test test_fetch_basic
1344 run_test test_fetch_list
1345 run_test test_fetch_branch
1346 run_test test_fetch_all
1347 run_test test_fetch_empty_packfile
1348 run_test test_fetch_delete_branch
1349 run_test test_fetch_delete_branch_mirror
1350 run_test test_fetch_update_tag
1351 run_test test_fetch_reference
1352 run_test test_fetch_replace_symref
1353 run_test test_fetch_update_headref
1354 run_test test_fetch_headref_deleted_locally
1355 run_test test_fetch_gotconfig_remote_repo
1356 run_test test_fetch_delete_remote_refs