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 name=$(getent passwd $USER | cut -d: -f5)
20 export GOT_AUTHOR="$name <$(whoami)@$(hostname)>"
22 function test_commit_basic {
23 local testroot=`test_init commit_basic`
25 got checkout $testroot/repo $testroot/wt > /dev/null
27 if [ "$ret" != "0" ]; then
28 test_done "$testroot" "$ret"
32 echo "modified alpha" > $testroot/wt/alpha
33 (cd $testroot/wt && got rm beta >/dev/null)
34 echo "new file" > $testroot/wt/new
35 (cd $testroot/wt && got add new >/dev/null)
37 (cd $testroot/wt && got commit -m 'test commit_basic' > $testroot/stdout)
39 local head_rev=`git_show_head $testroot/repo`
40 echo "A new" > $testroot/stdout.expected
41 echo "M alpha" >> $testroot/stdout.expected
42 echo "D beta" >> $testroot/stdout.expected
43 echo "created commit $head_rev" >> $testroot/stdout.expected
45 cmp $testroot/stdout.expected $testroot/stdout
47 if [ "$ret" != "0" ]; then
48 diff -u $testroot/stdout.expected $testroot/stdout
50 test_done "$testroot" "$ret"
53 function test_commit_new_subdir {
54 local testroot=`test_init commit_new_subdir`
56 got checkout $testroot/repo $testroot/wt > /dev/null
58 if [ "$ret" != "0" ]; then
59 test_done "$testroot" "$ret"
63 mkdir -p $testroot/wt/d
64 echo "new file" > $testroot/wt/d/new
65 echo "another new file" > $testroot/wt/d/new2
66 (cd $testroot/wt && got add d/new >/dev/null)
67 (cd $testroot/wt && got add d/new2 >/dev/null)
70 got commit -m 'test commit_new_subdir' > $testroot/stdout)
72 local head_rev=`git_show_head $testroot/repo`
73 echo "A d/new" > $testroot/stdout.expected
74 echo "A d/new2" >> $testroot/stdout.expected
75 echo "created commit $head_rev" >> $testroot/stdout.expected
77 cmp $testroot/stdout.expected $testroot/stdout
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
82 test_done "$testroot" "$ret"
85 function test_commit_subdir {
86 local testroot=`test_init commit_subdir`
88 got checkout $testroot/repo $testroot/wt > /dev/null
90 if [ "$ret" != "0" ]; then
91 test_done "$testroot" "$ret"
95 echo "modified alpha" > $testroot/wt/alpha
96 echo "modified zeta" > $testroot/wt/epsilon/zeta
99 got commit -m 'test commit_subdir' epsilon > $testroot/stdout)
101 local head_rev=`git_show_head $testroot/repo`
102 echo "M epsilon/zeta" >> $testroot/stdout.expected
103 echo "created commit $head_rev" >> $testroot/stdout.expected
105 cmp $testroot/stdout.expected $testroot/stdout
107 if [ "$ret" != "0" ]; then
108 diff -u $testroot/stdout.expected $testroot/stdout
110 test_done "$testroot" "$ret"
113 function test_commit_single_file {
114 local testroot=`test_init commit_single_file`
116 got checkout $testroot/repo $testroot/wt > /dev/null
118 if [ "$ret" != "0" ]; then
119 test_done "$testroot" "$ret"
123 echo "modified alpha" > $testroot/wt/alpha
124 echo "modified zeta" > $testroot/wt/epsilon/zeta
126 (cd $testroot/wt && got commit -m 'test commit_subdir' epsilon/zeta \
129 local head_rev=`git_show_head $testroot/repo`
130 echo "M epsilon/zeta" >> $testroot/stdout.expected
131 echo "created commit $head_rev" >> $testroot/stdout.expected
133 cmp $testroot/stdout.expected $testroot/stdout
135 if [ "$ret" != "0" ]; then
136 diff -u $testroot/stdout.expected $testroot/stdout
138 test_done "$testroot" "$ret"
141 function test_commit_out_of_date {
142 local testroot=`test_init commit_out_of_date`
144 got checkout $testroot/repo $testroot/wt > /dev/null
146 if [ "$ret" != "0" ]; then
147 test_done "$testroot" "$ret"
151 echo "modified alpha" > $testroot/repo/alpha
152 git_commit $testroot/repo -m "modified alpha"
154 echo "modified alpha" > $testroot/wt/alpha
156 (cd $testroot/wt && got commit -m 'test commit_out_of_date' \
157 > $testroot/stdout 2> $testroot/stderr)
159 local head_rev=`git_show_head $testroot/repo`
160 echo -n > $testroot/stdout.expected
161 echo "got: work tree must be updated before these" \
162 "changes can be committed" > $testroot/stderr.expected
164 cmp $testroot/stdout.expected $testroot/stdout
166 if [ "$ret" != "0" ]; then
167 diff -u $testroot/stdout.expected $testroot/stdout
168 test_done "$testroot" "$ret"
172 cmp $testroot/stderr.expected $testroot/stderr
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stderr.expected $testroot/stderr
177 test_done "$testroot" "$ret"
180 run_test test_commit_basic
181 run_test test_commit_new_subdir
182 run_test test_commit_subdir
183 run_test test_commit_single_file
184 run_test test_commit_out_of_date