3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 function test_checkout_basic {
20 local testroot=`test_init checkout_basic`
22 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
23 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
24 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
25 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
26 echo "Now shut up and hack" >> $testroot/stdout.expected
28 got checkout $testroot/repo $testroot/wt > $testroot/stdout
30 if [ "$ret" != "0" ]; then
31 test_done "$testroot" "$ret"
35 cmp -s $testroot/stdout.expected $testroot/stdout
37 if [ "$ret" != "0" ]; then
38 diff -u $testroot/stdout.expected $testroot/stdout
39 test_done "$testroot" "$ret"
43 echo "alpha" > $testroot/content.expected
44 echo "beta" >> $testroot/content.expected
45 echo "zeta" >> $testroot/content.expected
46 echo "delta" >> $testroot/content.expected
47 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
48 $testroot/wt/gamma/delta > $testroot/content
50 cmp -s $testroot/content.expected $testroot/content
52 if [ "$ret" != "0" ]; then
53 diff -u $testroot/content.expected $testroot/content
55 test_done "$testroot" "$ret"
58 function test_checkout_sets_xbit {
59 local testroot=`test_init checkout_sets_xbit 1`
61 touch $testroot/repo/xfile
62 chmod +x $testroot/repo/xfile
63 (cd $testroot/repo && git add .)
64 git_commit $testroot/repo -m "adding executable file"
66 echo "A $testroot/wt/xfile" > $testroot/stdout.expected
67 echo "Now shut up and hack" >> $testroot/stdout.expected
69 got checkout $testroot/repo $testroot/wt > $testroot/stdout
71 if [ "$ret" != "0" ]; then
72 test_done "$testroot" "$ret"
76 cmp -s $testroot/stdout.expected $testroot/stdout
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
84 ls -l $testroot/wt/xfile | grep -q '^-rwx'
86 if [ "$ret" != "0" ]; then
87 echo "file is not executable" >&2
88 ls -l $testroot/wt/xfile >&2
90 test_done "$testroot" "$ret"
93 function test_checkout_commit_from_wrong_branch {
94 local testroot=`test_init checkout_commit_from_wrong_branch`
96 (cd $testroot/repo && git checkout -q -b newbranch)
97 echo "modified alpha on new branch" > $testroot/repo/alpha
98 git_commit $testroot/repo -m "modified alpha on new branch"
100 local head_rev=`git_show_head $testroot/repo`
101 got checkout -b master -c $head_rev $testroot/repo $testroot/wt \
102 > $testroot/stdout 2> $testroot/stderr
104 if [ "$ret" == "0" ]; then
105 test_done "$testroot" "1"
109 echo -n "" > $testroot/stdout.expected
110 cmp -s $testroot/stdout.expected $testroot/stdout
112 if [ "$ret" != "0" ]; then
113 diff -u $testroot/stdout.expected $testroot/stdout
114 test_done "$testroot" "$ret"
118 echo "got: target commit is on a different branch" \
119 > $testroot/stderr.expected
120 cmp -s $testroot/stderr.expected $testroot/stderr
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/stderr.expected $testroot/stderr
124 test_done "$testroot" "$ret"
128 test_done "$testroot" "$ret"
131 run_test test_checkout_basic
132 run_test test_checkout_sets_xbit
133 run_test test_checkout_commit_from_wrong_branch