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 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 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 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 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 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 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 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 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 or 'gotadmin cleanup'; " \
339 >> $testroot/stderr.expected
340 echo -n "making the repository " >> $testroot/stderr.expected
341 echo "writable and running 'got update' will prevent this" \
342 >> $testroot/stderr.expected
343 cmp -s $testroot/stderr.expected $testroot/stderr
344 ret="$?"
345 if [ "$ret" != "0" ]; then
346 diff -u $testroot/stderr.expected $testroot/stderr
347 test_done "$testroot" "$ret"
348 return 1
349 fi
351 echo "alpha" > $testroot/content.expected
352 echo "beta" >> $testroot/content.expected
353 echo "zeta" >> $testroot/content.expected
354 echo "delta" >> $testroot/content.expected
355 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
356 $testroot/wt/gamma/delta > $testroot/content
358 cmp -s $testroot/content.expected $testroot/content
359 ret="$?"
360 if [ "$ret" != "0" ]; then
361 diff -u $testroot/content.expected $testroot/content
362 fi
363 chmod -R u+w $testroot/repo # make repo cleanup work
364 test_done "$testroot" "$ret"
367 test_checkout_into_nonempty_dir() {
368 local testroot=`test_init checkout_into_nonempty_dir`
370 mkdir -p $testroot/wt
371 make_test_tree $testroot/wt
373 got checkout $testroot/repo $testroot/wt > $testroot/stdout \
374 2> $testroot/stderr
375 ret="$?"
376 if [ "$ret" = "0" ]; then
377 echo "checkout succeeded unexpectedly" >&2
378 test_done "$testroot" "1"
379 return 1
380 fi
382 echo -n > $testroot/stdout.expected
383 cmp -s $testroot/stdout.expected $testroot/stdout
384 ret="$?"
385 if [ "$ret" != "0" ]; then
386 diff -u $testroot/stdout.expected $testroot/stdout
387 test_done "$testroot" "$ret"
388 return 1
389 fi
391 echo "got: $testroot/wt: directory exists and is not empty" \
392 > $testroot/stderr.expected
393 cmp -s $testroot/stderr.expected $testroot/stderr
394 ret="$?"
395 if [ "$ret" != "0" ]; then
396 diff -u $testroot/stderr.expected $testroot/stderr
397 test_done "$testroot" "$ret"
398 return 1
399 fi
401 echo "? $testroot/wt/alpha" > $testroot/stdout.expected
402 echo "? $testroot/wt/beta" >> $testroot/stdout.expected
403 echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
404 echo "? $testroot/wt/gamma/delta" >> $testroot/stdout.expected
405 echo "Now shut up and hack" >> $testroot/stdout.expected
407 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
408 ret="$?"
409 if [ "$ret" != "0" ]; then
410 test_done "$testroot" "$ret"
411 return 1
412 fi
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret="$?"
416 if [ "$ret" != "0" ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 test_done "$testroot" "$ret"
419 return 1
420 fi
422 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
423 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
424 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
425 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
426 echo "Now shut up and hack" >> $testroot/stdout.expected
428 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
429 ret="$?"
430 if [ "$ret" != "0" ]; then
431 test_done "$testroot" "$ret"
432 return 1
433 fi
435 cmp -s $testroot/stdout.expected $testroot/stdout
436 ret="$?"
437 if [ "$ret" != "0" ]; then
438 diff -u $testroot/stdout.expected $testroot/stdout
439 test_done "$testroot" "$ret"
440 return 1
441 fi
443 echo "alpha" > $testroot/content.expected
444 echo "beta" >> $testroot/content.expected
445 echo "zeta" >> $testroot/content.expected
446 echo "delta" >> $testroot/content.expected
447 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
448 $testroot/wt/gamma/delta > $testroot/content
450 cmp -s $testroot/content.expected $testroot/content
451 ret="$?"
452 if [ "$ret" != "0" ]; then
453 diff -u $testroot/content.expected $testroot/content
454 test_done "$testroot" "$ret"
455 return 1
456 fi
458 echo "modified alpha" > $testroot/wt/alpha
460 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
461 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
462 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
463 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
464 echo "Now shut up and hack" >> $testroot/stdout.expected
466 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
467 ret="$?"
468 if [ "$ret" != "0" ]; then
469 test_done "$testroot" "$ret"
470 return 1
471 fi
473 cmp -s $testroot/stdout.expected $testroot/stdout
474 ret="$?"
475 if [ "$ret" != "0" ]; then
476 diff -u $testroot/stdout.expected $testroot/stdout
477 test_done "$testroot" "$ret"
478 return 1
479 fi
481 echo "modified alpha" > $testroot/content.expected
482 echo "beta" >> $testroot/content.expected
483 echo "zeta" >> $testroot/content.expected
484 echo "delta" >> $testroot/content.expected
485 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
486 $testroot/wt/gamma/delta > $testroot/content
488 cmp -s $testroot/content.expected $testroot/content
489 ret="$?"
490 if [ "$ret" != "0" ]; then
491 diff -u $testroot/content.expected $testroot/content
492 test_done "$testroot" "$ret"
493 return 1
494 fi
496 echo 'M alpha' > $testroot/stdout.expected
497 (cd $testroot/wt && got status > $testroot/stdout)
499 cmp -s $testroot/stdout.expected $testroot/stdout
500 ret="$?"
501 if [ "$ret" != "0" ]; then
502 diff -u $testroot/stdout.expected $testroot/stdout
503 fi
504 test_done "$testroot" "$ret"
507 test_checkout_symlink() {
508 local testroot=`test_init checkout_symlink`
510 (cd $testroot/repo && ln -s alpha alpha.link)
511 (cd $testroot/repo && ln -s epsilon epsilon.link)
512 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
513 (cd $testroot/repo && ln -s passwd.link passwd2.link)
514 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
515 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
516 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
517 (cd $testroot/repo && git add .)
518 git_commit $testroot/repo -m "add symlinks"
520 got checkout $testroot/repo $testroot/wt > $testroot/stdout
521 ret="$?"
522 if [ "$ret" != "0" ]; then
523 echo "got checkout failed unexpectedly" >&2
524 test_done "$testroot" "$ret"
525 return 1
526 fi
528 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
529 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
530 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
531 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
532 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
533 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
534 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
535 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
536 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
537 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
538 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
539 echo "Now shut up and hack" >> $testroot/stdout.expected
541 cmp -s $testroot/stdout.expected $testroot/stdout
542 ret="$?"
543 if [ "$ret" != "0" ]; then
544 diff -u $testroot/stdout.expected $testroot/stdout
545 test_done "$testroot" "$ret"
546 return 1
547 fi
549 if ! [ -h $testroot/wt/alpha.link ]; then
550 echo "alpha.link is not a symlink"
551 test_done "$testroot" "1"
552 return 1
553 fi
555 readlink $testroot/wt/alpha.link > $testroot/stdout
556 echo "alpha" > $testroot/stdout.expected
557 cmp -s $testroot/stdout.expected $testroot/stdout
558 ret="$?"
559 if [ "$ret" != "0" ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
562 return 1
563 fi
565 if ! [ -h $testroot/wt/epsilon.link ]; then
566 echo "epsilon.link is not a symlink"
567 test_done "$testroot" "1"
568 return 1
569 fi
571 readlink $testroot/wt/epsilon.link > $testroot/stdout
572 echo "epsilon" > $testroot/stdout.expected
573 cmp -s $testroot/stdout.expected $testroot/stdout
574 ret="$?"
575 if [ "$ret" != "0" ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 test_done "$testroot" "$ret"
578 return 1
579 fi
581 if [ -h $testroot/wt/passwd.link ]; then
582 echo -n "passwd.link symlink points outside of work tree: " >&2
583 readlink $testroot/wt/passwd.link >&2
584 test_done "$testroot" "1"
585 return 1
586 fi
588 echo -n "/etc/passwd" > $testroot/content.expected
589 cp $testroot/wt/passwd.link $testroot/content
591 cmp -s $testroot/content.expected $testroot/content
592 ret="$?"
593 if [ "$ret" != "0" ]; then
594 diff -u $testroot/content.expected $testroot/content
595 test_done "$testroot" "$ret"
596 return 1
597 fi
599 if ! [ -h $testroot/wt/passwd2.link ]; then
600 echo "passwd2.link is not a symlink"
601 test_done "$testroot" "1"
602 return 1
603 fi
605 readlink $testroot/wt/passwd2.link > $testroot/stdout
606 echo "passwd.link" > $testroot/stdout.expected
607 cmp -s $testroot/stdout.expected $testroot/stdout
608 ret="$?"
609 if [ "$ret" != "0" ]; then
610 diff -u $testroot/stdout.expected $testroot/stdout
611 test_done "$testroot" "$ret"
612 return 1
613 fi
615 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
616 echo "../beta" > $testroot/stdout.expected
617 cmp -s $testroot/stdout.expected $testroot/stdout
618 ret="$?"
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/stdout.expected $testroot/stdout
621 test_done "$testroot" "$ret"
622 return 1
623 fi
625 readlink $testroot/wt/nonexistent.link > $testroot/stdout
626 echo "nonexistent" > $testroot/stdout.expected
627 cmp -s $testroot/stdout.expected $testroot/stdout
628 ret="$?"
629 if [ "$ret" != "0" ]; then
630 diff -u $testroot/stdout.expected $testroot/stdout
631 test_done "$testroot" "$ret"
632 return 1
633 fi
635 if [ -h $testroot/wt/dotgotfoo.link ]; then
636 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
637 readlink $testroot/wt/dotgotfoo.link >&2
638 test_done "$testroot" "1"
639 return 1
640 fi
642 echo -n ".got/foo" > $testroot/content.expected
643 cp $testroot/wt/dotgotfoo.link $testroot/content
645 cmp -s $testroot/content.expected $testroot/content
646 ret="$?"
647 if [ "$ret" != "0" ]; then
648 diff -u $testroot/content.expected $testroot/content
649 fi
650 test_done "$testroot" "$ret"
653 test_checkout_symlink_relative_wtpath() {
654 local testroot=`test_init checkout_symlink_with_wtpath`
656 (cd $testroot/repo && ln -s alpha alpha.link)
657 (cd $testroot/repo && ln -s epsilon epsilon.link)
658 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
659 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
660 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
661 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
662 (cd $testroot/repo && git add .)
663 git_commit $testroot/repo -m "add symlinks"
665 (cd $testroot && got checkout $testroot/repo wt > /dev/null)
666 ret="$?"
667 if [ "$ret" != "0" ]; then
668 test_done "$testroot" "$ret"
669 return 1
670 fi
672 if ! [ -h $testroot/wt/alpha.link ]; then
673 echo "alpha.link is not a symlink"
674 test_done "$testroot" "1"
675 return 1
676 fi
678 readlink $testroot/wt/alpha.link > $testroot/stdout
679 echo "alpha" > $testroot/stdout.expected
680 cmp -s $testroot/stdout.expected $testroot/stdout
681 ret="$?"
682 if [ "$ret" != "0" ]; then
683 diff -u $testroot/stdout.expected $testroot/stdout
684 test_done "$testroot" "$ret"
685 return 1
686 fi
688 if ! [ -h $testroot/wt/epsilon.link ]; then
689 echo "epsilon.link is not a symlink"
690 test_done "$testroot" "1"
691 return 1
692 fi
694 readlink $testroot/wt/epsilon.link > $testroot/stdout
695 echo "epsilon" > $testroot/stdout.expected
696 cmp -s $testroot/stdout.expected $testroot/stdout
697 ret="$?"
698 if [ "$ret" != "0" ]; then
699 diff -u $testroot/stdout.expected $testroot/stdout
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 if [ -h $testroot/wt/passwd.link ]; then
705 echo -n "passwd.link symlink points outside of work tree: " >&2
706 readlink $testroot/wt/passwd.link >&2
707 test_done "$testroot" "1"
708 return 1
709 fi
711 echo -n "/etc/passwd" > $testroot/content.expected
712 cp $testroot/wt/passwd.link $testroot/content
714 cmp -s $testroot/content.expected $testroot/content
715 ret="$?"
716 if [ "$ret" != "0" ]; then
717 diff -u $testroot/content.expected $testroot/content
718 test_done "$testroot" "$ret"
719 return 1
720 fi
722 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
723 echo "../beta" > $testroot/stdout.expected
724 cmp -s $testroot/stdout.expected $testroot/stdout
725 ret="$?"
726 if [ "$ret" != "0" ]; then
727 diff -u $testroot/stdout.expected $testroot/stdout
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 readlink $testroot/wt/nonexistent.link > $testroot/stdout
733 echo "nonexistent" > $testroot/stdout.expected
734 cmp -s $testroot/stdout.expected $testroot/stdout
735 ret="$?"
736 if [ "$ret" != "0" ]; then
737 diff -u $testroot/stdout.expected $testroot/stdout
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 if [ -h $testroot/wt/dotgotfoo.link ]; then
743 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
744 readlink $testroot/wt/dotgotfoo.link >&2
745 test_done "$testroot" "1"
746 return 1
747 fi
749 echo -n ".got/foo" > $testroot/content.expected
750 cp $testroot/wt/dotgotfoo.link $testroot/content
752 cmp -s $testroot/content.expected $testroot/content
753 ret="$?"
754 if [ "$ret" != "0" ]; then
755 diff -u $testroot/content.expected $testroot/content
756 fi
757 test_done "$testroot" "$ret"
760 test_checkout_repo_with_unknown_extension() {
761 local testroot=`test_init checkout_repo_with_unknown_extension`
763 (cd $testroot/repo &&
764 git config --add extensions.badExtension true)
765 (cd $testroot/repo &&
766 git config --add extensions.otherBadExtension 0)
768 echo "got: badExtension: unsupported repository format extension" \
769 > $testroot/stderr.expected
770 got checkout $testroot/repo $testroot/wt \
771 > $testroot/stdout 2> $testroot/stderr
773 ret="$?"
774 if [ "$ret" = "0" ]; then
775 echo "got checkout command succeeded unexpectedly" >&2
776 test_done "$testroot" "1"
777 return 1
778 fi
780 cmp -s $testroot/stderr.expected $testroot/stderr
781 ret="$?"
782 if [ "$ret" != "0" ]; then
783 diff -u $testroot/stderr.expected $testroot/stderr
784 fi
785 test_done "$testroot" "$ret"
788 test_parseargs "$@"
789 run_test test_checkout_basic
790 run_test test_checkout_dir_exists
791 run_test test_checkout_dir_not_empty
792 run_test test_checkout_sets_xbit
793 run_test test_checkout_commit_from_wrong_branch
794 run_test test_checkout_tag
795 run_test test_checkout_ignores_submodules
796 run_test test_checkout_read_only
797 run_test test_checkout_into_nonempty_dir
798 run_test test_checkout_symlink
799 run_test test_checkout_symlink_relative_wtpath
800 run_test test_checkout_repo_with_unknown_extension