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 "? $testroot/wt/alpha" > $testroot/stdout.expected
493 echo "? $testroot/wt/beta" >> $testroot/stdout.expected
494 echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
495 echo "? $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 echo "modified alpha" > $testroot/wt
/alpha
555 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
556 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
557 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
558 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
559 echo "Checked out refs/heads/master: $commit_id" \
560 >> $testroot/stdout.expected
561 echo "Now shut up and hack" >> $testroot/stdout.expected
563 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
565 if [ $ret -ne 0 ]; then
566 test_done
"$testroot" "$ret"
570 cmp -s $testroot/stdout.expected
$testroot/stdout
572 if [ $ret -ne 0 ]; then
573 diff -u $testroot/stdout.expected
$testroot/stdout
574 test_done
"$testroot" "$ret"
578 echo "modified alpha" > $testroot/content.expected
579 echo "beta" >> $testroot/content.expected
580 echo "zeta" >> $testroot/content.expected
581 echo "delta" >> $testroot/content.expected
582 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
583 $testroot/wt
/gamma
/delta
> $testroot/content
585 cmp -s $testroot/content.expected
$testroot/content
587 if [ $ret -ne 0 ]; then
588 diff -u $testroot/content.expected
$testroot/content
589 test_done
"$testroot" "$ret"
593 echo 'M alpha' > $testroot/stdout.expected
594 (cd $testroot/wt
&& got status
> $testroot/stdout
)
596 cmp -s $testroot/stdout.expected
$testroot/stdout
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected
$testroot/stdout
601 test_done
"$testroot" "$ret"
604 test_checkout_symlink
() {
605 local testroot
=`test_init checkout_symlink`
607 (cd $testroot/repo
&& ln -s alpha alpha.link
)
608 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
609 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
610 (cd $testroot/repo
&& ln -s passwd.link passwd2.link
)
611 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
612 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
613 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
614 (cd $testroot/repo
&& git add .
)
615 git_commit
$testroot/repo
-m "add symlinks"
616 local commit_id
=`git_show_head $testroot/repo`
618 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
620 if [ $ret -ne 0 ]; then
621 echo "got checkout failed unexpectedly" >&2
622 test_done
"$testroot" "$ret"
626 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
627 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
628 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
629 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
630 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
631 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
632 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
633 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
634 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
635 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
636 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
637 echo "Checked out refs/heads/master: $commit_id" \
638 >> $testroot/stdout.expected
639 echo "Now shut up and hack" >> $testroot/stdout.expected
641 cmp -s $testroot/stdout.expected
$testroot/stdout
643 if [ $ret -ne 0 ]; then
644 diff -u $testroot/stdout.expected
$testroot/stdout
645 test_done
"$testroot" "$ret"
649 if ! [ -h $testroot/wt
/alpha.link
]; then
650 echo "alpha.link is not a symlink"
651 test_done
"$testroot" "1"
655 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
656 echo "alpha" > $testroot/stdout.expected
657 cmp -s $testroot/stdout.expected
$testroot/stdout
659 if [ $ret -ne 0 ]; then
660 diff -u $testroot/stdout.expected
$testroot/stdout
661 test_done
"$testroot" "$ret"
665 if ! [ -h $testroot/wt
/epsilon.link
]; then
666 echo "epsilon.link is not a symlink"
667 test_done
"$testroot" "1"
671 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
672 echo "epsilon" > $testroot/stdout.expected
673 cmp -s $testroot/stdout.expected
$testroot/stdout
675 if [ $ret -ne 0 ]; then
676 diff -u $testroot/stdout.expected
$testroot/stdout
677 test_done
"$testroot" "$ret"
681 if [ -h $testroot/wt
/passwd.link
]; then
682 echo -n "passwd.link symlink points outside of work tree: " >&2
683 readlink
$testroot/wt
/passwd.link
>&2
684 test_done
"$testroot" "1"
688 echo -n "/etc/passwd" > $testroot/content.expected
689 cp $testroot/wt
/passwd.link
$testroot/content
691 cmp -s $testroot/content.expected
$testroot/content
693 if [ $ret -ne 0 ]; then
694 diff -u $testroot/content.expected
$testroot/content
695 test_done
"$testroot" "$ret"
699 if ! [ -h $testroot/wt
/passwd2.link
]; then
700 echo "passwd2.link is not a symlink"
701 test_done
"$testroot" "1"
705 readlink
$testroot/wt
/passwd2.link
> $testroot/stdout
706 echo "passwd.link" > $testroot/stdout.expected
707 cmp -s $testroot/stdout.expected
$testroot/stdout
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected
$testroot/stdout
711 test_done
"$testroot" "$ret"
715 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
716 echo "../beta" > $testroot/stdout.expected
717 cmp -s $testroot/stdout.expected
$testroot/stdout
719 if [ $ret -ne 0 ]; then
720 diff -u $testroot/stdout.expected
$testroot/stdout
721 test_done
"$testroot" "$ret"
725 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
726 echo "nonexistent" > $testroot/stdout.expected
727 cmp -s $testroot/stdout.expected
$testroot/stdout
729 if [ $ret -ne 0 ]; then
730 diff -u $testroot/stdout.expected
$testroot/stdout
731 test_done
"$testroot" "$ret"
735 if [ -h $testroot/wt
/dotgotfoo.link
]; then
736 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
737 readlink
$testroot/wt
/dotgotfoo.link
>&2
738 test_done
"$testroot" "1"
742 echo -n ".got/foo" > $testroot/content.expected
743 cp $testroot/wt
/dotgotfoo.link
$testroot/content
745 cmp -s $testroot/content.expected
$testroot/content
747 if [ $ret -ne 0 ]; then
748 diff -u $testroot/content.expected
$testroot/content
750 test_done
"$testroot" "$ret"
753 test_checkout_symlink_relative_wtpath
() {
754 local testroot
=`test_init checkout_symlink_with_wtpath`
756 (cd $testroot/repo
&& ln -s alpha alpha.link
)
757 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
758 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
759 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
760 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
761 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
762 (cd $testroot/repo
&& git add .
)
763 git_commit
$testroot/repo
-m "add symlinks"
765 (cd $testroot && got checkout
$testroot/repo wt
> /dev
/null
)
767 if [ $ret -ne 0 ]; then
768 test_done
"$testroot" "$ret"
772 if ! [ -h $testroot/wt
/alpha.link
]; then
773 echo "alpha.link is not a symlink"
774 test_done
"$testroot" "1"
778 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
779 echo "alpha" > $testroot/stdout.expected
780 cmp -s $testroot/stdout.expected
$testroot/stdout
782 if [ $ret -ne 0 ]; then
783 diff -u $testroot/stdout.expected
$testroot/stdout
784 test_done
"$testroot" "$ret"
788 if ! [ -h $testroot/wt
/epsilon.link
]; then
789 echo "epsilon.link is not a symlink"
790 test_done
"$testroot" "1"
794 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
795 echo "epsilon" > $testroot/stdout.expected
796 cmp -s $testroot/stdout.expected
$testroot/stdout
798 if [ $ret -ne 0 ]; then
799 diff -u $testroot/stdout.expected
$testroot/stdout
800 test_done
"$testroot" "$ret"
804 if [ -h $testroot/wt
/passwd.link
]; then
805 echo -n "passwd.link symlink points outside of work tree: " >&2
806 readlink
$testroot/wt
/passwd.link
>&2
807 test_done
"$testroot" "1"
811 echo -n "/etc/passwd" > $testroot/content.expected
812 cp $testroot/wt
/passwd.link
$testroot/content
814 cmp -s $testroot/content.expected
$testroot/content
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/content.expected
$testroot/content
818 test_done
"$testroot" "$ret"
822 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
823 echo "../beta" > $testroot/stdout.expected
824 cmp -s $testroot/stdout.expected
$testroot/stdout
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/stdout.expected
$testroot/stdout
828 test_done
"$testroot" "$ret"
832 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
833 echo "nonexistent" > $testroot/stdout.expected
834 cmp -s $testroot/stdout.expected
$testroot/stdout
836 if [ $ret -ne 0 ]; then
837 diff -u $testroot/stdout.expected
$testroot/stdout
838 test_done
"$testroot" "$ret"
842 if [ -h $testroot/wt
/dotgotfoo.link
]; then
843 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
844 readlink
$testroot/wt
/dotgotfoo.link
>&2
845 test_done
"$testroot" "1"
849 echo -n ".got/foo" > $testroot/content.expected
850 cp $testroot/wt
/dotgotfoo.link
$testroot/content
852 cmp -s $testroot/content.expected
$testroot/content
854 if [ $ret -ne 0 ]; then
855 diff -u $testroot/content.expected
$testroot/content
857 test_done
"$testroot" "$ret"
860 test_checkout_repo_with_unknown_extension
() {
861 local testroot
=`test_init checkout_repo_with_unknown_extension`
863 (cd $testroot/repo
&&
864 git config
--add extensions.badExtension foobar
)
865 (cd $testroot/repo
&&
866 git config
--add extensions.otherBadExtension
0)
868 echo "got: badExtension: unsupported repository format extension" \
869 > $testroot/stderr.expected
870 got checkout
$testroot/repo
$testroot/wt \
871 > $testroot/stdout
2> $testroot/stderr
874 if [ $ret -eq 0 ]; then
875 echo "got checkout command succeeded unexpectedly" >&2
876 test_done
"$testroot" "1"
880 cmp -s $testroot/stderr.expected
$testroot/stderr
882 if [ $ret -ne 0 ]; then
883 diff -u $testroot/stderr.expected
$testroot/stderr
885 test_done
"$testroot" "$ret"
888 test_checkout_quiet
() {
889 local testroot
=`test_init checkout_quiet`
891 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
892 git_show_head
$testroot/repo
>> $testroot/stdout.expected
893 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
895 got checkout
-q $testroot/repo
$testroot/wt
> $testroot/stdout
897 if [ $ret -ne 0 ]; then
898 test_done
"$testroot" "$ret"
902 cmp -s $testroot/stdout.expected
$testroot/stdout
904 if [ $ret -ne 0 ]; then
905 diff -u $testroot/stdout.expected
$testroot/stdout
906 test_done
"$testroot" "$ret"
910 echo "alpha" > $testroot/content.expected
911 echo "beta" >> $testroot/content.expected
912 echo "zeta" >> $testroot/content.expected
913 echo "delta" >> $testroot/content.expected
914 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
915 $testroot/wt
/gamma
/delta
> $testroot/content
917 cmp -s $testroot/content.expected
$testroot/content
919 if [ $ret -ne 0 ]; then
920 diff -u $testroot/content.expected
$testroot/content
922 test_done
"$testroot" "$ret"
925 test_checkout_umask
() {
926 local testroot
=`test_init checkout_umask`
928 # using a subshell to avoid clobbering global umask
929 (umask 044 && got checkout
"$testroot/repo" "$testroot/wt") \
932 if [ $ret -ne 0 ]; then
933 test_done
"$testroot" $ret
937 for f
in alpha beta epsilon
/zeta gamma
/delta
; do
938 ls -l "$testroot/wt/$f" |
grep -q ^
-rw-------
939 if [ $?
-ne 0 ]; then
940 echo "$f is not 0600 after checkout" >&2
941 ls -l "$testroot/wt/$f" >&2
942 test_done
"$testroot" 1
947 for d
in epsilon gamma
; do
948 ls -ld "$testroot/wt/$d" |
grep -q ^drwx--x--x
949 if [ $?
-ne 0 ]; then
950 echo "$d is not 711 after checkout" >&2
951 ls -ld "$testroot/wt/$d" >&2
952 test_done
"$testroot" 1
957 test_done
"$testroot" 0
960 test_checkout_ulimit_n
() {
961 local testroot
=`test_init checkout_ulimit_n`
963 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
964 git_show_head
$testroot/repo
>> $testroot/stdout.expected
965 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
967 # Drastically reduce the number of files we are allowed to use.
968 # This tests our down-scaling of caches which store open file handles.
969 # Checkout should still work; if it does not, then either there is
970 # a bug or the fixed limit used by this test case is no longer valid
971 # and must be raised. Use a subshell to avoid changing global ulimit.
972 (ulimit -n 33; got checkout
-q $testroot/repo
$testroot/wt \
975 if [ $ret -ne 0 ]; then
976 test_done
"$testroot" "$ret"
980 cmp -s $testroot/stdout.expected
$testroot/stdout
982 if [ $ret -ne 0 ]; then
983 diff -u $testroot/stdout.expected
$testroot/stdout
984 test_done
"$testroot" "$ret"
988 echo "alpha" > $testroot/content.expected
989 echo "beta" >> $testroot/content.expected
990 echo "zeta" >> $testroot/content.expected
991 echo "delta" >> $testroot/content.expected
992 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
993 $testroot/wt
/gamma
/delta
> $testroot/content
995 cmp -s $testroot/content.expected
$testroot/content
997 if [ $ret -ne 0 ]; then
998 diff -u $testroot/content.expected
$testroot/content
1000 test_done
"$testroot" "$ret"
1003 test_checkout_commit_keywords
() {
1004 local testroot
=$
(test_init checkout_commit_keywords
)
1006 set -- "$(git_show_head $testroot/repo)"
1008 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
1010 if [ $ret -ne 0 ]; then
1011 echo "checkout failed unexpectedly" >&2
1012 test_done
"$testroot" "$ret"
1016 for i
in $
(seq 4); do
1017 echo "zeta change $i" > "$testroot/wt/epsilon/zeta"
1019 (cd "$testroot/wt" && got ci
-m "commit number $i" > /dev
/null
)
1021 if [ $ret -ne 0 ]; then
1022 echo "commit failed unexpectedly" >&2
1023 test_done
"$testroot" "$ret"
1026 set -- "$@" "$(git_show_head $testroot/repo)"
1029 echo "A $testroot/wt2/alpha" > $testroot/stdout.expected
1030 echo "A $testroot/wt2/beta" >> $testroot/stdout.expected
1031 echo "A $testroot/wt2/epsilon/zeta" >> $testroot/stdout.expected
1032 echo "A $testroot/wt2/gamma/delta" >> $testroot/stdout.expected
1033 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1034 >> $testroot/stdout.expected
1035 echo "Now shut up and hack" >> $testroot/stdout.expected
1037 got co
-c :head:- $testroot/repo
$testroot/wt2
> $testroot/stdout
1039 if [ $ret -ne 0 ]; then
1040 test_done
"$testroot" "$ret"
1044 cmp -s $testroot/stdout.expected
$testroot/stdout
1046 if [ $ret -ne 0 ]; then
1047 diff -u $testroot/stdout.expected
$testroot/stdout
1048 test_done
"$testroot" "$ret"
1052 echo "A $testroot/wt3/alpha" > $testroot/stdout.expected
1053 echo "A $testroot/wt3/beta" >> $testroot/stdout.expected
1054 echo "A $testroot/wt3/epsilon/zeta" >> $testroot/stdout.expected
1055 echo "A $testroot/wt3/gamma/delta" >> $testroot/stdout.expected
1056 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1057 >> $testroot/stdout.expected
1058 echo "Now shut up and hack" >> $testroot/stdout.expected
1060 got co
-bmaster -c:base
:- $testroot/repo
$testroot/wt3
> \
1063 if [ $ret -ne 0 ]; then
1064 test_done
"$testroot" "$ret"
1068 cmp -s $testroot/stdout.expected
$testroot/stdout
1070 if [ $ret -ne 0 ]; then
1071 diff -u $testroot/stdout.expected
$testroot/stdout
1074 test_done
"$testroot" "$ret"
1078 run_test test_checkout_basic
1079 run_test test_checkout_dir_exists
1080 run_test test_checkout_dir_not_empty
1081 run_test test_checkout_into_repo
1082 run_test test_checkout_overlap_repo
1083 run_test test_checkout_sets_xbit
1084 run_test test_checkout_commit_from_wrong_branch
1085 run_test test_checkout_tag
1086 run_test test_checkout_ignores_submodules
1087 run_test test_checkout_read_only
1088 run_test test_checkout_into_nonempty_dir
1089 run_test test_checkout_symlink
1090 run_test test_checkout_symlink_relative_wtpath
1091 run_test test_checkout_repo_with_unknown_extension
1092 run_test test_checkout_quiet
1093 run_test test_checkout_umask
1094 run_test test_checkout_ulimit_n
1095 run_test test_checkout_commit_keywords