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 (cd $testroot/repo && git add .)
223 git_commit $testroot/repo -m "adding executable file"
224 local commit_id=`git_show_head $testroot/repo`
226 echo "A $testroot/wt/xfile" > $testroot/stdout.expected
227 echo "Checked out refs/heads/master: $commit_id" \
228 >> $testroot/stdout.expected
229 echo "Now shut up and hack" >> $testroot/stdout.expected
231 got checkout $testroot/repo $testroot/wt > $testroot/stdout
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 test_done "$testroot" "$ret"
235 return 1
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 (cd $testroot/repo && git checkout -q -b newbranch)
259 echo "modified alpha on new branch" > $testroot/repo/alpha
260 git_commit $testroot/repo -m "modified alpha on new branch"
262 local head_rev=`git_show_head $testroot/repo`
263 got checkout -b master -c $head_rev $testroot/repo $testroot/wt \
264 > $testroot/stdout 2> $testroot/stderr
265 ret=$?
266 if [ $ret -eq 0 ]; then
267 test_done "$testroot" "1"
268 return 1
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 (cd $testroot/repo && git tag -a -m "test" $tag)
306 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
307 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
308 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
309 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
310 echo "Checked out refs/heads/master: $commit_id" \
311 >> $testroot/stdout.expected
312 echo "Now shut up and hack" >> $testroot/stdout.expected
314 got checkout -c $tag $testroot/repo $testroot/wt > $testroot/stdout
315 ret=$?
316 if [ $ret -ne 0 ]; then
317 test_done "$testroot" "$ret"
318 return 1
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 (cd $testroot/repo && git -c protocol.file.allow=always \
350 submodule -q add ../repo2)
351 (cd $testroot/repo && git commit -q -m 'adding submodule')
352 local commit_id=`git_show_head $testroot/repo`
354 echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
355 echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
356 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
357 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
358 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
359 echo "Checked out refs/heads/master: $commit_id" \
360 >> $testroot/stdout.expected
361 echo "Now shut up and hack" >> $testroot/stdout.expected
363 got checkout $testroot/repo $testroot/wt > $testroot/stdout
364 ret=$?
365 if [ $ret -ne 0 ]; then
366 test_done "$testroot" "$ret"
367 return 1
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 "? $testroot/wt/alpha" > $testroot/stdout.expected
493 echo "? $testroot/wt/beta" >> $testroot/stdout.expected
494 echo "? $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
495 echo "? $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 echo "modified alpha" > $testroot/wt/alpha
555 echo "E $testroot/wt/alpha" > $testroot/stdout.expected
556 echo "E $testroot/wt/beta" >> $testroot/stdout.expected
557 echo "E $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
558 echo "E $testroot/wt/gamma/delta" >> $testroot/stdout.expected
559 echo "Checked out refs/heads/master: $commit_id" \
560 >> $testroot/stdout.expected
561 echo "Now shut up and hack" >> $testroot/stdout.expected
563 got checkout -E $testroot/repo $testroot/wt > $testroot/stdout
564 ret=$?
565 if [ $ret -ne 0 ]; then
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 cmp -s $testroot/stdout.expected $testroot/stdout
571 ret=$?
572 if [ $ret -ne 0 ]; then
573 diff -u $testroot/stdout.expected $testroot/stdout
574 test_done "$testroot" "$ret"
575 return 1
576 fi
578 echo "modified alpha" > $testroot/content.expected
579 echo "beta" >> $testroot/content.expected
580 echo "zeta" >> $testroot/content.expected
581 echo "delta" >> $testroot/content.expected
582 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
583 $testroot/wt/gamma/delta > $testroot/content
585 cmp -s $testroot/content.expected $testroot/content
586 ret=$?
587 if [ $ret -ne 0 ]; then
588 diff -u $testroot/content.expected $testroot/content
589 test_done "$testroot" "$ret"
590 return 1
591 fi
593 echo 'M alpha' > $testroot/stdout.expected
594 (cd $testroot/wt && got status > $testroot/stdout)
596 cmp -s $testroot/stdout.expected $testroot/stdout
597 ret=$?
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
600 fi
601 test_done "$testroot" "$ret"
604 test_checkout_symlink() {
605 local testroot=`test_init checkout_symlink`
607 (cd $testroot/repo && ln -s alpha alpha.link)
608 (cd $testroot/repo && ln -s epsilon epsilon.link)
609 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
610 (cd $testroot/repo && ln -s passwd.link passwd2.link)
611 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
612 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
613 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
614 (cd $testroot/repo && git add .)
615 git_commit $testroot/repo -m "add symlinks"
616 local commit_id=`git_show_head $testroot/repo`
618 got checkout $testroot/repo $testroot/wt > $testroot/stdout
619 ret=$?
620 if [ $ret -ne 0 ]; then
621 echo "got checkout failed unexpectedly" >&2
622 test_done "$testroot" "$ret"
623 return 1
624 fi
626 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
627 echo "A $testroot/wt/alpha.link" >> $testroot/stdout.expected
628 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
629 echo "A $testroot/wt/dotgotfoo.link" >> $testroot/stdout.expected
630 echo "A $testroot/wt/epsilon/beta.link" >> $testroot/stdout.expected
631 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
632 echo "A $testroot/wt/epsilon.link" >> $testroot/stdout.expected
633 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
634 echo "A $testroot/wt/nonexistent.link" >> $testroot/stdout.expected
635 echo "A $testroot/wt/passwd.link" >> $testroot/stdout.expected
636 echo "A $testroot/wt/passwd2.link" >> $testroot/stdout.expected
637 echo "Checked out refs/heads/master: $commit_id" \
638 >> $testroot/stdout.expected
639 echo "Now shut up and hack" >> $testroot/stdout.expected
641 cmp -s $testroot/stdout.expected $testroot/stdout
642 ret=$?
643 if [ $ret -ne 0 ]; then
644 diff -u $testroot/stdout.expected $testroot/stdout
645 test_done "$testroot" "$ret"
646 return 1
647 fi
649 if ! [ -h $testroot/wt/alpha.link ]; then
650 echo "alpha.link is not a symlink"
651 test_done "$testroot" "1"
652 return 1
653 fi
655 readlink $testroot/wt/alpha.link > $testroot/stdout
656 echo "alpha" > $testroot/stdout.expected
657 cmp -s $testroot/stdout.expected $testroot/stdout
658 ret=$?
659 if [ $ret -ne 0 ]; then
660 diff -u $testroot/stdout.expected $testroot/stdout
661 test_done "$testroot" "$ret"
662 return 1
663 fi
665 if ! [ -h $testroot/wt/epsilon.link ]; then
666 echo "epsilon.link is not a symlink"
667 test_done "$testroot" "1"
668 return 1
669 fi
671 readlink $testroot/wt/epsilon.link > $testroot/stdout
672 echo "epsilon" > $testroot/stdout.expected
673 cmp -s $testroot/stdout.expected $testroot/stdout
674 ret=$?
675 if [ $ret -ne 0 ]; then
676 diff -u $testroot/stdout.expected $testroot/stdout
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 if [ -h $testroot/wt/passwd.link ]; then
682 echo -n "passwd.link symlink points outside of work tree: " >&2
683 readlink $testroot/wt/passwd.link >&2
684 test_done "$testroot" "1"
685 return 1
686 fi
688 echo -n "/etc/passwd" > $testroot/content.expected
689 cp $testroot/wt/passwd.link $testroot/content
691 cmp -s $testroot/content.expected $testroot/content
692 ret=$?
693 if [ $ret -ne 0 ]; then
694 diff -u $testroot/content.expected $testroot/content
695 test_done "$testroot" "$ret"
696 return 1
697 fi
699 if ! [ -h $testroot/wt/passwd2.link ]; then
700 echo "passwd2.link is not a symlink"
701 test_done "$testroot" "1"
702 return 1
703 fi
705 readlink $testroot/wt/passwd2.link > $testroot/stdout
706 echo "passwd.link" > $testroot/stdout.expected
707 cmp -s $testroot/stdout.expected $testroot/stdout
708 ret=$?
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 test_done "$testroot" "$ret"
712 return 1
713 fi
715 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
716 echo "../beta" > $testroot/stdout.expected
717 cmp -s $testroot/stdout.expected $testroot/stdout
718 ret=$?
719 if [ $ret -ne 0 ]; then
720 diff -u $testroot/stdout.expected $testroot/stdout
721 test_done "$testroot" "$ret"
722 return 1
723 fi
725 readlink $testroot/wt/nonexistent.link > $testroot/stdout
726 echo "nonexistent" > $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/dotgotfoo.link ]; then
736 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
737 readlink $testroot/wt/dotgotfoo.link >&2
738 test_done "$testroot" "1"
739 return 1
740 fi
742 echo -n ".got/foo" > $testroot/content.expected
743 cp $testroot/wt/dotgotfoo.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 fi
750 test_done "$testroot" "$ret"
753 test_checkout_symlink_relative_wtpath() {
754 local testroot=`test_init checkout_symlink_with_wtpath`
756 (cd $testroot/repo && ln -s alpha alpha.link)
757 (cd $testroot/repo && ln -s epsilon epsilon.link)
758 (cd $testroot/repo && ln -s /etc/passwd passwd.link)
759 (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
760 (cd $testroot/repo && ln -s nonexistent nonexistent.link)
761 (cd $testroot/repo && ln -s .got/foo dotgotfoo.link)
762 (cd $testroot/repo && git add .)
763 git_commit $testroot/repo -m "add symlinks"
765 (cd $testroot && got checkout $testroot/repo wt > /dev/null)
766 ret=$?
767 if [ $ret -ne 0 ]; then
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 if ! [ -h $testroot/wt/alpha.link ]; then
773 echo "alpha.link is not a symlink"
774 test_done "$testroot" "1"
775 return 1
776 fi
778 readlink $testroot/wt/alpha.link > $testroot/stdout
779 echo "alpha" > $testroot/stdout.expected
780 cmp -s $testroot/stdout.expected $testroot/stdout
781 ret=$?
782 if [ $ret -ne 0 ]; then
783 diff -u $testroot/stdout.expected $testroot/stdout
784 test_done "$testroot" "$ret"
785 return 1
786 fi
788 if ! [ -h $testroot/wt/epsilon.link ]; then
789 echo "epsilon.link is not a symlink"
790 test_done "$testroot" "1"
791 return 1
792 fi
794 readlink $testroot/wt/epsilon.link > $testroot/stdout
795 echo "epsilon" > $testroot/stdout.expected
796 cmp -s $testroot/stdout.expected $testroot/stdout
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 diff -u $testroot/stdout.expected $testroot/stdout
800 test_done "$testroot" "$ret"
801 return 1
802 fi
804 if [ -h $testroot/wt/passwd.link ]; then
805 echo -n "passwd.link symlink points outside of work tree: " >&2
806 readlink $testroot/wt/passwd.link >&2
807 test_done "$testroot" "1"
808 return 1
809 fi
811 echo -n "/etc/passwd" > $testroot/content.expected
812 cp $testroot/wt/passwd.link $testroot/content
814 cmp -s $testroot/content.expected $testroot/content
815 ret=$?
816 if [ $ret -ne 0 ]; then
817 diff -u $testroot/content.expected $testroot/content
818 test_done "$testroot" "$ret"
819 return 1
820 fi
822 readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
823 echo "../beta" > $testroot/stdout.expected
824 cmp -s $testroot/stdout.expected $testroot/stdout
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/stdout.expected $testroot/stdout
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 readlink $testroot/wt/nonexistent.link > $testroot/stdout
833 echo "nonexistent" > $testroot/stdout.expected
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 if [ -h $testroot/wt/dotgotfoo.link ]; then
843 echo -n "dotgotfoo.link symlink points into .got dir: " >&2
844 readlink $testroot/wt/dotgotfoo.link >&2
845 test_done "$testroot" "1"
846 return 1
847 fi
849 echo -n ".got/foo" > $testroot/content.expected
850 cp $testroot/wt/dotgotfoo.link $testroot/content
852 cmp -s $testroot/content.expected $testroot/content
853 ret=$?
854 if [ $ret -ne 0 ]; then
855 diff -u $testroot/content.expected $testroot/content
856 fi
857 test_done "$testroot" "$ret"
860 test_checkout_repo_with_unknown_extension() {
861 local testroot=`test_init checkout_repo_with_unknown_extension`
863 (cd $testroot/repo &&
864 git config --add extensions.badExtension foobar)
865 (cd $testroot/repo &&
866 git config --add extensions.otherBadExtension 0)
868 echo "got: badExtension: unsupported repository format extension" \
869 > $testroot/stderr.expected
870 got checkout $testroot/repo $testroot/wt \
871 > $testroot/stdout 2> $testroot/stderr
873 ret=$?
874 if [ $ret -eq 0 ]; then
875 echo "got checkout command succeeded unexpectedly" >&2
876 test_done "$testroot" "1"
877 return 1
878 fi
880 cmp -s $testroot/stderr.expected $testroot/stderr
881 ret=$?
882 if [ $ret -ne 0 ]; then
883 diff -u $testroot/stderr.expected $testroot/stderr
884 fi
885 test_done "$testroot" "$ret"
888 test_checkout_quiet() {
889 local testroot=`test_init checkout_quiet`
891 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
892 git_show_head $testroot/repo >> $testroot/stdout.expected
893 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
895 got checkout -q $testroot/repo $testroot/wt > $testroot/stdout
896 ret=$?
897 if [ $ret -ne 0 ]; then
898 test_done "$testroot" "$ret"
899 return 1
900 fi
902 cmp -s $testroot/stdout.expected $testroot/stdout
903 ret=$?
904 if [ $ret -ne 0 ]; then
905 diff -u $testroot/stdout.expected $testroot/stdout
906 test_done "$testroot" "$ret"
907 return 1
908 fi
910 echo "alpha" > $testroot/content.expected
911 echo "beta" >> $testroot/content.expected
912 echo "zeta" >> $testroot/content.expected
913 echo "delta" >> $testroot/content.expected
914 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
915 $testroot/wt/gamma/delta > $testroot/content
917 cmp -s $testroot/content.expected $testroot/content
918 ret=$?
919 if [ $ret -ne 0 ]; then
920 diff -u $testroot/content.expected $testroot/content
921 fi
922 test_done "$testroot" "$ret"
925 test_checkout_umask() {
926 local testroot=`test_init checkout_umask`
928 # using a subshell to avoid clobbering global umask
929 (umask 044 && got checkout "$testroot/repo" "$testroot/wt") \
930 >/dev/null
931 ret=$?
932 if [ $ret -ne 0 ]; then
933 test_done "$testroot" $ret
934 return 1
935 fi
937 for f in alpha beta epsilon/zeta gamma/delta; do
938 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
939 if [ $? -ne 0 ]; then
940 echo "$f is not 0600 after checkout" >&2
941 ls -l "$testroot/wt/$f" >&2
942 test_done "$testroot" 1
943 return 1
944 fi
945 done
947 for d in epsilon gamma; do
948 ls -ld "$testroot/wt/$d" | grep -q ^drwx--x--x
949 if [ $? -ne 0 ]; then
950 echo "$d is not 711 after checkout" >&2
951 ls -ld "$testroot/wt/$d" >&2
952 test_done "$testroot" 1
953 return 1
954 fi
955 done
957 test_done "$testroot" 0
960 test_checkout_ulimit_n() {
961 local testroot=`test_init checkout_ulimit_n`
963 echo -n "Checked out refs/heads/master: " >> $testroot/stdout.expected
964 git_show_head $testroot/repo >> $testroot/stdout.expected
965 printf "\nNow shut up and hack\n" >> $testroot/stdout.expected
967 # Drastically reduce the number of files we are allowed to use.
968 # This tests our down-scaling of caches which store open file handles.
969 # Checkout should still work; if it does not, then either there is
970 # a bug or the fixed limit used by this test case is no longer valid
971 # and must be raised. Use a subshell to avoid changing global ulimit.
972 (ulimit -n 33; got checkout -q $testroot/repo $testroot/wt \
973 > $testroot/stdout)
974 ret=$?
975 if [ $ret -ne 0 ]; then
976 test_done "$testroot" "$ret"
977 return 1
978 fi
980 cmp -s $testroot/stdout.expected $testroot/stdout
981 ret=$?
982 if [ $ret -ne 0 ]; then
983 diff -u $testroot/stdout.expected $testroot/stdout
984 test_done "$testroot" "$ret"
985 return 1
986 fi
988 echo "alpha" > $testroot/content.expected
989 echo "beta" >> $testroot/content.expected
990 echo "zeta" >> $testroot/content.expected
991 echo "delta" >> $testroot/content.expected
992 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
993 $testroot/wt/gamma/delta > $testroot/content
995 cmp -s $testroot/content.expected $testroot/content
996 ret=$?
997 if [ $ret -ne 0 ]; then
998 diff -u $testroot/content.expected $testroot/content
999 fi
1000 test_done "$testroot" "$ret"
1003 test_checkout_commit_keywords() {
1004 local testroot=$(test_init checkout_commit_keywords)
1006 set -- "$(git_show_head $testroot/repo)"
1008 got checkout $testroot/repo $testroot/wt > /dev/null
1009 ret=$?
1010 if [ $ret -ne 0 ]; then
1011 echo "checkout failed unexpectedly" >&2
1012 test_done "$testroot" "$ret"
1013 return 1
1016 for i in $(seq 4); do
1017 echo "zeta change $i" > "$testroot/wt/epsilon/zeta"
1019 (cd "$testroot/wt" && got ci -m "commit number $i" > /dev/null)
1020 ret=$?
1021 if [ $ret -ne 0 ]; then
1022 echo "commit failed unexpectedly" >&2
1023 test_done "$testroot" "$ret"
1024 return 1
1026 set -- "$@" "$(git_show_head $testroot/repo)"
1027 done
1029 echo "A $testroot/wt2/alpha" > $testroot/stdout.expected
1030 echo "A $testroot/wt2/beta" >> $testroot/stdout.expected
1031 echo "A $testroot/wt2/epsilon/zeta" >> $testroot/stdout.expected
1032 echo "A $testroot/wt2/gamma/delta" >> $testroot/stdout.expected
1033 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1034 >> $testroot/stdout.expected
1035 echo "Now shut up and hack" >> $testroot/stdout.expected
1037 got co -c :head:- $testroot/repo $testroot/wt2 > $testroot/stdout
1038 ret=$?
1039 if [ $ret -ne 0 ]; then
1040 test_done "$testroot" "$ret"
1041 return 1
1044 cmp -s $testroot/stdout.expected $testroot/stdout
1045 ret=$?
1046 if [ $ret -ne 0 ]; then
1047 diff -u $testroot/stdout.expected $testroot/stdout
1048 test_done "$testroot" "$ret"
1049 return 1
1052 echo "A $testroot/wt3/alpha" > $testroot/stdout.expected
1053 echo "A $testroot/wt3/beta" >> $testroot/stdout.expected
1054 echo "A $testroot/wt3/epsilon/zeta" >> $testroot/stdout.expected
1055 echo "A $testroot/wt3/gamma/delta" >> $testroot/stdout.expected
1056 echo "Checked out refs/heads/master: $(pop_idx 4 $@)" \
1057 >> $testroot/stdout.expected
1058 echo "Now shut up and hack" >> $testroot/stdout.expected
1060 got co -bmaster -c:base:- $testroot/repo $testroot/wt3 > \
1061 $testroot/stdout
1062 ret=$?
1063 if [ $ret -ne 0 ]; then
1064 test_done "$testroot" "$ret"
1065 return 1
1068 cmp -s $testroot/stdout.expected $testroot/stdout
1069 ret=$?
1070 if [ $ret -ne 0 ]; then
1071 diff -u $testroot/stdout.expected $testroot/stdout
1074 test_done "$testroot" "$ret"
1077 test_parseargs "$@"
1078 run_test test_checkout_basic
1079 run_test test_checkout_dir_exists
1080 run_test test_checkout_dir_not_empty
1081 run_test test_checkout_into_repo
1082 run_test test_checkout_overlap_repo
1083 run_test test_checkout_sets_xbit
1084 run_test test_checkout_commit_from_wrong_branch
1085 run_test test_checkout_tag
1086 run_test test_checkout_ignores_submodules
1087 run_test test_checkout_read_only
1088 run_test test_checkout_into_nonempty_dir
1089 run_test test_checkout_symlink
1090 run_test test_checkout_symlink_relative_wtpath
1091 run_test test_checkout_repo_with_unknown_extension
1092 run_test test_checkout_quiet
1093 run_test test_checkout_umask
1094 run_test test_checkout_ulimit_n
1095 run_test test_checkout_commit_keywords