3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
19 test_checkout_basic
() {
20 local testroot
=`test_init checkout_basic`
21 local commit_id
=`git_show_head $testroot/repo`
23 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
24 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
25 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
26 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
27 echo "Checked out refs/heads/master: $commit_id" \
28 >> $testroot/stdout.expected
29 echo "Now shut up and hack" >> $testroot/stdout.expected
31 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
33 if [ "$ret" != "0" ]; then
34 test_done
"$testroot" "$ret"
38 cmp -s $testroot/stdout.expected
$testroot/stdout
40 if [ "$ret" != "0" ]; then
41 diff -u $testroot/stdout.expected
$testroot/stdout
42 test_done
"$testroot" "$ret"
46 echo "alpha" > $testroot/content.expected
47 echo "beta" >> $testroot/content.expected
48 echo "zeta" >> $testroot/content.expected
49 echo "delta" >> $testroot/content.expected
50 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
51 $testroot/wt
/gamma
/delta
> $testroot/content
53 cmp -s $testroot/content.expected
$testroot/content
55 if [ "$ret" != "0" ]; then
56 diff -u $testroot/content.expected
$testroot/content
58 test_done
"$testroot" "$ret"
61 test_checkout_dir_exists
() {
62 local testroot
=`test_init checkout_dir_exists`
63 local commit_id
=`git_show_head $testroot/repo`
65 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
66 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
67 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
68 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
69 echo "Checked out refs/heads/master: $commit_id" \
70 >> $testroot/stdout.expected
71 echo "Now shut up and hack" >> $testroot/stdout.expected
75 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
77 if [ "$ret" != "0" ]; then
78 test_done
"$testroot" "$ret"
82 cmp -s $testroot/stdout.expected
$testroot/stdout
84 if [ "$ret" != "0" ]; then
85 diff -u $testroot/stdout.expected
$testroot/stdout
86 test_done
"$testroot" "$ret"
90 echo "alpha" > $testroot/content.expected
91 echo "beta" >> $testroot/content.expected
92 echo "zeta" >> $testroot/content.expected
93 echo "delta" >> $testroot/content.expected
94 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
95 $testroot/wt
/gamma
/delta
> $testroot/content
97 cmp -s $testroot/content.expected
$testroot/content
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/content.expected
$testroot/content
102 test_done
"$testroot" "$ret"
105 test_checkout_dir_not_empty
() {
106 local testroot
=`test_init checkout_dir_not_empty`
107 local commit_id
=`git_show_head $testroot/repo`
109 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
110 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
111 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
112 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
113 echo "Checked out refs/heads/master: $commit_id" \
114 >> $testroot/stdout.expected
115 echo "Now shut up and hack" >> $testroot/stdout.expected
118 touch $testroot/wt
/foo
120 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout \
123 if [ "$ret" = "0" ]; then
124 echo "checkout succeeded unexpectedly" >&2
125 test_done
"$testroot" "1"
129 echo "got: $testroot/wt: directory exists and is not empty" \
130 > $testroot/stderr.expected
131 cmp -s $testroot/stderr.expected
$testroot/stderr
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stderr.expected
$testroot/stderr
135 test_done
"$testroot" "$ret"
139 echo -n > $testroot/stdout.expected
140 cmp -s $testroot/stdout.expected
$testroot/stdout
142 if [ "$ret" != "0" ]; then
143 diff -u $testroot/stdout.expected
$testroot/stdout
145 test_done
"$testroot" "$ret"
149 test_checkout_sets_xbit
() {
150 local testroot
=`test_init checkout_sets_xbit 1`
152 touch $testroot/repo
/xfile
153 chmod +x
$testroot/repo
/xfile
154 (cd $testroot/repo
&& git add .
)
155 git_commit
$testroot/repo
-m "adding executable file"
156 local commit_id
=`git_show_head $testroot/repo`
158 echo "A $testroot/wt/xfile" > $testroot/stdout.expected
159 echo "Checked out refs/heads/master: $commit_id" \
160 >> $testroot/stdout.expected
161 echo "Now shut up and hack" >> $testroot/stdout.expected
163 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
165 if [ "$ret" != "0" ]; then
166 test_done
"$testroot" "$ret"
170 cmp -s $testroot/stdout.expected
$testroot/stdout
172 if [ "$ret" != "0" ]; then
173 diff -u $testroot/stdout.expected
$testroot/stdout
174 test_done
"$testroot" "$ret"
178 ls -l $testroot/wt
/xfile |
grep -q '^-rwx'
180 if [ "$ret" != "0" ]; then
181 echo "file is not executable" >&2
182 ls -l $testroot/wt
/xfile
>&2
184 test_done
"$testroot" "$ret"
187 test_checkout_commit_from_wrong_branch
() {
188 local testroot
=`test_init checkout_commit_from_wrong_branch`
190 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
191 echo "modified alpha on new branch" > $testroot/repo
/alpha
192 git_commit
$testroot/repo
-m "modified alpha on new branch"
194 local head_rev
=`git_show_head $testroot/repo`
195 got checkout
-b master
-c $head_rev $testroot/repo
$testroot/wt \
196 > $testroot/stdout
2> $testroot/stderr
198 if [ "$ret" = "0" ]; then
199 test_done
"$testroot" "1"
203 echo -n "" > $testroot/stdout.expected
204 cmp -s $testroot/stdout.expected
$testroot/stdout
206 if [ "$ret" != "0" ]; then
207 diff -u $testroot/stdout.expected
$testroot/stdout
208 test_done
"$testroot" "$ret"
212 echo -n "got: target commit is not contained in branch 'master'; " \
213 > $testroot/stderr.expected
214 echo -n "the branch to use must be specified with -b; if necessary " \
215 >> $testroot/stderr.expected
216 echo -n "a new branch can be created for this commit with "\
217 >> $testroot/stderr.expected
218 echo "'got branch -c $head_rev BRANCH_NAME'" \
219 >> $testroot/stderr.expected
220 cmp -s $testroot/stderr.expected
$testroot/stderr
222 if [ "$ret" != "0" ]; then
223 diff -u $testroot/stderr.expected
$testroot/stderr
224 test_done
"$testroot" "$ret"
228 test_done
"$testroot" "$ret"
231 test_checkout_tag
() {
232 local testroot
=`test_init checkout_tag`
233 local commit_id
=`git_show_head $testroot/repo`
236 (cd $testroot/repo
&& git tag
-a -m "test" $tag)
238 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
239 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
240 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
241 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
242 echo "Checked out refs/heads/master: $commit_id" \
243 >> $testroot/stdout.expected
244 echo "Now shut up and hack" >> $testroot/stdout.expected
246 got checkout
-c $tag $testroot/repo
$testroot/wt
> $testroot/stdout
248 if [ "$ret" != "0" ]; then
249 test_done
"$testroot" "$ret"
253 cmp -s $testroot/stdout.expected
$testroot/stdout
255 if [ "$ret" != "0" ]; then
256 diff -u $testroot/stdout.expected
$testroot/stdout
257 test_done
"$testroot" "$ret"
261 echo "alpha" > $testroot/content.expected
262 echo "beta" >> $testroot/content.expected
263 echo "zeta" >> $testroot/content.expected
264 echo "delta" >> $testroot/content.expected
265 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
266 $testroot/wt
/gamma
/delta
> $testroot/content
268 cmp -s $testroot/content.expected
$testroot/content
270 if [ "$ret" != "0" ]; then
271 diff -u $testroot/content.expected
$testroot/content
273 test_done
"$testroot" "$ret"
276 test_checkout_ignores_submodules
() {
277 local testroot
=`test_init checkout_ignores_submodules`
279 make_single_file_repo
$testroot/repo2 foo
281 (cd $testroot/repo
&& git submodule
-q add ..
/repo2
)
282 (cd $testroot/repo
&& git commit
-q -m 'adding submodule')
283 local commit_id
=`git_show_head $testroot/repo`
285 echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
286 echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
287 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
288 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
289 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
290 echo "Checked out refs/heads/master: $commit_id" \
291 >> $testroot/stdout.expected
292 echo "Now shut up and hack" >> $testroot/stdout.expected
294 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
296 if [ "$ret" != "0" ]; then
297 test_done
"$testroot" "$ret"
301 cmp -s $testroot/stdout.expected
$testroot/stdout
303 if [ "$ret" != "0" ]; then
304 diff -u $testroot/stdout.expected
$testroot/stdout
305 test_done
"$testroot" "$ret"
309 echo "alpha" > $testroot/content.expected
310 echo "beta" >> $testroot/content.expected
311 echo "zeta" >> $testroot/content.expected
312 echo "delta" >> $testroot/content.expected
313 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
314 $testroot/wt
/gamma
/delta
> $testroot/content
316 cmp -s $testroot/content.expected
$testroot/content
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/content.expected
$testroot/content
321 test_done
"$testroot" "$ret"
324 test_checkout_read_only
() {
325 local testroot
=`test_init checkout_read_only`
326 local commit_id
=`git_show_head $testroot/repo`
328 # Make the repostiory read-only
329 chmod -R a-w
$testroot/repo
331 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
332 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
333 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
334 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
335 echo "Checked out refs/heads/master: $commit_id" \
336 >> $testroot/stdout.expected
337 echo "Now shut up and hack" >> $testroot/stdout.expected
339 got checkout
$testroot/repo
$testroot/wt \
340 > $testroot/stdout
2> $testroot/stderr
342 if [ "$ret" != "0" ]; then
343 test_done
"$testroot" "$ret"
347 cmp -s $testroot/stdout.expected
$testroot/stdout
349 if [ "$ret" != "0" ]; then
350 diff -u $testroot/stdout.expected
$testroot/stdout
351 test_done
"$testroot" "$ret"
355 echo -n "got: warning: could not create a reference " \
356 > $testroot/stderr.expected
357 echo -n "to the work tree's base commit; the commit could " \
358 >> $testroot/stderr.expected
359 echo -n "be garbage-collected by Git or 'gotadmin cleanup'; " \
360 >> $testroot/stderr.expected
361 echo -n "making the repository " >> $testroot/stderr.expected
362 echo "writable and running 'got update' will prevent this" \
363 >> $testroot/stderr.expected
364 cmp -s $testroot/stderr.expected
$testroot/stderr
366 if [ "$ret" != "0" ]; then
367 diff -u $testroot/stderr.expected
$testroot/stderr
368 test_done
"$testroot" "$ret"
372 echo "alpha" > $testroot/content.expected
373 echo "beta" >> $testroot/content.expected
374 echo "zeta" >> $testroot/content.expected
375 echo "delta" >> $testroot/content.expected
376 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
377 $testroot/wt
/gamma
/delta
> $testroot/content
379 cmp -s $testroot/content.expected
$testroot/content
381 if [ "$ret" != "0" ]; then
382 diff -u $testroot/content.expected
$testroot/content
384 chmod -R u
+w
$testroot/repo
# make repo cleanup work
385 test_done
"$testroot" "$ret"
388 test_checkout_into_nonempty_dir
() {
389 local testroot
=`test_init checkout_into_nonempty_dir`
390 local commit_id
=`git_show_head $testroot/repo`
392 mkdir
-p $testroot/wt
393 make_test_tree
$testroot/wt
395 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout \
398 if [ "$ret" = "0" ]; then
399 echo "checkout succeeded unexpectedly" >&2
400 test_done
"$testroot" "1"
404 echo -n > $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected
$testroot/stdout
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stdout.expected
$testroot/stdout
409 test_done
"$testroot" "$ret"
413 echo "got: $testroot/wt: directory exists and is not empty" \
414 > $testroot/stderr.expected
415 cmp -s $testroot/stderr.expected
$testroot/stderr
417 if [ "$ret" != "0" ]; then
418 diff -u $testroot/stderr.expected
$testroot/stderr
419 test_done
"$testroot" "$ret"
423 echo "? $testroot/wt/alpha" > $testroot/stdout.expected
424 echo "? $testroot/wt/beta" >> $testroot/stdout.expected
425 echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
426 echo "? $testroot/wt/gamma/delta" >> $testroot/stdout.expected
427 echo "Checked out refs/heads/master: $commit_id" \
428 >> $testroot/stdout.expected
429 echo "Now shut up and hack" >> $testroot/stdout.expected
431 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
433 if [ "$ret" != "0" ]; then
434 test_done
"$testroot" "$ret"
438 cmp -s $testroot/stdout.expected
$testroot/stdout
440 if [ "$ret" != "0" ]; then
441 diff -u $testroot/stdout.expected
$testroot/stdout
442 test_done
"$testroot" "$ret"
446 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
447 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
448 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
449 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
450 echo "Checked out refs/heads/master: $commit_id" \
451 >> $testroot/stdout.expected
452 echo "Now shut up and hack" >> $testroot/stdout.expected
454 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
456 if [ "$ret" != "0" ]; then
457 test_done
"$testroot" "$ret"
461 cmp -s $testroot/stdout.expected
$testroot/stdout
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/stdout.expected
$testroot/stdout
465 test_done
"$testroot" "$ret"
469 echo "alpha" > $testroot/content.expected
470 echo "beta" >> $testroot/content.expected
471 echo "zeta" >> $testroot/content.expected
472 echo "delta" >> $testroot/content.expected
473 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
474 $testroot/wt
/gamma
/delta
> $testroot/content
476 cmp -s $testroot/content.expected
$testroot/content
478 if [ "$ret" != "0" ]; then
479 diff -u $testroot/content.expected
$testroot/content
480 test_done
"$testroot" "$ret"
484 echo "modified alpha" > $testroot/wt
/alpha
486 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
487 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
488 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
489 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
490 echo "Checked out refs/heads/master: $commit_id" \
491 >> $testroot/stdout.expected
492 echo "Now shut up and hack" >> $testroot/stdout.expected
494 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
496 if [ "$ret" != "0" ]; then
497 test_done
"$testroot" "$ret"
501 cmp -s $testroot/stdout.expected
$testroot/stdout
503 if [ "$ret" != "0" ]; then
504 diff -u $testroot/stdout.expected
$testroot/stdout
505 test_done
"$testroot" "$ret"
509 echo "modified alpha" > $testroot/content.expected
510 echo "beta" >> $testroot/content.expected
511 echo "zeta" >> $testroot/content.expected
512 echo "delta" >> $testroot/content.expected
513 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
514 $testroot/wt
/gamma
/delta
> $testroot/content
516 cmp -s $testroot/content.expected
$testroot/content
518 if [ "$ret" != "0" ]; then
519 diff -u $testroot/content.expected
$testroot/content
520 test_done
"$testroot" "$ret"
524 echo 'M alpha' > $testroot/stdout.expected
525 (cd $testroot/wt
&& got status
> $testroot/stdout
)
527 cmp -s $testroot/stdout.expected
$testroot/stdout
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stdout.expected
$testroot/stdout
532 test_done
"$testroot" "$ret"
535 test_checkout_symlink
() {
536 local testroot
=`test_init checkout_symlink`
538 (cd $testroot/repo
&& ln -s alpha alpha.link
)
539 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
540 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
541 (cd $testroot/repo
&& ln -s passwd.link passwd2.link
)
542 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
543 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
544 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
545 (cd $testroot/repo
&& git add .
)
546 git_commit
$testroot/repo
-m "add symlinks"
547 local commit_id
=`git_show_head $testroot/repo`
549 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
551 if [ "$ret" != "0" ]; then
552 echo "got checkout failed unexpectedly" >&2
553 test_done
"$testroot" "$ret"
557 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
558 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
559 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
560 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
561 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
562 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
563 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
564 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
565 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
566 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
567 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
568 echo "Checked out refs/heads/master: $commit_id" \
569 >> $testroot/stdout.expected
570 echo "Now shut up and hack" >> $testroot/stdout.expected
572 cmp -s $testroot/stdout.expected
$testroot/stdout
574 if [ "$ret" != "0" ]; then
575 diff -u $testroot/stdout.expected
$testroot/stdout
576 test_done
"$testroot" "$ret"
580 if ! [ -h $testroot/wt
/alpha.link
]; then
581 echo "alpha.link is not a symlink"
582 test_done
"$testroot" "1"
586 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
587 echo "alpha" > $testroot/stdout.expected
588 cmp -s $testroot/stdout.expected
$testroot/stdout
590 if [ "$ret" != "0" ]; then
591 diff -u $testroot/stdout.expected
$testroot/stdout
592 test_done
"$testroot" "$ret"
596 if ! [ -h $testroot/wt
/epsilon.link
]; then
597 echo "epsilon.link is not a symlink"
598 test_done
"$testroot" "1"
602 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
603 echo "epsilon" > $testroot/stdout.expected
604 cmp -s $testroot/stdout.expected
$testroot/stdout
606 if [ "$ret" != "0" ]; then
607 diff -u $testroot/stdout.expected
$testroot/stdout
608 test_done
"$testroot" "$ret"
612 if [ -h $testroot/wt
/passwd.link
]; then
613 echo -n "passwd.link symlink points outside of work tree: " >&2
614 readlink
$testroot/wt
/passwd.link
>&2
615 test_done
"$testroot" "1"
619 echo -n "/etc/passwd" > $testroot/content.expected
620 cp $testroot/wt
/passwd.link
$testroot/content
622 cmp -s $testroot/content.expected
$testroot/content
624 if [ "$ret" != "0" ]; then
625 diff -u $testroot/content.expected
$testroot/content
626 test_done
"$testroot" "$ret"
630 if ! [ -h $testroot/wt
/passwd2.link
]; then
631 echo "passwd2.link is not a symlink"
632 test_done
"$testroot" "1"
636 readlink
$testroot/wt
/passwd2.link
> $testroot/stdout
637 echo "passwd.link" > $testroot/stdout.expected
638 cmp -s $testroot/stdout.expected
$testroot/stdout
640 if [ "$ret" != "0" ]; then
641 diff -u $testroot/stdout.expected
$testroot/stdout
642 test_done
"$testroot" "$ret"
646 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
647 echo "../beta" > $testroot/stdout.expected
648 cmp -s $testroot/stdout.expected
$testroot/stdout
650 if [ "$ret" != "0" ]; then
651 diff -u $testroot/stdout.expected
$testroot/stdout
652 test_done
"$testroot" "$ret"
656 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
657 echo "nonexistent" > $testroot/stdout.expected
658 cmp -s $testroot/stdout.expected
$testroot/stdout
660 if [ "$ret" != "0" ]; then
661 diff -u $testroot/stdout.expected
$testroot/stdout
662 test_done
"$testroot" "$ret"
666 if [ -h $testroot/wt
/dotgotfoo.link
]; then
667 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
668 readlink
$testroot/wt
/dotgotfoo.link
>&2
669 test_done
"$testroot" "1"
673 echo -n ".got/foo" > $testroot/content.expected
674 cp $testroot/wt
/dotgotfoo.link
$testroot/content
676 cmp -s $testroot/content.expected
$testroot/content
678 if [ "$ret" != "0" ]; then
679 diff -u $testroot/content.expected
$testroot/content
681 test_done
"$testroot" "$ret"
684 test_checkout_symlink_relative_wtpath
() {
685 local testroot
=`test_init checkout_symlink_with_wtpath`
687 (cd $testroot/repo
&& ln -s alpha alpha.link
)
688 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
689 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
690 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
691 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
692 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
693 (cd $testroot/repo
&& git add .
)
694 git_commit
$testroot/repo
-m "add symlinks"
696 (cd $testroot && got checkout
$testroot/repo wt
> /dev
/null
)
698 if [ "$ret" != "0" ]; then
699 test_done
"$testroot" "$ret"
703 if ! [ -h $testroot/wt
/alpha.link
]; then
704 echo "alpha.link is not a symlink"
705 test_done
"$testroot" "1"
709 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
710 echo "alpha" > $testroot/stdout.expected
711 cmp -s $testroot/stdout.expected
$testroot/stdout
713 if [ "$ret" != "0" ]; then
714 diff -u $testroot/stdout.expected
$testroot/stdout
715 test_done
"$testroot" "$ret"
719 if ! [ -h $testroot/wt
/epsilon.link
]; then
720 echo "epsilon.link is not a symlink"
721 test_done
"$testroot" "1"
725 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
726 echo "epsilon" > $testroot/stdout.expected
727 cmp -s $testroot/stdout.expected
$testroot/stdout
729 if [ "$ret" != "0" ]; then
730 diff -u $testroot/stdout.expected
$testroot/stdout
731 test_done
"$testroot" "$ret"
735 if [ -h $testroot/wt
/passwd.link
]; then
736 echo -n "passwd.link symlink points outside of work tree: " >&2
737 readlink
$testroot/wt
/passwd.link
>&2
738 test_done
"$testroot" "1"
742 echo -n "/etc/passwd" > $testroot/content.expected
743 cp $testroot/wt
/passwd.link
$testroot/content
745 cmp -s $testroot/content.expected
$testroot/content
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/content.expected
$testroot/content
749 test_done
"$testroot" "$ret"
753 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
754 echo "../beta" > $testroot/stdout.expected
755 cmp -s $testroot/stdout.expected
$testroot/stdout
757 if [ "$ret" != "0" ]; then
758 diff -u $testroot/stdout.expected
$testroot/stdout
759 test_done
"$testroot" "$ret"
763 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
764 echo "nonexistent" > $testroot/stdout.expected
765 cmp -s $testroot/stdout.expected
$testroot/stdout
767 if [ "$ret" != "0" ]; then
768 diff -u $testroot/stdout.expected
$testroot/stdout
769 test_done
"$testroot" "$ret"
773 if [ -h $testroot/wt
/dotgotfoo.link
]; then
774 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
775 readlink
$testroot/wt
/dotgotfoo.link
>&2
776 test_done
"$testroot" "1"
780 echo -n ".got/foo" > $testroot/content.expected
781 cp $testroot/wt
/dotgotfoo.link
$testroot/content
783 cmp -s $testroot/content.expected
$testroot/content
785 if [ "$ret" != "0" ]; then
786 diff -u $testroot/content.expected
$testroot/content
788 test_done
"$testroot" "$ret"
791 test_checkout_repo_with_unknown_extension
() {
792 local testroot
=`test_init checkout_repo_with_unknown_extension`
794 (cd $testroot/repo
&&
795 git config
--add extensions.badExtension true
)
796 (cd $testroot/repo
&&
797 git config
--add extensions.otherBadExtension
0)
799 echo "got: badExtension: unsupported repository format extension" \
800 > $testroot/stderr.expected
801 got checkout
$testroot/repo
$testroot/wt \
802 > $testroot/stdout
2> $testroot/stderr
805 if [ "$ret" = "0" ]; then
806 echo "got checkout command succeeded unexpectedly" >&2
807 test_done
"$testroot" "1"
811 cmp -s $testroot/stderr.expected
$testroot/stderr
813 if [ "$ret" != "0" ]; then
814 diff -u $testroot/stderr.expected
$testroot/stderr
816 test_done
"$testroot" "$ret"
819 test_checkout_quiet
() {
820 local testroot
=`test_init checkout_quiet`
822 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
823 git_show_head
$testroot/repo
>> $testroot/stdout.expected
824 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
826 got checkout
-q $testroot/repo
$testroot/wt
> $testroot/stdout
828 if [ "$ret" != "0" ]; then
829 test_done
"$testroot" "$ret"
833 cmp -s $testroot/stdout.expected
$testroot/stdout
835 if [ "$ret" != "0" ]; then
836 diff -u $testroot/stdout.expected
$testroot/stdout
837 test_done
"$testroot" "$ret"
841 echo "alpha" > $testroot/content.expected
842 echo "beta" >> $testroot/content.expected
843 echo "zeta" >> $testroot/content.expected
844 echo "delta" >> $testroot/content.expected
845 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
846 $testroot/wt
/gamma
/delta
> $testroot/content
848 cmp -s $testroot/content.expected
$testroot/content
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/content.expected
$testroot/content
853 test_done
"$testroot" "$ret"
857 run_test test_checkout_basic
858 run_test test_checkout_dir_exists
859 run_test test_checkout_dir_not_empty
860 run_test test_checkout_sets_xbit
861 run_test test_checkout_commit_from_wrong_branch
862 run_test test_checkout_tag
863 run_test test_checkout_ignores_submodules
864 run_test test_checkout_read_only
865 run_test test_checkout_into_nonempty_dir
866 run_test test_checkout_symlink
867 run_test test_checkout_symlink_relative_wtpath
868 run_test test_checkout_repo_with_unknown_extension
869 run_test test_checkout_quiet