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 -ne 0 ]; then
34 test_done
"$testroot" "$ret"
38 cmp -s $testroot/stdout.expected
$testroot/stdout
40 if [ $ret -ne 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 -ne 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 -ne 0 ]; then
78 test_done
"$testroot" "$ret"
82 cmp -s $testroot/stdout.expected
$testroot/stdout
84 if [ $ret -ne 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 -ne 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 -eq 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 -ne 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 -ne 0 ]; then
143 diff -u $testroot/stdout.expected
$testroot/stdout
145 test_done
"$testroot" "$ret"
149 test_checkout_into_repo
() {
150 local testroot
=`test_init checkout_into_repo`
151 local commit_id
=`git_show_head $testroot/repo`
153 got checkout
$testroot/repo
$testroot/repo
/wt \
154 > $testroot/stdout
2> $testroot/stderr
156 if [ $ret -eq 0 ]; then
157 echo "checkout succeeded unexpectedly" >&2
158 test_done
"$testroot" "1"
162 echo -n > $testroot/stdout.expected
164 cmp -s $testroot/stdout.expected
$testroot/stdout
166 if [ $ret -ne 0 ]; then
167 diff -u $testroot/stdout.expected
$testroot/stdout
168 test_done
"$testroot" "$ret"
172 echo -n "got: work tree and repository paths may not overlap: " \
173 > $testroot/stderr.expected
174 echo "$testroot/repo/wt: bad path" >> $testroot/stderr.expected
175 cmp -s $testroot/stderr.expected
$testroot/stderr
177 if [ $ret -ne 0 ]; then
178 diff -u $testroot/stderr.expected
$testroot/stderr
180 test_done
"$testroot" "$ret"
183 test_checkout_overlap_repo
() {
184 local testroot
=`test_init checkout_into_repo`
185 local commit_id
=`git_show_head $testroot/repo`
187 got checkout
$testroot/repo
$testroot \
188 > $testroot/stdout
2> $testroot/stderr
190 if [ $ret -eq 0 ]; then
191 echo "checkout succeeded unexpectedly" >&2
192 test_done
"$testroot" "1"
196 echo -n > $testroot/stdout.expected
198 cmp -s $testroot/stdout.expected
$testroot/stdout
200 if [ $ret -ne 0 ]; then
201 diff -u $testroot/stdout.expected
$testroot/stdout
202 test_done
"$testroot" "$ret"
206 echo -n "got: work tree and repository paths may not overlap: " \
207 > $testroot/stderr.expected
208 echo "$testroot: bad path" >> $testroot/stderr.expected
209 cmp -s $testroot/stderr.expected
$testroot/stderr
211 if [ $ret -ne 0 ]; then
212 diff -u $testroot/stderr.expected
$testroot/stderr
214 test_done
"$testroot" "$ret"
217 test_checkout_sets_xbit
() {
218 local testroot
=`test_init checkout_sets_xbit 1`
220 touch $testroot/repo
/xfile
221 chmod +x
$testroot/repo
/xfile
222 (cd $testroot/repo
&& git add .
)
223 git_commit
$testroot/repo
-m "adding executable file"
224 local commit_id
=`git_show_head $testroot/repo`
226 echo "A $testroot/wt/xfile" > $testroot/stdout.expected
227 echo "Checked out refs/heads/master: $commit_id" \
228 >> $testroot/stdout.expected
229 echo "Now shut up and hack" >> $testroot/stdout.expected
231 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
233 if [ $ret -ne 0 ]; then
234 test_done
"$testroot" "$ret"
238 cmp -s $testroot/stdout.expected
$testroot/stdout
240 if [ $ret -ne 0 ]; then
241 diff -u $testroot/stdout.expected
$testroot/stdout
242 test_done
"$testroot" "$ret"
246 ls -l $testroot/wt
/xfile |
grep -q '^-rwx'
248 if [ $ret -ne 0 ]; then
249 echo "file is not executable" >&2
250 ls -l $testroot/wt
/xfile
>&2
252 test_done
"$testroot" "$ret"
255 test_checkout_commit_from_wrong_branch
() {
256 local testroot
=`test_init checkout_commit_from_wrong_branch`
258 (cd $testroot/repo
&& git checkout
-q -b newbranch
)
259 echo "modified alpha on new branch" > $testroot/repo
/alpha
260 git_commit
$testroot/repo
-m "modified alpha on new branch"
262 local head_rev
=`git_show_head $testroot/repo`
263 got checkout
-b master
-c $head_rev $testroot/repo
$testroot/wt \
264 > $testroot/stdout
2> $testroot/stderr
266 if [ $ret -eq 0 ]; then
267 test_done
"$testroot" "1"
271 echo -n "" > $testroot/stdout.expected
272 cmp -s $testroot/stdout.expected
$testroot/stdout
274 if [ $ret -ne 0 ]; then
275 diff -u $testroot/stdout.expected
$testroot/stdout
276 test_done
"$testroot" "$ret"
280 echo -n "got: target commit is not contained in branch 'master'; " \
281 > $testroot/stderr.expected
282 echo -n "the branch to use must be specified with -b; if necessary " \
283 >> $testroot/stderr.expected
284 echo -n "a new branch can be created for this commit with "\
285 >> $testroot/stderr.expected
286 echo "'got branch -c $head_rev BRANCH_NAME'" \
287 >> $testroot/stderr.expected
288 cmp -s $testroot/stderr.expected
$testroot/stderr
290 if [ $ret -ne 0 ]; then
291 diff -u $testroot/stderr.expected
$testroot/stderr
292 test_done
"$testroot" "$ret"
296 test_done
"$testroot" "$ret"
299 test_checkout_tag
() {
300 local testroot
=`test_init checkout_tag`
301 local commit_id
=`git_show_head $testroot/repo`
304 (cd $testroot/repo
&& git tag
-a -m "test" $tag)
306 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
307 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
308 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
309 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
310 echo "Checked out refs/heads/master: $commit_id" \
311 >> $testroot/stdout.expected
312 echo "Now shut up and hack" >> $testroot/stdout.expected
314 got checkout
-c $tag $testroot/repo
$testroot/wt
> $testroot/stdout
316 if [ $ret -ne 0 ]; then
317 test_done
"$testroot" "$ret"
321 cmp -s $testroot/stdout.expected
$testroot/stdout
323 if [ $ret -ne 0 ]; then
324 diff -u $testroot/stdout.expected
$testroot/stdout
325 test_done
"$testroot" "$ret"
329 echo "alpha" > $testroot/content.expected
330 echo "beta" >> $testroot/content.expected
331 echo "zeta" >> $testroot/content.expected
332 echo "delta" >> $testroot/content.expected
333 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
334 $testroot/wt
/gamma
/delta
> $testroot/content
336 cmp -s $testroot/content.expected
$testroot/content
338 if [ $ret -ne 0 ]; then
339 diff -u $testroot/content.expected
$testroot/content
341 test_done
"$testroot" "$ret"
344 test_checkout_ignores_submodules
() {
345 local testroot
=`test_init checkout_ignores_submodules`
347 make_single_file_repo
$testroot/repo2 foo
349 (cd $testroot/repo
&& git
-c protocol.
file.allow
=always \
350 submodule
-q add ..
/repo2
)
351 (cd $testroot/repo
&& git commit
-q -m 'adding submodule')
352 local commit_id
=`git_show_head $testroot/repo`
354 echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
355 echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
356 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
357 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
358 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
359 echo "Checked out refs/heads/master: $commit_id" \
360 >> $testroot/stdout.expected
361 echo "Now shut up and hack" >> $testroot/stdout.expected
363 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
365 if [ $ret -ne 0 ]; then
366 test_done
"$testroot" "$ret"
370 cmp -s $testroot/stdout.expected
$testroot/stdout
372 if [ $ret -ne 0 ]; then
373 diff -u $testroot/stdout.expected
$testroot/stdout
374 test_done
"$testroot" "$ret"
378 echo "alpha" > $testroot/content.expected
379 echo "beta" >> $testroot/content.expected
380 echo "zeta" >> $testroot/content.expected
381 echo "delta" >> $testroot/content.expected
382 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
383 $testroot/wt
/gamma
/delta
> $testroot/content
385 cmp -s $testroot/content.expected
$testroot/content
387 if [ $ret -ne 0 ]; then
388 diff -u $testroot/content.expected
$testroot/content
390 test_done
"$testroot" "$ret"
393 test_checkout_read_only
() {
394 local testroot
=`test_init checkout_read_only`
395 local commit_id
=`git_show_head $testroot/repo`
397 # Make the repostiory read-only
398 chmod -R a-w
$testroot/repo
400 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
401 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
402 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
403 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
404 echo "Checked out refs/heads/master: $commit_id" \
405 >> $testroot/stdout.expected
406 echo "Now shut up and hack" >> $testroot/stdout.expected
408 got checkout
$testroot/repo
$testroot/wt \
409 > $testroot/stdout
2> $testroot/stderr
411 if [ $ret -ne 0 ]; then
412 test_done
"$testroot" "$ret"
416 cmp -s $testroot/stdout.expected
$testroot/stdout
418 if [ $ret -ne 0 ]; then
419 diff -u $testroot/stdout.expected
$testroot/stdout
420 test_done
"$testroot" "$ret"
424 echo -n "got: warning: could not create a reference " \
425 > $testroot/stderr.expected
426 echo -n "to the work tree's base commit; the commit could " \
427 >> $testroot/stderr.expected
428 echo -n "be garbage-collected by Git or 'gotadmin cleanup'; " \
429 >> $testroot/stderr.expected
430 echo -n "making the repository " >> $testroot/stderr.expected
431 echo "writable and running 'got update' will prevent this" \
432 >> $testroot/stderr.expected
433 cmp -s $testroot/stderr.expected
$testroot/stderr
435 if [ $ret -ne 0 ]; then
436 diff -u $testroot/stderr.expected
$testroot/stderr
437 test_done
"$testroot" "$ret"
441 echo "alpha" > $testroot/content.expected
442 echo "beta" >> $testroot/content.expected
443 echo "zeta" >> $testroot/content.expected
444 echo "delta" >> $testroot/content.expected
445 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
446 $testroot/wt
/gamma
/delta
> $testroot/content
448 cmp -s $testroot/content.expected
$testroot/content
450 if [ $ret -ne 0 ]; then
451 diff -u $testroot/content.expected
$testroot/content
453 chmod -R u
+w
$testroot/repo
# make repo cleanup work
454 test_done
"$testroot" "$ret"
457 test_checkout_into_nonempty_dir
() {
458 local testroot
=`test_init checkout_into_nonempty_dir`
459 local commit_id
=`git_show_head $testroot/repo`
461 mkdir
-p $testroot/wt
462 make_test_tree
$testroot/wt
464 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout \
467 if [ $ret -eq 0 ]; then
468 echo "checkout succeeded unexpectedly" >&2
469 test_done
"$testroot" "1"
473 echo -n > $testroot/stdout.expected
474 cmp -s $testroot/stdout.expected
$testroot/stdout
476 if [ $ret -ne 0 ]; then
477 diff -u $testroot/stdout.expected
$testroot/stdout
478 test_done
"$testroot" "$ret"
482 echo "got: $testroot/wt: directory exists and is not empty" \
483 > $testroot/stderr.expected
484 cmp -s $testroot/stderr.expected
$testroot/stderr
486 if [ $ret -ne 0 ]; then
487 diff -u $testroot/stderr.expected
$testroot/stderr
488 test_done
"$testroot" "$ret"
492 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
493 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
494 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
495 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
496 echo "Checked out refs/heads/master: $commit_id" \
497 >> $testroot/stdout.expected
498 echo "Now shut up and hack" >> $testroot/stdout.expected
500 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
502 if [ $ret -ne 0 ]; then
503 test_done
"$testroot" "$ret"
507 cmp -s $testroot/stdout.expected
$testroot/stdout
509 if [ $ret -ne 0 ]; then
510 diff -u $testroot/stdout.expected
$testroot/stdout
511 test_done
"$testroot" "$ret"
515 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
516 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
517 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
518 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
519 echo "Checked out refs/heads/master: $commit_id" \
520 >> $testroot/stdout.expected
521 echo "Now shut up and hack" >> $testroot/stdout.expected
523 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
525 if [ $ret -ne 0 ]; then
526 test_done
"$testroot" "$ret"
530 cmp -s $testroot/stdout.expected
$testroot/stdout
532 if [ $ret -ne 0 ]; then
533 diff -u $testroot/stdout.expected
$testroot/stdout
534 test_done
"$testroot" "$ret"
538 echo "alpha" > $testroot/content.expected
539 echo "beta" >> $testroot/content.expected
540 echo "zeta" >> $testroot/content.expected
541 echo "delta" >> $testroot/content.expected
542 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
543 $testroot/wt
/gamma
/delta
> $testroot/content
545 cmp -s $testroot/content.expected
$testroot/content
547 if [ $ret -ne 0 ]; then
548 diff -u $testroot/content.expected
$testroot/content
549 test_done
"$testroot" "$ret"
553 # retry, but with alpha modified
555 rm -rf "$testroot/wt/.got"
556 echo modified alpha
>$testroot/wt
/alpha
558 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
559 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
560 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
561 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
562 echo "Checked out refs/heads/master: $commit_id" \
563 >> $testroot/stdout.expected
564 echo "Now shut up and hack" >> $testroot/stdout.expected
566 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
568 if [ $ret -ne 0 ]; then
569 test_done
"$testroot" "$ret"
573 cmp -s $testroot/stdout.expected
$testroot/stdout
575 if [ $ret -ne 0 ]; then
576 diff -u $testroot/stdout.expected
$testroot/stdout
577 test_done
"$testroot" "$ret"
581 echo "modified alpha" > $testroot/content.expected
582 echo "beta" >> $testroot/content.expected
583 echo "zeta" >> $testroot/content.expected
584 echo "delta" >> $testroot/content.expected
585 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
586 $testroot/wt
/gamma
/delta
> $testroot/content
588 cmp -s $testroot/content.expected
$testroot/content
590 if [ $ret -ne 0 ]; then
591 diff -u $testroot/content.expected
$testroot/content
592 test_done
"$testroot" "$ret"
596 echo 'M alpha' > $testroot/stdout.expected
597 (cd $testroot/wt
&& got status
> $testroot/stdout
)
599 cmp -s $testroot/stdout.expected
$testroot/stdout
601 if [ $ret -ne 0 ]; then
602 diff -u $testroot/stdout.expected
$testroot/stdout
604 test_done
"$testroot" "$ret"
607 test_checkout_symlink
() {
608 local testroot
=`test_init checkout_symlink`
610 (cd $testroot/repo
&& ln -s alpha alpha.link
)
611 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
612 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
613 (cd $testroot/repo
&& ln -s passwd.link passwd2.link
)
614 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
615 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
616 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
617 (cd $testroot/repo
&& git add .
)
618 git_commit
$testroot/repo
-m "add symlinks"
619 local commit_id
=`git_show_head $testroot/repo`
621 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
623 if [ $ret -ne 0 ]; then
624 echo "got checkout failed unexpectedly" >&2
625 test_done
"$testroot" "$ret"
629 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
630 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
631 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
632 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
633 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
634 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
635 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
636 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
637 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
638 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
639 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
640 echo "Checked out refs/heads/master: $commit_id" \
641 >> $testroot/stdout.expected
642 echo "Now shut up and hack" >> $testroot/stdout.expected
644 cmp -s $testroot/stdout.expected
$testroot/stdout
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stdout.expected
$testroot/stdout
648 test_done
"$testroot" "$ret"
652 if ! [ -h $testroot/wt
/alpha.link
]; then
653 echo "alpha.link is not a symlink"
654 test_done
"$testroot" "1"
658 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
659 echo "alpha" > $testroot/stdout.expected
660 cmp -s $testroot/stdout.expected
$testroot/stdout
662 if [ $ret -ne 0 ]; then
663 diff -u $testroot/stdout.expected
$testroot/stdout
664 test_done
"$testroot" "$ret"
668 if ! [ -h $testroot/wt
/epsilon.link
]; then
669 echo "epsilon.link is not a symlink"
670 test_done
"$testroot" "1"
674 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
675 echo "epsilon" > $testroot/stdout.expected
676 cmp -s $testroot/stdout.expected
$testroot/stdout
678 if [ $ret -ne 0 ]; then
679 diff -u $testroot/stdout.expected
$testroot/stdout
680 test_done
"$testroot" "$ret"
684 if [ -h $testroot/wt
/passwd.link
]; then
685 echo -n "passwd.link symlink points outside of work tree: " >&2
686 readlink
$testroot/wt
/passwd.link
>&2
687 test_done
"$testroot" "1"
691 echo -n "/etc/passwd" > $testroot/content.expected
692 cp $testroot/wt
/passwd.link
$testroot/content
694 cmp -s $testroot/content.expected
$testroot/content
696 if [ $ret -ne 0 ]; then
697 diff -u $testroot/content.expected
$testroot/content
698 test_done
"$testroot" "$ret"
702 if ! [ -h $testroot/wt
/passwd2.link
]; then
703 echo "passwd2.link is not a symlink"
704 test_done
"$testroot" "1"
708 readlink
$testroot/wt
/passwd2.link
> $testroot/stdout
709 echo "passwd.link" > $testroot/stdout.expected
710 cmp -s $testroot/stdout.expected
$testroot/stdout
712 if [ $ret -ne 0 ]; then
713 diff -u $testroot/stdout.expected
$testroot/stdout
714 test_done
"$testroot" "$ret"
718 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
719 echo "../beta" > $testroot/stdout.expected
720 cmp -s $testroot/stdout.expected
$testroot/stdout
722 if [ $ret -ne 0 ]; then
723 diff -u $testroot/stdout.expected
$testroot/stdout
724 test_done
"$testroot" "$ret"
728 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
729 echo "nonexistent" > $testroot/stdout.expected
730 cmp -s $testroot/stdout.expected
$testroot/stdout
732 if [ $ret -ne 0 ]; then
733 diff -u $testroot/stdout.expected
$testroot/stdout
734 test_done
"$testroot" "$ret"
738 if [ -h $testroot/wt
/dotgotfoo.link
]; then
739 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
740 readlink
$testroot/wt
/dotgotfoo.link
>&2
741 test_done
"$testroot" "1"
745 echo -n ".got/foo" > $testroot/content.expected
746 cp $testroot/wt
/dotgotfoo.link
$testroot/content
748 cmp -s $testroot/content.expected
$testroot/content
750 if [ $ret -ne 0 ]; then
751 diff -u $testroot/content.expected
$testroot/content
753 test_done
"$testroot" "$ret"
756 test_checkout_symlink_relative_wtpath
() {
757 local testroot
=`test_init checkout_symlink_with_wtpath`
759 (cd $testroot/repo
&& ln -s alpha alpha.link
)
760 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
761 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
762 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
763 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
764 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
765 (cd $testroot/repo
&& git add .
)
766 git_commit
$testroot/repo
-m "add symlinks"
768 (cd $testroot && got checkout
$testroot/repo wt
> /dev
/null
)
770 if [ $ret -ne 0 ]; then
771 test_done
"$testroot" "$ret"
775 if ! [ -h $testroot/wt
/alpha.link
]; then
776 echo "alpha.link is not a symlink"
777 test_done
"$testroot" "1"
781 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
782 echo "alpha" > $testroot/stdout.expected
783 cmp -s $testroot/stdout.expected
$testroot/stdout
785 if [ $ret -ne 0 ]; then
786 diff -u $testroot/stdout.expected
$testroot/stdout
787 test_done
"$testroot" "$ret"
791 if ! [ -h $testroot/wt
/epsilon.link
]; then
792 echo "epsilon.link is not a symlink"
793 test_done
"$testroot" "1"
797 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
798 echo "epsilon" > $testroot/stdout.expected
799 cmp -s $testroot/stdout.expected
$testroot/stdout
801 if [ $ret -ne 0 ]; then
802 diff -u $testroot/stdout.expected
$testroot/stdout
803 test_done
"$testroot" "$ret"
807 if [ -h $testroot/wt
/passwd.link
]; then
808 echo -n "passwd.link symlink points outside of work tree: " >&2
809 readlink
$testroot/wt
/passwd.link
>&2
810 test_done
"$testroot" "1"
814 echo -n "/etc/passwd" > $testroot/content.expected
815 cp $testroot/wt
/passwd.link
$testroot/content
817 cmp -s $testroot/content.expected
$testroot/content
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/content.expected
$testroot/content
821 test_done
"$testroot" "$ret"
825 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
826 echo "../beta" > $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected
$testroot/stdout
829 if [ $ret -ne 0 ]; then
830 diff -u $testroot/stdout.expected
$testroot/stdout
831 test_done
"$testroot" "$ret"
835 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
836 echo "nonexistent" > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected
$testroot/stdout
839 if [ $ret -ne 0 ]; then
840 diff -u $testroot/stdout.expected
$testroot/stdout
841 test_done
"$testroot" "$ret"
845 if [ -h $testroot/wt
/dotgotfoo.link
]; then
846 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
847 readlink
$testroot/wt
/dotgotfoo.link
>&2
848 test_done
"$testroot" "1"
852 echo -n ".got/foo" > $testroot/content.expected
853 cp $testroot/wt
/dotgotfoo.link
$testroot/content
855 cmp -s $testroot/content.expected
$testroot/content
857 if [ $ret -ne 0 ]; then
858 diff -u $testroot/content.expected
$testroot/content
860 test_done
"$testroot" "$ret"
863 test_checkout_repo_with_unknown_extension
() {
864 local testroot
=`test_init checkout_repo_with_unknown_extension`
866 (cd $testroot/repo
&&
867 git config
--add extensions.badExtension foobar
)
868 (cd $testroot/repo
&&
869 git config
--add extensions.otherBadExtension
0)
871 echo "got: badExtension: unsupported repository format extension" \
872 > $testroot/stderr.expected
873 got checkout
$testroot/repo
$testroot/wt \
874 > $testroot/stdout
2> $testroot/stderr
877 if [ $ret -eq 0 ]; then
878 echo "got checkout command succeeded unexpectedly" >&2
879 test_done
"$testroot" "1"
883 cmp -s $testroot/stderr.expected
$testroot/stderr
885 if [ $ret -ne 0 ]; then
886 diff -u $testroot/stderr.expected
$testroot/stderr
888 test_done
"$testroot" "$ret"
891 test_checkout_quiet
() {
892 local testroot
=`test_init checkout_quiet`
894 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
895 git_show_head
$testroot/repo
>> $testroot/stdout.expected
896 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
898 got checkout
-q $testroot/repo
$testroot/wt
> $testroot/stdout
900 if [ $ret -ne 0 ]; then
901 test_done
"$testroot" "$ret"
905 cmp -s $testroot/stdout.expected
$testroot/stdout
907 if [ $ret -ne 0 ]; then
908 diff -u $testroot/stdout.expected
$testroot/stdout
909 test_done
"$testroot" "$ret"
913 echo "alpha" > $testroot/content.expected
914 echo "beta" >> $testroot/content.expected
915 echo "zeta" >> $testroot/content.expected
916 echo "delta" >> $testroot/content.expected
917 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
918 $testroot/wt
/gamma
/delta
> $testroot/content
920 cmp -s $testroot/content.expected
$testroot/content
922 if [ $ret -ne 0 ]; then
923 diff -u $testroot/content.expected
$testroot/content
925 test_done
"$testroot" "$ret"
928 test_checkout_umask
() {
929 local testroot
=`test_init checkout_umask`
931 # using a subshell to avoid clobbering global umask
932 (umask 044 && got checkout
"$testroot/repo" "$testroot/wt") \
935 if [ $ret -ne 0 ]; then
936 test_done
"$testroot" $ret
940 for f
in alpha beta epsilon
/zeta gamma
/delta
; do
941 ls -l "$testroot/wt/$f" |
grep -q ^
-rw-------
942 if [ $?
-ne 0 ]; then
943 echo "$f is not 0600 after checkout" >&2
944 ls -l "$testroot/wt/$f" >&2
945 test_done
"$testroot" 1
950 for d
in epsilon gamma
; do
951 ls -ld "$testroot/wt/$d" |
grep -q ^drwx--x--x
952 if [ $?
-ne 0 ]; then
953 echo "$d is not 711 after checkout" >&2
954 ls -ld "$testroot/wt/$d" >&2
955 test_done
"$testroot" 1
960 test_done
"$testroot" 0
963 test_checkout_ulimit_n
() {
964 local testroot
=`test_init checkout_ulimit_n`
966 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
967 git_show_head
$testroot/repo
>> $testroot/stdout.expected
968 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
970 # Drastically reduce the number of files we are allowed to use.
971 # This tests our down-scaling of caches which store open file handles.
972 # Checkout should still work; if it does not, then either there is
973 # a bug or the fixed limit used by this test case is no longer valid
974 # and must be raised. Use a subshell to avoid changing global ulimit.
975 (ulimit -n 33; got checkout
-q $testroot/repo
$testroot/wt \
978 if [ $ret -ne 0 ]; then
979 test_done
"$testroot" "$ret"
983 cmp -s $testroot/stdout.expected
$testroot/stdout
985 if [ $ret -ne 0 ]; then
986 diff -u $testroot/stdout.expected
$testroot/stdout
987 test_done
"$testroot" "$ret"
991 echo "alpha" > $testroot/content.expected
992 echo "beta" >> $testroot/content.expected
993 echo "zeta" >> $testroot/content.expected
994 echo "delta" >> $testroot/content.expected
995 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
996 $testroot/wt
/gamma
/delta
> $testroot/content
998 cmp -s $testroot/content.expected
$testroot/content
1000 if [ $ret -ne 0 ]; then
1001 diff -u $testroot/content.expected
$testroot/content
1003 test_done
"$testroot" "$ret"
1006 test_checkout_commit_keywords
() {
1007 local testroot
=$
(test_init checkout_commit_keywords
)
1009 set -- "$(git_show_head $testroot/repo)"
1011 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1013 if [ $ret -ne 0 ]; then
1014 echo "checkout failed unexpectedly" >&2
1015 test_done
"$testroot" "$ret"
1019 for i
in $
(seq 4); do
1020 echo "zeta change $i" > "$testroot/wt/epsilon/zeta"
1022 (cd "$testroot/wt" && got ci
-m "commit number $i" > /dev
/null
)
1024 if [ $ret -ne 0 ]; then
1025 echo "commit failed unexpectedly" >&2
1026 test_done
"$testroot" "$ret"
1029 set -- "$@" "$(git_show_head $testroot/repo)"
1032 echo "A $testroot/wt2/alpha" > $testroot/stdout.expected
1033 echo "A $testroot/wt2/beta" >> $testroot/stdout.expected
1034 echo "A $testroot/wt2/epsilon/zeta" >> $testroot/stdout.expected
1035 echo "A $testroot/wt2/gamma/delta" >> $testroot/stdout.expected
1036 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1037 >> $testroot/stdout.expected
1038 echo "Now shut up and hack" >> $testroot/stdout.expected
1040 got co
-c :head:- $testroot/repo
$testroot/wt2
> $testroot/stdout
1042 if [ $ret -ne 0 ]; then
1043 test_done
"$testroot" "$ret"
1047 cmp -s $testroot/stdout.expected
$testroot/stdout
1049 if [ $ret -ne 0 ]; then
1050 diff -u $testroot/stdout.expected
$testroot/stdout
1051 test_done
"$testroot" "$ret"
1055 echo "A $testroot/wt3/alpha" > $testroot/stdout.expected
1056 echo "A $testroot/wt3/beta" >> $testroot/stdout.expected
1057 echo "A $testroot/wt3/epsilon/zeta" >> $testroot/stdout.expected
1058 echo "A $testroot/wt3/gamma/delta" >> $testroot/stdout.expected
1059 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1060 >> $testroot/stdout.expected
1061 echo "Now shut up and hack" >> $testroot/stdout.expected
1063 got co
-bmaster -c:base
:- $testroot/repo
$testroot/wt3
> \
1066 if [ $ret -ne 0 ]; then
1067 test_done
"$testroot" "$ret"
1071 cmp -s $testroot/stdout.expected
$testroot/stdout
1073 if [ $ret -ne 0 ]; then
1074 diff -u $testroot/stdout.expected
$testroot/stdout
1077 test_done
"$testroot" "$ret"
1081 run_test test_checkout_basic
1082 run_test test_checkout_dir_exists
1083 run_test test_checkout_dir_not_empty
1084 run_test test_checkout_into_repo
1085 run_test test_checkout_overlap_repo
1086 run_test test_checkout_sets_xbit
1087 run_test test_checkout_commit_from_wrong_branch
1088 run_test test_checkout_tag
1089 run_test test_checkout_ignores_submodules
1090 run_test test_checkout_read_only
1091 run_test test_checkout_into_nonempty_dir
1092 run_test test_checkout_symlink
1093 run_test test_checkout_symlink_relative_wtpath
1094 run_test test_checkout_repo_with_unknown_extension
1095 run_test test_checkout_quiet
1096 run_test test_checkout_umask
1097 run_test test_checkout_ulimit_n
1098 run_test test_checkout_commit_keywords