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 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
26 ret="$?"
27 if [ "$ret" != "0" ]; then
28 test_done "$testroot" "$ret"
29 return 1
30 fi
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
46 ret="$?"
47 if [ "$ret" != "0" ]; then
48 diff -u $testroot/stdout.expected $testroot/stdout
49 fi
50 test_done "$testroot" "$ret"
51 }
53 function test_commit_new_subdir {
54 local testroot=`test_init commit_new_subdir`
56 got checkout $testroot/repo $testroot/wt > /dev/null
57 ret="$?"
58 if [ "$ret" != "0" ]; then
59 test_done "$testroot" "$ret"
60 return 1
61 fi
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)
69 (cd $testroot/wt && \
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
78 ret="$?"
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
81 fi
82 test_done "$testroot" "$ret"
83 }
85 function test_commit_subdir {
86 local testroot=`test_init commit_subdir`
88 got checkout $testroot/repo $testroot/wt > /dev/null
89 ret="$?"
90 if [ "$ret" != "0" ]; then
91 test_done "$testroot" "$ret"
92 return 1
93 fi
95 echo "modified alpha" > $testroot/wt/alpha
96 echo "modified zeta" > $testroot/wt/epsilon/zeta
98 (cd $testroot/wt && \
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
106 ret="$?"
107 if [ "$ret" != "0" ]; then
108 diff -u $testroot/stdout.expected $testroot/stdout
109 fi
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
117 ret="$?"
118 if [ "$ret" != "0" ]; then
119 test_done "$testroot" "$ret"
120 return 1
121 fi
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 \
127 > $testroot/stdout)
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
134 ret="$?"
135 if [ "$ret" != "0" ]; then
136 diff -u $testroot/stdout.expected $testroot/stdout
137 fi
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
145 ret="$?"
146 if [ "$ret" != "0" ]; then
147 test_done "$testroot" "$ret"
148 return 1
149 fi
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
165 ret="$?"
166 if [ "$ret" != "0" ]; then
167 diff -u $testroot/stdout.expected $testroot/stdout
168 test_done "$testroot" "$ret"
169 return 1
170 fi
172 cmp $testroot/stderr.expected $testroot/stderr
173 ret="$?"
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stderr.expected $testroot/stderr
176 fi
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