portable: release 0.93
[got-portable.git] / regress / cmdline / checkout.sh
blob95f34afe31e5991bc2dfc22ad99e44cdd23832cc
1 #!/bin/sh
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.
17 . ./common.sh
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
32 ret=$?
33 if [ $ret -ne 0 ]; then
34 test_done "$testroot" "$ret"
35 return 1
38 cmp -s $testroot/stdout.expected $testroot/stdout
39 ret=$?
40 if [ $ret -ne 0 ]; then
41 diff -u $testroot/stdout.expected $testroot/stdout
42 test_done "$testroot" "$ret"
43 return 1
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
54 ret=$?
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
73 mkdir $testroot/wt
75 got checkout $testroot/repo $testroot/wt > $testroot/stdout
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 test_done "$testroot" "$ret"
79 return 1
82 cmp -s $testroot/stdout.expected $testroot/stdout
83 ret=$?
84 if [ $ret -ne 0 ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
86 test_done "$testroot" "$ret"
87 return 1
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
98 ret=$?
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
117 mkdir $testroot/wt
118 touch $testroot/wt/foo
120 got checkout $testroot/repo $testroot/wt > $testroot/stdout \
121 2> $testroot/stderr
122 ret=$?
123 if [ $ret -eq 0 ]; then
124 echo "checkout succeeded unexpectedly" >&2
125 test_done "$testroot" "1"
126 return 1
129 echo "got: $testroot/wt: directory exists and is not empty" \
130 > $testroot/stderr.expected
131 cmp -s $testroot/stderr.expected $testroot/stderr
132 ret=$?
133 if [ $ret -ne 0 ]; then
134 diff -u $testroot/stderr.expected $testroot/stderr
135 test_done "$testroot" "$ret"
136 return 1
139 echo -n > $testroot/stdout.expected
140 cmp -s $testroot/stdout.expected $testroot/stdout
141 ret=$?
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
155 ret=$?
156 if [ $ret -eq 0 ]; then
157 echo "checkout succeeded unexpectedly" >&2
158 test_done "$testroot" "1"
159 return 1
162 echo -n > $testroot/stdout.expected
164 cmp -s $testroot/stdout.expected $testroot/stdout
165 ret=$?
166 if [ $ret -ne 0 ]; then
167 diff -u $testroot/stdout.expected $testroot/stdout
168 test_done "$testroot" "$ret"
169 return 1
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
176 ret=$?
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
189 ret=$?
190 if [ $ret -eq 0 ]; then
191 echo "checkout succeeded unexpectedly" >&2
192 test_done "$testroot" "1"
193 return 1
196 echo -n > $testroot/stdout.expected
198 cmp -s $testroot/stdout.expected $testroot/stdout
199 ret=$?
200 if [ $ret -ne 0 ]; then
201 diff -u $testroot/stdout.expected $testroot/stdout
202 test_done "$testroot" "$ret"
203 return 1
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
210 ret=$?
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
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 test_done "$testroot" "$ret"
235 return 1
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret=$?
240 if [ $ret -ne 0 ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
242 test_done "$testroot" "$ret"
243 return 1
246 ls -l $testroot/wt/xfile | grep -q '^-rwx'
247 ret=$?
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
265 ret=$?
266 if [ $ret -eq 0 ]; then
267 test_done "$testroot" "1"
268 return 1
271 echo -n "" > $testroot/stdout.expected
272 cmp -s $testroot/stdout.expected $testroot/stdout
273 ret=$?
274 if [ $ret -ne 0 ]; then
275 diff -u $testroot/stdout.expected $testroot/stdout
276 test_done "$testroot" "$ret"
277 return 1
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
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 diff -u $testroot/stderr.expected $testroot/stderr
292 test_done "$testroot" "$ret"
293 return 1
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`
302 local tag="1.0.0"
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
315 ret=$?
316 if [ $ret -ne 0 ]; then
317 test_done "$testroot" "$ret"
318 return 1
321 cmp -s $testroot/stdout.expected $testroot/stdout
322 ret=$?
323 if [ $ret -ne 0 ]; then
324 diff -u $testroot/stdout.expected $testroot/stdout
325 test_done "$testroot" "$ret"
326 return 1
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
337 ret=$?
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
364 ret=$?
365 if [ $ret -ne 0 ]; then
366 test_done "$testroot" "$ret"
367 return 1
370 cmp -s $testroot/stdout.expected $testroot/stdout
371 ret=$?
372 if [ $ret -ne 0 ]; then
373 diff -u $testroot/stdout.expected $testroot/stdout
374 test_done "$testroot" "$ret"
375 return 1
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
386 ret=$?
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
410 ret=$?
411 if [ $ret -ne 0 ]; then
412 test_done "$testroot" "$ret"
413 return 1
416 cmp -s $testroot/stdout.expected $testroot/stdout
417 ret=$?
418 if [ $ret -ne 0 ]; then
419 diff -u $testroot/stdout.expected $testroot/stdout
420 test_done "$testroot" "$ret"
421 return 1
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
434 ret=$?
435 if [ $ret -ne 0 ]; then
436 diff -u $testroot/stderr.expected $testroot/stderr
437 test_done "$testroot" "$ret"
438 return 1
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
449 ret=$?
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 \
465 2> $testroot/stderr
466 ret=$?
467 if [ $ret -eq 0 ]; then
468 echo "checkout succeeded unexpectedly" >&2
469 test_done "$testroot" "1"
470 return 1
473 echo -n > $testroot/stdout.expected
474 cmp -s $testroot/stdout.expected $testroot/stdout
475 ret=$?
476 if [ $ret -ne 0 ]; then
477 diff -u $testroot/stdout.expected $testroot/stdout
478 test_done "$testroot" "$ret"
479 return 1
482 echo "got: $testroot/wt: directory exists and is not empty" \
483 > $testroot/stderr.expected
484 cmp -s $testroot/stderr.expected $testroot/stderr
485 ret=$?
486 if [ $ret -ne 0 ]; then
487 diff -u $testroot/stderr.expected $testroot/stderr
488 test_done "$testroot" "$ret"
489 return 1
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
501 ret=$?
502 if [ $ret -ne 0 ]; then
503 test_done "$testroot" "$ret"
504 return 1
507 cmp -s $testroot/stdout.expected $testroot/stdout
508 ret=$?
509 if [ $ret -ne 0 ]; then
510 diff -u $testroot/stdout.expected $testroot/stdout
511 test_done "$testroot" "$ret"
512 return 1
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
524 ret=$?
525 if [ $ret -ne 0 ]; then
526 test_done "$testroot" "$ret"
527 return 1
530 cmp -s $testroot/stdout.expected $testroot/stdout
531 ret=$?
532 if [ $ret -ne 0 ]; then
533 diff -u $testroot/stdout.expected $testroot/stdout
534 test_done "$testroot" "$ret"
535 return 1
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
546 ret=$?
547 if [ $ret -ne 0 ]; then
548 diff -u $testroot/content.expected $testroot/content
549 test_done "$testroot" "$ret"
550 return 1
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
567 ret=$?
568 if [ $ret -ne 0 ]; then
569 test_done "$testroot" "$ret"
570 return 1
573 cmp -s $testroot/stdout.expected $testroot/stdout
574 ret=$?
575 if [ $ret -ne 0 ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 test_done "$testroot" "$ret"
578 return 1
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
589 ret=$?
590 if [ $ret -ne 0 ]; then
591 diff -u $testroot/content.expected $testroot/content
592 test_done "$testroot" "$ret"
593 return 1
596 echo 'M alpha' > $testroot/stdout.expected
597 (cd $testroot/wt && got status > $testroot/stdout)
599 cmp -s $testroot/stdout.expected $testroot/stdout
600 ret=$?
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
622 ret=$?
623 if [ $ret -ne 0 ]; then
624 echo "got checkout failed unexpectedly" >&2
625 test_done "$testroot" "$ret"
626 return 1
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
645 ret=$?
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 test_done "$testroot" "$ret"
649 return 1
652 if ! [ -h $testroot/wt/alpha.link ]; then
653 echo "alpha.link is not a symlink"
654 test_done "$testroot" "1"
655 return 1
658 readlink $testroot/wt/alpha.link > $testroot/stdout
659 echo "alpha" > $testroot/stdout.expected
660 cmp -s $testroot/stdout.expected $testroot/stdout
661 ret=$?
662 if [ $ret -ne 0 ]; then
663 diff -u $testroot/stdout.expected $testroot/stdout
664 test_done "$testroot" "$ret"
665 return 1
668 if ! [ -h $testroot/wt/epsilon.link ]; then
669 echo "epsilon.link is not a symlink"
670 test_done "$testroot" "1"
671 return 1
674 readlink $testroot/wt/epsilon.link > $testroot/stdout
675 echo "epsilon" > $testroot/stdout.expected
676 cmp -s $testroot/stdout.expected $testroot/stdout
677 ret=$?
678 if [ $ret -ne 0 ]; then
679 diff -u $testroot/stdout.expected $testroot/stdout
680 test_done "$testroot" "$ret"
681 return 1
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"
688 return 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
695 ret=$?
696 if [ $ret -ne 0 ]; then
697 diff -u $testroot/content.expected $testroot/content
698 test_done "$testroot" "$ret"
699 return 1
702 if ! [ -h $testroot/wt/passwd2.link ]; then
703 echo "passwd2.link is not a symlink"
704 test_done "$testroot" "1"
705 return 1
708 readlink $testroot/wt/passwd2.link > $testroot/stdout
709 echo "passwd.link" > $testroot/stdout.expected
710 cmp -s $testroot/stdout.expected $testroot/stdout
711 ret=$?
712 if [ $ret -ne 0 ]; then
713 diff -u $testroot/stdout.expected $testroot/stdout
714 test_done "$testroot" "$ret"
715 return 1
718 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
719 echo "../beta" > $testroot/stdout.expected
720 cmp -s $testroot/stdout.expected $testroot/stdout
721 ret=$?
722 if [ $ret -ne 0 ]; then
723 diff -u $testroot/stdout.expected $testroot/stdout
724 test_done "$testroot" "$ret"
725 return 1
728 readlink $testroot/wt/nonexistent.link > $testroot/stdout
729 echo "nonexistent" > $testroot/stdout.expected
730 cmp -s $testroot/stdout.expected $testroot/stdout
731 ret=$?
732 if [ $ret -ne 0 ]; then
733 diff -u $testroot/stdout.expected $testroot/stdout
734 test_done "$testroot" "$ret"
735 return 1
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"
742 return 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
749 ret=$?
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)
769 ret=$?
770 if [ $ret -ne 0 ]; then
771 test_done "$testroot" "$ret"
772 return 1
775 if ! [ -h $testroot/wt/alpha.link ]; then
776 echo "alpha.link is not a symlink"
777 test_done "$testroot" "1"
778 return 1
781 readlink $testroot/wt/alpha.link > $testroot/stdout
782 echo "alpha" > $testroot/stdout.expected
783 cmp -s $testroot/stdout.expected $testroot/stdout
784 ret=$?
785 if [ $ret -ne 0 ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done "$testroot" "$ret"
788 return 1
791 if ! [ -h $testroot/wt/epsilon.link ]; then
792 echo "epsilon.link is not a symlink"
793 test_done "$testroot" "1"
794 return 1
797 readlink $testroot/wt/epsilon.link > $testroot/stdout
798 echo "epsilon" > $testroot/stdout.expected
799 cmp -s $testroot/stdout.expected $testroot/stdout
800 ret=$?
801 if [ $ret -ne 0 ]; then
802 diff -u $testroot/stdout.expected $testroot/stdout
803 test_done "$testroot" "$ret"
804 return 1
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"
811 return 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
818 ret=$?
819 if [ $ret -ne 0 ]; then
820 diff -u $testroot/content.expected $testroot/content
821 test_done "$testroot" "$ret"
822 return 1
825 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
826 echo "../beta" > $testroot/stdout.expected
827 cmp -s $testroot/stdout.expected $testroot/stdout
828 ret=$?
829 if [ $ret -ne 0 ]; then
830 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
832 return 1
835 readlink $testroot/wt/nonexistent.link > $testroot/stdout
836 echo "nonexistent" > $testroot/stdout.expected
837 cmp -s $testroot/stdout.expected $testroot/stdout
838 ret=$?
839 if [ $ret -ne 0 ]; then
840 diff -u $testroot/stdout.expected $testroot/stdout
841 test_done "$testroot" "$ret"
842 return 1
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"
849 return 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
856 ret=$?
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
876 ret=$?
877 if [ $ret -eq 0 ]; then
878 echo "got checkout command succeeded unexpectedly" >&2
879 test_done "$testroot" "1"
880 return 1
883 cmp -s $testroot/stderr.expected $testroot/stderr
884 ret=$?
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
899 ret=$?
900 if [ $ret -ne 0 ]; then
901 test_done "$testroot" "$ret"
902 return 1
905 cmp -s $testroot/stdout.expected $testroot/stdout
906 ret=$?
907 if [ $ret -ne 0 ]; then
908 diff -u $testroot/stdout.expected $testroot/stdout
909 test_done "$testroot" "$ret"
910 return 1
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
921 ret=$?
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") \
933 >/dev/null
934 ret=$?
935 if [ $ret -ne 0 ]; then
936 test_done "$testroot" $ret
937 return 1
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
946 return 1
948 done
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
956 return 1
958 done
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 \
976 > $testroot/stdout)
977 ret=$?
978 if [ $ret -ne 0 ]; then
979 test_done "$testroot" "$ret"
980 return 1
983 cmp -s $testroot/stdout.expected $testroot/stdout
984 ret=$?
985 if [ $ret -ne 0 ]; then
986 diff -u $testroot/stdout.expected $testroot/stdout
987 test_done "$testroot" "$ret"
988 return 1
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
999 ret=$?
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
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 echo "checkout failed unexpectedly" >&2
1015 test_done "$testroot" "$ret"
1016 return 1
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)
1023 ret=$?
1024 if [ $ret -ne 0 ]; then
1025 echo "commit failed unexpectedly" >&2
1026 test_done "$testroot" "$ret"
1027 return 1
1029 set -- "$@" "$(git_show_head $testroot/repo)"
1030 done
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
1041 ret=$?
1042 if [ $ret -ne 0 ]; then
1043 test_done "$testroot" "$ret"
1044 return 1
1047 cmp -s $testroot/stdout.expected $testroot/stdout
1048 ret=$?
1049 if [ $ret -ne 0 ]; then
1050 diff -u $testroot/stdout.expected $testroot/stdout
1051 test_done "$testroot" "$ret"
1052 return 1
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 > \
1064 $testroot/stdout
1065 ret=$?
1066 if [ $ret -ne 0 ]; then
1067 test_done "$testroot" "$ret"
1068 return 1
1071 cmp -s $testroot/stdout.expected $testroot/stdout
1072 ret=$?
1073 if [ $ret -ne 0 ]; then
1074 diff -u $testroot/stdout.expected $testroot/stdout
1077 test_done "$testroot" "$ret"
1080 test_parseargs "$@"
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