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 -q -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 got ref -l -r $testroot/repo > $testroot/stdout.expected
150 cmp -s $testroot/stdout $testroot/stdout.expected
151 ret="$?"
152 if [ "$ret" != "0" ]; then
153 diff -u $testroot/stdout.expected $testroot/stdout
154 fi
155 test_done "$testroot" "$ret"
158 test_fetch_branch() {
159 local testroot=`test_init fetch_branch`
160 local testurl=ssh://127.0.0.1/$testroot
161 local commit_id=`git_show_head $testroot/repo`
163 got clone -q $testurl/repo $testroot/repo-clone
164 ret="$?"
165 if [ "$ret" != "0" ]; then
166 echo "got clone command failed unexpectedly" >&2
167 test_done "$testroot" "$ret"
168 return 1
169 fi
171 got branch -r $testroot/repo -c $commit_id foo
172 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
173 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
174 local tag_id=`got ref -r $testroot/repo -l \
175 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
177 echo "modified alpha on master" > $testroot/repo/alpha
178 git_commit $testroot/repo -m "modified alpha"
179 local commit_id2=`git_show_head $testroot/repo`
181 (cd $testroot/repo && git checkout -q foo)
182 echo "modified alpha on foo" > $testroot/repo/alpha
183 git_commit $testroot/repo -m "modified alpha"
184 local commit_id3=`git_show_head $testroot/repo`
186 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
187 ret="$?"
188 if [ "$ret" != "0" ]; then
189 echo "got fetch command failed unexpectedly" >&2
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 echo -n > $testroot/stdout.expected
196 cmp -s $testroot/stdout $testroot/stdout.expected
197 ret="$?"
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stdout.expected $testroot/stdout
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 got ref -l -r $testroot/repo-clone > $testroot/stdout
206 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
207 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
208 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
209 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
210 >> $testroot/stdout.expected
211 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
212 # refs/remotes/origin/master is umodified because it wasn't fetched
213 echo "refs/remotes/origin/master: $commit_id" \
214 >> $testroot/stdout.expected
215 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
216 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
218 cmp -s $testroot/stdout $testroot/stdout.expected
219 ret="$?"
220 if [ "$ret" != "0" ]; then
221 diff -u $testroot/stdout.expected $testroot/stdout
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 got fetch -q -r $testroot/repo-clone -b master > $testroot/stdout
227 ret="$?"
228 if [ "$ret" != "0" ]; then
229 echo "got fetch command failed unexpectedly" >&2
230 test_done "$testroot" "$ret"
231 return 1
232 fi
234 echo -n > $testroot/stdout.expected
236 cmp -s $testroot/stdout $testroot/stdout.expected
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 diff -u $testroot/stdout.expected $testroot/stdout
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 got ref -l -r $testroot/repo-clone > $testroot/stdout
246 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
247 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
248 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
249 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
250 >> $testroot/stdout.expected
251 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
252 echo "refs/remotes/origin/master: $commit_id2" \
253 >> $testroot/stdout.expected
254 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
255 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
257 cmp -s $testroot/stdout $testroot/stdout.expected
258 ret="$?"
259 if [ "$ret" != "0" ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 fi
262 test_done "$testroot" "$ret"
265 test_fetch_all() {
266 local testroot=`test_init fetch_all`
267 local testurl=ssh://127.0.0.1/$testroot
268 local commit_id=`git_show_head $testroot/repo`
270 got clone -q $testurl/repo $testroot/repo-clone
271 ret="$?"
272 if [ "$ret" != "0" ]; then
273 echo "got clone command failed unexpectedly" >&2
274 test_done "$testroot" "$ret"
275 return 1
276 fi
278 got branch -r $testroot/repo -c $commit_id foo
279 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
280 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
281 local tag_id=`got ref -r $testroot/repo -l \
282 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
284 got ref -l -r $testroot/repo-clone > $testroot/stdout
286 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
287 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
288 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
289 >> $testroot/stdout.expected
290 echo "refs/remotes/origin/master: $commit_id" \
291 >> $testroot/stdout.expected
292 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
294 cmp -s $testroot/stdout $testroot/stdout.expected
295 ret="$?"
296 if [ "$ret" != "0" ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 got fetch -q -a -r $testroot/repo-clone
303 ret="$?"
304 if [ "$ret" != "0" ]; then
305 echo "got fetch command failed unexpectedly" >&2
306 test_done "$testroot" "$ret"
307 return 1
308 fi
310 got ref -l -r $testroot/repo-clone > $testroot/stdout
312 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
313 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
314 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
315 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
316 >> $testroot/stdout.expected
317 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
318 echo "refs/remotes/origin/master: $commit_id" \
319 >> $testroot/stdout.expected
320 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
321 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
323 cmp -s $testroot/stdout $testroot/stdout.expected
324 ret="$?"
325 if [ "$ret" != "0" ]; then
326 diff -u $testroot/stdout.expected $testroot/stdout
327 fi
328 test_done "$testroot" "$ret"
331 test_fetch_empty_packfile() {
332 local testroot=`test_init fetch_empty_packfile`
333 local testurl=ssh://127.0.0.1/$testroot
334 local commit_id=`git_show_head $testroot/repo`
336 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
337 local tag_id=`got ref -r $testroot/repo -l \
338 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
340 got clone -q $testurl/repo $testroot/repo-clone
341 ret="$?"
342 if [ "$ret" != "0" ]; then
343 echo "got clone command failed unexpectedly" >&2
344 test_done "$testroot" "$ret"
345 return 1
346 fi
348 got branch -r $testroot/repo -c $commit_id foo
349 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
351 got ref -l -r $testroot/repo-clone > $testroot/stdout
353 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
354 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
355 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
356 >> $testroot/stdout.expected
357 echo "refs/remotes/origin/master: $commit_id" \
358 >> $testroot/stdout.expected
359 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
360 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
362 cmp -s $testroot/stdout $testroot/stdout.expected
363 ret="$?"
364 if [ "$ret" != "0" ]; then
365 diff -u $testroot/stdout.expected $testroot/stdout
366 test_done "$testroot" "$ret"
367 return 1
368 fi
370 got fetch -q -a -r $testroot/repo-clone
371 ret="$?"
372 if [ "$ret" != "0" ]; then
373 echo "got fetch command failed unexpectedly" >&2
374 test_done "$testroot" "$ret"
375 return 1
376 fi
378 got ref -l -r $testroot/repo-clone > $testroot/stdout
380 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
381 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
382 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
383 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
384 >> $testroot/stdout.expected
385 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
386 echo "refs/remotes/origin/master: $commit_id" \
387 >> $testroot/stdout.expected
388 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
389 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
391 cmp -s $testroot/stdout $testroot/stdout.expected
392 ret="$?"
393 if [ "$ret" != "0" ]; then
394 diff -u $testroot/stdout.expected $testroot/stdout
395 fi
396 test_done "$testroot" "$ret"
399 test_fetch_delete_branch() {
400 local testroot=`test_init fetch_delete_branch`
401 local testurl=ssh://127.0.0.1/$testroot
402 local commit_id=`git_show_head $testroot/repo`
405 got branch -r $testroot/repo -c $commit_id foo
406 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
407 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
408 local tag_id=`got ref -r $testroot/repo -l \
409 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
411 got clone -a -q $testurl/repo $testroot/repo-clone
412 ret="$?"
413 if [ "$ret" != "0" ]; then
414 echo "got clone command failed unexpectedly" >&2
415 test_done "$testroot" "$ret"
416 return 1
417 fi
419 got ref -l -r $testroot/repo-clone > $testroot/stdout
421 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
422 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
423 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
424 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
425 >> $testroot/stdout.expected
426 echo "refs/remotes/origin/foo: $commit_id" \
427 >> $testroot/stdout.expected
428 echo "refs/remotes/origin/master: $commit_id" \
429 >> $testroot/stdout.expected
430 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
431 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
433 cmp -s $testroot/stdout $testroot/stdout.expected
434 ret="$?"
435 if [ "$ret" != "0" ]; then
436 diff -u $testroot/stdout.expected $testroot/stdout
437 test_done "$testroot" "$ret"
438 return 1
439 fi
441 got branch -r $testroot/repo -d foo
443 got fetch -q -r $testroot/repo-clone
444 ret="$?"
445 if [ "$ret" != "0" ]; then
446 echo "got fetch command failed unexpectedly" >&2
447 test_done "$testroot" "$ret"
448 return 1
449 fi
451 got ref -l -r $testroot/repo-clone > $testroot/stdout
453 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
454 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
455 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
456 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
457 >> $testroot/stdout.expected
458 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
459 echo "refs/remotes/origin/master: $commit_id" \
460 >> $testroot/stdout.expected
461 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
462 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
464 cmp -s $testroot/stdout $testroot/stdout.expected
465 ret="$?"
466 if [ "$ret" != "0" ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
473 ret="$?"
474 if [ "$ret" != "0" ]; then
475 echo "got fetch command failed unexpectedly" >&2
476 test_done "$testroot" "$ret"
477 return 1
478 fi
480 echo -n > $testroot/stdout.expected
482 cmp -s $testroot/stdout $testroot/stdout.expected
483 ret="$?"
484 if [ "$ret" != "0" ]; then
485 diff -u $testroot/stdout.expected $testroot/stdout
486 test_done "$testroot" "$ret"
487 return 1
488 fi
490 got ref -l -r $testroot/repo-clone > $testroot/stdout
492 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
493 # refs/heads/foo is now deleted
494 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
495 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
496 >> $testroot/stdout.expected
497 # refs/remotes/origin/foo is now deleted
498 echo "refs/remotes/origin/master: $commit_id" \
499 >> $testroot/stdout.expected
500 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
501 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
503 cmp -s $testroot/stdout $testroot/stdout.expected
504 ret="$?"
505 if [ "$ret" != "0" ]; then
506 diff -u $testroot/stdout.expected $testroot/stdout
507 fi
508 test_done "$testroot" "$ret"
512 test_fetch_update_tag() {
513 local testroot=`test_init fetch_update_tag`
514 local testurl=ssh://127.0.0.1/$testroot
515 local commit_id=`git_show_head $testroot/repo`
518 got branch -r $testroot/repo -c $commit_id foo
519 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
520 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
521 local tag_id=`got ref -r $testroot/repo -l \
522 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
524 got clone -a -q $testurl/repo $testroot/repo-clone
525 ret="$?"
526 if [ "$ret" != "0" ]; then
527 echo "got clone command failed unexpectedly" >&2
528 test_done "$testroot" "$ret"
529 return 1
530 fi
532 echo "modified alpha on master" > $testroot/repo/alpha
533 git_commit $testroot/repo -m "modified alpha"
534 local commit_id2=`git_show_head $testroot/repo`
536 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
537 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
538 local tag_id2=`got ref -r $testroot/repo -l \
539 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
541 got ref -l -r $testroot/repo-clone > $testroot/stdout
543 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
544 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
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 echo "refs/remotes/origin/foo: $commit_id" \
549 >> $testroot/stdout.expected
550 echo "refs/remotes/origin/master: $commit_id" \
551 >> $testroot/stdout.expected
552 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
553 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
555 cmp -s $testroot/stdout $testroot/stdout.expected
556 ret="$?"
557 if [ "$ret" != "0" ]; then
558 diff -u $testroot/stdout.expected $testroot/stdout
559 test_done "$testroot" "$ret"
560 return 1
561 fi
563 got fetch -a -q -r $testroot/repo-clone
564 ret="$?"
565 if [ "$ret" != "0" ]; then
566 echo "got fetch command failed unexpectedly" >&2
567 test_done "$testroot" "$ret"
568 return 1
569 fi
571 got ref -l -r $testroot/repo-clone > $testroot/stdout
573 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
574 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
575 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
576 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
577 >> $testroot/stdout.expected
578 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
579 echo "refs/remotes/origin/master: $commit_id2" \
580 >> $testroot/stdout.expected
581 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
582 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
584 cmp -s $testroot/stdout $testroot/stdout.expected
585 ret="$?"
586 if [ "$ret" != "0" ]; then
587 diff -u $testroot/stdout.expected $testroot/stdout
588 test_done "$testroot" "$ret"
589 return 1
590 fi
592 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
593 tail -n 1 > $testroot/stdout
594 ret="$?"
595 if [ "$ret" != "0" ]; then
596 echo "got fetch command failed unexpectedly" >&2
597 test_done "$testroot" "$ret"
598 return 1
599 fi
601 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
602 > $testroot/stdout.expected
604 cmp -s $testroot/stdout $testroot/stdout.expected
605 ret="$?"
606 if [ "$ret" != "0" ]; then
607 diff -u $testroot/stdout.expected $testroot/stdout
608 test_done "$testroot" "$ret"
609 return 1
610 fi
612 got ref -l -r $testroot/repo-clone > $testroot/stdout
614 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
615 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
616 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
617 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
618 >> $testroot/stdout.expected
619 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
620 echo "refs/remotes/origin/master: $commit_id2" \
621 >> $testroot/stdout.expected
622 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
623 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
625 cmp -s $testroot/stdout $testroot/stdout.expected
626 ret="$?"
627 if [ "$ret" != "0" ]; then
628 diff -u $testroot/stdout.expected $testroot/stdout
629 test_done "$testroot" "$ret"
630 return 1
631 fi
633 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
634 ret="$?"
635 if [ "$ret" != "0" ]; then
636 echo "got fetch command failed unexpectedly" >&2
637 test_done "$testroot" "$ret"
638 return 1
639 fi
641 echo -n > $testroot/stdout.expected
643 cmp -s $testroot/stdout $testroot/stdout.expected
644 ret="$?"
645 if [ "$ret" != "0" ]; then
646 diff -u $testroot/stdout.expected $testroot/stdout
647 test_done "$testroot" "$ret"
648 return 1
649 fi
651 got ref -l -r $testroot/repo-clone > $testroot/stdout
653 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
654 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
655 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
656 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
657 >> $testroot/stdout.expected
658 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
659 echo "refs/remotes/origin/master: $commit_id2" \
660 >> $testroot/stdout.expected
661 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
662 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
664 cmp -s $testroot/stdout $testroot/stdout.expected
665 ret="$?"
666 if [ "$ret" != "0" ]; then
667 diff -u $testroot/stdout.expected $testroot/stdout
668 fi
669 test_done "$testroot" "$ret"
672 test_fetch_reference() {
673 local testroot=`test_init fetch_reference`
674 local testurl=ssh://127.0.0.1/$testroot
675 local commit_id=`git_show_head $testroot/repo`
677 got clone -q $testurl/repo $testroot/repo-clone
678 ret="$?"
679 if [ "$ret" != "0" ]; then
680 echo "got clone command failed unexpectedly" >&2
681 test_done "$testroot" "$ret"
682 return 1
683 fi
685 got branch -r $testroot/repo -c $commit_id foo
686 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
687 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
688 local tag_id=`got ref -r $testroot/repo -l \
689 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
691 echo "modified alpha on master" > $testroot/repo/alpha
692 git_commit $testroot/repo -m "modified alpha"
693 local commit_id2=`git_show_head $testroot/repo`
695 (cd $testroot/repo && git checkout -q foo)
696 echo "modified alpha on foo" > $testroot/repo/alpha
697 git_commit $testroot/repo -m "modified alpha"
698 local commit_id3=`git_show_head $testroot/repo`
699 (cd $testroot/repo && git checkout -q master)
701 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
702 > $testroot/stdout 2> $testroot/stderr
703 ret="$?"
704 if [ "$ret" = "0" ]; then
705 echo "got fetch command succeeded unexpectedly" >&2
706 test_done "$testroot" "1"
707 return 1
708 fi
710 echo -n > $testroot/stdout.expected
712 cmp -s $testroot/stdout $testroot/stdout.expected
713 ret="$?"
714 if [ "$ret" != "0" ]; then
715 diff -u $testroot/stdout.expected $testroot/stdout
716 test_done "$testroot" "$ret"
717 return 1
718 fi
720 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
721 > $testroot/stderr.expected
723 cmp -s $testroot/stderr $testroot/stderr.expected
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 diff -u $testroot/stderr.expected $testroot/stderr
727 test_done "$testroot" "$ret"
728 return 1
729 fi
731 got fetch -q -r $testroot/repo-clone -R refs/hoo
732 ret="$?"
733 if [ "$ret" != "0" ]; then
734 echo "got fetch command failed unexpectedly" >&2
735 test_done "$testroot" "$ret"
736 return 1
737 fi
739 got ref -l -r $testroot/repo-clone > $testroot/stdout
741 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
742 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
743 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
744 >> $testroot/stdout.expected
745 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
746 >> $testroot/stdout.expected
747 echo "refs/remotes/origin/master: $commit_id2" \
748 >> $testroot/stdout.expected
749 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
751 cmp -s $testroot/stdout $testroot/stdout.expected
752 ret="$?"
753 if [ "$ret" != "0" ]; then
754 diff -u $testroot/stdout.expected $testroot/stdout
755 fi
756 test_done "$testroot" "$ret"
760 test_fetch_replace_symref() {
761 local testroot=`test_init fetch_replace_symref`
762 local testurl=ssh://127.0.0.1/$testroot
763 local commit_id=`git_show_head $testroot/repo`
765 got clone -m -q $testurl/repo $testroot/repo-clone
766 ret="$?"
767 if [ "$ret" != "0" ]; then
768 echo "got clone command failed unexpectedly" >&2
769 test_done "$testroot" "$ret"
770 return 1
771 fi
773 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
774 got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
776 got ref -l -r $testroot/repo-clone > $testroot/stdout
778 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
779 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
780 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
782 cmp -s $testroot/stdout $testroot/stdout.expected
783 ret="$?"
784 if [ "$ret" != "0" ]; then
785 diff -u $testroot/stdout.expected $testroot/stdout
786 test_done "$testroot" "$ret"
787 return 1
788 fi
790 got fetch -r $testroot/repo-clone -R refs/hoo \
791 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
792 ret="$?"
793 if [ "$ret" != "0" ]; then
794 echo "got fetch command failed unexpectedly" >&2
795 test_done "$testroot" "$ret"
796 return 1
797 fi
799 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
800 > $testroot/stdout.expected
802 cmp -s $testroot/stdout $testroot/stdout.expected
803 ret="$?"
804 if [ "$ret" != "0" ]; then
805 diff -u $testroot/stdout.expected $testroot/stdout
806 test_done "$testroot" "$ret"
807 return 1
808 fi
810 got ref -l -r $testroot/repo-clone > $testroot/stdout
812 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
813 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
814 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
816 cmp -s $testroot/stdout $testroot/stdout.expected
817 ret="$?"
818 if [ "$ret" != "0" ]; then
819 diff -u $testroot/stdout.expected $testroot/stdout
820 fi
821 test_done "$testroot" "$ret"
825 test_fetch_update_headref() {
826 local testroot=`test_init fetch_update_headref`
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" != "0" ]; then
833 echo "got clone command failed unexpectedly" >&2
834 test_done "$testroot" "$ret"
835 return 1
836 fi
838 got ref -l -r $testroot/repo-clone > $testroot/stdout
840 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
841 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
842 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
843 >> $testroot/stdout.expected
844 echo "refs/remotes/origin/master: $commit_id" \
845 >> $testroot/stdout.expected
847 cmp -s $testroot/stdout $testroot/stdout.expected
848 ret="$?"
849 if [ "$ret" != "0" ]; then
850 diff -u $testroot/stdout.expected $testroot/stdout
851 test_done "$testroot" "$ret"
852 return 1
853 fi
855 got ref -r $testroot/repo -c refs/heads/master refs/heads/foo
856 got ref -r $testroot/repo -s refs/heads/foo HEAD
857 got ref -l -r $testroot/repo > $testroot/stdout
859 echo "HEAD: refs/heads/foo" > $testroot/stdout.expected
860 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
861 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
863 cmp -s $testroot/stdout $testroot/stdout.expected
864 ret="$?"
865 if [ "$ret" != "0" ]; then
866 diff -u $testroot/stdout.expected $testroot/stdout
867 test_done "$testroot" "$ret"
868 return 1
869 fi
871 got fetch -q -r $testroot/repo-clone
873 got ref -l -r $testroot/repo-clone > $testroot/stdout
875 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
876 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
877 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
878 >> $testroot/stdout.expected
879 echo "refs/remotes/origin/master: $commit_id" \
880 >> $testroot/stdout.expected
882 cmp -s $testroot/stdout $testroot/stdout.expected
883 ret="$?"
884 if [ "$ret" != "0" ]; then
885 diff -u $testroot/stdout.expected $testroot/stdout
886 test_done "$testroot" "$ret"
887 return 1
888 fi
890 got fetch -q -r $testroot/repo-clone -a
892 got ref -l -r $testroot/repo-clone > $testroot/stdout
894 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
895 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
896 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
897 echo "refs/remotes/origin/HEAD: refs/remotes/origin/foo" \
898 >> $testroot/stdout.expected
899 echo "refs/remotes/origin/foo: $commit_id" \
900 >> $testroot/stdout.expected
901 echo "refs/remotes/origin/master: $commit_id" \
902 >> $testroot/stdout.expected
904 cmp -s $testroot/stdout $testroot/stdout.expected
905 ret="$?"
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/stdout.expected $testroot/stdout
908 fi
909 test_done "$testroot" "$ret"
912 test_fetch_headref_deleted_locally() {
913 local testroot=`test_init fetch_headref_deleted_locally`
914 local testurl=ssh://127.0.0.1/$testroot
915 local commit_id=`git_show_head $testroot/repo`
917 got clone -q $testurl/repo $testroot/repo-clone
918 ret="$?"
919 if [ "$ret" != "0" ]; then
920 echo "got clone command failed unexpectedly" >&2
921 test_done "$testroot" "$ret"
922 return 1
923 fi
925 got ref -l -r $testroot/repo-clone > $testroot/stdout
927 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
928 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
929 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
930 >> $testroot/stdout.expected
931 echo "refs/remotes/origin/master: $commit_id" \
932 >> $testroot/stdout.expected
934 cmp -s $testroot/stdout $testroot/stdout.expected
935 ret="$?"
936 if [ "$ret" != "0" ]; then
937 diff -u $testroot/stdout.expected $testroot/stdout
938 test_done "$testroot" "$ret"
939 return 1
940 fi
942 got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD > /dev/null
944 got fetch -q -r $testroot/repo-clone
945 ret="$?"
946 if [ "$ret" != "0" ]; then
947 echo "got fetch command failed unexpectedly" >&2
948 test_done "$testroot" "$ret"
949 return 1
950 fi
951 got ref -l -r $testroot/repo-clone > $testroot/stdout
953 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
954 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
955 # refs/remotes/origin/HEAD has been restored:
956 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
957 >> $testroot/stdout.expected
958 echo "refs/remotes/origin/master: $commit_id" \
959 >> $testroot/stdout.expected
961 cmp -s $testroot/stdout $testroot/stdout.expected
962 ret="$?"
963 if [ "$ret" != "0" ]; then
964 diff -u $testroot/stdout.expected $testroot/stdout
965 fi
966 test_done "$testroot" "$ret"
969 test_fetch_gotconfig_remote_repo() {
970 local testroot=`test_init fetch_gotconfig_remote_repo`
971 local testurl=ssh://127.0.0.1/$testroot
972 local commit_id=`git_show_head $testroot/repo`
974 got branch -r $testroot/repo -c $commit_id foo
975 got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
976 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
978 got clone -q $testurl/repo $testroot/repo-clone
979 ret="$?"
980 if [ "$ret" != "0" ]; then
981 echo "got clone command failed unexpectedly" >&2
982 test_done "$testroot" "$ret"
983 return 1
984 fi
986 cat > $testroot/repo-clone/got.conf <<EOF
987 remote "foobar" {
988 protocol ssh
989 server 127.0.0.1
990 repository "$testroot/repo"
993 remote "barbaz" {
994 protocol ssh
995 server 127.0.0.1
996 repository "$testroot/does-not-exist"
998 EOF
999 echo "got: nonexistent: remote repository not found" \
1000 > $testroot/stderr.expected
1001 (cd $testroot/repo-clone && got fetch -q nonexistent \
1002 > $testroot/stdout 2> $testroot/stderr)
1003 ret="$?"
1004 if [ "$ret" = "0" ]; then
1005 echo "got fetch command succeeded unexpectedly" >&2
1006 diff -u $testroot/stderr.expected $testroot/stderr
1007 test_done "$testroot" "1"
1008 return 1
1011 (cd $testroot/repo-clone && got fetch -q -l foobar \
1012 > $testroot/stdout)
1013 ret="$?"
1014 if [ "$ret" != "0" ]; then
1015 echo "got fetch command failed unexpectedly" >&2
1016 test_done "$testroot" "$ret"
1017 return 1
1020 got ref -l -r $testroot/repo > $testroot/stdout.expected
1022 cmp -s $testroot/stdout $testroot/stdout.expected
1023 ret="$?"
1024 if [ "$ret" != "0" ]; then
1025 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1027 return 1
1030 got checkout $testroot/repo $testroot/wt > /dev/null
1032 cat > $testroot/wt/.got/got.conf <<EOF
1033 remote "barbaz" {
1034 protocol ssh
1035 server 127.0.0.1
1036 repository "$testroot/repo"
1038 EOF
1039 (cd $testroot/wt && got fetch -q -l barbaz > $testroot/stdout)
1040 ret="$?"
1041 if [ "$ret" != "0" ]; then
1042 echo "got fetch command failed unexpectedly" >&2
1043 test_done "$testroot" "$ret"
1044 return 1
1047 got ref -l -r $testroot/repo > $testroot/stdout.expected
1049 cmp -s $testroot/stdout $testroot/stdout.expected
1050 ret="$?"
1051 if [ "$ret" != "0" ]; then
1052 diff -u $testroot/stdout.expected $testroot/stdout
1053 test_done "$testroot" "$ret"
1054 return 1
1057 cat > $testroot/repo-clone/got.conf <<EOF
1058 remote "origin" {
1059 protocol ssh
1060 server 127.0.0.1
1061 repository "$testroot/repo"
1062 branch { "foo" }
1063 reference { "hoo/boo/zoo" }
1065 EOF
1066 (cd $testroot/repo-clone && got fetch -q > $testroot/stdout)
1068 local tag_id=`got ref -r $testroot/repo -l \
1069 | grep "^refs/tags/1.0" | tr -d ' ' | cut -d: -f2`
1070 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1071 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
1072 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1073 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1074 >> $testroot/stdout.expected
1075 echo "refs/remotes/origin/foo: $commit_id" \
1076 >> $testroot/stdout.expected
1077 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
1078 >> $testroot/stdout.expected
1079 echo "refs/remotes/origin/master: $commit_id" \
1080 >> $testroot/stdout.expected
1081 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
1083 got ref -l -r $testroot/repo-clone > $testroot/stdout
1085 cmp -s $testroot/stdout $testroot/stdout.expected
1086 ret="$?"
1087 if [ "$ret" != "0" ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1090 test_done "$testroot" "$ret"
1093 test_fetch_delete_remote_refs() {
1094 local testroot=`test_init fetch_basic`
1095 local testurl=ssh://127.0.0.1/$testroot
1096 local commit_id=`git_show_head $testroot/repo`
1098 got clone -q $testurl/repo $testroot/repo-clone
1099 ret="$?"
1100 if [ "$ret" != "0" ]; then
1101 echo "got clone command failed unexpectedly" >&2
1102 test_done "$testroot" "$ret"
1103 return 1
1106 got ref -l -r $testroot/repo-clone > $testroot/stdout
1107 if [ "$ret" != "0" ]; then
1108 echo "got ref command failed unexpectedly" >&2
1109 test_done "$testroot" "$ret"
1110 return 1
1113 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1114 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1115 echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \
1116 >> $testroot/stdout.expected
1117 echo "refs/remotes/origin/master: $commit_id" \
1118 >> $testroot/stdout.expected
1120 cmp -s $testroot/stdout $testroot/stdout.expected
1121 ret="$?"
1122 if [ "$ret" != "0" ]; then
1123 diff -u $testroot/stdout.expected $testroot/stdout
1124 test_done "$testroot" "$ret"
1125 return 1
1128 got fetch -q -r $testroot/repo-clone -X > $testroot/stdout \
1129 2> $testroot/stderr
1130 ret="$?"
1131 if [ "$ret" = "0" ]; then
1132 echo "got fetch command succeeded unexpectedly" >&2
1133 test_done "$testroot" "$ret"
1134 return 1
1137 echo "got: -X option requires a remote name" > $testroot/stderr.expected
1138 cmp -s $testroot/stderr $testroot/stderr.expected
1139 ret="$?"
1140 if [ "$ret" != "0" ]; then
1141 diff -u $testroot/stderr.expected $testroot/stderr
1142 test_done "$testroot" "$ret"
1143 return 1
1146 got fetch -q -r $testroot/repo-clone -X origin > $testroot/stdout \
1147 2> $testroot/stderr
1148 ret="$?"
1149 if [ "$ret" != "0" ]; then
1150 echo "got fetch command failed unexpectedly" >&2
1151 test_done "$testroot" "$ret"
1152 return 1
1155 echo -n "Deleted refs/remotes/origin/HEAD: " > $testroot/stdout.expected
1156 echo "refs/remotes/origin/master" >> $testroot/stdout.expected
1157 echo "Deleted refs/remotes/origin/master: $commit_id" \
1158 >> $testroot/stdout.expected
1160 cmp -s $testroot/stdout $testroot/stdout.expected
1161 ret="$?"
1162 if [ "$ret" != "0" ]; then
1163 diff -u $testroot/stdout.expected $testroot/stdout
1164 test_done "$testroot" "$ret"
1165 return 1
1168 got ref -l -r $testroot/repo-clone > $testroot/stdout
1169 if [ "$ret" != "0" ]; then
1170 echo "got ref command failed unexpectedly" >&2
1171 test_done "$testroot" "$ret"
1172 return 1
1175 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
1176 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
1178 cmp -s $testroot/stdout $testroot/stdout.expected
1179 ret="$?"
1180 if [ "$ret" != "0" ]; then
1181 diff -u $testroot/stdout.expected $testroot/stdout
1183 test_done "$testroot" "$ret"
1187 test_parseargs "$@"
1188 run_test test_fetch_basic
1189 run_test test_fetch_list
1190 run_test test_fetch_branch
1191 run_test test_fetch_all
1192 run_test test_fetch_empty_packfile
1193 run_test test_fetch_delete_branch
1194 run_test test_fetch_update_tag
1195 run_test test_fetch_reference
1196 run_test test_fetch_replace_symref
1197 run_test test_fetch_update_headref
1198 run_test test_fetch_headref_deleted_locally
1199 run_test test_fetch_gotconfig_remote_repo
1200 run_test test_fetch_delete_remote_refs