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_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
160 fi
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
170 fi
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
179 fi
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
194 fi
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
204 fi
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
213 fi
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 git -C $testroot/repo 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
236 fi
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
244 fi
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
251 fi
252 test_done "$testroot" "$ret"
255 test_checkout_commit_from_wrong_branch() {
256 local testroot=`test_init checkout_commit_from_wrong_branch`
258 git -C $testroot/repo 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
269 fi
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
278 fi
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
294 fi
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 git -C $testroot/repo 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
319 fi
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
327 fi
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
340 fi
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 git -C $testroot/repo -c protocol.file.allow=always \
350 submodule -q add ../repo2
351 git -C $testroot/repo 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
368 fi
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
376 fi
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
389 fi
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
414 fi
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
422 fi
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
439 fi
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
452 fi
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
471 fi
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
480 fi
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
490 fi
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
505 fi
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
513 fi
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
528 fi
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
536 fi
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
551 fi
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
571 fi
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 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
594 fi
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
603 fi
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 git -C $testroot/repo 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
627 fi
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
650 fi
652 if ! [ -h $testroot/wt/alpha.link ]; then
653 echo "alpha.link is not a symlink"
654 test_done "$testroot" "1"
655 return 1
656 fi
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
666 fi
668 if ! [ -h $testroot/wt/epsilon.link ]; then
669 echo "epsilon.link is not a symlink"
670 test_done "$testroot" "1"
671 return 1
672 fi
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
682 fi
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
689 fi
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
700 fi
702 if ! [ -h $testroot/wt/passwd2.link ]; then
703 echo "passwd2.link is not a symlink"
704 test_done "$testroot" "1"
705 return 1
706 fi
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
716 fi
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
726 fi
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
736 fi
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
743 fi
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
752 fi
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 git -C $testroot/repo 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
773 fi
775 if ! [ -h $testroot/wt/alpha.link ]; then
776 echo "alpha.link is not a symlink"
777 test_done "$testroot" "1"
778 return 1
779 fi
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
789 fi
791 if ! [ -h $testroot/wt/epsilon.link ]; then
792 echo "epsilon.link is not a symlink"
793 test_done "$testroot" "1"
794 return 1
795 fi
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
805 fi
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
812 fi
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
823 fi
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
833 fi
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
843 fi
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
850 fi
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
859 fi
860 test_done "$testroot" "$ret"
863 test_checkout_repo_with_unknown_extension() {
864 local testroot=`test_init checkout_repo_with_unknown_extension`
866 git -C $testroot/repo config --add extensions.badExtension foobar
867 git -C $testroot/repo config --add extensions.otherBadExtension 0
869 echo "got: badExtension: unsupported repository format extension" \
870 > $testroot/stderr.expected
871 got checkout $testroot/repo $testroot/wt \
872 > $testroot/stdout 2> $testroot/stderr
874 ret=$?
875 if [ $ret -eq 0 ]; then
876 echo "got checkout command succeeded unexpectedly" >&2
877 test_done "$testroot" "1"
878 return 1
879 fi
881 cmp -s $testroot/stderr.expected $testroot/stderr
882 ret=$?
883 if [ $ret -ne 0 ]; then
884 diff -u $testroot/stderr.expected $testroot/stderr
885 fi
886 test_done "$testroot" "$ret"
889 test_checkout_quiet() {
890 local testroot=`test_init checkout_quiet`
892 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
893 git_show_head $testroot/repo >> $testroot/stdout.expected
894 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
896 got checkout -q $testroot/repo $testroot/wt > $testroot/stdout
897 ret=$?
898 if [ $ret -ne 0 ]; then
899 test_done "$testroot" "$ret"
900 return 1
901 fi
903 cmp -s $testroot/stdout.expected $testroot/stdout
904 ret=$?
905 if [ $ret -ne 0 ]; then
906 diff -u $testroot/stdout.expected $testroot/stdout
907 test_done "$testroot" "$ret"
908 return 1
909 fi
911 echo "alpha" > $testroot/content.expected
912 echo "beta" >> $testroot/content.expected
913 echo "zeta" >> $testroot/content.expected
914 echo "delta" >> $testroot/content.expected
915 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
916 $testroot/wt/gamma/delta > $testroot/content
918 cmp -s $testroot/content.expected $testroot/content
919 ret=$?
920 if [ $ret -ne 0 ]; then
921 diff -u $testroot/content.expected $testroot/content
922 fi
923 test_done "$testroot" "$ret"
926 test_checkout_umask() {
927 local testroot=`test_init checkout_umask`
929 # using a subshell to avoid clobbering global umask
930 (umask 044 && got checkout "$testroot/repo" "$testroot/wt") \
931 >/dev/null
932 ret=$?
933 if [ $ret -ne 0 ]; then
934 test_done "$testroot" $ret
935 return 1
936 fi
938 for f in alpha beta epsilon/zeta gamma/delta; do
939 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
940 if [ $? -ne 0 ]; then
941 echo "$f is not 0600 after checkout" >&2
942 ls -l "$testroot/wt/$f" >&2
943 test_done "$testroot" 1
944 return 1
945 fi
946 done
948 for d in epsilon gamma; do
949 ls -ld "$testroot/wt/$d" | grep -q ^drwx--x--x
950 if [ $? -ne 0 ]; then
951 echo "$d is not 711 after checkout" >&2
952 ls -ld "$testroot/wt/$d" >&2
953 test_done "$testroot" 1
954 return 1
955 fi
956 done
958 test_done "$testroot" 0
961 test_checkout_ulimit_n() {
962 local testroot=`test_init checkout_ulimit_n`
964 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
965 git_show_head $testroot/repo >> $testroot/stdout.expected
966 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
968 # Drastically reduce the number of files we are allowed to use.
969 # This tests our down-scaling of caches which store open file handles.
970 # Checkout should still work; if it does not, then either there is
971 # a bug or the fixed limit used by this test case is no longer valid
972 # and must be raised. Use a subshell to avoid changing global ulimit.
973 (ulimit -n 33; got checkout -q $testroot/repo $testroot/wt \
974 > $testroot/stdout)
975 ret=$?
976 if [ $ret -ne 0 ]; then
977 test_done "$testroot" "$ret"
978 return 1
979 fi
981 cmp -s $testroot/stdout.expected $testroot/stdout
982 ret=$?
983 if [ $ret -ne 0 ]; then
984 diff -u $testroot/stdout.expected $testroot/stdout
985 test_done "$testroot" "$ret"
986 return 1
987 fi
989 echo "alpha" > $testroot/content.expected
990 echo "beta" >> $testroot/content.expected
991 echo "zeta" >> $testroot/content.expected
992 echo "delta" >> $testroot/content.expected
993 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
994 $testroot/wt/gamma/delta > $testroot/content
996 cmp -s $testroot/content.expected $testroot/content
997 ret=$?
998 if [ $ret -ne 0 ]; then
999 diff -u $testroot/content.expected $testroot/content
1001 test_done "$testroot" "$ret"
1004 test_checkout_commit_keywords() {
1005 local testroot=$(test_init checkout_commit_keywords)
1007 set -- "$(git_show_head $testroot/repo)"
1009 got checkout $testroot/repo $testroot/wt > /dev/null
1010 ret=$?
1011 if [ $ret -ne 0 ]; then
1012 echo "checkout failed unexpectedly" >&2
1013 test_done "$testroot" "$ret"
1014 return 1
1017 for i in $(seq 4); do
1018 echo "zeta change $i" > "$testroot/wt/epsilon/zeta"
1020 (cd "$testroot/wt" && got ci -m "commit number $i" > /dev/null)
1021 ret=$?
1022 if [ $ret -ne 0 ]; then
1023 echo "commit failed unexpectedly" >&2
1024 test_done "$testroot" "$ret"
1025 return 1
1027 set -- "$@" "$(git_show_head $testroot/repo)"
1028 done
1030 echo "A $testroot/wt2/alpha" > $testroot/stdout.expected
1031 echo "A $testroot/wt2/beta" >> $testroot/stdout.expected
1032 echo "A $testroot/wt2/epsilon/zeta" >> $testroot/stdout.expected
1033 echo "A $testroot/wt2/gamma/delta" >> $testroot/stdout.expected
1034 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1035 >> $testroot/stdout.expected
1036 echo "Now shut up and hack" >> $testroot/stdout.expected
1038 got co -c :head:- $testroot/repo $testroot/wt2 > $testroot/stdout
1039 ret=$?
1040 if [ $ret -ne 0 ]; then
1041 test_done "$testroot" "$ret"
1042 return 1
1045 cmp -s $testroot/stdout.expected $testroot/stdout
1046 ret=$?
1047 if [ $ret -ne 0 ]; then
1048 diff -u $testroot/stdout.expected $testroot/stdout
1049 test_done "$testroot" "$ret"
1050 return 1
1053 echo "A $testroot/wt3/alpha" > $testroot/stdout.expected
1054 echo "A $testroot/wt3/beta" >> $testroot/stdout.expected
1055 echo "A $testroot/wt3/epsilon/zeta" >> $testroot/stdout.expected
1056 echo "A $testroot/wt3/gamma/delta" >> $testroot/stdout.expected
1057 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1058 >> $testroot/stdout.expected
1059 echo "Now shut up and hack" >> $testroot/stdout.expected
1061 got co -bmaster -c:base:- $testroot/repo $testroot/wt3 > \
1062 $testroot/stdout
1063 ret=$?
1064 if [ $ret -ne 0 ]; then
1065 test_done "$testroot" "$ret"
1066 return 1
1069 cmp -s $testroot/stdout.expected $testroot/stdout
1070 ret=$?
1071 if [ $ret -ne 0 ]; then
1072 diff -u $testroot/stdout.expected $testroot/stdout
1075 test_done "$testroot" "$ret"
1078 test_parseargs "$@"
1079 run_test test_checkout_basic
1080 run_test test_checkout_dir_exists
1081 run_test test_checkout_dir_not_empty
1082 run_test test_checkout_into_repo
1083 run_test test_checkout_overlap_repo
1084 run_test test_checkout_sets_xbit
1085 run_test test_checkout_commit_from_wrong_branch
1086 run_test test_checkout_tag
1087 run_test test_checkout_ignores_submodules
1088 run_test test_checkout_read_only
1089 run_test test_checkout_into_nonempty_dir
1090 run_test test_checkout_symlink
1091 run_test test_checkout_symlink_relative_wtpath
1092 run_test test_checkout_repo_with_unknown_extension
1093 run_test test_checkout_quiet
1094 run_test test_checkout_umask
1095 run_test test_checkout_ulimit_n
1096 run_test test_checkout_commit_keywords