Blame


1 fccbfb98 2019-08-03 stsp #!/bin/sh
2 fccbfb98 2019-08-03 stsp #
3 fccbfb98 2019-08-03 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 fccbfb98 2019-08-03 stsp #
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.
8 fccbfb98 2019-08-03 stsp #
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.
16 fccbfb98 2019-08-03 stsp
17 fccbfb98 2019-08-03 stsp . ./common.sh
18 fccbfb98 2019-08-03 stsp
19 fccbfb98 2019-08-03 stsp function test_stage_basic {
20 fccbfb98 2019-08-03 stsp local testroot=`test_init stage_basic`
21 fccbfb98 2019-08-03 stsp
22 fccbfb98 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 fccbfb98 2019-08-03 stsp ret="$?"
24 fccbfb98 2019-08-03 stsp if [ "$ret" != "0" ]; then
25 fccbfb98 2019-08-03 stsp test_done "$testroot" "$ret"
26 fccbfb98 2019-08-03 stsp return 1
27 fccbfb98 2019-08-03 stsp fi
28 fccbfb98 2019-08-03 stsp
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)
33 fccbfb98 2019-08-03 stsp
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)
38 fccbfb98 2019-08-03 stsp
39 fccbfb98 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
40 fccbfb98 2019-08-03 stsp ret="$?"
41 fccbfb98 2019-08-03 stsp if [ "$ret" != "0" ]; then
42 fccbfb98 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
43 fccbfb98 2019-08-03 stsp fi
44 fccbfb98 2019-08-03 stsp test_done "$testroot" "$ret"
45 fccbfb98 2019-08-03 stsp }
46 fccbfb98 2019-08-03 stsp
47 c363b2c1 2019-08-03 stsp function test_stage_status {
48 c363b2c1 2019-08-03 stsp local testroot=`test_init stage_status`
49 c363b2c1 2019-08-03 stsp
50 c363b2c1 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
51 c363b2c1 2019-08-03 stsp ret="$?"
52 c363b2c1 2019-08-03 stsp if [ "$ret" != "0" ]; then
53 c363b2c1 2019-08-03 stsp test_done "$testroot" "$ret"
54 c363b2c1 2019-08-03 stsp return 1
55 c363b2c1 2019-08-03 stsp fi
56 c363b2c1 2019-08-03 stsp
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)
65 c363b2c1 2019-08-03 stsp
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)
73 c363b2c1 2019-08-03 stsp
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
76 c363b2c1 2019-08-03 stsp ret="$?"
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"
80 244725f2 2019-08-03 stsp return 1
81 c363b2c1 2019-08-03 stsp fi
82 244725f2 2019-08-03 stsp
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
85 244725f2 2019-08-03 stsp
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
92 244725f2 2019-08-03 stsp
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
95 244725f2 2019-08-03 stsp ret="$?"
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"
99 244725f2 2019-08-03 stsp return 1
100 244725f2 2019-08-03 stsp fi
101 244725f2 2019-08-03 stsp
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
107 244725f2 2019-08-03 stsp ret="$?"
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"
111 244725f2 2019-08-03 stsp return 1
112 244725f2 2019-08-03 stsp fi
113 244725f2 2019-08-03 stsp
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
119 244725f2 2019-08-03 stsp ret="$?"
120 244725f2 2019-08-03 stsp if [ "$ret" != "0" ]; then
121 244725f2 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
122 244725f2 2019-08-03 stsp fi
123 c363b2c1 2019-08-03 stsp test_done "$testroot" "$ret"
124 244725f2 2019-08-03 stsp
125 c363b2c1 2019-08-03 stsp }
126 c363b2c1 2019-08-03 stsp
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`
129 1e1446d3 2019-08-03 stsp
130 1e1446d3 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
131 1e1446d3 2019-08-03 stsp ret="$?"
132 1e1446d3 2019-08-03 stsp if [ "$ret" != "0" ]; then
133 1e1446d3 2019-08-03 stsp test_done "$testroot" "$ret"
134 1e1446d3 2019-08-03 stsp return 1
135 1e1446d3 2019-08-03 stsp fi
136 1e1446d3 2019-08-03 stsp
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)
141 1e1446d3 2019-08-03 stsp
142 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
143 1e1446d3 2019-08-03 stsp
144 1e1446d3 2019-08-03 stsp (cd $testroot/wt && got add beta \
145 1e1446d3 2019-08-03 stsp > $testroot/stdout 2> $testroot/stderr)
146 1e1446d3 2019-08-03 stsp ret="$?"
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"
150 1e1446d3 2019-08-03 stsp return 1
151 1e1446d3 2019-08-03 stsp fi
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
155 1e1446d3 2019-08-03 stsp ret="$?"
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"
159 1e1446d3 2019-08-03 stsp return 1
160 1e1446d3 2019-08-03 stsp fi
161 1e1446d3 2019-08-03 stsp
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)
166 1e1446d3 2019-08-03 stsp ret="$?"
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"
170 1e1446d3 2019-08-03 stsp return 1
171 1e1446d3 2019-08-03 stsp fi
172 1e1446d3 2019-08-03 stsp cmp -s $testroot/stdout.expected $testroot/stdout
173 1e1446d3 2019-08-03 stsp ret="$?"
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"
177 1e1446d3 2019-08-03 stsp return 1
178 1e1446d3 2019-08-03 stsp fi
179 1e1446d3 2019-08-03 stsp done
180 1e1446d3 2019-08-03 stsp
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
184 1e1446d3 2019-08-03 stsp
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
187 1e1446d3 2019-08-03 stsp ret="$?"
188 1e1446d3 2019-08-03 stsp if [ "$ret" != "0" ]; then
189 1e1446d3 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
190 1e1446d3 2019-08-03 stsp fi
191 1e1446d3 2019-08-03 stsp test_done "$testroot" "$ret"
192 1e1446d3 2019-08-03 stsp }
193 1e1446d3 2019-08-03 stsp
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`
196 9acbc4fa 2019-08-03 stsp
197 9acbc4fa 2019-08-03 stsp got checkout $testroot/repo $testroot/wt > /dev/null
198 9acbc4fa 2019-08-03 stsp ret="$?"
199 9acbc4fa 2019-08-03 stsp if [ "$ret" != "0" ]; then
200 9acbc4fa 2019-08-03 stsp test_done "$testroot" "$ret"
201 9acbc4fa 2019-08-03 stsp return 1
202 9acbc4fa 2019-08-03 stsp fi
203 9acbc4fa 2019-08-03 stsp
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)
208 9acbc4fa 2019-08-03 stsp
209 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got stage alpha beta foo > $testroot/stdout)
210 9acbc4fa 2019-08-03 stsp
211 9acbc4fa 2019-08-03 stsp (cd $testroot/wt && got rm beta \
212 9acbc4fa 2019-08-03 stsp > $testroot/stdout 2> $testroot/stderr)
213 9acbc4fa 2019-08-03 stsp ret="$?"
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"
217 9acbc4fa 2019-08-03 stsp return 1
218 9acbc4fa 2019-08-03 stsp fi
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
222 9acbc4fa 2019-08-03 stsp ret="$?"
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"
226 9acbc4fa 2019-08-03 stsp return 1
227 9acbc4fa 2019-08-03 stsp fi
228 9acbc4fa 2019-08-03 stsp
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)
234 9acbc4fa 2019-08-03 stsp ret="$?"
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"
238 9acbc4fa 2019-08-03 stsp return 1
239 9acbc4fa 2019-08-03 stsp fi
240 9acbc4fa 2019-08-03 stsp cmp -s $testroot/stderr.expected $testroot/stderr
241 9acbc4fa 2019-08-03 stsp ret="$?"
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"
245 9acbc4fa 2019-08-03 stsp return 1
246 9acbc4fa 2019-08-03 stsp fi
247 9acbc4fa 2019-08-03 stsp done
248 9acbc4fa 2019-08-03 stsp
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
252 9acbc4fa 2019-08-03 stsp
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
255 9acbc4fa 2019-08-03 stsp ret="$?"
256 9acbc4fa 2019-08-03 stsp if [ "$ret" != "0" ]; then
257 9acbc4fa 2019-08-03 stsp diff -u $testroot/stdout.expected $testroot/stdout
258 9acbc4fa 2019-08-03 stsp fi
259 9acbc4fa 2019-08-03 stsp test_done "$testroot" "$ret"
260 9acbc4fa 2019-08-03 stsp }
261 9acbc4fa 2019-08-03 stsp
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