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 $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 $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 $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 'test commit_subdir' 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 $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 $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 $testroot/stderr.expected $testroot/stderr
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
174 test_done "$testroot" "$ret"
177 run_test test_commit_basic
178 run_test test_commit_new_subdir
179 run_test test_commit_subdir
180 run_test test_commit_single_file
181 run_test test_commit_out_of_date