speed up 'got histedit -l' and 'got rebase -l'
[got-portable.git] / regress / cmdline / checkout.sh
blob14a25416da706b0bced0477529b71a35b28914d1
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" != "0" ]; then
34 test_done "$testroot" "$ret"
35 return 1
38 cmp -s $testroot/stdout.expected $testroot/stdout
39 ret="$?"
40 if [ "$ret" != "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" != "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" != "0" ]; then
78 test_done "$testroot" "$ret"
79 return 1
82 cmp -s $testroot/stdout.expected $testroot/stdout
83 ret="$?"
84 if [ "$ret" != "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" != "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" = "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" != "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" != "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
164 ret="$?"
165 if [ "$ret" != "0" ]; then
166 test_done "$testroot" "$ret"
167 return 1
170 cmp -s $testroot/stdout.expected $testroot/stdout
171 ret="$?"
172 if [ "$ret" != "0" ]; then
173 diff -u $testroot/stdout.expected $testroot/stdout
174 test_done "$testroot" "$ret"
175 return 1
178 ls -l $testroot/wt/xfile | grep -q '^-rwx'
179 ret="$?"
180 if [ "$ret" != "0" ]; then
181 echo "file is not executable" >&2
182 ls -l $testroot/wt/xfile >&2
184 test_done "$testroot" "$ret"
187 test_checkout_commit_from_wrong_branch() {
188 local testroot=`test_init checkout_commit_from_wrong_branch`
190 (cd $testroot/repo && git checkout -q -b newbranch)
191 echo "modified alpha on new branch" > $testroot/repo/alpha
192 git_commit $testroot/repo -m "modified alpha on new branch"
194 local head_rev=`git_show_head $testroot/repo`
195 got checkout -b master -c $head_rev $testroot/repo $testroot/wt \
196 > $testroot/stdout 2> $testroot/stderr
197 ret="$?"
198 if [ "$ret" = "0" ]; then
199 test_done "$testroot" "1"
200 return 1
203 echo -n "" > $testroot/stdout.expected
204 cmp -s $testroot/stdout.expected $testroot/stdout
205 ret="$?"
206 if [ "$ret" != "0" ]; then
207 diff -u $testroot/stdout.expected $testroot/stdout
208 test_done "$testroot" "$ret"
209 return 1
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
221 ret="$?"
222 if [ "$ret" != "0" ]; then
223 diff -u $testroot/stderr.expected $testroot/stderr
224 test_done "$testroot" "$ret"
225 return 1
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`
234 local tag="1.0.0"
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
247 ret="$?"
248 if [ "$ret" != "0" ]; then
249 test_done "$testroot" "$ret"
250 return 1
253 cmp -s $testroot/stdout.expected $testroot/stdout
254 ret="$?"
255 if [ "$ret" != "0" ]; then
256 diff -u $testroot/stdout.expected $testroot/stdout
257 test_done "$testroot" "$ret"
258 return 1
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
269 ret="$?"
270 if [ "$ret" != "0" ]; then
271 diff -u $testroot/content.expected $testroot/content
273 test_done "$testroot" "$ret"
276 test_checkout_ignores_submodules() {
277 local testroot=`test_init checkout_ignores_submodules`
279 make_single_file_repo $testroot/repo2 foo
281 (cd $testroot/repo && git submodule -q add ../repo2)
282 (cd $testroot/repo && git commit -q -m 'adding submodule')
283 local commit_id=`git_show_head $testroot/repo`
285 echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
286 echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
287 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
288 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
289 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
290 echo "Checked out refs/heads/master: $commit_id" \
291 >> $testroot/stdout.expected
292 echo "Now shut up and hack" >> $testroot/stdout.expected
294 got checkout $testroot/repo $testroot/wt > $testroot/stdout
295 ret="$?"
296 if [ "$ret" != "0" ]; then
297 test_done "$testroot" "$ret"
298 return 1
301 cmp -s $testroot/stdout.expected $testroot/stdout
302 ret="$?"
303 if [ "$ret" != "0" ]; then
304 diff -u $testroot/stdout.expected $testroot/stdout
305 test_done "$testroot" "$ret"
306 return 1
309 echo "alpha" > $testroot/content.expected
310 echo "beta" >> $testroot/content.expected
311 echo "zeta" >> $testroot/content.expected
312 echo "delta" >> $testroot/content.expected
313 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
314 $testroot/wt/gamma/delta > $testroot/content
316 cmp -s $testroot/content.expected $testroot/content
317 ret="$?"
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/content.expected $testroot/content
321 test_done "$testroot" "$ret"
324 test_checkout_read_only() {
325 local testroot=`test_init checkout_read_only`
326 local commit_id=`git_show_head $testroot/repo`
328 # Make the repostiory read-only
329 chmod -R a-w $testroot/repo
331 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
332 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
333 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
334 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
335 echo "Checked out refs/heads/master: $commit_id" \
336 >> $testroot/stdout.expected
337 echo "Now shut up and hack" >> $testroot/stdout.expected
339 got checkout $testroot/repo $testroot/wt \
340 > $testroot/stdout 2> $testroot/stderr
341 ret="$?"
342 if [ "$ret" != "0" ]; then
343 test_done "$testroot" "$ret"
344 return 1
347 cmp -s $testroot/stdout.expected $testroot/stdout
348 ret="$?"
349 if [ "$ret" != "0" ]; then
350 diff -u $testroot/stdout.expected $testroot/stdout
351 test_done "$testroot" "$ret"
352 return 1
355 echo -n "got: warning: could not create a reference " \
356 > $testroot/stderr.expected
357 echo -n "to the work tree's base commit; the commit could " \
358 >> $testroot/stderr.expected
359 echo -n "be garbage-collected by Git or 'gotadmin cleanup'; " \
360 >> $testroot/stderr.expected
361 echo -n "making the repository " >> $testroot/stderr.expected
362 echo "writable and running 'got update' will prevent this" \
363 >> $testroot/stderr.expected
364 cmp -s $testroot/stderr.expected $testroot/stderr
365 ret="$?"
366 if [ "$ret" != "0" ]; then
367 diff -u $testroot/stderr.expected $testroot/stderr
368 test_done "$testroot" "$ret"
369 return 1
372 echo "alpha" > $testroot/content.expected
373 echo "beta" >> $testroot/content.expected
374 echo "zeta" >> $testroot/content.expected
375 echo "delta" >> $testroot/content.expected
376 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
377 $testroot/wt/gamma/delta > $testroot/content
379 cmp -s $testroot/content.expected $testroot/content
380 ret="$?"
381 if [ "$ret" != "0" ]; then
382 diff -u $testroot/content.expected $testroot/content
384 chmod -R u+w $testroot/repo # make repo cleanup work
385 test_done "$testroot" "$ret"
388 test_checkout_into_nonempty_dir() {
389 local testroot=`test_init checkout_into_nonempty_dir`
390 local commit_id=`git_show_head $testroot/repo`
392 mkdir -p $testroot/wt
393 make_test_tree $testroot/wt
395 got checkout $testroot/repo $testroot/wt > $testroot/stdout \
396 2> $testroot/stderr
397 ret="$?"
398 if [ "$ret" = "0" ]; then
399 echo "checkout succeeded unexpectedly" >&2
400 test_done "$testroot" "1"
401 return 1
404 echo -n > $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected $testroot/stdout
406 ret="$?"
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 test_done "$testroot" "$ret"
410 return 1
413 echo "got: $testroot/wt: directory exists and is not empty" \
414 > $testroot/stderr.expected
415 cmp -s $testroot/stderr.expected $testroot/stderr
416 ret="$?"
417 if [ "$ret" != "0" ]; then
418 diff -u $testroot/stderr.expected $testroot/stderr
419 test_done "$testroot" "$ret"
420 return 1
423 echo "? $testroot/wt/alpha" > $testroot/stdout.expected
424 echo "? $testroot/wt/beta" >> $testroot/stdout.expected
425 echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
426 echo "? $testroot/wt/gamma/delta" >> $testroot/stdout.expected
427 echo "Checked out refs/heads/master: $commit_id" \
428 >> $testroot/stdout.expected
429 echo "Now shut up and hack" >> $testroot/stdout.expected
431 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
432 ret="$?"
433 if [ "$ret" != "0" ]; then
434 test_done "$testroot" "$ret"
435 return 1
438 cmp -s $testroot/stdout.expected $testroot/stdout
439 ret="$?"
440 if [ "$ret" != "0" ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
446 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
447 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
448 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
449 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
450 echo "Checked out refs/heads/master: $commit_id" \
451 >> $testroot/stdout.expected
452 echo "Now shut up and hack" >> $testroot/stdout.expected
454 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
455 ret="$?"
456 if [ "$ret" != "0" ]; then
457 test_done "$testroot" "$ret"
458 return 1
461 cmp -s $testroot/stdout.expected $testroot/stdout
462 ret="$?"
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/stdout.expected $testroot/stdout
465 test_done "$testroot" "$ret"
466 return 1
469 echo "alpha" > $testroot/content.expected
470 echo "beta" >> $testroot/content.expected
471 echo "zeta" >> $testroot/content.expected
472 echo "delta" >> $testroot/content.expected
473 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
474 $testroot/wt/gamma/delta > $testroot/content
476 cmp -s $testroot/content.expected $testroot/content
477 ret="$?"
478 if [ "$ret" != "0" ]; then
479 diff -u $testroot/content.expected $testroot/content
480 test_done "$testroot" "$ret"
481 return 1
484 echo "modified alpha" > $testroot/wt/alpha
486 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
487 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
488 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
489 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
490 echo "Checked out refs/heads/master: $commit_id" \
491 >> $testroot/stdout.expected
492 echo "Now shut up and hack" >> $testroot/stdout.expected
494 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
495 ret="$?"
496 if [ "$ret" != "0" ]; then
497 test_done "$testroot" "$ret"
498 return 1
501 cmp -s $testroot/stdout.expected $testroot/stdout
502 ret="$?"
503 if [ "$ret" != "0" ]; then
504 diff -u $testroot/stdout.expected $testroot/stdout
505 test_done "$testroot" "$ret"
506 return 1
509 echo "modified alpha" > $testroot/content.expected
510 echo "beta" >> $testroot/content.expected
511 echo "zeta" >> $testroot/content.expected
512 echo "delta" >> $testroot/content.expected
513 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
514 $testroot/wt/gamma/delta > $testroot/content
516 cmp -s $testroot/content.expected $testroot/content
517 ret="$?"
518 if [ "$ret" != "0" ]; then
519 diff -u $testroot/content.expected $testroot/content
520 test_done "$testroot" "$ret"
521 return 1
524 echo 'M alpha' > $testroot/stdout.expected
525 (cd $testroot/wt && got status > $testroot/stdout)
527 cmp -s $testroot/stdout.expected $testroot/stdout
528 ret="$?"
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done "$testroot" "$ret"
535 test_checkout_symlink() {
536 local testroot=`test_init checkout_symlink`
538 (cd $testroot/repo && ln -s alpha alpha.link)
539 (cd $testroot/repo && ln -s epsilon epsilon.link)
540 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
541 (cd $testroot/repo && ln -s passwd.link passwd2.link)
542 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
543 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
544 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
545 (cd $testroot/repo && git add .)
546 git_commit $testroot/repo -m "add symlinks"
547 local commit_id=`git_show_head $testroot/repo`
549 got checkout $testroot/repo $testroot/wt > $testroot/stdout
550 ret="$?"
551 if [ "$ret" != "0" ]; then
552 echo "got checkout failed unexpectedly" >&2
553 test_done "$testroot" "$ret"
554 return 1
557 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
558 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
559 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
560 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
561 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
562 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
563 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
564 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
565 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
566 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
567 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
568 echo "Checked out refs/heads/master: $commit_id" \
569 >> $testroot/stdout.expected
570 echo "Now shut up and hack" >> $testroot/stdout.expected
572 cmp -s $testroot/stdout.expected $testroot/stdout
573 ret="$?"
574 if [ "$ret" != "0" ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
580 if ! [ -h $testroot/wt/alpha.link ]; then
581 echo "alpha.link is not a symlink"
582 test_done "$testroot" "1"
583 return 1
586 readlink $testroot/wt/alpha.link > $testroot/stdout
587 echo "alpha" > $testroot/stdout.expected
588 cmp -s $testroot/stdout.expected $testroot/stdout
589 ret="$?"
590 if [ "$ret" != "0" ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
592 test_done "$testroot" "$ret"
593 return 1
596 if ! [ -h $testroot/wt/epsilon.link ]; then
597 echo "epsilon.link is not a symlink"
598 test_done "$testroot" "1"
599 return 1
602 readlink $testroot/wt/epsilon.link > $testroot/stdout
603 echo "epsilon" > $testroot/stdout.expected
604 cmp -s $testroot/stdout.expected $testroot/stdout
605 ret="$?"
606 if [ "$ret" != "0" ]; then
607 diff -u $testroot/stdout.expected $testroot/stdout
608 test_done "$testroot" "$ret"
609 return 1
612 if [ -h $testroot/wt/passwd.link ]; then
613 echo -n "passwd.link symlink points outside of work tree: " >&2
614 readlink $testroot/wt/passwd.link >&2
615 test_done "$testroot" "1"
616 return 1
619 echo -n "/etc/passwd" > $testroot/content.expected
620 cp $testroot/wt/passwd.link $testroot/content
622 cmp -s $testroot/content.expected $testroot/content
623 ret="$?"
624 if [ "$ret" != "0" ]; then
625 diff -u $testroot/content.expected $testroot/content
626 test_done "$testroot" "$ret"
627 return 1
630 if ! [ -h $testroot/wt/passwd2.link ]; then
631 echo "passwd2.link is not a symlink"
632 test_done "$testroot" "1"
633 return 1
636 readlink $testroot/wt/passwd2.link > $testroot/stdout
637 echo "passwd.link" > $testroot/stdout.expected
638 cmp -s $testroot/stdout.expected $testroot/stdout
639 ret="$?"
640 if [ "$ret" != "0" ]; then
641 diff -u $testroot/stdout.expected $testroot/stdout
642 test_done "$testroot" "$ret"
643 return 1
646 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
647 echo "../beta" > $testroot/stdout.expected
648 cmp -s $testroot/stdout.expected $testroot/stdout
649 ret="$?"
650 if [ "$ret" != "0" ]; then
651 diff -u $testroot/stdout.expected $testroot/stdout
652 test_done "$testroot" "$ret"
653 return 1
656 readlink $testroot/wt/nonexistent.link > $testroot/stdout
657 echo "nonexistent" > $testroot/stdout.expected
658 cmp -s $testroot/stdout.expected $testroot/stdout
659 ret="$?"
660 if [ "$ret" != "0" ]; then
661 diff -u $testroot/stdout.expected $testroot/stdout
662 test_done "$testroot" "$ret"
663 return 1
666 if [ -h $testroot/wt/dotgotfoo.link ]; then
667 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
668 readlink $testroot/wt/dotgotfoo.link >&2
669 test_done "$testroot" "1"
670 return 1
673 echo -n ".got/foo" > $testroot/content.expected
674 cp $testroot/wt/dotgotfoo.link $testroot/content
676 cmp -s $testroot/content.expected $testroot/content
677 ret="$?"
678 if [ "$ret" != "0" ]; then
679 diff -u $testroot/content.expected $testroot/content
681 test_done "$testroot" "$ret"
684 test_checkout_symlink_relative_wtpath() {
685 local testroot=`test_init checkout_symlink_with_wtpath`
687 (cd $testroot/repo && ln -s alpha alpha.link)
688 (cd $testroot/repo && ln -s epsilon epsilon.link)
689 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
690 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
691 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
692 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
693 (cd $testroot/repo && git add .)
694 git_commit $testroot/repo -m "add symlinks"
696 (cd $testroot && got checkout $testroot/repo wt > /dev/null)
697 ret="$?"
698 if [ "$ret" != "0" ]; then
699 test_done "$testroot" "$ret"
700 return 1
703 if ! [ -h $testroot/wt/alpha.link ]; then
704 echo "alpha.link is not a symlink"
705 test_done "$testroot" "1"
706 return 1
709 readlink $testroot/wt/alpha.link > $testroot/stdout
710 echo "alpha" > $testroot/stdout.expected
711 cmp -s $testroot/stdout.expected $testroot/stdout
712 ret="$?"
713 if [ "$ret" != "0" ]; then
714 diff -u $testroot/stdout.expected $testroot/stdout
715 test_done "$testroot" "$ret"
716 return 1
719 if ! [ -h $testroot/wt/epsilon.link ]; then
720 echo "epsilon.link is not a symlink"
721 test_done "$testroot" "1"
722 return 1
725 readlink $testroot/wt/epsilon.link > $testroot/stdout
726 echo "epsilon" > $testroot/stdout.expected
727 cmp -s $testroot/stdout.expected $testroot/stdout
728 ret="$?"
729 if [ "$ret" != "0" ]; then
730 diff -u $testroot/stdout.expected $testroot/stdout
731 test_done "$testroot" "$ret"
732 return 1
735 if [ -h $testroot/wt/passwd.link ]; then
736 echo -n "passwd.link symlink points outside of work tree: " >&2
737 readlink $testroot/wt/passwd.link >&2
738 test_done "$testroot" "1"
739 return 1
742 echo -n "/etc/passwd" > $testroot/content.expected
743 cp $testroot/wt/passwd.link $testroot/content
745 cmp -s $testroot/content.expected $testroot/content
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/content.expected $testroot/content
749 test_done "$testroot" "$ret"
750 return 1
753 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
754 echo "../beta" > $testroot/stdout.expected
755 cmp -s $testroot/stdout.expected $testroot/stdout
756 ret="$?"
757 if [ "$ret" != "0" ]; then
758 diff -u $testroot/stdout.expected $testroot/stdout
759 test_done "$testroot" "$ret"
760 return 1
763 readlink $testroot/wt/nonexistent.link > $testroot/stdout
764 echo "nonexistent" > $testroot/stdout.expected
765 cmp -s $testroot/stdout.expected $testroot/stdout
766 ret="$?"
767 if [ "$ret" != "0" ]; then
768 diff -u $testroot/stdout.expected $testroot/stdout
769 test_done "$testroot" "$ret"
770 return 1
773 if [ -h $testroot/wt/dotgotfoo.link ]; then
774 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
775 readlink $testroot/wt/dotgotfoo.link >&2
776 test_done "$testroot" "1"
777 return 1
780 echo -n ".got/foo" > $testroot/content.expected
781 cp $testroot/wt/dotgotfoo.link $testroot/content
783 cmp -s $testroot/content.expected $testroot/content
784 ret="$?"
785 if [ "$ret" != "0" ]; then
786 diff -u $testroot/content.expected $testroot/content
788 test_done "$testroot" "$ret"
791 test_checkout_repo_with_unknown_extension() {
792 local testroot=`test_init checkout_repo_with_unknown_extension`
794 (cd $testroot/repo &&
795 git config --add extensions.badExtension true)
796 (cd $testroot/repo &&
797 git config --add extensions.otherBadExtension 0)
799 echo "got: badExtension: unsupported repository format extension" \
800 > $testroot/stderr.expected
801 got checkout $testroot/repo $testroot/wt \
802 > $testroot/stdout 2> $testroot/stderr
804 ret="$?"
805 if [ "$ret" = "0" ]; then
806 echo "got checkout command succeeded unexpectedly" >&2
807 test_done "$testroot" "1"
808 return 1
811 cmp -s $testroot/stderr.expected $testroot/stderr
812 ret="$?"
813 if [ "$ret" != "0" ]; then
814 diff -u $testroot/stderr.expected $testroot/stderr
816 test_done "$testroot" "$ret"
819 test_checkout_quiet() {
820 local testroot=`test_init checkout_quiet`
822 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
823 git_show_head $testroot/repo >> $testroot/stdout.expected
824 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
826 got checkout -q $testroot/repo $testroot/wt > $testroot/stdout
827 ret="$?"
828 if [ "$ret" != "0" ]; then
829 test_done "$testroot" "$ret"
830 return 1
833 cmp -s $testroot/stdout.expected $testroot/stdout
834 ret="$?"
835 if [ "$ret" != "0" ]; then
836 diff -u $testroot/stdout.expected $testroot/stdout
837 test_done "$testroot" "$ret"
838 return 1
841 echo "alpha" > $testroot/content.expected
842 echo "beta" >> $testroot/content.expected
843 echo "zeta" >> $testroot/content.expected
844 echo "delta" >> $testroot/content.expected
845 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
846 $testroot/wt/gamma/delta > $testroot/content
848 cmp -s $testroot/content.expected $testroot/content
849 ret="$?"
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/content.expected $testroot/content
853 test_done "$testroot" "$ret"
856 test_parseargs "$@"
857 run_test test_checkout_basic
858 run_test test_checkout_dir_exists
859 run_test test_checkout_dir_not_empty
860 run_test test_checkout_sets_xbit
861 run_test test_checkout_commit_from_wrong_branch
862 run_test test_checkout_tag
863 run_test test_checkout_ignores_submodules
864 run_test test_checkout_read_only
865 run_test test_checkout_into_nonempty_dir
866 run_test test_checkout_symlink
867 run_test test_checkout_symlink_relative_wtpath
868 run_test test_checkout_repo_with_unknown_extension
869 run_test test_checkout_quiet