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 function 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/master: $commit_id2" \
110 >> $testroot/stdout.expected
112 cmp -s $testroot/stdout $testroot/stdout.expected
113 ret="$?"
114 if [ "$ret" != "0" ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 fi
117 test_done "$testroot" "$ret"
120 function test_fetch_list {
121 local testroot=`test_init fetch_list`
122 local testurl=ssh://127.0.0.1/$testroot
123 local commit_id=`git_show_head $testroot/repo`
125 got branch -r $testroot/repo -c $commit_id foo
126 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
127 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
129 got clone -q $testurl/repo $testroot/repo-clone
130 ret="$?"
131 if [ "$ret" != "0" ]; then
132 echo "got clone command failed unexpectedly" >&2
133 test_done "$testroot" "$ret"
134 return 1
135 fi
137 (cd $testroot/repo-clone && got fetch -l \
138 > $testroot/stdout 2>$testroot/stderr)
139 ret="$?"
140 if [ "$ret" != "0" ]; then
141 echo "got fetch command failed unexpectedly" >&2
142 test_done "$testroot" "$ret"
143 return 1
144 fi
146 echo "Connected to \"origin\" 127.0.0.1" > $testroot/stdout.expected
147 got ref -l -r $testroot/repo >> $testroot/stdout.expected
149 cmp -s $testroot/stdout $testroot/stdout.expected
150 ret="$?"
151 if [ "$ret" != "0" ]; then
152 diff -u $testroot/stdout.expected $testroot/stdout
153 fi
154 test_done "$testroot" "$ret"
157 function test_fetch_branch {
158 local testroot=`test_init fetch_branch`
159 local testurl=ssh://127.0.0.1/$testroot
160 local commit_id=`git_show_head $testroot/repo`
162 got clone -q $testurl/repo $testroot/repo-clone
163 ret="$?"
164 if [ "$ret" != "0" ]; then
165 echo "got clone command failed unexpectedly" >&2
166 test_done "$testroot" "$ret"
167 return 1
168 fi
170 got branch -r $testroot/repo -c $commit_id foo
171 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
172 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
173 local tag_id=`got ref -r $testroot/repo -l \
174 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
176 echo "modified alpha on master" > $testroot/repo/alpha
177 git_commit $testroot/repo -m "modified alpha"
178 local commit_id2=`git_show_head $testroot/repo`
180 (cd $testroot/repo && git checkout -q foo)
181 echo "modified alpha on foo" > $testroot/repo/alpha
182 git_commit $testroot/repo -m "modified alpha"
183 local commit_id3=`git_show_head $testroot/repo`
185 got fetch -q -r $testroot/repo-clone -b foo > $testroot/stdout
186 ret="$?"
187 if [ "$ret" != "0" ]; then
188 echo "got fetch command failed unexpectedly" >&2
189 test_done "$testroot" "$ret"
190 return 1
191 fi
193 echo -n > $testroot/stdout.expected
195 cmp -s $testroot/stdout $testroot/stdout.expected
196 ret="$?"
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
200 return 1
201 fi
203 got ref -l -r $testroot/repo-clone > $testroot/stdout
205 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
206 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
207 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
208 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
209 # refs/remotes/origin/master is umodified because it wasn't fetched
210 echo "refs/remotes/origin/master: $commit_id" \
211 >> $testroot/stdout.expected
212 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
213 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
215 cmp -s $testroot/stdout $testroot/stdout.expected
216 ret="$?"
217 if [ "$ret" != "0" ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 test_done "$testroot" "$ret"
220 return 1
221 fi
223 got fetch -q -r $testroot/repo-clone -b master > $testroot/stdout
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 echo "got fetch command failed unexpectedly" >&2
227 test_done "$testroot" "$ret"
228 return 1
229 fi
231 echo -n > $testroot/stdout.expected
233 cmp -s $testroot/stdout $testroot/stdout.expected
234 ret="$?"
235 if [ "$ret" != "0" ]; then
236 diff -u $testroot/stdout.expected $testroot/stdout
237 test_done "$testroot" "$ret"
238 return 1
239 fi
241 got ref -l -r $testroot/repo-clone > $testroot/stdout
243 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
244 echo "refs/heads/foo: $commit_id3" >> $testroot/stdout.expected
245 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
246 echo "refs/remotes/origin/foo: $commit_id3" >> $testroot/stdout.expected
247 echo "refs/remotes/origin/master: $commit_id2" \
248 >> $testroot/stdout.expected
249 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
250 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
252 cmp -s $testroot/stdout $testroot/stdout.expected
253 ret="$?"
254 if [ "$ret" != "0" ]; then
255 diff -u $testroot/stdout.expected $testroot/stdout
256 fi
257 test_done "$testroot" "$ret"
260 function test_fetch_all {
261 local testroot=`test_init fetch_all`
262 local testurl=ssh://127.0.0.1/$testroot
263 local commit_id=`git_show_head $testroot/repo`
265 got clone -q $testurl/repo $testroot/repo-clone
266 ret="$?"
267 if [ "$ret" != "0" ]; then
268 echo "got clone command failed unexpectedly" >&2
269 test_done "$testroot" "$ret"
270 return 1
271 fi
273 got branch -r $testroot/repo -c $commit_id foo
274 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
275 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
276 local tag_id=`got ref -r $testroot/repo -l \
277 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
279 got ref -l -r $testroot/repo-clone > $testroot/stdout
281 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
282 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
283 echo "refs/remotes/origin/master: $commit_id" \
284 >> $testroot/stdout.expected
285 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
287 cmp -s $testroot/stdout $testroot/stdout.expected
288 ret="$?"
289 if [ "$ret" != "0" ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 test_done "$testroot" "$ret"
292 return 1
293 fi
295 got fetch -q -a -r $testroot/repo-clone
296 ret="$?"
297 if [ "$ret" != "0" ]; then
298 echo "got fetch command failed unexpectedly" >&2
299 test_done "$testroot" "$ret"
300 return 1
301 fi
303 got ref -l -r $testroot/repo-clone > $testroot/stdout
305 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
306 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
307 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
308 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
309 echo "refs/remotes/origin/master: $commit_id" \
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" != "0" ]; then
317 diff -u $testroot/stdout.expected $testroot/stdout
318 fi
319 test_done "$testroot" "$ret"
322 function test_fetch_empty_packfile {
323 local testroot=`test_init fetch_empty_packfile`
324 local testurl=ssh://127.0.0.1/$testroot
325 local commit_id=`git_show_head $testroot/repo`
327 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
328 local tag_id=`got ref -r $testroot/repo -l \
329 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
331 got clone -q $testurl/repo $testroot/repo-clone
332 ret="$?"
333 if [ "$ret" != "0" ]; then
334 echo "got clone command failed unexpectedly" >&2
335 test_done "$testroot" "$ret"
336 return 1
337 fi
339 got branch -r $testroot/repo -c $commit_id foo
340 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
342 got ref -l -r $testroot/repo-clone > $testroot/stdout
344 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
345 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
346 echo "refs/remotes/origin/master: $commit_id" \
347 >> $testroot/stdout.expected
348 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
349 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
351 cmp -s $testroot/stdout $testroot/stdout.expected
352 ret="$?"
353 if [ "$ret" != "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" != "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/foo: $commit_id" >> $testroot/stdout.expected
373 echo "refs/remotes/origin/master: $commit_id" \
374 >> $testroot/stdout.expected
375 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
376 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
378 cmp -s $testroot/stdout $testroot/stdout.expected
379 ret="$?"
380 if [ "$ret" != "0" ]; then
381 diff -u $testroot/stdout.expected $testroot/stdout
382 fi
383 test_done "$testroot" "$ret"
386 function test_fetch_delete_branch {
387 local testroot=`test_init fetch_delete_branch`
388 local testurl=ssh://127.0.0.1/$testroot
389 local commit_id=`git_show_head $testroot/repo`
392 got branch -r $testroot/repo -c $commit_id foo
393 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
394 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
395 local tag_id=`got ref -r $testroot/repo -l \
396 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
398 got clone -a -q $testurl/repo $testroot/repo-clone
399 ret="$?"
400 if [ "$ret" != "0" ]; then
401 echo "got clone command failed unexpectedly" >&2
402 test_done "$testroot" "$ret"
403 return 1
404 fi
406 got ref -l -r $testroot/repo-clone > $testroot/stdout
408 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
409 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
410 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
411 echo "refs/remotes/origin/foo: $commit_id" \
412 >> $testroot/stdout.expected
413 echo "refs/remotes/origin/master: $commit_id" \
414 >> $testroot/stdout.expected
415 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
416 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
418 cmp -s $testroot/stdout $testroot/stdout.expected
419 ret="$?"
420 if [ "$ret" != "0" ]; then
421 diff -u $testroot/stdout.expected $testroot/stdout
422 test_done "$testroot" "$ret"
423 return 1
424 fi
426 got branch -r $testroot/repo -d foo
428 got fetch -q -r $testroot/repo-clone
429 ret="$?"
430 if [ "$ret" != "0" ]; then
431 echo "got fetch command failed unexpectedly" >&2
432 test_done "$testroot" "$ret"
433 return 1
434 fi
436 got ref -l -r $testroot/repo-clone > $testroot/stdout
438 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
439 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
440 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
441 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
442 echo "refs/remotes/origin/master: $commit_id" \
443 >> $testroot/stdout.expected
444 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
445 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
447 cmp -s $testroot/stdout $testroot/stdout.expected
448 ret="$?"
449 if [ "$ret" != "0" ]; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" "$ret"
452 return 1
453 fi
455 got fetch -d -q -r $testroot/repo-clone > $testroot/stdout
456 ret="$?"
457 if [ "$ret" != "0" ]; then
458 echo "got fetch command failed unexpectedly" >&2
459 test_done "$testroot" "$ret"
460 return 1
461 fi
463 echo -n > $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 ref -l -r $testroot/repo-clone > $testroot/stdout
475 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
476 # refs/heads/foo is now deleted
477 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
478 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
479 echo "refs/remotes/origin/master: $commit_id" \
480 >> $testroot/stdout.expected
481 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
482 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
484 cmp -s $testroot/stdout $testroot/stdout.expected
485 ret="$?"
486 if [ "$ret" != "0" ]; then
487 diff -u $testroot/stdout.expected $testroot/stdout
488 fi
489 test_done "$testroot" "$ret"
493 function test_fetch_update_tag {
494 local testroot=`test_init fetch_update_tag`
495 local testurl=ssh://127.0.0.1/$testroot
496 local commit_id=`git_show_head $testroot/repo`
499 got branch -r $testroot/repo -c $commit_id foo
500 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
501 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
502 local tag_id=`got ref -r $testroot/repo -l \
503 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
505 got clone -a -q $testurl/repo $testroot/repo-clone
506 ret="$?"
507 if [ "$ret" != "0" ]; then
508 echo "got clone command failed unexpectedly" >&2
509 test_done "$testroot" "$ret"
510 return 1
511 fi
513 echo "modified alpha on master" > $testroot/repo/alpha
514 git_commit $testroot/repo -m "modified alpha"
515 local commit_id2=`git_show_head $testroot/repo`
517 got ref -r $testroot/repo -d "refs/tags/1.0" >/dev/null
518 got tag -r $testroot/repo -c $commit_id2 -m tag "1.0" >/dev/null
519 local tag_id2=`got ref -r $testroot/repo -l \
520 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
522 got ref -l -r $testroot/repo-clone > $testroot/stdout
524 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
525 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
526 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
527 echo "refs/remotes/origin/foo: $commit_id" \
528 >> $testroot/stdout.expected
529 echo "refs/remotes/origin/master: $commit_id" \
530 >> $testroot/stdout.expected
531 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
532 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
534 cmp -s $testroot/stdout $testroot/stdout.expected
535 ret="$?"
536 if [ "$ret" != "0" ]; then
537 diff -u $testroot/stdout.expected $testroot/stdout
538 test_done "$testroot" "$ret"
539 return 1
540 fi
542 got fetch -q -r $testroot/repo-clone
543 ret="$?"
544 if [ "$ret" != "0" ]; then
545 echo "got fetch command failed unexpectedly" >&2
546 test_done "$testroot" "$ret"
547 return 1
548 fi
550 got ref -l -r $testroot/repo-clone > $testroot/stdout
552 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
553 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
554 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
555 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
556 echo "refs/remotes/origin/master: $commit_id2" \
557 >> $testroot/stdout.expected
558 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
559 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
561 cmp -s $testroot/stdout $testroot/stdout.expected
562 ret="$?"
563 if [ "$ret" != "0" ]; then
564 diff -u $testroot/stdout.expected $testroot/stdout
565 test_done "$testroot" "$ret"
566 return 1
567 fi
569 got fetch -r $testroot/repo-clone 2> $testroot/stderr | \
570 tail -n 1 > $testroot/stdout
571 ret="$?"
572 if [ "$ret" != "0" ]; then
573 echo "got fetch command failed unexpectedly" >&2
574 test_done "$testroot" "$ret"
575 return 1
576 fi
578 echo "Rejecting update of existing tag refs/tags/1.0: $tag_id2" \
579 > $testroot/stdout.expected
581 cmp -s $testroot/stdout $testroot/stdout.expected
582 ret="$?"
583 if [ "$ret" != "0" ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 test_done "$testroot" "$ret"
586 return 1
587 fi
589 got ref -l -r $testroot/repo-clone > $testroot/stdout
591 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
592 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
593 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
594 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
595 echo "refs/remotes/origin/master: $commit_id2" \
596 >> $testroot/stdout.expected
597 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
598 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
600 cmp -s $testroot/stdout $testroot/stdout.expected
601 ret="$?"
602 if [ "$ret" != "0" ]; then
603 diff -u $testroot/stdout.expected $testroot/stdout
604 test_done "$testroot" "$ret"
605 return 1
606 fi
608 got fetch -q -t -r $testroot/repo-clone > $testroot/stdout
609 ret="$?"
610 if [ "$ret" != "0" ]; then
611 echo "got fetch command failed unexpectedly" >&2
612 test_done "$testroot" "$ret"
613 return 1
614 fi
616 echo -n > $testroot/stdout.expected
618 cmp -s $testroot/stdout $testroot/stdout.expected
619 ret="$?"
620 if [ "$ret" != "0" ]; then
621 diff -u $testroot/stdout.expected $testroot/stdout
622 test_done "$testroot" "$ret"
623 return 1
624 fi
626 got ref -l -r $testroot/repo-clone > $testroot/stdout
628 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
629 echo "refs/heads/foo: $commit_id" >> $testroot/stdout.expected
630 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
631 echo "refs/remotes/origin/foo: $commit_id" >> $testroot/stdout.expected
632 echo "refs/remotes/origin/master: $commit_id2" \
633 >> $testroot/stdout.expected
634 # refs/hoo/boo/zoo is missing because it is outside of refs/heads
635 echo "refs/tags/1.0: $tag_id2" >> $testroot/stdout.expected
637 cmp -s $testroot/stdout $testroot/stdout.expected
638 ret="$?"
639 if [ "$ret" != "0" ]; then
640 diff -u $testroot/stdout.expected $testroot/stdout
641 fi
642 test_done "$testroot" "$ret"
645 function test_fetch_reference {
646 local testroot=`test_init fetch_reference`
647 local testurl=ssh://127.0.0.1/$testroot
648 local commit_id=`git_show_head $testroot/repo`
650 got clone -q $testurl/repo $testroot/repo-clone
651 ret="$?"
652 if [ "$ret" != "0" ]; then
653 echo "got clone command failed unexpectedly" >&2
654 test_done "$testroot" "$ret"
655 return 1
656 fi
658 got branch -r $testroot/repo -c $commit_id foo
659 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
660 got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
661 local tag_id=`got ref -r $testroot/repo -l \
662 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
664 echo "modified alpha on master" > $testroot/repo/alpha
665 git_commit $testroot/repo -m "modified alpha"
666 local commit_id2=`git_show_head $testroot/repo`
668 (cd $testroot/repo && git checkout -q foo)
669 echo "modified alpha on foo" > $testroot/repo/alpha
670 git_commit $testroot/repo -m "modified alpha"
671 local commit_id3=`git_show_head $testroot/repo`
672 (cd $testroot/repo && git checkout -q master)
674 got fetch -q -r $testroot/repo-clone -R refs/remotes/origin/main \
675 > $testroot/stdout 2> $testroot/stderr
676 ret="$?"
677 if [ "$ret" == "0" ]; then
678 echo "got fetch command succeeded unexpectedly" >&2
679 test_done "$testroot" "1"
680 return 1
681 fi
683 echo -n > $testroot/stdout.expected
685 cmp -s $testroot/stdout $testroot/stdout.expected
686 ret="$?"
687 if [ "$ret" != "0" ]; then
688 diff -u $testroot/stdout.expected $testroot/stdout
689 test_done "$testroot" "$ret"
690 return 1
691 fi
693 echo "got: refs/remotes/origin/main: reference cannot be fetched" \
694 > $testroot/stderr.expected
696 cmp -s $testroot/stderr $testroot/stderr.expected
697 ret="$?"
698 if [ "$ret" != "0" ]; then
699 diff -u $testroot/stderr.expected $testroot/stderr
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 got fetch -q -r $testroot/repo-clone -R refs/hoo
705 ret="$?"
706 if [ "$ret" != "0" ]; then
707 echo "got fetch command failed unexpectedly" >&2
708 test_done "$testroot" "$ret"
709 return 1
710 fi
712 got ref -l -r $testroot/repo-clone > $testroot/stdout
714 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
715 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
716 echo "refs/remotes/origin/hoo/boo/zoo: $commit_id" \
717 >> $testroot/stdout.expected
718 echo "refs/remotes/origin/master: $commit_id2" \
719 >> $testroot/stdout.expected
720 echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
722 cmp -s $testroot/stdout $testroot/stdout.expected
723 ret="$?"
724 if [ "$ret" != "0" ]; then
725 diff -u $testroot/stdout.expected $testroot/stdout
726 fi
727 test_done "$testroot" "$ret"
731 function test_fetch_replace_symref {
732 local testroot=`test_init fetch_replace_symref`
733 local testurl=ssh://127.0.0.1/$testroot
734 local commit_id=`git_show_head $testroot/repo`
736 got clone -m -q $testurl/repo $testroot/repo-clone
737 ret="$?"
738 if [ "$ret" != "0" ]; then
739 echo "got clone command failed unexpectedly" >&2
740 test_done "$testroot" "$ret"
741 return 1
742 fi
744 got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
745 got ref -r $testroot/repo-clone -s refs/hoo/boo/zoo refs/heads/master
747 got ref -l -r $testroot/repo-clone > $testroot/stdout
749 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
750 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
751 echo "refs/hoo/boo/zoo: refs/heads/master" >> $testroot/stdout.expected
753 cmp -s $testroot/stdout $testroot/stdout.expected
754 ret="$?"
755 if [ "$ret" != "0" ]; then
756 diff -u $testroot/stdout.expected $testroot/stdout
757 test_done "$testroot" "$ret"
758 return 1
759 fi
761 got fetch -r $testroot/repo-clone -R refs/hoo \
762 2> $testroot/stderr | grep ^Replacing > $testroot/stdout
763 ret="$?"
764 if [ "$ret" != "0" ]; then
765 echo "got fetch command failed unexpectedly" >&2
766 test_done "$testroot" "$ret"
767 return 1
768 fi
770 echo "Replacing reference refs/hoo/boo/zoo: refs/heads/master" \
771 > $testroot/stdout.expected
773 cmp -s $testroot/stdout $testroot/stdout.expected
774 ret="$?"
775 if [ "$ret" != "0" ]; then
776 diff -u $testroot/stdout.expected $testroot/stdout
777 test_done "$testroot" "$ret"
778 return 1
779 fi
781 got ref -l -r $testroot/repo-clone > $testroot/stdout
783 echo "HEAD: refs/heads/master" > $testroot/stdout.expected
784 echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
785 echo "refs/hoo/boo/zoo: $commit_id" >> $testroot/stdout.expected
787 cmp -s $testroot/stdout $testroot/stdout.expected
788 ret="$?"
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stdout.expected $testroot/stdout
791 fi
792 test_done "$testroot" "$ret"
796 run_test test_fetch_basic
797 run_test test_fetch_list
798 run_test test_fetch_branch
799 run_test test_fetch_all
800 run_test test_fetch_empty_packfile
801 run_test test_fetch_delete_branch
802 run_test test_fetch_update_tag
803 run_test test_fetch_reference
804 run_test test_fetch_replace_symref