Blame


1 0e673013 2019-01-02 stsp #!/bin/sh
2 0e673013 2019-01-02 stsp #
3 0e673013 2019-01-02 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 0e673013 2019-01-02 stsp #
5 0e673013 2019-01-02 stsp # Permission to use, copy, modify, and distribute this software for any
6 0e673013 2019-01-02 stsp # purpose with or without fee is hereby granted, provided that the above
7 0e673013 2019-01-02 stsp # copyright notice and this permission notice appear in all copies.
8 0e673013 2019-01-02 stsp #
9 0e673013 2019-01-02 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 0e673013 2019-01-02 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 0e673013 2019-01-02 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 0e673013 2019-01-02 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 0e673013 2019-01-02 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 0e673013 2019-01-02 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 0e673013 2019-01-02 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 0e673013 2019-01-02 stsp
17 0e673013 2019-01-02 stsp . ./common.sh
18 0e673013 2019-01-02 stsp
19 0e673013 2019-01-02 stsp function test_checkout_basic {
20 0e673013 2019-01-02 stsp local testroot=`test_init checkout_basic`
21 0e673013 2019-01-02 stsp
22 0e673013 2019-01-02 stsp echo "A $testroot/wt/alpha" > $testroot/stdout.expected
23 0e673013 2019-01-02 stsp echo "A $testroot/wt/beta" >> $testroot/stdout.expected
24 0e673013 2019-01-02 stsp echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
25 0e673013 2019-01-02 stsp echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
26 0e673013 2019-01-02 stsp echo "Now shut up and hack" >> $testroot/stdout.expected
27 0e673013 2019-01-02 stsp
28 0e673013 2019-01-02 stsp got checkout $testroot/repo $testroot/wt > $testroot/stdout
29 e60e7f5b 2019-02-10 stsp ret="$?"
30 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
31 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
32 0e673013 2019-01-02 stsp return 1
33 0e673013 2019-01-02 stsp fi
34 0e673013 2019-01-02 stsp
35 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
36 e60e7f5b 2019-02-10 stsp ret="$?"
37 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
38 0e673013 2019-01-02 stsp diff -u $testroot/stdout.expected $testroot/stdout
39 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
40 0e673013 2019-01-02 stsp return 1
41 0e673013 2019-01-02 stsp fi
42 0e673013 2019-01-02 stsp
43 0e673013 2019-01-02 stsp echo "alpha" > $testroot/content.expected
44 0e673013 2019-01-02 stsp echo "beta" >> $testroot/content.expected
45 0e673013 2019-01-02 stsp echo "zeta" >> $testroot/content.expected
46 0e673013 2019-01-02 stsp echo "delta" >> $testroot/content.expected
47 0e673013 2019-01-02 stsp cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
48 0e673013 2019-01-02 stsp $testroot/wt/gamma/delta > $testroot/content
49 0e673013 2019-01-02 stsp
50 8d301dd9 2019-05-14 stsp cmp -s $testroot/content.expected $testroot/content
51 693719bc 2019-01-03 stsp ret="$?"
52 693719bc 2019-01-03 stsp if [ "$ret" != "0" ]; then
53 0e673013 2019-01-02 stsp diff -u $testroot/content.expected $testroot/content
54 0e673013 2019-01-02 stsp fi
55 693719bc 2019-01-03 stsp test_done "$testroot" "$ret"
56 0e673013 2019-01-02 stsp }
57 0e673013 2019-01-02 stsp
58 68ed9ba5 2019-02-10 stsp function test_checkout_sets_xbit {
59 68ed9ba5 2019-02-10 stsp local testroot=`test_init checkout_sets_xbit 1`
60 68ed9ba5 2019-02-10 stsp
61 68ed9ba5 2019-02-10 stsp touch $testroot/repo/xfile
62 68ed9ba5 2019-02-10 stsp chmod +x $testroot/repo/xfile
63 68ed9ba5 2019-02-10 stsp (cd $testroot/repo && git add .)
64 68ed9ba5 2019-02-10 stsp git_commit $testroot/repo -m "adding executable file"
65 68ed9ba5 2019-02-10 stsp
66 68ed9ba5 2019-02-10 stsp echo "A $testroot/wt/xfile" > $testroot/stdout.expected
67 68ed9ba5 2019-02-10 stsp echo "Now shut up and hack" >> $testroot/stdout.expected
68 68ed9ba5 2019-02-10 stsp
69 68ed9ba5 2019-02-10 stsp got checkout $testroot/repo $testroot/wt > $testroot/stdout
70 68ed9ba5 2019-02-10 stsp ret="$?"
71 68ed9ba5 2019-02-10 stsp if [ "$ret" != "0" ]; then
72 68ed9ba5 2019-02-10 stsp test_done "$testroot" "$ret"
73 68ed9ba5 2019-02-10 stsp return 1
74 68ed9ba5 2019-02-10 stsp fi
75 68ed9ba5 2019-02-10 stsp
76 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
77 68ed9ba5 2019-02-10 stsp ret="$?"
78 68ed9ba5 2019-02-10 stsp if [ "$ret" != "0" ]; then
79 68ed9ba5 2019-02-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
80 68ed9ba5 2019-02-10 stsp test_done "$testroot" "$ret"
81 68ed9ba5 2019-02-10 stsp return 1
82 68ed9ba5 2019-02-10 stsp fi
83 68ed9ba5 2019-02-10 stsp
84 68ed9ba5 2019-02-10 stsp ls -l $testroot/wt/xfile | grep -q '^-rwx'
85 68ed9ba5 2019-02-10 stsp ret="$?"
86 68ed9ba5 2019-02-10 stsp if [ "$ret" != "0" ]; then
87 68ed9ba5 2019-02-10 stsp echo "file is not executable" >&2
88 68ed9ba5 2019-02-10 stsp ls -l $testroot/wt/xfile >&2
89 68ed9ba5 2019-02-10 stsp fi
90 68ed9ba5 2019-02-10 stsp test_done "$testroot" "$ret"
91 68ed9ba5 2019-02-10 stsp }
92 68ed9ba5 2019-02-10 stsp
93 45d344f6 2019-05-14 stsp function test_checkout_commit_from_wrong_branch {
94 45d344f6 2019-05-14 stsp local testroot=`test_init checkout_commit_from_wrong_branch`
95 45d344f6 2019-05-14 stsp
96 45d344f6 2019-05-14 stsp (cd $testroot/repo && git checkout -q -b newbranch)
97 45d344f6 2019-05-14 stsp echo "modified alpha on new branch" > $testroot/repo/alpha
98 45d344f6 2019-05-14 stsp git_commit $testroot/repo -m "modified alpha on new branch"
99 45d344f6 2019-05-14 stsp
100 45d344f6 2019-05-14 stsp local head_rev=`git_show_head $testroot/repo`
101 45d344f6 2019-05-14 stsp got checkout -b master -c $head_rev $testroot/repo $testroot/wt \
102 45d344f6 2019-05-14 stsp > $testroot/stdout 2> $testroot/stderr
103 45d344f6 2019-05-14 stsp ret="$?"
104 45d344f6 2019-05-14 stsp if [ "$ret" == "0" ]; then
105 45d344f6 2019-05-14 stsp test_done "$testroot" "1"
106 45d344f6 2019-05-14 stsp return 1
107 45d344f6 2019-05-14 stsp fi
108 45d344f6 2019-05-14 stsp
109 45d344f6 2019-05-14 stsp echo -n "" > $testroot/stdout.expected
110 45d344f6 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
111 45d344f6 2019-05-14 stsp ret="$?"
112 45d344f6 2019-05-14 stsp if [ "$ret" != "0" ]; then
113 45d344f6 2019-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
114 45d344f6 2019-05-14 stsp test_done "$testroot" "$ret"
115 45d344f6 2019-05-14 stsp return 1
116 45d344f6 2019-05-14 stsp fi
117 45d344f6 2019-05-14 stsp
118 45d344f6 2019-05-14 stsp echo "got: target commit is on a different branch" \
119 45d344f6 2019-05-14 stsp > $testroot/stderr.expected
120 45d344f6 2019-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
121 45d344f6 2019-05-14 stsp ret="$?"
122 45d344f6 2019-05-14 stsp if [ "$ret" != "0" ]; then
123 45d344f6 2019-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
124 45d344f6 2019-05-14 stsp test_done "$testroot" "$ret"
125 45d344f6 2019-05-14 stsp return 1
126 45d344f6 2019-05-14 stsp fi
127 45d344f6 2019-05-14 stsp
128 45d344f6 2019-05-14 stsp test_done "$testroot" "$ret"
129 45d344f6 2019-05-14 stsp }
130 45d344f6 2019-05-14 stsp
131 0e673013 2019-01-02 stsp run_test test_checkout_basic
132 68ed9ba5 2019-02-10 stsp run_test test_checkout_sets_xbit
133 45d344f6 2019-05-14 stsp run_test test_checkout_commit_from_wrong_branch