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_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 -ne 0 ]; then
166 test_done
"$testroot" "$ret"
170 cmp -s $testroot/stdout.expected
$testroot/stdout
172 if [ $ret -ne 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 -ne 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 -eq 0 ]; then
199 test_done
"$testroot" "1"
203 echo -n "" > $testroot/stdout.expected
204 cmp -s $testroot/stdout.expected
$testroot/stdout
206 if [ $ret -ne 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 -ne 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 -ne 0 ]; then
249 test_done
"$testroot" "$ret"
253 cmp -s $testroot/stdout.expected
$testroot/stdout
255 if [ $ret -ne 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 -ne 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
-c protocol.
file.allow
=always \
282 submodule
-q add ..
/repo2
)
283 (cd $testroot/repo
&& git commit
-q -m 'adding submodule')
284 local commit_id
=`git_show_head $testroot/repo`
286 echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
287 echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
288 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
289 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
290 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
291 echo "Checked out refs/heads/master: $commit_id" \
292 >> $testroot/stdout.expected
293 echo "Now shut up and hack" >> $testroot/stdout.expected
295 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
297 if [ $ret -ne 0 ]; then
298 test_done
"$testroot" "$ret"
302 cmp -s $testroot/stdout.expected
$testroot/stdout
304 if [ $ret -ne 0 ]; then
305 diff -u $testroot/stdout.expected
$testroot/stdout
306 test_done
"$testroot" "$ret"
310 echo "alpha" > $testroot/content.expected
311 echo "beta" >> $testroot/content.expected
312 echo "zeta" >> $testroot/content.expected
313 echo "delta" >> $testroot/content.expected
314 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
315 $testroot/wt
/gamma
/delta
> $testroot/content
317 cmp -s $testroot/content.expected
$testroot/content
319 if [ $ret -ne 0 ]; then
320 diff -u $testroot/content.expected
$testroot/content
322 test_done
"$testroot" "$ret"
325 test_checkout_read_only
() {
326 local testroot
=`test_init checkout_read_only`
327 local commit_id
=`git_show_head $testroot/repo`
329 # Make the repostiory read-only
330 chmod -R a-w
$testroot/repo
332 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
333 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
334 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
335 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
336 echo "Checked out refs/heads/master: $commit_id" \
337 >> $testroot/stdout.expected
338 echo "Now shut up and hack" >> $testroot/stdout.expected
340 got checkout
$testroot/repo
$testroot/wt \
341 > $testroot/stdout
2> $testroot/stderr
343 if [ $ret -ne 0 ]; then
344 test_done
"$testroot" "$ret"
348 cmp -s $testroot/stdout.expected
$testroot/stdout
350 if [ $ret -ne 0 ]; then
351 diff -u $testroot/stdout.expected
$testroot/stdout
352 test_done
"$testroot" "$ret"
356 echo -n "got: warning: could not create a reference " \
357 > $testroot/stderr.expected
358 echo -n "to the work tree's base commit; the commit could " \
359 >> $testroot/stderr.expected
360 echo -n "be garbage-collected by Git or 'gotadmin cleanup'; " \
361 >> $testroot/stderr.expected
362 echo -n "making the repository " >> $testroot/stderr.expected
363 echo "writable and running 'got update' will prevent this" \
364 >> $testroot/stderr.expected
365 cmp -s $testroot/stderr.expected
$testroot/stderr
367 if [ $ret -ne 0 ]; then
368 diff -u $testroot/stderr.expected
$testroot/stderr
369 test_done
"$testroot" "$ret"
373 echo "alpha" > $testroot/content.expected
374 echo "beta" >> $testroot/content.expected
375 echo "zeta" >> $testroot/content.expected
376 echo "delta" >> $testroot/content.expected
377 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
378 $testroot/wt
/gamma
/delta
> $testroot/content
380 cmp -s $testroot/content.expected
$testroot/content
382 if [ $ret -ne 0 ]; then
383 diff -u $testroot/content.expected
$testroot/content
385 chmod -R u
+w
$testroot/repo
# make repo cleanup work
386 test_done
"$testroot" "$ret"
389 test_checkout_into_nonempty_dir
() {
390 local testroot
=`test_init checkout_into_nonempty_dir`
391 local commit_id
=`git_show_head $testroot/repo`
393 mkdir
-p $testroot/wt
394 make_test_tree
$testroot/wt
396 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout \
399 if [ $ret -eq 0 ]; then
400 echo "checkout succeeded unexpectedly" >&2
401 test_done
"$testroot" "1"
405 echo -n > $testroot/stdout.expected
406 cmp -s $testroot/stdout.expected
$testroot/stdout
408 if [ $ret -ne 0 ]; then
409 diff -u $testroot/stdout.expected
$testroot/stdout
410 test_done
"$testroot" "$ret"
414 echo "got: $testroot/wt: directory exists and is not empty" \
415 > $testroot/stderr.expected
416 cmp -s $testroot/stderr.expected
$testroot/stderr
418 if [ $ret -ne 0 ]; then
419 diff -u $testroot/stderr.expected
$testroot/stderr
420 test_done
"$testroot" "$ret"
424 echo "? $testroot/wt/alpha" > $testroot/stdout.expected
425 echo "? $testroot/wt/beta" >> $testroot/stdout.expected
426 echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
427 echo "? $testroot/wt/gamma/delta" >> $testroot/stdout.expected
428 echo "Checked out refs/heads/master: $commit_id" \
429 >> $testroot/stdout.expected
430 echo "Now shut up and hack" >> $testroot/stdout.expected
432 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
434 if [ $ret -ne 0 ]; then
435 test_done
"$testroot" "$ret"
439 cmp -s $testroot/stdout.expected
$testroot/stdout
441 if [ $ret -ne 0 ]; then
442 diff -u $testroot/stdout.expected
$testroot/stdout
443 test_done
"$testroot" "$ret"
447 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
448 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
449 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
450 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
451 echo "Checked out refs/heads/master: $commit_id" \
452 >> $testroot/stdout.expected
453 echo "Now shut up and hack" >> $testroot/stdout.expected
455 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
457 if [ $ret -ne 0 ]; then
458 test_done
"$testroot" "$ret"
462 cmp -s $testroot/stdout.expected
$testroot/stdout
464 if [ $ret -ne 0 ]; then
465 diff -u $testroot/stdout.expected
$testroot/stdout
466 test_done
"$testroot" "$ret"
470 echo "alpha" > $testroot/content.expected
471 echo "beta" >> $testroot/content.expected
472 echo "zeta" >> $testroot/content.expected
473 echo "delta" >> $testroot/content.expected
474 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
475 $testroot/wt
/gamma
/delta
> $testroot/content
477 cmp -s $testroot/content.expected
$testroot/content
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/content.expected
$testroot/content
481 test_done
"$testroot" "$ret"
485 echo "modified alpha" > $testroot/wt
/alpha
487 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
488 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
489 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
490 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
491 echo "Checked out refs/heads/master: $commit_id" \
492 >> $testroot/stdout.expected
493 echo "Now shut up and hack" >> $testroot/stdout.expected
495 got checkout
-E $testroot/repo
$testroot/wt
> $testroot/stdout
497 if [ $ret -ne 0 ]; then
498 test_done
"$testroot" "$ret"
502 cmp -s $testroot/stdout.expected
$testroot/stdout
504 if [ $ret -ne 0 ]; then
505 diff -u $testroot/stdout.expected
$testroot/stdout
506 test_done
"$testroot" "$ret"
510 echo "modified alpha" > $testroot/content.expected
511 echo "beta" >> $testroot/content.expected
512 echo "zeta" >> $testroot/content.expected
513 echo "delta" >> $testroot/content.expected
514 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
515 $testroot/wt
/gamma
/delta
> $testroot/content
517 cmp -s $testroot/content.expected
$testroot/content
519 if [ $ret -ne 0 ]; then
520 diff -u $testroot/content.expected
$testroot/content
521 test_done
"$testroot" "$ret"
525 echo 'M alpha' > $testroot/stdout.expected
526 (cd $testroot/wt
&& got status
> $testroot/stdout
)
528 cmp -s $testroot/stdout.expected
$testroot/stdout
530 if [ $ret -ne 0 ]; then
531 diff -u $testroot/stdout.expected
$testroot/stdout
533 test_done
"$testroot" "$ret"
536 test_checkout_symlink
() {
537 local testroot
=`test_init checkout_symlink`
539 (cd $testroot/repo
&& ln -s alpha alpha.link
)
540 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
541 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
542 (cd $testroot/repo
&& ln -s passwd.link passwd2.link
)
543 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
544 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
545 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
546 (cd $testroot/repo
&& git add .
)
547 git_commit
$testroot/repo
-m "add symlinks"
548 local commit_id
=`git_show_head $testroot/repo`
550 got checkout
$testroot/repo
$testroot/wt
> $testroot/stdout
552 if [ $ret -ne 0 ]; then
553 echo "got checkout failed unexpectedly" >&2
554 test_done
"$testroot" "$ret"
558 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
559 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
560 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
561 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
562 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
563 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
564 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
565 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
566 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
567 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
568 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
569 echo "Checked out refs/heads/master: $commit_id" \
570 >> $testroot/stdout.expected
571 echo "Now shut up and hack" >> $testroot/stdout.expected
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 if ! [ -h $testroot/wt
/alpha.link
]; then
582 echo "alpha.link is not a symlink"
583 test_done
"$testroot" "1"
587 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
588 echo "alpha" > $testroot/stdout.expected
589 cmp -s $testroot/stdout.expected
$testroot/stdout
591 if [ $ret -ne 0 ]; then
592 diff -u $testroot/stdout.expected
$testroot/stdout
593 test_done
"$testroot" "$ret"
597 if ! [ -h $testroot/wt
/epsilon.link
]; then
598 echo "epsilon.link is not a symlink"
599 test_done
"$testroot" "1"
603 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
604 echo "epsilon" > $testroot/stdout.expected
605 cmp -s $testroot/stdout.expected
$testroot/stdout
607 if [ $ret -ne 0 ]; then
608 diff -u $testroot/stdout.expected
$testroot/stdout
609 test_done
"$testroot" "$ret"
613 if [ -h $testroot/wt
/passwd.link
]; then
614 echo -n "passwd.link symlink points outside of work tree: " >&2
615 readlink
$testroot/wt
/passwd.link
>&2
616 test_done
"$testroot" "1"
620 echo -n "/etc/passwd" > $testroot/content.expected
621 cp $testroot/wt
/passwd.link
$testroot/content
623 cmp -s $testroot/content.expected
$testroot/content
625 if [ $ret -ne 0 ]; then
626 diff -u $testroot/content.expected
$testroot/content
627 test_done
"$testroot" "$ret"
631 if ! [ -h $testroot/wt
/passwd2.link
]; then
632 echo "passwd2.link is not a symlink"
633 test_done
"$testroot" "1"
637 readlink
$testroot/wt
/passwd2.link
> $testroot/stdout
638 echo "passwd.link" > $testroot/stdout.expected
639 cmp -s $testroot/stdout.expected
$testroot/stdout
641 if [ $ret -ne 0 ]; then
642 diff -u $testroot/stdout.expected
$testroot/stdout
643 test_done
"$testroot" "$ret"
647 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
648 echo "../beta" > $testroot/stdout.expected
649 cmp -s $testroot/stdout.expected
$testroot/stdout
651 if [ $ret -ne 0 ]; then
652 diff -u $testroot/stdout.expected
$testroot/stdout
653 test_done
"$testroot" "$ret"
657 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
658 echo "nonexistent" > $testroot/stdout.expected
659 cmp -s $testroot/stdout.expected
$testroot/stdout
661 if [ $ret -ne 0 ]; then
662 diff -u $testroot/stdout.expected
$testroot/stdout
663 test_done
"$testroot" "$ret"
667 if [ -h $testroot/wt
/dotgotfoo.link
]; then
668 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
669 readlink
$testroot/wt
/dotgotfoo.link
>&2
670 test_done
"$testroot" "1"
674 echo -n ".got/foo" > $testroot/content.expected
675 cp $testroot/wt
/dotgotfoo.link
$testroot/content
677 cmp -s $testroot/content.expected
$testroot/content
679 if [ $ret -ne 0 ]; then
680 diff -u $testroot/content.expected
$testroot/content
682 test_done
"$testroot" "$ret"
685 test_checkout_symlink_relative_wtpath
() {
686 local testroot
=`test_init checkout_symlink_with_wtpath`
688 (cd $testroot/repo
&& ln -s alpha alpha.link
)
689 (cd $testroot/repo
&& ln -s epsilon epsilon.link
)
690 (cd $testroot/repo
&& ln -s /etc
/passwd passwd.link
)
691 (cd $testroot/repo
&& ln -s ..
/beta epsilon
/beta.link
)
692 (cd $testroot/repo
&& ln -s nonexistent nonexistent.link
)
693 (cd $testroot/repo
&& ln -s .got
/foo dotgotfoo.link
)
694 (cd $testroot/repo
&& git add .
)
695 git_commit
$testroot/repo
-m "add symlinks"
697 (cd $testroot && got checkout
$testroot/repo wt
> /dev
/null
)
699 if [ $ret -ne 0 ]; then
700 test_done
"$testroot" "$ret"
704 if ! [ -h $testroot/wt
/alpha.link
]; then
705 echo "alpha.link is not a symlink"
706 test_done
"$testroot" "1"
710 readlink
$testroot/wt
/alpha.link
> $testroot/stdout
711 echo "alpha" > $testroot/stdout.expected
712 cmp -s $testroot/stdout.expected
$testroot/stdout
714 if [ $ret -ne 0 ]; then
715 diff -u $testroot/stdout.expected
$testroot/stdout
716 test_done
"$testroot" "$ret"
720 if ! [ -h $testroot/wt
/epsilon.link
]; then
721 echo "epsilon.link is not a symlink"
722 test_done
"$testroot" "1"
726 readlink
$testroot/wt
/epsilon.link
> $testroot/stdout
727 echo "epsilon" > $testroot/stdout.expected
728 cmp -s $testroot/stdout.expected
$testroot/stdout
730 if [ $ret -ne 0 ]; then
731 diff -u $testroot/stdout.expected
$testroot/stdout
732 test_done
"$testroot" "$ret"
736 if [ -h $testroot/wt
/passwd.link
]; then
737 echo -n "passwd.link symlink points outside of work tree: " >&2
738 readlink
$testroot/wt
/passwd.link
>&2
739 test_done
"$testroot" "1"
743 echo -n "/etc/passwd" > $testroot/content.expected
744 cp $testroot/wt
/passwd.link
$testroot/content
746 cmp -s $testroot/content.expected
$testroot/content
748 if [ $ret -ne 0 ]; then
749 diff -u $testroot/content.expected
$testroot/content
750 test_done
"$testroot" "$ret"
754 readlink
$testroot/wt
/epsilon
/beta.link
> $testroot/stdout
755 echo "../beta" > $testroot/stdout.expected
756 cmp -s $testroot/stdout.expected
$testroot/stdout
758 if [ $ret -ne 0 ]; then
759 diff -u $testroot/stdout.expected
$testroot/stdout
760 test_done
"$testroot" "$ret"
764 readlink
$testroot/wt
/nonexistent.link
> $testroot/stdout
765 echo "nonexistent" > $testroot/stdout.expected
766 cmp -s $testroot/stdout.expected
$testroot/stdout
768 if [ $ret -ne 0 ]; then
769 diff -u $testroot/stdout.expected
$testroot/stdout
770 test_done
"$testroot" "$ret"
774 if [ -h $testroot/wt
/dotgotfoo.link
]; then
775 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
776 readlink
$testroot/wt
/dotgotfoo.link
>&2
777 test_done
"$testroot" "1"
781 echo -n ".got/foo" > $testroot/content.expected
782 cp $testroot/wt
/dotgotfoo.link
$testroot/content
784 cmp -s $testroot/content.expected
$testroot/content
786 if [ $ret -ne 0 ]; then
787 diff -u $testroot/content.expected
$testroot/content
789 test_done
"$testroot" "$ret"
792 test_checkout_repo_with_unknown_extension
() {
793 local testroot
=`test_init checkout_repo_with_unknown_extension`
795 (cd $testroot/repo
&&
796 git config
--add extensions.badExtension foobar
)
797 (cd $testroot/repo
&&
798 git config
--add extensions.otherBadExtension
0)
800 echo "got: badExtension: unsupported repository format extension" \
801 > $testroot/stderr.expected
802 got checkout
$testroot/repo
$testroot/wt \
803 > $testroot/stdout
2> $testroot/stderr
806 if [ $ret -eq 0 ]; then
807 echo "got checkout command succeeded unexpectedly" >&2
808 test_done
"$testroot" "1"
812 cmp -s $testroot/stderr.expected
$testroot/stderr
814 if [ $ret -ne 0 ]; then
815 diff -u $testroot/stderr.expected
$testroot/stderr
817 test_done
"$testroot" "$ret"
820 test_checkout_quiet
() {
821 local testroot
=`test_init checkout_quiet`
823 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
824 git_show_head
$testroot/repo
>> $testroot/stdout.expected
825 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
827 got checkout
-q $testroot/repo
$testroot/wt
> $testroot/stdout
829 if [ $ret -ne 0 ]; then
830 test_done
"$testroot" "$ret"
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 echo "alpha" > $testroot/content.expected
843 echo "beta" >> $testroot/content.expected
844 echo "zeta" >> $testroot/content.expected
845 echo "delta" >> $testroot/content.expected
846 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
847 $testroot/wt
/gamma
/delta
> $testroot/content
849 cmp -s $testroot/content.expected
$testroot/content
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/content.expected
$testroot/content
854 test_done
"$testroot" "$ret"
857 test_checkout_umask
() {
858 local testroot
=`test_init checkout_umask`
860 # using a subshell to avoid clobbering global umask
861 (umask 044 && got checkout
"$testroot/repo" "$testroot/wt") \
864 if [ $ret -ne 0 ]; then
865 test_done
"$testroot" $ret
869 for f
in alpha beta epsilon
/zeta gamma
/delta
; do
870 ls -l "$testroot/wt/$f" |
grep -q ^
-rw-------
871 if [ $?
-ne 0 ]; then
872 echo "$f is not 0600 after checkout" >&2
873 ls -l "$testroot/wt/$f" >&2
874 test_done
"$testroot" 1
879 for d
in epsilon gamma
; do
880 ls -ld "$testroot/wt/$d" |
grep -q ^drwx--x--x
881 if [ $?
-ne 0 ]; then
882 echo "$d is not 711 after checkout" >&2
883 ls -ld "$testroot/wt/$d" >&2
884 test_done
"$testroot" 1
889 test_done
"$testroot" 0
892 test_checkout_ulimit_n
() {
893 local testroot
=`test_init checkout_ulimit_n`
895 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
896 git_show_head
$testroot/repo
>> $testroot/stdout.expected
897 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
899 # Drastically reduce the number of files we are allowed to use.
900 # This tests our down-scaling of caches which store open file handles.
901 # Checkout should still work; if it does not, then either there is
902 # a bug or the fixed limit used by this test case is no longer valid
903 # and must be raised. Use a subshell to avoid changing global ulimit.
904 (ulimit -n 33; got checkout
-q $testroot/repo
$testroot/wt \
907 if [ $ret -ne 0 ]; then
908 test_done
"$testroot" "$ret"
912 cmp -s $testroot/stdout.expected
$testroot/stdout
914 if [ $ret -ne 0 ]; then
915 diff -u $testroot/stdout.expected
$testroot/stdout
916 test_done
"$testroot" "$ret"
920 echo "alpha" > $testroot/content.expected
921 echo "beta" >> $testroot/content.expected
922 echo "zeta" >> $testroot/content.expected
923 echo "delta" >> $testroot/content.expected
924 cat $testroot/wt
/alpha
$testroot/wt
/beta
$testroot/wt
/epsilon
/zeta \
925 $testroot/wt
/gamma
/delta
> $testroot/content
927 cmp -s $testroot/content.expected
$testroot/content
929 if [ $ret -ne 0 ]; then
930 diff -u $testroot/content.expected
$testroot/content
932 test_done
"$testroot" "$ret"
936 run_test test_checkout_basic
937 run_test test_checkout_dir_exists
938 run_test test_checkout_dir_not_empty
939 run_test test_checkout_sets_xbit
940 run_test test_checkout_commit_from_wrong_branch
941 run_test test_checkout_tag
942 run_test test_checkout_ignores_submodules
943 run_test test_checkout_read_only
944 run_test test_checkout_into_nonempty_dir
945 run_test test_checkout_symlink
946 run_test test_checkout_symlink_relative_wtpath
947 run_test test_checkout_repo_with_unknown_extension
948 run_test test_checkout_quiet
949 run_test test_checkout_umask
950 run_test test_checkout_ulimit_n