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" != "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 if [ "$ret" != "0" ]; then
38 echo "got ref command failed unexpectedly" >&2
39 test_done "$testroot" "$ret"
40 return 1
41 fi
43 got fetch -q -r $testroot/repo-clone > $testroot/stdout \
44 2> $testroot/stderr
45 ret="$?"
46 if [ "$ret" != "0" ]; then
47 echo "got fetch command failed unexpectedly" >&2
48 test_done "$testroot" "$ret"
49 return 1
50 fi
52 echo -n > $testroot/stdout.expected
54 cmp -s $testroot/stdout $testroot/stdout.expected
55 ret="$?"
56 if [ "$ret" != "0" ]; then
57 diff -u $testroot/stdout.expected $testroot/stdout
58 test_done "$testroot" "$ret"
59 return 1
60 fi
62 got log -l0 -p -r $testroot/repo > $testroot/log-repo
63 if [ "$ret" != "0" ]; then
64 echo "got log command failed unexpectedly" >&2
65 test_done "$testroot" "$ret"
66 return 1
67 fi
68 got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone
69 if [ "$ret" != "0" ]; then
70 echo "got log command failed unexpectedly" >&2
71 test_done "$testroot" "$ret"
72 return 1
73 fi
74 cmp -s $testroot/log-repo $testroot/log-repo-clone
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 echo "log -p output of cloned repository differs" >&2
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 got ref -l -r $testroot/repo > $testroot/stdout
83 if [ "$ret" != "0" ]; then
84 echo "got ref command failed unexpectedly" >&2
85 test_done "$testroot" "$ret"
86 return 1
87 fi
89 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
90 echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected
92 cmp -s $testroot/stdout $testroot/stdout.expected
93 ret="$?"
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/stdout.expected $testroot/stdout
96 test_done "$testroot" "$ret"
97 return 1
98 fi
100 got ref -l -r $testroot/repo-clone > $testroot/stdout
101 if [ "$ret" != "0" ]; then
102 echo "got ref command failed unexpectedly" >&2
103 test_done "$testroot" "$ret"
104 return 1
105 fi
107 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
108 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
109 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
110 >> $testroot/stdout.expected
111 echo "refs/remotes/origin/master: $commit_id2" \
112 >> $testroot/stdout.expected
114 cmp -s $testroot/stdout $testroot/stdout.expected
115 ret="$?"
116 if [ "$ret" != "0" ]; then
117 diff -u $testroot/stdout.expected $testroot/stdout
118 fi
119 test_done "$testroot" "$ret"
122 test_fetch_list() {
123 local testroot=`test_init fetch_list`
124 local testurl=ssh://127.0.0.1/$testroot
125 local commit_id=`git_show_head $testroot/repo`
127 got branch -r $testroot/repo -c $commit_id foo
128 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
129 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
131 got clone -q $testurl/repo $testroot/repo-clone
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 echo "got clone command failed unexpectedly" >&2
135 test_done "$testroot" "$ret"
136 return 1
137 fi
139 (cd $testroot/repo-clone && got fetch -l \
140 > $testroot/stdout 2>$testroot/stderr)
141 ret="$?"
142 if [ "$ret" != "0" ]; then
143 echo "got fetch command failed unexpectedly" >&2
144 test_done "$testroot" "$ret"
145 return 1
146 fi
148 echo "Connecting to \"origin\" 127.0.0.1" > $testroot/stdout.expected
149 got ref -l -r $testroot/repo >> $testroot/stdout.expected
151 cmp -s $testroot/stdout $testroot/stdout.expected
152 ret="$?"
153 if [ "$ret" != "0" ]; then
154 diff -u $testroot/stdout.expected $testroot/stdout
155 fi
156 test_done "$testroot" "$ret"
159 test_fetch_branch() {
160 local testroot=`test_init fetch_branch`
161 local testurl=ssh://127.0.0.1/$testroot
162 local commit_id=`git_show_head $testroot/repo`
164 got clone -q $testurl/repo $testroot/repo-clone
165 ret="$?"
166 if [ "$ret" != "0" ]; then
167 echo "got clone command failed unexpectedly" >&2
168 test_done "$testroot" "$ret"
169 return 1
170 fi
172 got branch -r $testroot/repo -c $commit_id foo
173 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
174 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
175 local tag_id=`got ref -r $testroot/repo -l \
176 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
178 echo "modified alpha on master" > $testroot/repo/alpha
179 git_commit $testroot/repo -m "modified alpha"
180 local commit_id2=`git_show_head $testroot/repo`
182 (cd $testroot/repo && git checkout -q foo)
183 echo "modified alpha on foo" > $testroot/repo/alpha
184 git_commit $testroot/repo -m "modified alpha"
185 local commit_id3=`git_show_head $testroot/repo`
187 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
188 ret="$?"
189 if [ "$ret" != "0" ]; then
190 echo "got fetch command failed unexpectedly" >&2
191 test_done "$testroot" "$ret"
192 return 1
193 fi
195 echo -n > $testroot/stdout.expected
197 cmp -s $testroot/stdout $testroot/stdout.expected
198 ret="$?"
199 if [ "$ret" != "0" ]; then
200 diff -u $testroot/stdout.expected $testroot/stdout
201 test_done "$testroot" "$ret"
202 return 1
203 fi
205 got ref -l -r $testroot/repo-clone > $testroot/stdout
207 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
208 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
209 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
210 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
211 >> $testroot/stdout.expected
212 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
213 # refs/remotes/origin/master is umodified because it wasn't fetched
214 echo "refs/remotes/origin/master: $commit_id" \
215 >> $testroot/stdout.expected
216 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
217 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
219 cmp -s $testroot/stdout $testroot/stdout.expected
220 ret="$?"
221 if [ "$ret" != "0" ]; then
222 diff -u $testroot/stdout.expected $testroot/stdout
223 test_done "$testroot" "$ret"
224 return 1
225 fi
227 got fetch -q -r $testroot/repo-clone -b master > $testroot/stdout
228 ret="$?"
229 if [ "$ret" != "0" ]; then
230 echo "got fetch command failed unexpectedly" >&2
231 test_done "$testroot" "$ret"
232 return 1
233 fi
235 echo -n > $testroot/stdout.expected
237 cmp -s $testroot/stdout $testroot/stdout.expected
238 ret="$?"
239 if [ "$ret" != "0" ]; then
240 diff -u $testroot/stdout.expected $testroot/stdout
241 test_done "$testroot" "$ret"
242 return 1
243 fi
245 got ref -l -r $testroot/repo-clone > $testroot/stdout
247 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
248 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
249 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
250 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
251 >> $testroot/stdout.expected
252 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
253 echo "refs/remotes/origin/master: $commit_id2" \
254 >> $testroot/stdout.expected
255 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
256 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
258 cmp -s $testroot/stdout $testroot/stdout.expected
259 ret="$?"
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 fi
263 test_done "$testroot" "$ret"
266 test_fetch_all() {
267 local testroot=`test_init fetch_all`
268 local testurl=ssh://127.0.0.1/$testroot
269 local commit_id=`git_show_head $testroot/repo`
271 got clone -q $testurl/repo $testroot/repo-clone
272 ret="$?"
273 if [ "$ret" != "0" ]; then
274 echo "got clone command failed unexpectedly" >&2
275 test_done "$testroot" "$ret"
276 return 1
277 fi
279 got branch -r $testroot/repo -c $commit_id foo
280 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
281 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
282 local tag_id=`got ref -r $testroot/repo -l \
283 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
285 got ref -l -r $testroot/repo-clone > $testroot/stdout
287 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
288 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
289 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
290 >> $testroot/stdout.expected
291 echo "refs/remotes/origin/master: $commit_id" \
292 >> $testroot/stdout.expected
293 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
295 cmp -s $testroot/stdout $testroot/stdout.expected
296 ret="$?"
297 if [ "$ret" != "0" ]; then
298 diff -u $testroot/stdout.expected $testroot/stdout
299 test_done "$testroot" "$ret"
300 return 1
301 fi
303 got fetch -q -a -r $testroot/repo-clone
304 ret="$?"
305 if [ "$ret" != "0" ]; then
306 echo "got fetch command failed unexpectedly" >&2
307 test_done "$testroot" "$ret"
308 return 1
309 fi
311 got ref -l -r $testroot/repo-clone > $testroot/stdout
313 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
314 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
315 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
316 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
317 >> $testroot/stdout.expected
318 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
319 echo "refs/remotes/origin/master: $commit_id" \
320 >> $testroot/stdout.expected
321 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
322 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
324 cmp -s $testroot/stdout $testroot/stdout.expected
325 ret="$?"
326 if [ "$ret" != "0" ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 fi
329 test_done "$testroot" "$ret"
332 test_fetch_empty_packfile() {
333 local testroot=`test_init fetch_empty_packfile`
334 local testurl=ssh://127.0.0.1/$testroot
335 local commit_id=`git_show_head $testroot/repo`
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 clone -q $testurl/repo $testroot/repo-clone
342 ret="$?"
343 if [ "$ret" != "0" ]; then
344 echo "got clone command failed unexpectedly" >&2
345 test_done "$testroot" "$ret"
346 return 1
347 fi
349 got branch -r $testroot/repo -c $commit_id foo
350 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
352 got ref -l -r $testroot/repo-clone > $testroot/stdout
354 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
355 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
356 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
357 >> $testroot/stdout.expected
358 echo "refs/remotes/origin/master: $commit_id" \
359 >> $testroot/stdout.expected
360 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
361 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
363 cmp -s $testroot/stdout $testroot/stdout.expected
364 ret="$?"
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/stdout.expected $testroot/stdout
367 test_done "$testroot" "$ret"
368 return 1
369 fi
371 got fetch -q -a -r $testroot/repo-clone
372 ret="$?"
373 if [ "$ret" != "0" ]; then
374 echo "got fetch command failed unexpectedly" >&2
375 test_done "$testroot" "$ret"
376 return 1
377 fi
379 got ref -l -r $testroot/repo-clone > $testroot/stdout
381 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
382 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
383 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
384 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
385 >> $testroot/stdout.expected
386 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
387 echo "refs/remotes/origin/master: $commit_id" \
388 >> $testroot/stdout.expected
389 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
390 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
392 cmp -s $testroot/stdout $testroot/stdout.expected
393 ret="$?"
394 if [ "$ret" != "0" ]; then
395 diff -u $testroot/stdout.expected $testroot/stdout
396 fi
397 test_done "$testroot" "$ret"
400 test_fetch_delete_branch() {
401 local testroot=`test_init fetch_delete_branch`
402 local testurl=ssh://127.0.0.1/$testroot
403 local commit_id=`git_show_head $testroot/repo`
406 got branch -r $testroot/repo -c $commit_id foo
407 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
408 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
409 local tag_id=`got ref -r $testroot/repo -l \
410 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
412 got clone -a -q $testurl/repo $testroot/repo-clone
413 ret="$?"
414 if [ "$ret" != "0" ]; then
415 echo "got clone command failed unexpectedly" >&2
416 test_done "$testroot" "$ret"
417 return 1
418 fi
420 got ref -l -r $testroot/repo-clone > $testroot/stdout
422 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
423 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
424 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
425 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
426 >> $testroot/stdout.expected
427 echo "refs/remotes/origin/foo: $commit_id" \
428 >> $testroot/stdout.expected
429 echo "refs/remotes/origin/master: $commit_id" \
430 >> $testroot/stdout.expected
431 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
432 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
434 cmp -s $testroot/stdout $testroot/stdout.expected
435 ret="$?"
436 if [ "$ret" != "0" ]; then
437 diff -u $testroot/stdout.expected $testroot/stdout
438 test_done "$testroot" "$ret"
439 return 1
440 fi
442 got branch -r $testroot/repo -d foo
444 got fetch -q -r $testroot/repo-clone
445 ret="$?"
446 if [ "$ret" != "0" ]; then
447 echo "got fetch command failed unexpectedly" >&2
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 got ref -l -r $testroot/repo-clone > $testroot/stdout
454 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
455 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
456 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
457 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
458 >> $testroot/stdout.expected
459 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
460 echo "refs/remotes/origin/master: $commit_id" \
461 >> $testroot/stdout.expected
462 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
463 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
465 cmp -s $testroot/stdout $testroot/stdout.expected
466 ret="$?"
467 if [ "$ret" != "0" ]; then
468 diff -u $testroot/stdout.expected $testroot/stdout
469 test_done "$testroot" "$ret"
470 return 1
471 fi
473 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
474 ret="$?"
475 if [ "$ret" != "0" ]; then
476 echo "got fetch command failed unexpectedly" >&2
477 test_done "$testroot" "$ret"
478 return 1
479 fi
481 echo -n > $testroot/stdout.expected
483 cmp -s $testroot/stdout $testroot/stdout.expected
484 ret="$?"
485 if [ "$ret" != "0" ]; then
486 diff -u $testroot/stdout.expected $testroot/stdout
487 test_done "$testroot" "$ret"
488 return 1
489 fi
491 got ref -l -r $testroot/repo-clone > $testroot/stdout
493 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
494 # refs/heads/foo is now deleted
495 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
496 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
497 >> $testroot/stdout.expected
498 # refs/remotes/origin/foo is now deleted
499 echo "refs/remotes/origin/master: $commit_id" \
500 >> $testroot/stdout.expected
501 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
502 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
504 cmp -s $testroot/stdout $testroot/stdout.expected
505 ret="$?"
506 if [ "$ret" != "0" ]; then
507 diff -u $testroot/stdout.expected $testroot/stdout
508 fi
509 test_done "$testroot" "$ret"
513 test_fetch_update_tag() {
514 local testroot=`test_init fetch_update_tag`
515 local testurl=ssh://127.0.0.1/$testroot
516 local commit_id=`git_show_head $testroot/repo`
519 got branch -r $testroot/repo -c $commit_id foo
520 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
521 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
522 local tag_id=`got ref -r $testroot/repo -l \
523 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
525 got clone -a -q $testurl/repo $testroot/repo-clone
526 ret="$?"
527 if [ "$ret" != "0" ]; then
528 echo "got clone command failed unexpectedly" >&2
529 test_done "$testroot" "$ret"
530 return 1
531 fi
533 echo "modified alpha on master" > $testroot/repo/alpha
534 git_commit $testroot/repo -m "modified alpha"
535 local commit_id2=`git_show_head $testroot/repo`
537 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
538 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
539 local tag_id2=`got ref -r $testroot/repo -l \
540 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
542 got ref -l -r $testroot/repo-clone > $testroot/stdout
544 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
545 echo "refs/heads/foo: $commit_id" >> $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/foo: $commit_id" \
550 >> $testroot/stdout.expected
551 echo "refs/remotes/origin/master: $commit_id" \
552 >> $testroot/stdout.expected
553 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
554 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
556 cmp -s $testroot/stdout $testroot/stdout.expected
557 ret="$?"
558 if [ "$ret" != "0" ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
561 return 1
562 fi
564 got fetch -q -r $testroot/repo-clone
565 ret="$?"
566 if [ "$ret" != "0" ]; then
567 echo "got fetch command failed unexpectedly" >&2
568 test_done "$testroot" "$ret"
569 return 1
570 fi
572 got ref -l -r $testroot/repo-clone > $testroot/stdout
574 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
575 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
576 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
577 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
578 >> $testroot/stdout.expected
579 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
580 echo "refs/remotes/origin/master: $commit_id2" \
581 >> $testroot/stdout.expected
582 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
583 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
585 cmp -s $testroot/stdout $testroot/stdout.expected
586 ret="$?"
587 if [ "$ret" != "0" ]; then
588 diff -u $testroot/stdout.expected $testroot/stdout
589 test_done "$testroot" "$ret"
590 return 1
591 fi
593 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
594 tail -n 1 > $testroot/stdout
595 ret="$?"
596 if [ "$ret" != "0" ]; then
597 echo "got fetch command failed unexpectedly" >&2
598 test_done "$testroot" "$ret"
599 return 1
600 fi
602 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
603 > $testroot/stdout.expected
605 cmp -s $testroot/stdout $testroot/stdout.expected
606 ret="$?"
607 if [ "$ret" != "0" ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
610 return 1
611 fi
613 got ref -l -r $testroot/repo-clone > $testroot/stdout
615 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
616 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
617 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
618 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
619 >> $testroot/stdout.expected
620 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
621 echo "refs/remotes/origin/master: $commit_id2" \
622 >> $testroot/stdout.expected
623 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
624 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
626 cmp -s $testroot/stdout $testroot/stdout.expected
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
631 return 1
632 fi
634 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
635 ret="$?"
636 if [ "$ret" != "0" ]; then
637 echo "got fetch command failed unexpectedly" >&2
638 test_done "$testroot" "$ret"
639 return 1
640 fi
642 echo -n > $testroot/stdout.expected
644 cmp -s $testroot/stdout $testroot/stdout.expected
645 ret="$?"
646 if [ "$ret" != "0" ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 test_done "$testroot" "$ret"
649 return 1
650 fi
652 got ref -l -r $testroot/repo-clone > $testroot/stdout
654 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
655 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
656 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
657 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
658 >> $testroot/stdout.expected
659 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
660 echo "refs/remotes/origin/master: $commit_id2" \
661 >> $testroot/stdout.expected
662 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
663 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
665 cmp -s $testroot/stdout $testroot/stdout.expected
666 ret="$?"
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stdout.expected $testroot/stdout
669 fi
670 test_done "$testroot" "$ret"
673 test_fetch_reference() {
674 local testroot=`test_init fetch_reference`
675 local testurl=ssh://127.0.0.1/$testroot
676 local commit_id=`git_show_head $testroot/repo`
678 got clone -q $testurl/repo $testroot/repo-clone
679 ret="$?"
680 if [ "$ret" != "0" ]; then
681 echo "got clone command failed unexpectedly" >&2
682 test_done "$testroot" "$ret"
683 return 1
684 fi
686 got branch -r $testroot/repo -c $commit_id foo
687 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
688 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
689 local tag_id=`got ref -r $testroot/repo -l \
690 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
692 echo "modified alpha on master" > $testroot/repo/alpha
693 git_commit $testroot/repo -m "modified alpha"
694 local commit_id2=`git_show_head $testroot/repo`
696 (cd $testroot/repo && git checkout -q foo)
697 echo "modified alpha on foo" > $testroot/repo/alpha
698 git_commit $testroot/repo -m "modified alpha"
699 local commit_id3=`git_show_head $testroot/repo`
700 (cd $testroot/repo && git checkout -q master)
702 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
703 > $testroot/stdout 2> $testroot/stderr
704 ret="$?"
705 if [ "$ret" == "0" ]; then
706 echo "got fetch command succeeded unexpectedly" >&2
707 test_done "$testroot" "1"
708 return 1
709 fi
711 echo -n > $testroot/stdout.expected
713 cmp -s $testroot/stdout $testroot/stdout.expected
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
722 > $testroot/stderr.expected
724 cmp -s $testroot/stderr $testroot/stderr.expected
725 ret="$?"
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/stderr.expected $testroot/stderr
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 got fetch -q -r $testroot/repo-clone -R refs/hoo
733 ret="$?"
734 if [ "$ret" != "0" ]; then
735 echo "got fetch command failed unexpectedly" >&2
736 test_done "$testroot" "$ret"
737 return 1
738 fi
740 got ref -l -r $testroot/repo-clone > $testroot/stdout
742 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
743 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
744 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
745 >> $testroot/stdout.expected
746 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
747 >> $testroot/stdout.expected
748 echo "refs/remotes/origin/master: $commit_id2" \
749 >> $testroot/stdout.expected
750 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
752 cmp -s $testroot/stdout $testroot/stdout.expected
753 ret="$?"
754 if [ "$ret" != "0" ]; then
755 diff -u $testroot/stdout.expected $testroot/stdout
756 fi
757 test_done "$testroot" "$ret"
761 test_fetch_replace_symref() {
762 local testroot=`test_init fetch_replace_symref`
763 local testurl=ssh://127.0.0.1/$testroot
764 local commit_id=`git_show_head $testroot/repo`
766 got clone -m -q $testurl/repo $testroot/repo-clone
767 ret="$?"
768 if [ "$ret" != "0" ]; then
769 echo "got clone command failed unexpectedly" >&2
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
775 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
777 got ref -l -r $testroot/repo-clone > $testroot/stdout
779 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
780 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
781 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
783 cmp -s $testroot/stdout $testroot/stdout.expected
784 ret="$?"
785 if [ "$ret" != "0" ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done "$testroot" "$ret"
788 return 1
789 fi
791 got fetch -r $testroot/repo-clone -R refs/hoo \
792 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
793 ret="$?"
794 if [ "$ret" != "0" ]; then
795 echo "got fetch command failed unexpectedly" >&2
796 test_done "$testroot" "$ret"
797 return 1
798 fi
800 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
801 > $testroot/stdout.expected
803 cmp -s $testroot/stdout $testroot/stdout.expected
804 ret="$?"
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/stdout.expected $testroot/stdout
807 test_done "$testroot" "$ret"
808 return 1
809 fi
811 got ref -l -r $testroot/repo-clone > $testroot/stdout
813 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
814 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
815 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
817 cmp -s $testroot/stdout $testroot/stdout.expected
818 ret="$?"
819 if [ "$ret" != "0" ]; then
820 diff -u $testroot/stdout.expected $testroot/stdout
821 fi
822 test_done "$testroot" "$ret"
826 test_fetch_update_headref() {
827 local testroot=`test_init fetch_update_headref`
828 local testurl=ssh://127.0.0.1/$testroot
829 local commit_id=`git_show_head $testroot/repo`
831 got clone -q $testurl/repo $testroot/repo-clone
832 ret="$?"
833 if [ "$ret" != "0" ]; then
834 echo "got clone command failed unexpectedly" >&2
835 test_done "$testroot" "$ret"
836 return 1
837 fi
839 got ref -l -r $testroot/repo-clone > $testroot/stdout
841 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
842 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
843 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
844 >> $testroot/stdout.expected
845 echo "refs/remotes/origin/master: $commit_id" \
846 >> $testroot/stdout.expected
848 cmp -s $testroot/stdout $testroot/stdout.expected
849 ret="$?"
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 test_done "$testroot" "$ret"
853 return 1
854 fi
856 got ref -r $testroot/repo -c refs/heads/master refs/heads/foo
857 got ref -r $testroot/repo -s refs/heads/foo HEAD
858 got ref -l -r $testroot/repo > $testroot/stdout
860 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
861 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
862 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
864 cmp -s $testroot/stdout $testroot/stdout.expected
865 ret="$?"
866 if [ "$ret" != "0" ]; then
867 diff -u $testroot/stdout.expected $testroot/stdout
868 test_done "$testroot" "$ret"
869 return 1
870 fi
872 got fetch -q -r $testroot/repo-clone
874 got ref -l -r $testroot/repo-clone > $testroot/stdout
876 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
877 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
878 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
879 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
880 >> $testroot/stdout.expected
881 echo "refs/remotes/origin/foo: $commit_id" \
882 >> $testroot/stdout.expected
883 echo "refs/remotes/origin/master: $commit_id" \
884 >> $testroot/stdout.expected
886 cmp -s $testroot/stdout $testroot/stdout.expected
887 ret="$?"
888 if [ "$ret" != "0" ]; then
889 diff -u $testroot/stdout.expected $testroot/stdout
890 fi
891 test_done "$testroot" "$ret"
894 test_fetch_headref_deleted_locally() {
895 local testroot=`test_init fetch_headref_deleted_locally`
896 local testurl=ssh://127.0.0.1/$testroot
897 local commit_id=`git_show_head $testroot/repo`
899 got clone -q $testurl/repo $testroot/repo-clone
900 ret="$?"
901 if [ "$ret" != "0" ]; then
902 echo "got clone command failed unexpectedly" >&2
903 test_done "$testroot" "$ret"
904 return 1
905 fi
907 got ref -l -r $testroot/repo-clone > $testroot/stdout
909 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
910 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
911 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
912 >> $testroot/stdout.expected
913 echo "refs/remotes/origin/master: $commit_id" \
914 >> $testroot/stdout.expected
916 cmp -s $testroot/stdout $testroot/stdout.expected
917 ret="$?"
918 if [ "$ret" != "0" ]; then
919 diff -u $testroot/stdout.expected $testroot/stdout
920 test_done "$testroot" "$ret"
921 return 1
922 fi
924 got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD
926 got fetch -q -r $testroot/repo-clone
927 ret="$?"
928 if [ "$ret" != "0" ]; then
929 echo "got fetch command failed unexpectedly" >&2
930 test_done "$testroot" "$ret"
931 return 1
932 fi
933 got ref -l -r $testroot/repo-clone > $testroot/stdout
935 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
936 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
937 # refs/remotes/origin/HEAD has been restored:
938 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
939 >> $testroot/stdout.expected
940 echo "refs/remotes/origin/master: $commit_id" \
941 >> $testroot/stdout.expected
943 cmp -s $testroot/stdout $testroot/stdout.expected
944 ret="$?"
945 if [ "$ret" != "0" ]; then
946 diff -u $testroot/stdout.expected $testroot/stdout
947 fi
948 test_done "$testroot" "$ret"
951 test_fetch_gotconfig_remote_repo() {
952 local testroot=`test_init fetch_gotconfig_remote_repo`
953 local testurl=ssh://127.0.0.1/$testroot
954 local commit_id=`git_show_head $testroot/repo`
956 got branch -r $testroot/repo -c $commit_id foo
957 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
958 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
960 got clone -q $testurl/repo $testroot/repo-clone
961 ret="$?"
962 if [ "$ret" != "0" ]; then
963 echo "got clone command failed unexpectedly" >&2
964 test_done "$testroot" "$ret"
965 return 1
966 fi
968 cat > $testroot/repo-clone/got.conf <<EOF
969 remote "foobar" {
970 protocol ssh
971 server 127.0.0.1
972 repository "$testroot/repo"
975 remote "barbaz" {
976 protocol ssh
977 server 127.0.0.1
978 repository "$testroot/does-not-exist"
980 EOF
981 echo "got: nonexistent: remote repository not found" \
982 > $testroot/stderr.expected
983 (cd $testroot/repo-clone && got fetch nonexistent \
984 > $testroot/stdout 2> $testroot/stderr)
985 ret="$?"
986 if [ "$ret" == "0" ]; then
987 echo "got fetch command succeeded unexpectedly" >&2
988 diff -u $testroot/stderr.expected $testroot/stderr
989 test_done "$testroot" "1"
990 return 1
991 fi
993 (cd $testroot/repo-clone && got fetch -l foobar \
994 > $testroot/stdout)
995 ret="$?"
996 if [ "$ret" != "0" ]; then
997 echo "got fetch command failed unexpectedly" >&2
998 test_done "$testroot" "$ret"
999 return 1
1002 echo "Connecting to \"foobar\" 127.0.0.1" > $testroot/stdout.expected
1003 got ref -l -r $testroot/repo >> $testroot/stdout.expected
1005 cmp -s $testroot/stdout $testroot/stdout.expected
1006 ret="$?"
1007 if [ "$ret" != "0" ]; then
1008 diff -u $testroot/stdout.expected $testroot/stdout
1009 test_done "$testroot" "$ret"
1010 return 1
1013 got checkout $testroot/repo $testroot/wt > /dev/null
1015 cat > $testroot/wt/.got/got.conf <<EOF
1016 remote "barbaz" {
1017 protocol ssh
1018 server 127.0.0.1
1019 repository "$testroot/repo"
1021 EOF
1022 (cd $testroot/wt && got fetch -l barbaz > $testroot/stdout)
1023 ret="$?"
1024 if [ "$ret" != "0" ]; then
1025 echo "got fetch command failed unexpectedly" >&2
1026 test_done "$testroot" "$ret"
1027 return 1
1030 echo "Connecting to \"barbaz\" 127.0.0.1" > $testroot/stdout.expected
1031 got ref -l -r $testroot/repo >> $testroot/stdout.expected
1033 cmp -s $testroot/stdout $testroot/stdout.expected
1034 ret="$?"
1035 if [ "$ret" != "0" ]; then
1036 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1042 test_parseargs "$@"
1043 run_test test_fetch_basic
1044 run_test test_fetch_list
1045 run_test test_fetch_branch
1046 run_test test_fetch_all
1047 run_test test_fetch_empty_packfile
1048 run_test test_fetch_delete_branch
1049 run_test test_fetch_update_tag
1050 run_test test_fetch_reference
1051 run_test test_fetch_replace_symref
1052 run_test test_fetch_update_headref
1053 run_test test_fetch_headref_deleted_locally
1054 run_test test_fetch_gotconfig_remote_repo