Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 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_checkout_basic {
20 local testroot=`test_init checkout_basic`
22 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
23 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
24 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
25 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
26 echo "Now shut up and hack" >> $testroot/stdout.expected
28 got checkout $testroot/repo $testroot/wt > $testroot/stdout
29 ret="$?"
30 if [ "$ret" != "0" ]; then
31 test_done "$testroot" "$ret"
32 return 1
33 fi
35 cmp -s $testroot/stdout.expected $testroot/stdout
36 ret="$?"
37 if [ "$ret" != "0" ]; then
38 diff -u $testroot/stdout.expected $testroot/stdout
39 test_done "$testroot" "$ret"
40 return 1
41 fi
43 echo "alpha" > $testroot/content.expected
44 echo "beta" >> $testroot/content.expected
45 echo "zeta" >> $testroot/content.expected
46 echo "delta" >> $testroot/content.expected
47 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
48 $testroot/wt/gamma/delta > $testroot/content
50 cmp -s $testroot/content.expected $testroot/content
51 ret="$?"
52 if [ "$ret" != "0" ]; then
53 diff -u $testroot/content.expected $testroot/content
54 fi
55 test_done "$testroot" "$ret"
56 }
58 function test_checkout_dir_exists {
59 local testroot=`test_init checkout_dir_exists`
61 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
62 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
63 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
64 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
65 echo "Now shut up and hack" >> $testroot/stdout.expected
67 mkdir $testroot/wt
69 got checkout $testroot/repo $testroot/wt > $testroot/stdout
70 ret="$?"
71 if [ "$ret" != "0" ]; then
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 cmp -s $testroot/stdout.expected $testroot/stdout
77 ret="$?"
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 echo "alpha" > $testroot/content.expected
85 echo "beta" >> $testroot/content.expected
86 echo "zeta" >> $testroot/content.expected
87 echo "delta" >> $testroot/content.expected
88 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
89 $testroot/wt/gamma/delta > $testroot/content
91 cmp -s $testroot/content.expected $testroot/content
92 ret="$?"
93 if [ "$ret" != "0" ]; then
94 diff -u $testroot/content.expected $testroot/content
95 fi
96 test_done "$testroot" "$ret"
97 }
99 function test_checkout_dir_not_empty {
100 local testroot=`test_init checkout_dir_not_empty`
102 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
103 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
104 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
105 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
106 echo "Now shut up and hack" >> $testroot/stdout.expected
108 mkdir $testroot/wt
109 touch $testroot/wt/foo
111 got checkout $testroot/repo $testroot/wt > $testroot/stdout \
112 2> $testroot/stderr
113 ret="$?"
114 if [ "$ret" == "0" ]; then
115 echo "checkout succeeded unexpectedly" >&2
116 test_done "$testroot" "1"
117 return 1
118 fi
120 echo "got: $testroot/wt: directory exists and is not empty" \
121 > $testroot/stderr.expected
122 cmp -s $testroot/stderr.expected $testroot/stderr
123 ret="$?"
124 if [ "$ret" != "0" ]; then
125 diff -u $testroot/stderr.expected $testroot/stderr
126 test_done "$testroot" "$ret"
127 return 1
128 fi
130 echo -n > $testroot/stdout.expected
131 cmp -s $testroot/stdout.expected $testroot/stdout
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stdout.expected $testroot/stdout
135 fi
136 test_done "$testroot" "$ret"
140 function test_checkout_sets_xbit {
141 local testroot=`test_init checkout_sets_xbit 1`
143 touch $testroot/repo/xfile
144 chmod +x $testroot/repo/xfile
145 (cd $testroot/repo && git add .)
146 git_commit $testroot/repo -m "adding executable file"
148 echo "A $testroot/wt/xfile" > $testroot/stdout.expected
149 echo "Now shut up and hack" >> $testroot/stdout.expected
151 got checkout $testroot/repo $testroot/wt > $testroot/stdout
152 ret="$?"
153 if [ "$ret" != "0" ]; then
154 test_done "$testroot" "$ret"
155 return 1
156 fi
158 cmp -s $testroot/stdout.expected $testroot/stdout
159 ret="$?"
160 if [ "$ret" != "0" ]; then
161 diff -u $testroot/stdout.expected $testroot/stdout
162 test_done "$testroot" "$ret"
163 return 1
164 fi
166 ls -l $testroot/wt/xfile | grep -q '^-rwx'
167 ret="$?"
168 if [ "$ret" != "0" ]; then
169 echo "file is not executable" >&2
170 ls -l $testroot/wt/xfile >&2
171 fi
172 test_done "$testroot" "$ret"
175 function test_checkout_commit_from_wrong_branch {
176 local testroot=`test_init checkout_commit_from_wrong_branch`
178 (cd $testroot/repo && git checkout -q -b newbranch)
179 echo "modified alpha on new branch" > $testroot/repo/alpha
180 git_commit $testroot/repo -m "modified alpha on new branch"
182 local head_rev=`git_show_head $testroot/repo`
183 got checkout -b master -c $head_rev $testroot/repo $testroot/wt \
184 > $testroot/stdout 2> $testroot/stderr
185 ret="$?"
186 if [ "$ret" == "0" ]; then
187 test_done "$testroot" "1"
188 return 1
189 fi
191 echo -n "" > $testroot/stdout.expected
192 cmp -s $testroot/stdout.expected $testroot/stdout
193 ret="$?"
194 if [ "$ret" != "0" ]; then
195 diff -u $testroot/stdout.expected $testroot/stdout
196 test_done "$testroot" "$ret"
197 return 1
198 fi
200 echo -n "got: target commit is not contained in branch 'master'; " \
201 > $testroot/stderr.expected
202 echo -n "the branch to use must be specified with -b; if necessary " \
203 >> $testroot/stderr.expected
204 echo -n "a new branch can be created for this commit with "\
205 >> $testroot/stderr.expected
206 echo "'got branch -c $head_rev BRANCH_NAME'" \
207 >> $testroot/stderr.expected
208 cmp -s $testroot/stderr.expected $testroot/stderr
209 ret="$?"
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/stderr.expected $testroot/stderr
212 test_done "$testroot" "$ret"
213 return 1
214 fi
216 test_done "$testroot" "$ret"
219 function test_checkout_tag {
220 local testroot=`test_init checkout_tag`
221 local tag="1.0.0"
223 (cd $testroot/repo && git tag -a -m "test" $tag)
225 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
226 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
227 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
228 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
229 echo "Now shut up and hack" >> $testroot/stdout.expected
231 got checkout -c $tag $testroot/repo $testroot/wt > $testroot/stdout
232 ret="$?"
233 if [ "$ret" != "0" ]; then
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret="$?"
240 if [ "$ret" != "0" ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 echo "alpha" > $testroot/content.expected
247 echo "beta" >> $testroot/content.expected
248 echo "zeta" >> $testroot/content.expected
249 echo "delta" >> $testroot/content.expected
250 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
251 $testroot/wt/gamma/delta > $testroot/content
253 cmp -s $testroot/content.expected $testroot/content
254 ret="$?"
255 if [ "$ret" != "0" ]; then
256 diff -u $testroot/content.expected $testroot/content
257 fi
258 test_done "$testroot" "$ret"
261 function test_checkout_ignores_submodules {
262 local testroot=`test_init checkout_ignores_submodules`
264 make_single_file_repo $testroot/repo2 foo
266 (cd $testroot/repo && git submodule -q add ../repo2)
267 (cd $testroot/repo && git commit -q -m 'adding submodule')
269 echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
270 echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
271 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
272 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
273 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
274 echo "Now shut up and hack" >> $testroot/stdout.expected
276 got checkout $testroot/repo $testroot/wt > $testroot/stdout
277 ret="$?"
278 if [ "$ret" != "0" ]; then
279 test_done "$testroot" "$ret"
280 return 1
281 fi
283 cmp -s $testroot/stdout.expected $testroot/stdout
284 ret="$?"
285 if [ "$ret" != "0" ]; then
286 diff -u $testroot/stdout.expected $testroot/stdout
287 test_done "$testroot" "$ret"
288 return 1
289 fi
291 echo "alpha" > $testroot/content.expected
292 echo "beta" >> $testroot/content.expected
293 echo "zeta" >> $testroot/content.expected
294 echo "delta" >> $testroot/content.expected
295 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
296 $testroot/wt/gamma/delta > $testroot/content
298 cmp -s $testroot/content.expected $testroot/content
299 ret="$?"
300 if [ "$ret" != "0" ]; then
301 diff -u $testroot/content.expected $testroot/content
302 fi
303 test_done "$testroot" "$ret"
306 function test_checkout_read_only {
307 local testroot=`test_init checkout_read_only`
309 # Make the repostiory read-only
310 chmod -R a-w $testroot/repo
312 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
313 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
314 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
315 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
316 echo "Now shut up and hack" >> $testroot/stdout.expected
318 got checkout $testroot/repo $testroot/wt \
319 > $testroot/stdout 2> $testroot/stderr
320 ret="$?"
321 if [ "$ret" != "0" ]; then
322 test_done "$testroot" "$ret"
323 return 1
324 fi
326 cmp -s $testroot/stdout.expected $testroot/stdout
327 ret="$?"
328 if [ "$ret" != "0" ]; then
329 diff -u $testroot/stdout.expected $testroot/stdout
330 test_done "$testroot" "$ret"
331 return 1
332 fi
334 echo -n "got: warning: could not create a reference " \
335 > $testroot/stderr.expected
336 echo -n "to the work tree's base commit; the commit could " \
337 >> $testroot/stderr.expected
338 echo -n "be garbage-collected by Git; making the repository " \
339 >> $testroot/stderr.expected
340 echo "writable and running 'got update' will prevent this" \
341 >> $testroot/stderr.expected
342 cmp -s $testroot/stderr.expected $testroot/stderr
343 ret="$?"
344 if [ "$ret" != "0" ]; then
345 diff -u $testroot/stderr.expected $testroot/stderr
346 test_done "$testroot" "$ret"
347 return 1
348 fi
350 echo "alpha" > $testroot/content.expected
351 echo "beta" >> $testroot/content.expected
352 echo "zeta" >> $testroot/content.expected
353 echo "delta" >> $testroot/content.expected
354 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
355 $testroot/wt/gamma/delta > $testroot/content
357 cmp -s $testroot/content.expected $testroot/content
358 ret="$?"
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/content.expected $testroot/content
361 fi
362 chmod -R u+w $testroot/repo # make repo cleanup work
363 test_done "$testroot" "$ret"
366 function test_checkout_into_nonempty_dir {
367 local testroot=`test_init checkout_into_nonempty_dir`
369 mkdir -p $testroot/wt
370 make_test_tree $testroot/wt
372 got checkout $testroot/repo $testroot/wt > $testroot/stdout \
373 2> $testroot/stderr
374 ret="$?"
375 if [ "$ret" == "0" ]; then
376 echo "checkout succeeded unexpectedly" >&2
377 test_done "$testroot" "1"
378 return 1
379 fi
381 echo -n > $testroot/stdout.expected
382 cmp -s $testroot/stdout.expected $testroot/stdout
383 ret="$?"
384 if [ "$ret" != "0" ]; then
385 diff -u $testroot/stdout.expected $testroot/stdout
386 test_done "$testroot" "$ret"
387 return 1
388 fi
390 echo "got: $testroot/wt: directory exists and is not empty" \
391 > $testroot/stderr.expected
392 cmp -s $testroot/stderr.expected $testroot/stderr
393 ret="$?"
394 if [ "$ret" != "0" ]; then
395 diff -u $testroot/stderr.expected $testroot/stderr
396 test_done "$testroot" "$ret"
397 return 1
398 fi
400 echo "? $testroot/wt/alpha" > $testroot/stdout.expected
401 echo "? $testroot/wt/beta" >> $testroot/stdout.expected
402 echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
403 echo "? $testroot/wt/gamma/delta" >> $testroot/stdout.expected
404 echo "Now shut up and hack" >> $testroot/stdout.expected
406 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
407 ret="$?"
408 if [ "$ret" != "0" ]; then
409 test_done "$testroot" "$ret"
410 return 1
411 fi
413 cmp -s $testroot/stdout.expected $testroot/stdout
414 ret="$?"
415 if [ "$ret" != "0" ]; then
416 diff -u $testroot/stdout.expected $testroot/stdout
417 test_done "$testroot" "$ret"
418 return 1
419 fi
421 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
422 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
423 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
424 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
425 echo "Now shut up and hack" >> $testroot/stdout.expected
427 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
428 ret="$?"
429 if [ "$ret" != "0" ]; then
430 test_done "$testroot" "$ret"
431 return 1
432 fi
434 cmp -s $testroot/stdout.expected $testroot/stdout
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 echo "alpha" > $testroot/content.expected
443 echo "beta" >> $testroot/content.expected
444 echo "zeta" >> $testroot/content.expected
445 echo "delta" >> $testroot/content.expected
446 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
447 $testroot/wt/gamma/delta > $testroot/content
449 cmp -s $testroot/content.expected $testroot/content
450 ret="$?"
451 if [ "$ret" != "0" ]; then
452 diff -u $testroot/content.expected $testroot/content
453 test_done "$testroot" "$ret"
454 return 1
455 fi
457 echo "modified alpha" > $testroot/wt/alpha
459 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
460 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
461 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
462 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
463 echo "Now shut up and hack" >> $testroot/stdout.expected
465 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
466 ret="$?"
467 if [ "$ret" != "0" ]; then
468 test_done "$testroot" "$ret"
469 return 1
470 fi
472 cmp -s $testroot/stdout.expected $testroot/stdout
473 ret="$?"
474 if [ "$ret" != "0" ]; then
475 diff -u $testroot/stdout.expected $testroot/stdout
476 test_done "$testroot" "$ret"
477 return 1
478 fi
480 echo "modified alpha" > $testroot/content.expected
481 echo "beta" >> $testroot/content.expected
482 echo "zeta" >> $testroot/content.expected
483 echo "delta" >> $testroot/content.expected
484 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
485 $testroot/wt/gamma/delta > $testroot/content
487 cmp -s $testroot/content.expected $testroot/content
488 ret="$?"
489 if [ "$ret" != "0" ]; then
490 diff -u $testroot/content.expected $testroot/content
491 test_done "$testroot" "$ret"
492 return 1
493 fi
495 echo 'M alpha' > $testroot/stdout.expected
496 (cd $testroot/wt && got status > $testroot/stdout)
498 cmp -s $testroot/stdout.expected $testroot/stdout
499 ret="$?"
500 if [ "$ret" != "0" ]; then
501 diff -u $testroot/stdout.expected $testroot/stdout
502 fi
503 test_done "$testroot" "$ret"
506 function test_checkout_symlink {
507 local testroot=`test_init checkout_symlink`
509 (cd $testroot/repo && ln -s alpha alpha.link)
510 (cd $testroot/repo && ln -s epsilon epsilon.link)
511 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
512 (cd $testroot/repo && ln -s passwd.link passwd2.link)
513 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
514 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
515 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
516 (cd $testroot/repo && git add .)
517 git_commit $testroot/repo -m "add symlinks"
519 got checkout $testroot/repo $testroot/wt > $testroot/stdout
520 ret="$?"
521 if [ "$ret" != "0" ]; then
522 echo "got checkout failed unexpectedly" >&2
523 test_done "$testroot" "$ret"
524 return 1
525 fi
527 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
528 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
529 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
530 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
531 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
532 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
533 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
534 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
535 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
536 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
537 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
538 echo "Now shut up and hack" >> $testroot/stdout.expected
540 cmp -s $testroot/stdout.expected $testroot/stdout
541 ret="$?"
542 if [ "$ret" != "0" ]; then
543 diff -u $testroot/stdout.expected $testroot/stdout
544 test_done "$testroot" "$ret"
545 return 1
546 fi
548 if ! [ -h $testroot/wt/alpha.link ]; then
549 echo "alpha.link is not a symlink"
550 test_done "$testroot" "1"
551 return 1
552 fi
554 readlink $testroot/wt/alpha.link > $testroot/stdout
555 echo "alpha" > $testroot/stdout.expected
556 cmp -s $testroot/stdout.expected $testroot/stdout
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 if ! [ -h $testroot/wt/epsilon.link ]; then
565 echo "epsilon.link is not a symlink"
566 test_done "$testroot" "1"
567 return 1
568 fi
570 readlink $testroot/wt/epsilon.link > $testroot/stdout
571 echo "epsilon" > $testroot/stdout.expected
572 cmp -s $testroot/stdout.expected $testroot/stdout
573 ret="$?"
574 if [ "$ret" != "0" ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 if [ -h $testroot/wt/passwd.link ]; then
581 echo -n "passwd.link symlink points outside of work tree: " >&2
582 readlink $testroot/wt/passwd.link >&2
583 test_done "$testroot" "1"
584 return 1
585 fi
587 echo -n "/etc/passwd" > $testroot/content.expected
588 cp $testroot/wt/passwd.link $testroot/content
590 cmp -s $testroot/content.expected $testroot/content
591 ret="$?"
592 if [ "$ret" != "0" ]; then
593 diff -u $testroot/content.expected $testroot/content
594 test_done "$testroot" "$ret"
595 return 1
596 fi
598 if ! [ -h $testroot/wt/passwd2.link ]; then
599 echo "passwd2.link is not a symlink"
600 test_done "$testroot" "1"
601 return 1
602 fi
604 readlink $testroot/wt/passwd2.link > $testroot/stdout
605 echo "passwd.link" > $testroot/stdout.expected
606 cmp -s $testroot/stdout.expected $testroot/stdout
607 ret="$?"
608 if [ "$ret" != "0" ]; then
609 diff -u $testroot/stdout.expected $testroot/stdout
610 test_done "$testroot" "$ret"
611 return 1
612 fi
614 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
615 echo "../beta" > $testroot/stdout.expected
616 cmp -s $testroot/stdout.expected $testroot/stdout
617 ret="$?"
618 if [ "$ret" != "0" ]; then
619 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 readlink $testroot/wt/nonexistent.link > $testroot/stdout
625 echo "nonexistent" > $testroot/stdout.expected
626 cmp -s $testroot/stdout.expected $testroot/stdout
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 if [ -h $testroot/wt/dotgotfoo.link ]; then
635 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
636 readlink $testroot/wt/dotgotfoo.link >&2
637 test_done "$testroot" "1"
638 return 1
639 fi
641 echo -n ".got/foo" > $testroot/content.expected
642 cp $testroot/wt/dotgotfoo.link $testroot/content
644 cmp -s $testroot/content.expected $testroot/content
645 ret="$?"
646 if [ "$ret" != "0" ]; then
647 diff -u $testroot/content.expected $testroot/content
648 fi
649 test_done "$testroot" "$ret"
652 function test_checkout_symlink_relative_wtpath {
653 local testroot=`test_init checkout_symlink_with_wtpath`
655 (cd $testroot/repo && ln -s alpha alpha.link)
656 (cd $testroot/repo && ln -s epsilon epsilon.link)
657 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
658 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
659 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
660 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
661 (cd $testroot/repo && git add .)
662 git_commit $testroot/repo -m "add symlinks"
664 (cd $testroot && got checkout $testroot/repo wt > /dev/null)
665 ret="$?"
666 if [ "$ret" != "0" ]; then
667 test_done "$testroot" "$ret"
668 return 1
669 fi
671 if ! [ -h $testroot/wt/alpha.link ]; then
672 echo "alpha.link is not a symlink"
673 test_done "$testroot" "1"
674 return 1
675 fi
677 readlink $testroot/wt/alpha.link > $testroot/stdout
678 echo "alpha" > $testroot/stdout.expected
679 cmp -s $testroot/stdout.expected $testroot/stdout
680 ret="$?"
681 if [ "$ret" != "0" ]; then
682 diff -u $testroot/stdout.expected $testroot/stdout
683 test_done "$testroot" "$ret"
684 return 1
685 fi
687 if ! [ -h $testroot/wt/epsilon.link ]; then
688 echo "epsilon.link is not a symlink"
689 test_done "$testroot" "1"
690 return 1
691 fi
693 readlink $testroot/wt/epsilon.link > $testroot/stdout
694 echo "epsilon" > $testroot/stdout.expected
695 cmp -s $testroot/stdout.expected $testroot/stdout
696 ret="$?"
697 if [ "$ret" != "0" ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 test_done "$testroot" "$ret"
700 return 1
701 fi
703 if [ -h $testroot/wt/passwd.link ]; then
704 echo -n "passwd.link symlink points outside of work tree: " >&2
705 readlink $testroot/wt/passwd.link >&2
706 test_done "$testroot" "1"
707 return 1
708 fi
710 echo -n "/etc/passwd" > $testroot/content.expected
711 cp $testroot/wt/passwd.link $testroot/content
713 cmp -s $testroot/content.expected $testroot/content
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 diff -u $testroot/content.expected $testroot/content
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
722 echo "../beta" > $testroot/stdout.expected
723 cmp -s $testroot/stdout.expected $testroot/stdout
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 diff -u $testroot/stdout.expected $testroot/stdout
727 test_done "$testroot" "$ret"
728 return 1
729 fi
731 readlink $testroot/wt/nonexistent.link > $testroot/stdout
732 echo "nonexistent" > $testroot/stdout.expected
733 cmp -s $testroot/stdout.expected $testroot/stdout
734 ret="$?"
735 if [ "$ret" != "0" ]; then
736 diff -u $testroot/stdout.expected $testroot/stdout
737 test_done "$testroot" "$ret"
738 return 1
739 fi
741 if [ -h $testroot/wt/dotgotfoo.link ]; then
742 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
743 readlink $testroot/wt/dotgotfoo.link >&2
744 test_done "$testroot" "1"
745 return 1
746 fi
748 echo -n ".got/foo" > $testroot/content.expected
749 cp $testroot/wt/dotgotfoo.link $testroot/content
751 cmp -s $testroot/content.expected $testroot/content
752 ret="$?"
753 if [ "$ret" != "0" ]; then
754 diff -u $testroot/content.expected $testroot/content
755 fi
756 test_done "$testroot" "$ret"
759 test_parseargs "$@"
760 run_test test_checkout_basic
761 run_test test_checkout_dir_exists
762 run_test test_checkout_dir_not_empty
763 run_test test_checkout_sets_xbit
764 run_test test_checkout_commit_from_wrong_branch
765 run_test test_checkout_tag
766 run_test test_checkout_ignores_submodules
767 run_test test_checkout_read_only
768 run_test test_checkout_into_nonempty_dir
769 run_test test_checkout_symlink
770 run_test test_checkout_symlink_relative_wtpath