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_dir_exists {
59 local testroot=`test_init checkout_dir_exists`
61 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
62 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
63 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
64 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
65 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 echo "alpha" > $testroot/content.expected
85 echo "beta" >> $testroot/content.expected
86 echo "zeta" >> $testroot/content.expected
87 echo "delta" >> $testroot/content.expected
88 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
89 $testroot/wt/gamma/delta > $testroot/content
91 cmp -s $testroot/content.expected $testroot/content
93 if [ "$ret" != "0" ]; then
94 diff -u $testroot/content.expected $testroot/content
96 test_done "$testroot" "$ret"
99 function test_checkout_dir_not_empty {
100 local testroot=`test_init checkout_dir_not_empty`
102 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
103 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
104 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
105 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
106 echo "Now shut up and hack" >> $testroot/stdout.expected
109 touch $testroot/wt/foo
111 got checkout $testroot/repo $testroot/wt > $testroot/stdout \
114 if [ "$ret" == "0" ]; then
115 echo "checkout succeeded unexpectedly" >&2
116 test_done "$testroot" "1"
120 echo "got: $testroot/wt: directory exists and is not empty" \
121 > $testroot/stderr.expected
122 cmp -s $testroot/stderr.expected $testroot/stderr
124 if [ "$ret" != "0" ]; then
125 diff -u $testroot/stderr.expected $testroot/stderr
126 test_done "$testroot" "$ret"
130 echo -n > $testroot/stdout.expected
131 cmp -s $testroot/stdout.expected $testroot/stdout
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stdout.expected $testroot/stdout
136 test_done "$testroot" "$ret"
140 function test_checkout_sets_xbit {
141 local testroot=`test_init checkout_sets_xbit 1`
143 touch $testroot/repo/xfile
144 chmod +x $testroot/repo/xfile
145 (cd $testroot/repo && git add .)
146 git_commit $testroot/repo -m "adding executable file"
148 echo "A $testroot/wt/xfile" > $testroot/stdout.expected
149 echo "Now shut up and hack" >> $testroot/stdout.expected
151 got checkout $testroot/repo $testroot/wt > $testroot/stdout
153 if [ "$ret" != "0" ]; then
154 test_done "$testroot" "$ret"
158 cmp -s $testroot/stdout.expected $testroot/stdout
160 if [ "$ret" != "0" ]; then
161 diff -u $testroot/stdout.expected $testroot/stdout
162 test_done "$testroot" "$ret"
166 ls -l $testroot/wt/xfile | grep -q '^-rwx'
168 if [ "$ret" != "0" ]; then
169 echo "file is not executable" >&2
170 ls -l $testroot/wt/xfile >&2
172 test_done "$testroot" "$ret"
175 function test_checkout_commit_from_wrong_branch {
176 local testroot=`test_init checkout_commit_from_wrong_branch`
178 (cd $testroot/repo && git checkout -q -b newbranch)
179 echo "modified alpha on new branch" > $testroot/repo/alpha
180 git_commit $testroot/repo -m "modified alpha on new branch"
182 local head_rev=`git_show_head $testroot/repo`
183 got checkout -b master -c $head_rev $testroot/repo $testroot/wt \
184 > $testroot/stdout 2> $testroot/stderr
186 if [ "$ret" == "0" ]; then
187 test_done "$testroot" "1"
191 echo -n "" > $testroot/stdout.expected
192 cmp -s $testroot/stdout.expected $testroot/stdout
194 if [ "$ret" != "0" ]; then
195 diff -u $testroot/stdout.expected $testroot/stdout
196 test_done "$testroot" "$ret"
200 echo "got: target commit is on a different branch" \
201 > $testroot/stderr.expected
202 cmp -s $testroot/stderr.expected $testroot/stderr
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stderr.expected $testroot/stderr
206 test_done "$testroot" "$ret"
210 test_done "$testroot" "$ret"
213 function test_checkout_tag {
214 local testroot=`test_init checkout_tag`
217 (cd $testroot/repo && git tag -a -m "test" $tag)
219 echo "A $testroot/wt/alpha" > $testroot/stdout.expected
220 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
221 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
222 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
223 echo "Now shut up and hack" >> $testroot/stdout.expected
225 got checkout -c $tag $testroot/repo $testroot/wt > $testroot/stdout
227 if [ "$ret" != "0" ]; then
228 test_done "$testroot" "$ret"
232 cmp -s $testroot/stdout.expected $testroot/stdout
234 if [ "$ret" != "0" ]; then
235 diff -u $testroot/stdout.expected $testroot/stdout
236 test_done "$testroot" "$ret"
240 echo "alpha" > $testroot/content.expected
241 echo "beta" >> $testroot/content.expected
242 echo "zeta" >> $testroot/content.expected
243 echo "delta" >> $testroot/content.expected
244 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
245 $testroot/wt/gamma/delta > $testroot/content
247 cmp -s $testroot/content.expected $testroot/content
249 if [ "$ret" != "0" ]; then
250 diff -u $testroot/content.expected $testroot/content
252 test_done "$testroot" "$ret"
255 function test_checkout_ignores_submodules {
256 local testroot=`test_init checkout_ignores_submodules`
258 (cd $testroot && git clone -q repo repo2 >/dev/null)
259 (cd $testroot/repo && git submodule -q add ../repo2)
260 (cd $testroot/repo && git commit -q -m 'adding submodule')
262 echo "A $testroot/wt/.gitmodules" > $testroot/stdout.expected
263 echo "A $testroot/wt/alpha" >> $testroot/stdout.expected
264 echo "A $testroot/wt/beta" >> $testroot/stdout.expected
265 echo "A $testroot/wt/epsilon/zeta" >> $testroot/stdout.expected
266 echo "A $testroot/wt/gamma/delta" >> $testroot/stdout.expected
267 echo "Now shut up and hack" >> $testroot/stdout.expected
269 got checkout $testroot/repo $testroot/wt > $testroot/stdout
271 if [ "$ret" != "0" ]; then
272 test_done "$testroot" "$ret"
276 cmp -s $testroot/stdout.expected $testroot/stdout
278 if [ "$ret" != "0" ]; then
279 diff -u $testroot/stdout.expected $testroot/stdout
280 test_done "$testroot" "$ret"
284 echo "alpha" > $testroot/content.expected
285 echo "beta" >> $testroot/content.expected
286 echo "zeta" >> $testroot/content.expected
287 echo "delta" >> $testroot/content.expected
288 cat $testroot/wt/alpha $testroot/wt/beta $testroot/wt/epsilon/zeta \
289 $testroot/wt/gamma/delta > $testroot/content
291 cmp -s $testroot/content.expected $testroot/content
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/content.expected $testroot/content
296 test_done "$testroot" "$ret"
299 run_test test_checkout_basic
300 run_test test_checkout_dir_exists
301 run_test test_checkout_dir_not_empty
302 run_test test_checkout_sets_xbit
303 run_test test_checkout_commit_from_wrong_branch
304 run_test test_checkout_tag
305 run_test test_checkout_ignores_submodules