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 -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
296 ret=$?
297 if [ $ret -ne 0 ]; then
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 cmp -s $testroot/stdout.expected $testroot/stdout
303 ret=$?
304 if [ $ret -ne 0 ]; then
305 diff -u $testroot/stdout.expected $testroot/stdout
306 test_done "$testroot" "$ret"
307 return 1
308 fi
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
318 ret=$?
319 if [ $ret -ne 0 ]; then
320 diff -u $testroot/content.expected $testroot/content
321 fi
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
342 ret=$?
343 if [ $ret -ne 0 ]; then
344 test_done "$testroot" "$ret"
345 return 1
346 fi
348 cmp -s $testroot/stdout.expected $testroot/stdout
349 ret=$?
350 if [ $ret -ne 0 ]; then
351 diff -u $testroot/stdout.expected $testroot/stdout
352 test_done "$testroot" "$ret"
353 return 1
354 fi
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
366 ret=$?
367 if [ $ret -ne 0 ]; then
368 diff -u $testroot/stderr.expected $testroot/stderr
369 test_done "$testroot" "$ret"
370 return 1
371 fi
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
381 ret=$?
382 if [ $ret -ne 0 ]; then
383 diff -u $testroot/content.expected $testroot/content
384 fi
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 \
397 2> $testroot/stderr
398 ret=$?
399 if [ $ret -eq 0 ]; then
400 echo "checkout succeeded unexpectedly" >&2
401 test_done "$testroot" "1"
402 return 1
403 fi
405 echo -n > $testroot/stdout.expected
406 cmp -s $testroot/stdout.expected $testroot/stdout
407 ret=$?
408 if [ $ret -ne 0 ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
411 return 1
412 fi
414 echo "got: $testroot/wt: directory exists and is not empty" \
415 > $testroot/stderr.expected
416 cmp -s $testroot/stderr.expected $testroot/stderr
417 ret=$?
418 if [ $ret -ne 0 ]; then
419 diff -u $testroot/stderr.expected $testroot/stderr
420 test_done "$testroot" "$ret"
421 return 1
422 fi
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
433 ret=$?
434 if [ $ret -ne 0 ]; then
435 test_done "$testroot" "$ret"
436 return 1
437 fi
439 cmp -s $testroot/stdout.expected $testroot/stdout
440 ret=$?
441 if [ $ret -ne 0 ]; then
442 diff -u $testroot/stdout.expected $testroot/stdout
443 test_done "$testroot" "$ret"
444 return 1
445 fi
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
456 ret=$?
457 if [ $ret -ne 0 ]; then
458 test_done "$testroot" "$ret"
459 return 1
460 fi
462 cmp -s $testroot/stdout.expected $testroot/stdout
463 ret=$?
464 if [ $ret -ne 0 ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 test_done "$testroot" "$ret"
467 return 1
468 fi
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
478 ret=$?
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/content.expected $testroot/content
481 test_done "$testroot" "$ret"
482 return 1
483 fi
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
496 ret=$?
497 if [ $ret -ne 0 ]; then
498 test_done "$testroot" "$ret"
499 return 1
500 fi
502 cmp -s $testroot/stdout.expected $testroot/stdout
503 ret=$?
504 if [ $ret -ne 0 ]; then
505 diff -u $testroot/stdout.expected $testroot/stdout
506 test_done "$testroot" "$ret"
507 return 1
508 fi
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
518 ret=$?
519 if [ $ret -ne 0 ]; then
520 diff -u $testroot/content.expected $testroot/content
521 test_done "$testroot" "$ret"
522 return 1
523 fi
525 echo 'M alpha' > $testroot/stdout.expected
526 (cd $testroot/wt && got status > $testroot/stdout)
528 cmp -s $testroot/stdout.expected $testroot/stdout
529 ret=$?
530 if [ $ret -ne 0 ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 fi
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
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 echo "got checkout failed unexpectedly" >&2
554 test_done "$testroot" "$ret"
555 return 1
556 fi
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
574 ret=$?
575 if [ $ret -ne 0 ]; then
576 diff -u $testroot/stdout.expected $testroot/stdout
577 test_done "$testroot" "$ret"
578 return 1
579 fi
581 if ! [ -h $testroot/wt/alpha.link ]; then
582 echo "alpha.link is not a symlink"
583 test_done "$testroot" "1"
584 return 1
585 fi
587 readlink $testroot/wt/alpha.link > $testroot/stdout
588 echo "alpha" > $testroot/stdout.expected
589 cmp -s $testroot/stdout.expected $testroot/stdout
590 ret=$?
591 if [ $ret -ne 0 ]; then
592 diff -u $testroot/stdout.expected $testroot/stdout
593 test_done "$testroot" "$ret"
594 return 1
595 fi
597 if ! [ -h $testroot/wt/epsilon.link ]; then
598 echo "epsilon.link is not a symlink"
599 test_done "$testroot" "1"
600 return 1
601 fi
603 readlink $testroot/wt/epsilon.link > $testroot/stdout
604 echo "epsilon" > $testroot/stdout.expected
605 cmp -s $testroot/stdout.expected $testroot/stdout
606 ret=$?
607 if [ $ret -ne 0 ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
610 return 1
611 fi
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"
617 return 1
618 fi
620 echo -n "/etc/passwd" > $testroot/content.expected
621 cp $testroot/wt/passwd.link $testroot/content
623 cmp -s $testroot/content.expected $testroot/content
624 ret=$?
625 if [ $ret -ne 0 ]; then
626 diff -u $testroot/content.expected $testroot/content
627 test_done "$testroot" "$ret"
628 return 1
629 fi
631 if ! [ -h $testroot/wt/passwd2.link ]; then
632 echo "passwd2.link is not a symlink"
633 test_done "$testroot" "1"
634 return 1
635 fi
637 readlink $testroot/wt/passwd2.link > $testroot/stdout
638 echo "passwd.link" > $testroot/stdout.expected
639 cmp -s $testroot/stdout.expected $testroot/stdout
640 ret=$?
641 if [ $ret -ne 0 ]; then
642 diff -u $testroot/stdout.expected $testroot/stdout
643 test_done "$testroot" "$ret"
644 return 1
645 fi
647 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
648 echo "../beta" > $testroot/stdout.expected
649 cmp -s $testroot/stdout.expected $testroot/stdout
650 ret=$?
651 if [ $ret -ne 0 ]; then
652 diff -u $testroot/stdout.expected $testroot/stdout
653 test_done "$testroot" "$ret"
654 return 1
655 fi
657 readlink $testroot/wt/nonexistent.link > $testroot/stdout
658 echo "nonexistent" > $testroot/stdout.expected
659 cmp -s $testroot/stdout.expected $testroot/stdout
660 ret=$?
661 if [ $ret -ne 0 ]; then
662 diff -u $testroot/stdout.expected $testroot/stdout
663 test_done "$testroot" "$ret"
664 return 1
665 fi
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"
671 return 1
672 fi
674 echo -n ".got/foo" > $testroot/content.expected
675 cp $testroot/wt/dotgotfoo.link $testroot/content
677 cmp -s $testroot/content.expected $testroot/content
678 ret=$?
679 if [ $ret -ne 0 ]; then
680 diff -u $testroot/content.expected $testroot/content
681 fi
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)
698 ret=$?
699 if [ $ret -ne 0 ]; then
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 if ! [ -h $testroot/wt/alpha.link ]; then
705 echo "alpha.link is not a symlink"
706 test_done "$testroot" "1"
707 return 1
708 fi
710 readlink $testroot/wt/alpha.link > $testroot/stdout
711 echo "alpha" > $testroot/stdout.expected
712 cmp -s $testroot/stdout.expected $testroot/stdout
713 ret=$?
714 if [ $ret -ne 0 ]; then
715 diff -u $testroot/stdout.expected $testroot/stdout
716 test_done "$testroot" "$ret"
717 return 1
718 fi
720 if ! [ -h $testroot/wt/epsilon.link ]; then
721 echo "epsilon.link is not a symlink"
722 test_done "$testroot" "1"
723 return 1
724 fi
726 readlink $testroot/wt/epsilon.link > $testroot/stdout
727 echo "epsilon" > $testroot/stdout.expected
728 cmp -s $testroot/stdout.expected $testroot/stdout
729 ret=$?
730 if [ $ret -ne 0 ]; then
731 diff -u $testroot/stdout.expected $testroot/stdout
732 test_done "$testroot" "$ret"
733 return 1
734 fi
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"
740 return 1
741 fi
743 echo -n "/etc/passwd" > $testroot/content.expected
744 cp $testroot/wt/passwd.link $testroot/content
746 cmp -s $testroot/content.expected $testroot/content
747 ret=$?
748 if [ $ret -ne 0 ]; then
749 diff -u $testroot/content.expected $testroot/content
750 test_done "$testroot" "$ret"
751 return 1
752 fi
754 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
755 echo "../beta" > $testroot/stdout.expected
756 cmp -s $testroot/stdout.expected $testroot/stdout
757 ret=$?
758 if [ $ret -ne 0 ]; then
759 diff -u $testroot/stdout.expected $testroot/stdout
760 test_done "$testroot" "$ret"
761 return 1
762 fi
764 readlink $testroot/wt/nonexistent.link > $testroot/stdout
765 echo "nonexistent" > $testroot/stdout.expected
766 cmp -s $testroot/stdout.expected $testroot/stdout
767 ret=$?
768 if [ $ret -ne 0 ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 test_done "$testroot" "$ret"
771 return 1
772 fi
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"
778 return 1
779 fi
781 echo -n ".got/foo" > $testroot/content.expected
782 cp $testroot/wt/dotgotfoo.link $testroot/content
784 cmp -s $testroot/content.expected $testroot/content
785 ret=$?
786 if [ $ret -ne 0 ]; then
787 diff -u $testroot/content.expected $testroot/content
788 fi
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
805 ret=$?
806 if [ $ret -eq 0 ]; then
807 echo "got checkout command succeeded unexpectedly" >&2
808 test_done "$testroot" "1"
809 return 1
810 fi
812 cmp -s $testroot/stderr.expected $testroot/stderr
813 ret=$?
814 if [ $ret -ne 0 ]; then
815 diff -u $testroot/stderr.expected $testroot/stderr
816 fi
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
828 ret=$?
829 if [ $ret -ne 0 ]; then
830 test_done "$testroot" "$ret"
831 return 1
832 fi
834 cmp -s $testroot/stdout.expected $testroot/stdout
835 ret=$?
836 if [ $ret -ne 0 ]; then
837 diff -u $testroot/stdout.expected $testroot/stdout
838 test_done "$testroot" "$ret"
839 return 1
840 fi
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
850 ret=$?
851 if [ $ret -ne 0 ]; then
852 diff -u $testroot/content.expected $testroot/content
853 fi
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") \
862 >/dev/null
863 ret=$?
864 if [ $ret -ne 0 ]; then
865 test_done "$testroot" $ret
866 return 1
867 fi
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
875 return 1
876 fi
877 done
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
885 return 1
886 fi
887 done
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 \
905 > $testroot/stdout)
906 ret=$?
907 if [ $ret -ne 0 ]; then
908 test_done "$testroot" "$ret"
909 return 1
910 fi
912 cmp -s $testroot/stdout.expected $testroot/stdout
913 ret=$?
914 if [ $ret -ne 0 ]; then
915 diff -u $testroot/stdout.expected $testroot/stdout
916 test_done "$testroot" "$ret"
917 return 1
918 fi
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
928 ret=$?
929 if [ $ret -ne 0 ]; then
930 diff -u $testroot/content.expected $testroot/content
931 fi
932 test_done "$testroot" "$ret"
935 test_parseargs "$@"
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