Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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
36 fi
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
44 fi
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
57 fi
58 test_done "$testroot" "$ret"
59 }
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
80 fi
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
88 fi
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
101 fi
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
127 fi
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
137 fi
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
144 fi
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 -ne 0 ]; then
166 test_done "$testroot" "$ret"
167 return 1
168 fi
170 cmp -s $testroot/stdout.expected $testroot/stdout
171 ret=$?
172 if [ $ret -ne 0 ]; then
173 diff -u $testroot/stdout.expected $testroot/stdout
174 test_done "$testroot" "$ret"
175 return 1
176 fi
178 ls -l $testroot/wt/xfile | grep -q '^-rwx'
179 ret=$?
180 if [ $ret -ne 0 ]; then
181 echo "file is not executable" >&2
182 ls -l $testroot/wt/xfile >&2
183 fi
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 -eq 0 ]; then
199 test_done "$testroot" "1"
200 return 1
201 fi
203 echo -n "" > $testroot/stdout.expected
204 cmp -s $testroot/stdout.expected $testroot/stdout
205 ret=$?
206 if [ $ret -ne 0 ]; then
207 diff -u $testroot/stdout.expected $testroot/stdout
208 test_done "$testroot" "$ret"
209 return 1
210 fi
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 -ne 0 ]; then
223 diff -u $testroot/stderr.expected $testroot/stderr
224 test_done "$testroot" "$ret"
225 return 1
226 fi
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 -ne 0 ]; then
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 cmp -s $testroot/stdout.expected $testroot/stdout
254 ret=$?
255 if [ $ret -ne 0 ]; then
256 diff -u $testroot/stdout.expected $testroot/stdout
257 test_done "$testroot" "$ret"
258 return 1
259 fi
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 -ne 0 ]; then
271 diff -u $testroot/content.expected $testroot/content
272 fi
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 -ne 0 ]; then
297 test_done "$testroot" "$ret"
298 return 1
299 fi
301 cmp -s $testroot/stdout.expected $testroot/stdout
302 ret=$?
303 if [ $ret -ne 0 ]; then
304 diff -u $testroot/stdout.expected $testroot/stdout
305 test_done "$testroot" "$ret"
306 return 1
307 fi
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 -ne 0 ]; then
319 diff -u $testroot/content.expected $testroot/content
320 fi
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 -ne 0 ]; then
343 test_done "$testroot" "$ret"
344 return 1
345 fi
347 cmp -s $testroot/stdout.expected $testroot/stdout
348 ret=$?
349 if [ $ret -ne 0 ]; then
350 diff -u $testroot/stdout.expected $testroot/stdout
351 test_done "$testroot" "$ret"
352 return 1
353 fi
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 -ne 0 ]; then
367 diff -u $testroot/stderr.expected $testroot/stderr
368 test_done "$testroot" "$ret"
369 return 1
370 fi
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 -ne 0 ]; then
382 diff -u $testroot/content.expected $testroot/content
383 fi
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 -eq 0 ]; then
399 echo "checkout succeeded unexpectedly" >&2
400 test_done "$testroot" "1"
401 return 1
402 fi
404 echo -n > $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected $testroot/stdout
406 ret=$?
407 if [ $ret -ne 0 ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 test_done "$testroot" "$ret"
410 return 1
411 fi
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 -ne 0 ]; then
418 diff -u $testroot/stderr.expected $testroot/stderr
419 test_done "$testroot" "$ret"
420 return 1
421 fi
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 -ne 0 ]; then
434 test_done "$testroot" "$ret"
435 return 1
436 fi
438 cmp -s $testroot/stdout.expected $testroot/stdout
439 ret=$?
440 if [ $ret -ne 0 ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
444 fi
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 -ne 0 ]; then
457 test_done "$testroot" "$ret"
458 return 1
459 fi
461 cmp -s $testroot/stdout.expected $testroot/stdout
462 ret=$?
463 if [ $ret -ne 0 ]; then
464 diff -u $testroot/stdout.expected $testroot/stdout
465 test_done "$testroot" "$ret"
466 return 1
467 fi
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 -ne 0 ]; then
479 diff -u $testroot/content.expected $testroot/content
480 test_done "$testroot" "$ret"
481 return 1
482 fi
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 -ne 0 ]; then
497 test_done "$testroot" "$ret"
498 return 1
499 fi
501 cmp -s $testroot/stdout.expected $testroot/stdout
502 ret=$?
503 if [ $ret -ne 0 ]; then
504 diff -u $testroot/stdout.expected $testroot/stdout
505 test_done "$testroot" "$ret"
506 return 1
507 fi
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 -ne 0 ]; then
519 diff -u $testroot/content.expected $testroot/content
520 test_done "$testroot" "$ret"
521 return 1
522 fi
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 -ne 0 ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 fi
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 -ne 0 ]; then
552 echo "got checkout failed unexpectedly" >&2
553 test_done "$testroot" "$ret"
554 return 1
555 fi
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 -ne 0 ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 if ! [ -h $testroot/wt/alpha.link ]; then
581 echo "alpha.link is not a symlink"
582 test_done "$testroot" "1"
583 return 1
584 fi
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 -ne 0 ]; then
591 diff -u $testroot/stdout.expected $testroot/stdout
592 test_done "$testroot" "$ret"
593 return 1
594 fi
596 if ! [ -h $testroot/wt/epsilon.link ]; then
597 echo "epsilon.link is not a symlink"
598 test_done "$testroot" "1"
599 return 1
600 fi
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 -ne 0 ]; then
607 diff -u $testroot/stdout.expected $testroot/stdout
608 test_done "$testroot" "$ret"
609 return 1
610 fi
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
617 fi
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 -ne 0 ]; then
625 diff -u $testroot/content.expected $testroot/content
626 test_done "$testroot" "$ret"
627 return 1
628 fi
630 if ! [ -h $testroot/wt/passwd2.link ]; then
631 echo "passwd2.link is not a symlink"
632 test_done "$testroot" "1"
633 return 1
634 fi
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 -ne 0 ]; then
641 diff -u $testroot/stdout.expected $testroot/stdout
642 test_done "$testroot" "$ret"
643 return 1
644 fi
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 -ne 0 ]; then
651 diff -u $testroot/stdout.expected $testroot/stdout
652 test_done "$testroot" "$ret"
653 return 1
654 fi
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 -ne 0 ]; then
661 diff -u $testroot/stdout.expected $testroot/stdout
662 test_done "$testroot" "$ret"
663 return 1
664 fi
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
671 fi
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 -ne 0 ]; then
679 diff -u $testroot/content.expected $testroot/content
680 fi
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 -ne 0 ]; then
699 test_done "$testroot" "$ret"
700 return 1
701 fi
703 if ! [ -h $testroot/wt/alpha.link ]; then
704 echo "alpha.link is not a symlink"
705 test_done "$testroot" "1"
706 return 1
707 fi
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 -ne 0 ]; then
714 diff -u $testroot/stdout.expected $testroot/stdout
715 test_done "$testroot" "$ret"
716 return 1
717 fi
719 if ! [ -h $testroot/wt/epsilon.link ]; then
720 echo "epsilon.link is not a symlink"
721 test_done "$testroot" "1"
722 return 1
723 fi
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 -ne 0 ]; then
730 diff -u $testroot/stdout.expected $testroot/stdout
731 test_done "$testroot" "$ret"
732 return 1
733 fi
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
740 fi
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 -ne 0 ]; then
748 diff -u $testroot/content.expected $testroot/content
749 test_done "$testroot" "$ret"
750 return 1
751 fi
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 -ne 0 ]; then
758 diff -u $testroot/stdout.expected $testroot/stdout
759 test_done "$testroot" "$ret"
760 return 1
761 fi
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 -ne 0 ]; then
768 diff -u $testroot/stdout.expected $testroot/stdout
769 test_done "$testroot" "$ret"
770 return 1
771 fi
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
778 fi
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 -ne 0 ]; then
786 diff -u $testroot/content.expected $testroot/content
787 fi
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 -eq 0 ]; then
806 echo "got checkout command succeeded unexpectedly" >&2
807 test_done "$testroot" "1"
808 return 1
809 fi
811 cmp -s $testroot/stderr.expected $testroot/stderr
812 ret=$?
813 if [ $ret -ne 0 ]; then
814 diff -u $testroot/stderr.expected $testroot/stderr
815 fi
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 -ne 0 ]; then
829 test_done "$testroot" "$ret"
830 return 1
831 fi
833 cmp -s $testroot/stdout.expected $testroot/stdout
834 ret=$?
835 if [ $ret -ne 0 ]; then
836 diff -u $testroot/stdout.expected $testroot/stdout
837 test_done "$testroot" "$ret"
838 return 1
839 fi
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 -ne 0 ]; then
851 diff -u $testroot/content.expected $testroot/content
852 fi
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