3 fccbfb98 2019-08-03 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 fccbfb98 2019-08-03 stsp # Permission to use, copy, modify, and distribute this software for any
6 fccbfb98 2019-08-03 stsp # purpose with or without fee is hereby granted, provided that the above
7 fccbfb98 2019-08-03 stsp # copyright notice and this permission notice appear in all copies.
9 fccbfb98 2019-08-03 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 fccbfb98 2019-08-03 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 fccbfb98 2019-08-03 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 fccbfb98 2019-08-03 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 fccbfb98 2019-08-03 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 fccbfb98 2019-08-03 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 fccbfb98 2019-08-03 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 fccbfb98 2019-08-03 stsp . ./common.sh
19 fccbfb98 2019-08-03 stsp function test_stage_basic {
20 fccbfb98 2019-08-03 stsp local testroot=`test_init stage_basic`
22 fccbfb98 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 fccbfb98 2019-08-03 stsp if [ "$ret" != "0" ]; then
25 fccbfb98 2019-08-03 stsp test_done "$testroot" "$ret"
29 fccbfb98 2019-08-03 stsp echo "modified file" > $testroot/wt/alpha
30 fccbfb98 2019-08-03 stsp (cd $testroot/wt && got rm beta > /dev/null)
31 fccbfb98 2019-08-03 stsp echo "new file" > $testroot/wt/foo
32 fccbfb98 2019-08-03 stsp (cd $testroot/wt && got add foo > /dev/null)
34 88d0e355 2019-08-03 stsp echo ' M alpha' > $testroot/stdout.expected
35 88d0e355 2019-08-03 stsp echo ' D beta' >> $testroot/stdout.expected
36 88d0e355 2019-08-03 stsp echo ' A foo' >> $testroot/stdout.expected
37 fccbfb98 2019-08-03 stsp (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
39 fccbfb98 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
41 fccbfb98 2019-08-03 stsp if [ "$ret" != "0" ]; then
42 fccbfb98 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
44 fccbfb98 2019-08-03 stsp test_done "$testroot" "$ret"
47 c363b2c1 2019-08-03 stsp function test_stage_status {
48 c363b2c1 2019-08-03 stsp local testroot=`test_init stage_status`
50 c363b2c1 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
52 c363b2c1 2019-08-03 stsp if [ "$ret" != "0" ]; then
53 c363b2c1 2019-08-03 stsp test_done "$testroot" "$ret"
57 c363b2c1 2019-08-03 stsp echo "modified file" > $testroot/wt/alpha
58 c363b2c1 2019-08-03 stsp (cd $testroot/wt && got rm beta > /dev/null)
59 c363b2c1 2019-08-03 stsp echo "new file" > $testroot/wt/foo
60 c363b2c1 2019-08-03 stsp (cd $testroot/wt && got add foo > /dev/null)
61 c363b2c1 2019-08-03 stsp echo "new file" > $testroot/wt/epsilon/new
62 c363b2c1 2019-08-03 stsp (cd $testroot/wt && got add epsilon/new > /dev/null)
63 c363b2c1 2019-08-03 stsp echo "modified file" > $testroot/wt/epsilon/zeta
64 c363b2c1 2019-08-03 stsp (cd $testroot/wt && got rm gamma/delta > /dev/null)
66 c363b2c1 2019-08-03 stsp echo ' M alpha' > $testroot/stdout.expected
67 c363b2c1 2019-08-03 stsp echo ' D beta' >> $testroot/stdout.expected
68 c363b2c1 2019-08-03 stsp echo 'A epsilon/new' >> $testroot/stdout.expected
69 c363b2c1 2019-08-03 stsp echo 'M epsilon/zeta' >> $testroot/stdout.expected
70 c363b2c1 2019-08-03 stsp echo ' A foo' >> $testroot/stdout.expected
71 c363b2c1 2019-08-03 stsp echo 'D gamma/delta' >> $testroot/stdout.expected
72 c363b2c1 2019-08-03 stsp (cd $testroot/wt && got stage alpha beta foo > /dev/null)
74 c363b2c1 2019-08-03 stsp (cd $testroot/wt && got status > $testroot/stdout)
75 c363b2c1 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
77 c363b2c1 2019-08-03 stsp if [ "$ret" != "0" ]; then
78 c363b2c1 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
79 244725f2 2019-08-03 stsp test_done "$testroot" "$ret"
83 244725f2 2019-08-03 stsp echo "modified file again" >> $testroot/wt/alpha
84 244725f2 2019-08-03 stsp echo "modified added file again" >> $testroot/wt/foo
86 244725f2 2019-08-03 stsp echo 'MM alpha' > $testroot/stdout.expected
87 244725f2 2019-08-03 stsp echo ' D beta' >> $testroot/stdout.expected
88 244725f2 2019-08-03 stsp echo 'A epsilon/new' >> $testroot/stdout.expected
89 244725f2 2019-08-03 stsp echo 'M epsilon/zeta' >> $testroot/stdout.expected
90 244725f2 2019-08-03 stsp echo 'MA foo' >> $testroot/stdout.expected
91 244725f2 2019-08-03 stsp echo 'D gamma/delta' >> $testroot/stdout.expected
93 244725f2 2019-08-03 stsp (cd $testroot/wt && got status > $testroot/stdout)
94 244725f2 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
96 244725f2 2019-08-03 stsp if [ "$ret" != "0" ]; then
97 244725f2 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
98 244725f2 2019-08-03 stsp test_done "$testroot" "$ret"
102 244725f2 2019-08-03 stsp # test no-op change of added file with new stat(2) timestamp
103 244725f2 2019-08-03 stsp echo "new file" > $testroot/wt/foo
104 244725f2 2019-08-03 stsp echo ' A foo' > $testroot/stdout.expected
105 244725f2 2019-08-03 stsp (cd $testroot/wt && got status foo > $testroot/stdout)
106 244725f2 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
108 244725f2 2019-08-03 stsp if [ "$ret" != "0" ]; then
109 244725f2 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
110 244725f2 2019-08-03 stsp test_done "$testroot" "$ret"
114 244725f2 2019-08-03 stsp # test staged deleted file which is restored on disk
115 244725f2 2019-08-03 stsp echo "new file" > $testroot/wt/beta
116 244725f2 2019-08-03 stsp echo ' D beta' > $testroot/stdout.expected
117 244725f2 2019-08-03 stsp (cd $testroot/wt && got status beta > $testroot/stdout)
118 244725f2 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
120 244725f2 2019-08-03 stsp if [ "$ret" != "0" ]; then
121 244725f2 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
123 c363b2c1 2019-08-03 stsp test_done "$testroot" "$ret"
127 1e1446d3 2019-08-03 stsp function test_stage_add_already_staged_file {
128 1e1446d3 2019-08-03 stsp local testroot=`test_init stage_add_already_staged_file`
130 1e1446d3 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
132 1e1446d3 2019-08-03 stsp if [ "$ret" != "0" ]; then
133 1e1446d3 2019-08-03 stsp test_done "$testroot" "$ret"
137 1e1446d3 2019-08-03 stsp echo "modified file" > $testroot/wt/alpha
138 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got rm beta > /dev/null)
139 1e1446d3 2019-08-03 stsp echo "new file" > $testroot/wt/foo
140 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got add foo > /dev/null)
142 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
144 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got add beta \
145 1e1446d3 2019-08-03 stsp > $testroot/stdout 2> $testroot/stderr)
147 1e1446d3 2019-08-03 stsp if [ "$ret" == "0" ]; then
148 1e1446d3 2019-08-03 stsp echo "got add command succeeded unexpectedly" >&2
149 1e1446d3 2019-08-03 stsp test_done "$testroot" "1"
152 1e1446d3 2019-08-03 stsp echo "got: realpath: beta: No such file or directory" \
153 1e1446d3 2019-08-03 stsp > $testroot/stderr.expected
154 1e1446d3 2019-08-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
156 1e1446d3 2019-08-03 stsp if [ "$ret" != "0" ]; then
157 1e1446d3 2019-08-03 stsp diff -u $testroot/stderr.expected $testroot/stderr
158 1e1446d3 2019-08-03 stsp test_done "$testroot" "$ret"
162 1e1446d3 2019-08-03 stsp echo -n > $testroot/stdout.expected
163 1e1446d3 2019-08-03 stsp for f in alpha foo; do
164 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got add $f \
165 1e1446d3 2019-08-03 stsp > $testroot/stdout 2> $testroot/stderr)
167 1e1446d3 2019-08-03 stsp if [ "$ret" != "0" ]; then
168 1e1446d3 2019-08-03 stsp echo "got add command failed unexpectedly" >&2
169 1e1446d3 2019-08-03 stsp test_done "$testroot" "1"
172 1e1446d3 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
174 1e1446d3 2019-08-03 stsp if [ "$ret" != "0" ]; then
175 1e1446d3 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
176 1e1446d3 2019-08-03 stsp test_done "$testroot" "$ret"
181 1e1446d3 2019-08-03 stsp echo ' M alpha' > $testroot/stdout.expected
182 1e1446d3 2019-08-03 stsp echo ' D beta' >> $testroot/stdout.expected
183 1e1446d3 2019-08-03 stsp echo ' A foo' >> $testroot/stdout.expected
185 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got status > $testroot/stdout)
186 1e1446d3 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
188 1e1446d3 2019-08-03 stsp if [ "$ret" != "0" ]; then
189 1e1446d3 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
191 1e1446d3 2019-08-03 stsp test_done "$testroot" "$ret"
194 9acbc4fa 2019-08-03 stsp function test_stage_rm_already_staged_file {
195 9acbc4fa 2019-08-03 stsp local testroot=`test_init stage_rm_already_staged_file`
197 9acbc4fa 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
199 9acbc4fa 2019-08-03 stsp if [ "$ret" != "0" ]; then
200 9acbc4fa 2019-08-03 stsp test_done "$testroot" "$ret"
204 9acbc4fa 2019-08-03 stsp echo "modified file" > $testroot/wt/alpha
205 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got rm beta > /dev/null)
206 9acbc4fa 2019-08-03 stsp echo "new file" > $testroot/wt/foo
207 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got add foo > /dev/null)
209 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
211 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got rm beta \
212 9acbc4fa 2019-08-03 stsp > $testroot/stdout 2> $testroot/stderr)
214 9acbc4fa 2019-08-03 stsp if [ "$ret" == "0" ]; then
215 9acbc4fa 2019-08-03 stsp echo "got rm command succeeded unexpectedly" >&2
216 9acbc4fa 2019-08-03 stsp test_done "$testroot" "1"
219 9acbc4fa 2019-08-03 stsp echo "got: realpath: beta: No such file or directory" \
220 9acbc4fa 2019-08-03 stsp > $testroot/stderr.expected
221 9acbc4fa 2019-08-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
223 9acbc4fa 2019-08-03 stsp if [ "$ret" != "0" ]; then
224 9acbc4fa 2019-08-03 stsp diff -u $testroot/stderr.expected $testroot/stderr
225 9acbc4fa 2019-08-03 stsp test_done "$testroot" "$ret"
229 9acbc4fa 2019-08-03 stsp for f in alpha foo; do
230 9acbc4fa 2019-08-03 stsp echo "got: $f: file has staged changes" \
231 9acbc4fa 2019-08-03 stsp > $testroot/stderr.expected
232 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got rm $f \
233 9acbc4fa 2019-08-03 stsp > $testroot/stdout 2> $testroot/stderr)
235 9acbc4fa 2019-08-03 stsp if [ "$ret" == "0" ]; then
236 9acbc4fa 2019-08-03 stsp echo "got rm command succeeded unexpectedly" >&2
237 9acbc4fa 2019-08-03 stsp test_done "$testroot" "1"
240 9acbc4fa 2019-08-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
242 9acbc4fa 2019-08-03 stsp if [ "$ret" != "0" ]; then
243 9acbc4fa 2019-08-03 stsp diff -u $testroot/stderr.expected $testroot/stderr
244 9acbc4fa 2019-08-03 stsp test_done "$testroot" "$ret"
249 9acbc4fa 2019-08-03 stsp echo ' M alpha' > $testroot/stdout.expected
250 9acbc4fa 2019-08-03 stsp echo ' D beta' >> $testroot/stdout.expected
251 9acbc4fa 2019-08-03 stsp echo ' A foo' >> $testroot/stdout.expected
253 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got status > $testroot/stdout)
254 9acbc4fa 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
256 9acbc4fa 2019-08-03 stsp if [ "$ret" != "0" ]; then
257 9acbc4fa 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
259 9acbc4fa 2019-08-03 stsp test_done "$testroot" "$ret"
262 fccbfb98 2019-08-03 stsp run_test test_stage_basic
263 c363b2c1 2019-08-03 stsp run_test test_stage_status
264 1e1446d3 2019-08-03 stsp run_test test_stage_add_already_staged_file
265 9acbc4fa 2019-08-03 stsp run_test test_stage_rm_already_staged_file