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 function test_commit_basic {
20 local testroot=`test_init commit_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "modified alpha" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta >/dev/null)
31 echo "new file" > $testroot/wt/new
32 (cd $testroot/wt && got add new >/dev/null)
34 (cd $testroot/wt && got commit -m 'test commit_basic' > $testroot/stdout)
36 local head_rev=`git_show_head $testroot/repo`
37 echo "A new" > $testroot/stdout.expected
38 echo "M alpha" >> $testroot/stdout.expected
39 echo "D beta" >> $testroot/stdout.expected
40 echo "Created commit $head_rev" >> $testroot/stdout.expected
42 cmp -s $testroot/stdout.expected $testroot/stdout
43 ret="$?"
44 if [ "$ret" != "0" ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
46 fi
47 test_done "$testroot" "$ret"
48 }
50 function test_commit_new_subdir {
51 local testroot=`test_init commit_new_subdir`
53 got checkout $testroot/repo $testroot/wt > /dev/null
54 ret="$?"
55 if [ "$ret" != "0" ]; then
56 test_done "$testroot" "$ret"
57 return 1
58 fi
60 mkdir -p $testroot/wt/d
61 echo "new file" > $testroot/wt/d/new
62 echo "another new file" > $testroot/wt/d/new2
63 (cd $testroot/wt && got add d/new >/dev/null)
64 (cd $testroot/wt && got add d/new2 >/dev/null)
66 (cd $testroot/wt && \
67 got commit -m 'test commit_new_subdir' > $testroot/stdout)
69 local head_rev=`git_show_head $testroot/repo`
70 echo "A d/new" > $testroot/stdout.expected
71 echo "A d/new2" >> $testroot/stdout.expected
72 echo "Created commit $head_rev" >> $testroot/stdout.expected
74 cmp -s $testroot/stdout.expected $testroot/stdout
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 fi
79 test_done "$testroot" "$ret"
80 }
82 function test_commit_subdir {
83 local testroot=`test_init commit_subdir`
85 got checkout $testroot/repo $testroot/wt > /dev/null
86 ret="$?"
87 if [ "$ret" != "0" ]; then
88 test_done "$testroot" "$ret"
89 return 1
90 fi
92 echo "modified alpha" > $testroot/wt/alpha
93 echo "modified zeta" > $testroot/wt/epsilon/zeta
95 (cd $testroot/wt && \
96 got commit -m 'test commit_subdir' epsilon > $testroot/stdout)
98 local head_rev=`git_show_head $testroot/repo`
99 echo "M epsilon/zeta" >> $testroot/stdout.expected
100 echo "Created commit $head_rev" >> $testroot/stdout.expected
102 cmp -s $testroot/stdout.expected $testroot/stdout
103 ret="$?"
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
106 fi
107 test_done "$testroot" "$ret"
110 function test_commit_single_file {
111 local testroot=`test_init commit_single_file`
113 got checkout $testroot/repo $testroot/wt > /dev/null
114 ret="$?"
115 if [ "$ret" != "0" ]; then
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 echo "modified alpha" > $testroot/wt/alpha
121 echo "modified zeta" > $testroot/wt/epsilon/zeta
123 (cd $testroot/wt && got commit -m 'changed zeta' epsilon/zeta \
124 > $testroot/stdout)
126 local head_rev=`git_show_head $testroot/repo`
127 echo "M epsilon/zeta" >> $testroot/stdout.expected
128 echo "Created commit $head_rev" >> $testroot/stdout.expected
130 cmp -s $testroot/stdout.expected $testroot/stdout
131 ret="$?"
132 if [ "$ret" != "0" ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
134 fi
135 test_done "$testroot" "$ret"
138 function test_commit_out_of_date {
139 local testroot=`test_init commit_out_of_date`
141 got checkout $testroot/repo $testroot/wt > /dev/null
142 ret="$?"
143 if [ "$ret" != "0" ]; then
144 test_done "$testroot" "$ret"
145 return 1
146 fi
148 echo "modified alpha" > $testroot/repo/alpha
149 git_commit $testroot/repo -m "modified alpha"
151 echo "modified alpha" > $testroot/wt/alpha
153 (cd $testroot/wt && got commit -m 'test commit_out_of_date' \
154 > $testroot/stdout 2> $testroot/stderr)
156 local head_rev=`git_show_head $testroot/repo`
157 echo -n > $testroot/stdout.expected
158 echo "got: work tree must be updated before these" \
159 "changes can be committed" > $testroot/stderr.expected
161 cmp -s $testroot/stdout.expected $testroot/stdout
162 ret="$?"
163 if [ "$ret" != "0" ]; then
164 diff -u $testroot/stdout.expected $testroot/stdout
165 test_done "$testroot" "$ret"
166 return 1
167 fi
169 cmp -s $testroot/stderr.expected $testroot/stderr
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
173 fi
174 test_done "$testroot" "$ret"
177 function test_commit_added_subdirs {
178 local testroot=`test_init commit_added_subdirs`
180 got checkout $testroot/repo $testroot/wt > /dev/null
181 ret="$?"
182 if [ "$ret" != "0" ]; then
183 test_done "$testroot" "$ret"
184 return 1
185 fi
187 mkdir -p $testroot/wt/d
188 echo "new file" > $testroot/wt/d/new
189 echo "new file 2" > $testroot/wt/d/new2
190 mkdir -p $testroot/wt/d/f
191 echo "new file 3" > $testroot/wt/d/f/new3
192 mkdir -p $testroot/wt/d/f/g
193 echo "new file 4" > $testroot/wt/d/f/g/new4
195 (cd $testroot/wt && got add $testroot/wt/*/new* \
196 $testroot/wt/*/*/new* $testroot/wt/*/*/*/new* > /dev/null)
198 (cd $testroot/wt && got commit -m 'test commit_added_subdirs' \
199 > $testroot/stdout 2> $testroot/stderr)
201 local head_rev=`git_show_head $testroot/repo`
202 echo "A d/f/g/new4" > $testroot/stdout.expected
203 echo "A d/f/new3" >> $testroot/stdout.expected
204 echo "A d/new" >> $testroot/stdout.expected
205 echo "A d/new2" >> $testroot/stdout.expected
206 echo "Created commit $head_rev" >> $testroot/stdout.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret="$?"
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 fi
213 test_done "$testroot" "$ret"
216 function test_commit_rejects_conflicted_file {
217 local testroot=`test_init update_rejects_conflicted_file`
219 local initial_rev=`git_show_head $testroot/repo`
221 got checkout $testroot/repo $testroot/wt > /dev/null
222 ret="$?"
223 if [ "$ret" != "0" ]; then
224 test_done "$testroot" "$ret"
225 return 1
226 fi
228 echo "modified alpha" > $testroot/wt/alpha
229 (cd $testroot/wt && got commit -m "modified alpha" >/dev/null)
231 (cd $testroot/wt && got update -c $initial_rev > /dev/null)
233 echo "modified alpha, too" > $testroot/wt/alpha
235 echo "C alpha" > $testroot/stdout.expected
236 echo -n "Updated to commit " >> $testroot/stdout.expected
237 git_show_head $testroot/repo >> $testroot/stdout.expected
238 echo >> $testroot/stdout.expected
240 (cd $testroot/wt && got update > $testroot/stdout)
242 cmp -s $testroot/stdout.expected $testroot/stdout
243 ret="$?"
244 if [ "$ret" != "0" ]; then
245 diff -u $testroot/stdout.expected $testroot/stdout
246 test_done "$testroot" "$ret"
247 return 1
248 fi
250 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
251 2> $testroot/stderr)
253 echo -n > $testroot/stdout.expected
254 echo "got: cannot commit file in conflicted status" \
255 > $testroot/stderr.expected
257 cmp -s $testroot/stdout.expected $testroot/stdout
258 ret="$?"
259 if [ "$ret" != "0" ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
262 return 1
263 fi
264 cmp -s $testroot/stderr.expected $testroot/stderr
265 ret="$?"
266 if [ "$ret" != "0" ]; then
267 diff -u $testroot/stderr.expected $testroot/stderr
268 fi
269 test_done "$testroot" "$ret"
272 function test_commit_single_file_multiple {
273 local testroot=`test_init commit_single_file_multiple`
275 got checkout $testroot/repo $testroot/wt > /dev/null
276 ret="$?"
277 if [ "$ret" != "0" ]; then
278 test_done "$testroot" "$ret"
279 return 1
280 fi
282 for i in 1 2 3 4; do
283 echo "modified alpha" >> $testroot/wt/alpha
285 (cd $testroot/wt && \
286 got commit -m "changed alpha" > $testroot/stdout)
288 local head_rev=`git_show_head $testroot/repo`
289 echo "M alpha" > $testroot/stdout.expected
290 echo "Created commit $head_rev" >> $testroot/stdout.expected
292 cmp -s $testroot/stdout.expected $testroot/stdout
293 ret="$?"
294 if [ "$ret" != "0" ]; then
295 diff -u $testroot/stdout.expected $testroot/stdout
296 test_done "$testroot" "$ret"
297 return 1
298 fi
299 done
301 test_done "$testroot" "0"
304 run_test test_commit_basic
305 run_test test_commit_new_subdir
306 run_test test_commit_subdir
307 run_test test_commit_single_file
308 run_test test_commit_out_of_date
309 run_test test_commit_added_subdirs
310 run_test test_commit_rejects_conflicted_file
311 run_test test_commit_single_file_multiple