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_commit_basic {
20 local testroot=`test_init commit_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
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
44 if [ "$ret" != "0" ]; then
45 diff -u $testroot/stdout.expected $testroot/stdout
47 test_done "$testroot" "$ret"
50 function test_commit_new_subdir {
51 local testroot=`test_init commit_new_subdir`
53 got checkout $testroot/repo $testroot/wt > /dev/null
55 if [ "$ret" != "0" ]; then
56 test_done "$testroot" "$ret"
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)
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
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
82 function test_commit_subdir {
83 local testroot=`test_init commit_subdir`
85 got checkout $testroot/repo $testroot/wt > /dev/null
87 if [ "$ret" != "0" ]; then
88 test_done "$testroot" "$ret"
92 echo "modified alpha" > $testroot/wt/alpha
93 echo "modified zeta" > $testroot/wt/epsilon/zeta
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
104 if [ "$ret" != "0" ]; then
105 diff -u $testroot/stdout.expected $testroot/stdout
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
115 if [ "$ret" != "0" ]; then
116 test_done "$testroot" "$ret"
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 \
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
132 if [ "$ret" != "0" ]; then
133 diff -u $testroot/stdout.expected $testroot/stdout
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
143 if [ "$ret" != "0" ]; then
144 test_done "$testroot" "$ret"
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
163 if [ "$ret" != "0" ]; then
164 diff -u $testroot/stdout.expected $testroot/stdout
165 test_done "$testroot" "$ret"
169 cmp -s $testroot/stderr.expected $testroot/stderr
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
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
182 if [ "$ret" != "0" ]; then
183 test_done "$testroot" "$ret"
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
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
213 test_done "$testroot" "$ret"
216 function test_commit_rejects_conflicted_file {
217 local testroot=`test_init commit_rejects_conflicted_file`
219 local initial_rev=`git_show_head $testroot/repo`
221 got checkout $testroot/repo $testroot/wt > /dev/null
223 if [ "$ret" != "0" ]; then
224 test_done "$testroot" "$ret"
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
244 if [ "$ret" != "0" ]; then
245 diff -u $testroot/stdout.expected $testroot/stdout
246 test_done "$testroot" "$ret"
250 (cd $testroot/wt && got commit -m 'commit it' > $testroot/stdout \
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
259 if [ "$ret" != "0" ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
264 cmp -s $testroot/stderr.expected $testroot/stderr
266 if [ "$ret" != "0" ]; then
267 diff -u $testroot/stderr.expected $testroot/stderr
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
277 if [ "$ret" != "0" ]; then
278 test_done "$testroot" "$ret"
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
294 if [ "$ret" != "0" ]; then
295 diff -u $testroot/stdout.expected $testroot/stdout
296 test_done "$testroot" "$ret"
301 test_done "$testroot" "0"
304 function test_commit_added_and_modified_in_same_dir {
305 local testroot=`test_init commit_added_and_modified_in_same_dir`
307 got checkout $testroot/repo $testroot/wt > /dev/null
309 if [ "$ret" != "0" ]; then
310 test_done "$testroot" "$ret"
314 echo "modified zeta" > $testroot/wt/epsilon/zeta
315 echo "new file" > $testroot/wt/epsilon/new
316 (cd $testroot/wt && got add epsilon/new >/dev/null)
318 (cd $testroot/wt && got commit \
319 -m 'added and modified in same dir' > $testroot/stdout \
322 local head_rev=`git_show_head $testroot/repo`
323 echo "A epsilon/new" > $testroot/stdout.expected
324 echo "M epsilon/zeta" >> $testroot/stdout.expected
325 echo "Created commit $head_rev" >> $testroot/stdout.expected
327 cmp -s $testroot/stdout.expected $testroot/stdout
329 if [ "$ret" != "0" ]; then
330 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
335 function test_commit_path_prefix {
336 local testroot=`test_init commit_path_prefix`
337 local commit1=`git_show_head $testroot/repo`
339 got checkout -p gamma $testroot/repo $testroot/wt > /dev/null
341 if [ "$ret" != "0" ]; then
342 test_done "$testroot" "$ret"
346 echo "modified delta" > $testroot/wt/delta
348 (cd $testroot/wt && got commit -m 'changed gamma/delta' > $testroot/stdout)
350 local commit2=`git_show_head $testroot/repo`
351 echo "M delta" > $testroot/stdout.expected
352 echo "Created commit $commit2" >> $testroot/stdout.expected
354 cmp -s $testroot/stdout.expected $testroot/stdout
356 if [ "$ret" != "0" ]; then
357 diff -u $testroot/stdout.expected $testroot/stdout
358 test_done "$testroot" "$ret"
362 echo "diff $commit1 $commit2" > $testroot/stdout.expected
363 echo -n 'blob - ' >> $testroot/stdout.expected
364 got tree -r $testroot/repo -c $commit1 -i gamma | grep 'delta$' \
365 | cut -d' ' -f 1 >> $testroot/stdout.expected
366 echo -n 'blob + ' >> $testroot/stdout.expected
367 got tree -r $testroot/repo -c $commit2 -i gamma | grep 'delta$' | \
368 cut -d' ' -f 1 >> $testroot/stdout.expected
369 echo '--- gamma/delta' >> $testroot/stdout.expected
370 echo '+++ gamma/delta' >> $testroot/stdout.expected
371 echo '@@ -1 +1 @@' >> $testroot/stdout.expected
372 echo '-delta' >> $testroot/stdout.expected
373 echo '+modified delta' >> $testroot/stdout.expected
375 got diff -r $testroot/repo $commit1 $commit2 > $testroot/stdout
376 cmp -s $testroot/stdout.expected $testroot/stdout
378 if [ "$ret" != "0" ]; then
379 diff -u $testroot/stdout.expected $testroot/stdout
381 test_done "$testroot" "$ret"
384 function test_commit_dir_path {
385 local testroot=`test_init commit_dir_path`
387 got checkout $testroot/repo $testroot/wt > /dev/null
389 if [ "$ret" != "0" ]; then
390 test_done "$testroot" "$ret"
394 echo "modified alpha" > $testroot/wt/alpha
395 echo "modified zeta" > $testroot/wt/epsilon/zeta
397 (cd $testroot/wt && got commit -m 'changed zeta' epsilon \
400 local head_rev=`git_show_head $testroot/repo`
401 echo "M epsilon/zeta" >> $testroot/stdout.expected
402 echo "Created commit $head_rev" >> $testroot/stdout.expected
404 cmp -s $testroot/stdout.expected $testroot/stdout
406 if [ "$ret" != "0" ]; then
407 diff -u $testroot/stdout.expected $testroot/stdout
408 test_done "$testroot" "$ret"
412 echo "M alpha" > $testroot/stdout.expected
413 (cd $testroot/wt && got status > $testroot/stdout)
414 cmp -s $testroot/stdout.expected $testroot/stdout
416 if [ "$ret" != "0" ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
419 test_done "$testroot" "$ret"
422 run_test test_commit_basic
423 run_test test_commit_new_subdir
424 run_test test_commit_subdir
425 run_test test_commit_single_file
426 run_test test_commit_out_of_date
427 run_test test_commit_added_subdirs
428 run_test test_commit_rejects_conflicted_file
429 run_test test_commit_single_file_multiple
430 run_test test_commit_added_and_modified_in_same_dir
431 run_test test_commit_path_prefix
432 run_test test_commit_dir_path