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_stage_basic {
20 local testroot=`test_init stage_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
29 echo "modified file" > $testroot/wt/alpha
30 (cd $testroot/wt && got rm beta > /dev/null)
31 echo "new file" > $testroot/wt/foo
32 (cd $testroot/wt && got add foo > /dev/null)
34 echo ' M alpha' > $testroot/stdout.expected
35 echo ' D beta' >> $testroot/stdout.expected
36 echo ' A foo' >> $testroot/stdout.expected
37 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
39 cmp -s $testroot/stdout.expected $testroot/stdout
41 if [ "$ret" != "0" ]; then
42 diff -u $testroot/stdout.expected $testroot/stdout
44 test_done "$testroot" "$ret"
47 function test_stage_status {
48 local testroot=`test_init stage_status`
50 got checkout $testroot/repo $testroot/wt > /dev/null
52 if [ "$ret" != "0" ]; then
53 test_done "$testroot" "$ret"
57 echo "modified file" > $testroot/wt/alpha
58 (cd $testroot/wt && got rm beta > /dev/null)
59 echo "new file" > $testroot/wt/foo
60 (cd $testroot/wt && got add foo > /dev/null)
61 echo "new file" > $testroot/wt/epsilon/new
62 (cd $testroot/wt && got add epsilon/new > /dev/null)
63 echo "modified file" > $testroot/wt/epsilon/zeta
64 (cd $testroot/wt && got rm gamma/delta > /dev/null)
66 echo ' M alpha' > $testroot/stdout.expected
67 echo ' D beta' >> $testroot/stdout.expected
68 echo 'A epsilon/new' >> $testroot/stdout.expected
69 echo 'M epsilon/zeta' >> $testroot/stdout.expected
70 echo ' A foo' >> $testroot/stdout.expected
71 echo 'D gamma/delta' >> $testroot/stdout.expected
72 (cd $testroot/wt && got stage alpha beta foo > /dev/null)
74 (cd $testroot/wt && got status > $testroot/stdout)
75 cmp -s $testroot/stdout.expected $testroot/stdout
77 if [ "$ret" != "0" ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
83 echo "modified file again" >> $testroot/wt/alpha
84 echo "modified added file again" >> $testroot/wt/foo
86 echo 'MM alpha' > $testroot/stdout.expected
87 echo ' D beta' >> $testroot/stdout.expected
88 echo 'A epsilon/new' >> $testroot/stdout.expected
89 echo 'M epsilon/zeta' >> $testroot/stdout.expected
90 echo 'MA foo' >> $testroot/stdout.expected
91 echo 'D gamma/delta' >> $testroot/stdout.expected
93 (cd $testroot/wt && got status > $testroot/stdout)
94 cmp -s $testroot/stdout.expected $testroot/stdout
96 if [ "$ret" != "0" ]; then
97 diff -u $testroot/stdout.expected $testroot/stdout
98 test_done "$testroot" "$ret"
102 # test no-op change of added file with new stat(2) timestamp
103 echo "new file" > $testroot/wt/foo
104 echo ' A foo' > $testroot/stdout.expected
105 (cd $testroot/wt && got status foo > $testroot/stdout)
106 cmp -s $testroot/stdout.expected $testroot/stdout
108 if [ "$ret" != "0" ]; then
109 diff -u $testroot/stdout.expected $testroot/stdout
110 test_done "$testroot" "$ret"
114 # test staged deleted file which is restored on disk
115 echo "new file" > $testroot/wt/beta
116 echo ' D beta' > $testroot/stdout.expected
117 (cd $testroot/wt && got status beta > $testroot/stdout)
118 cmp -s $testroot/stdout.expected $testroot/stdout
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
123 test_done "$testroot" "$ret"
127 function test_stage_add_already_staged_file {
128 local testroot=`test_init stage_add_already_staged_file`
130 got checkout $testroot/repo $testroot/wt > /dev/null
132 if [ "$ret" != "0" ]; then
133 test_done "$testroot" "$ret"
137 echo "modified file" > $testroot/wt/alpha
138 (cd $testroot/wt && got rm beta > /dev/null)
139 echo "new file" > $testroot/wt/foo
140 (cd $testroot/wt && got add foo > /dev/null)
142 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
144 (cd $testroot/wt && got add beta \
145 > $testroot/stdout 2> $testroot/stderr)
147 if [ "$ret" == "0" ]; then
148 echo "got add command succeeded unexpectedly" >&2
149 test_done "$testroot" "1"
152 echo "got: realpath: beta: No such file or directory" \
153 > $testroot/stderr.expected
154 cmp -s $testroot/stderr.expected $testroot/stderr
156 if [ "$ret" != "0" ]; then
157 diff -u $testroot/stderr.expected $testroot/stderr
158 test_done "$testroot" "$ret"
162 echo -n > $testroot/stdout.expected
163 for f in alpha foo; do
164 (cd $testroot/wt && got add $f \
165 > $testroot/stdout 2> $testroot/stderr)
167 if [ "$ret" != "0" ]; then
168 echo "got add command failed unexpectedly" >&2
169 test_done "$testroot" "1"
172 cmp -s $testroot/stdout.expected $testroot/stdout
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stdout.expected $testroot/stdout
176 test_done "$testroot" "$ret"
181 echo ' M alpha' > $testroot/stdout.expected
182 echo ' D beta' >> $testroot/stdout.expected
183 echo ' A foo' >> $testroot/stdout.expected
185 (cd $testroot/wt && got status > $testroot/stdout)
186 cmp -s $testroot/stdout.expected $testroot/stdout
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
191 test_done "$testroot" "$ret"
194 function test_stage_rm_already_staged_file {
195 local testroot=`test_init stage_rm_already_staged_file`
197 got checkout $testroot/repo $testroot/wt > /dev/null
199 if [ "$ret" != "0" ]; then
200 test_done "$testroot" "$ret"
204 echo "modified file" > $testroot/wt/alpha
205 (cd $testroot/wt && got rm beta > /dev/null)
206 echo "new file" > $testroot/wt/foo
207 (cd $testroot/wt && got add foo > /dev/null)
209 (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
211 (cd $testroot/wt && got rm beta \
212 > $testroot/stdout 2> $testroot/stderr)
214 if [ "$ret" == "0" ]; then
215 echo "got rm command succeeded unexpectedly" >&2
216 test_done "$testroot" "1"
219 echo "got: realpath: beta: No such file or directory" \
220 > $testroot/stderr.expected
221 cmp -s $testroot/stderr.expected $testroot/stderr
223 if [ "$ret" != "0" ]; then
224 diff -u $testroot/stderr.expected $testroot/stderr
225 test_done "$testroot" "$ret"
229 for f in alpha foo; do
230 echo "got: $f: file has staged changes" \
231 > $testroot/stderr.expected
232 (cd $testroot/wt && got rm $f \
233 > $testroot/stdout 2> $testroot/stderr)
235 if [ "$ret" == "0" ]; then
236 echo "got rm command succeeded unexpectedly" >&2
237 test_done "$testroot" "1"
240 cmp -s $testroot/stderr.expected $testroot/stderr
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stderr.expected $testroot/stderr
244 test_done "$testroot" "$ret"
249 echo ' M alpha' > $testroot/stdout.expected
250 echo ' D beta' >> $testroot/stdout.expected
251 echo ' A foo' >> $testroot/stdout.expected
253 (cd $testroot/wt && got status > $testroot/stdout)
254 cmp -s $testroot/stdout.expected $testroot/stdout
256 if [ "$ret" != "0" ]; then
257 diff -u $testroot/stdout.expected $testroot/stdout
259 test_done "$testroot" "$ret"
262 run_test test_stage_basic
263 run_test test_stage_status
264 run_test test_stage_add_already_staged_file
265 run_test test_stage_rm_already_staged_file