Blame


1 a129376b 2019-03-28 stsp #!/bin/sh
2 a129376b 2019-03-28 stsp #
3 a129376b 2019-03-28 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 a129376b 2019-03-28 stsp #
5 a129376b 2019-03-28 stsp # Permission to use, copy, modify, and distribute this software for any
6 a129376b 2019-03-28 stsp # purpose with or without fee is hereby granted, provided that the above
7 a129376b 2019-03-28 stsp # copyright notice and this permission notice appear in all copies.
8 a129376b 2019-03-28 stsp #
9 a129376b 2019-03-28 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 a129376b 2019-03-28 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 a129376b 2019-03-28 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 a129376b 2019-03-28 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 a129376b 2019-03-28 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 a129376b 2019-03-28 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 a129376b 2019-03-28 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 a129376b 2019-03-28 stsp
17 a129376b 2019-03-28 stsp . ./common.sh
18 a129376b 2019-03-28 stsp
19 a129376b 2019-03-28 stsp function test_revert_basic {
20 a129376b 2019-03-28 stsp local testroot=`test_init revert_basic`
21 a129376b 2019-03-28 stsp
22 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 a129376b 2019-03-28 stsp ret="$?"
24 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
25 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
26 a129376b 2019-03-28 stsp return 1
27 a129376b 2019-03-28 stsp fi
28 a129376b 2019-03-28 stsp
29 5e54fb30 2019-05-31 stsp echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
30 a129376b 2019-03-28 stsp
31 5e54fb30 2019-05-31 stsp echo 'R epsilon/zeta' > $testroot/stdout.expected
32 a129376b 2019-03-28 stsp
33 5e54fb30 2019-05-31 stsp (cd $testroot/wt && got revert epsilon/zeta > $testroot/stdout)
34 a129376b 2019-03-28 stsp
35 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
36 a129376b 2019-03-28 stsp ret="$?"
37 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
38 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
39 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
40 a129376b 2019-03-28 stsp return 1
41 a129376b 2019-03-28 stsp fi
42 a129376b 2019-03-28 stsp
43 5e54fb30 2019-05-31 stsp echo "zeta" > $testroot/content.expected
44 5e54fb30 2019-05-31 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
45 a129376b 2019-03-28 stsp
46 8d301dd9 2019-05-14 stsp cmp -s $testroot/content.expected $testroot/content
47 a129376b 2019-03-28 stsp ret="$?"
48 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
49 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
50 a129376b 2019-03-28 stsp fi
51 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
52 a129376b 2019-03-28 stsp
53 a129376b 2019-03-28 stsp }
54 a129376b 2019-03-28 stsp
55 a129376b 2019-03-28 stsp function test_revert_rm {
56 a129376b 2019-03-28 stsp local testroot=`test_init revert_rm`
57 a129376b 2019-03-28 stsp
58 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
59 a129376b 2019-03-28 stsp ret="$?"
60 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
61 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
62 a129376b 2019-03-28 stsp return 1
63 a129376b 2019-03-28 stsp fi
64 a129376b 2019-03-28 stsp
65 a129376b 2019-03-28 stsp (cd $testroot/wt && got rm beta >/dev/null)
66 a129376b 2019-03-28 stsp
67 a129376b 2019-03-28 stsp echo 'R beta' > $testroot/stdout.expected
68 a129376b 2019-03-28 stsp
69 a129376b 2019-03-28 stsp (cd $testroot/wt && got revert beta > $testroot/stdout)
70 a129376b 2019-03-28 stsp
71 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
72 a129376b 2019-03-28 stsp ret="$?"
73 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
74 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
75 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
76 a129376b 2019-03-28 stsp return 1
77 a129376b 2019-03-28 stsp fi
78 a129376b 2019-03-28 stsp
79 a129376b 2019-03-28 stsp echo "beta" > $testroot/content.expected
80 a129376b 2019-03-28 stsp cat $testroot/wt/beta > $testroot/content
81 a129376b 2019-03-28 stsp
82 8d301dd9 2019-05-14 stsp cmp -s $testroot/content.expected $testroot/content
83 a129376b 2019-03-28 stsp ret="$?"
84 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
85 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
86 a129376b 2019-03-28 stsp fi
87 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
88 a129376b 2019-03-28 stsp }
89 a129376b 2019-03-28 stsp
90 a129376b 2019-03-28 stsp function test_revert_add {
91 a129376b 2019-03-28 stsp local testroot=`test_init revert_add`
92 a129376b 2019-03-28 stsp
93 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
94 a129376b 2019-03-28 stsp ret="$?"
95 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
96 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
97 a129376b 2019-03-28 stsp return 1
98 a129376b 2019-03-28 stsp fi
99 a129376b 2019-03-28 stsp
100 a129376b 2019-03-28 stsp echo "new file" > $testroot/wt/new
101 a129376b 2019-03-28 stsp (cd $testroot/wt && got add new >/dev/null)
102 a129376b 2019-03-28 stsp
103 a129376b 2019-03-28 stsp echo 'R new' > $testroot/stdout.expected
104 a129376b 2019-03-28 stsp
105 a129376b 2019-03-28 stsp (cd $testroot/wt && got revert new > $testroot/stdout)
106 a129376b 2019-03-28 stsp
107 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
108 a129376b 2019-03-28 stsp ret="$?"
109 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
110 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
111 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
112 a129376b 2019-03-28 stsp return 1
113 a129376b 2019-03-28 stsp fi
114 a129376b 2019-03-28 stsp
115 a129376b 2019-03-28 stsp echo "new file" > $testroot/content.expected
116 a129376b 2019-03-28 stsp cat $testroot/wt/new > $testroot/content
117 a129376b 2019-03-28 stsp
118 8d301dd9 2019-05-14 stsp cmp -s $testroot/content.expected $testroot/content
119 a129376b 2019-03-28 stsp ret="$?"
120 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
121 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
122 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
123 a129376b 2019-03-28 stsp return 1
124 a129376b 2019-03-28 stsp fi
125 a129376b 2019-03-28 stsp
126 a129376b 2019-03-28 stsp echo '? new' > $testroot/stdout.expected
127 a129376b 2019-03-28 stsp
128 a129376b 2019-03-28 stsp (cd $testroot/wt && got status > $testroot/stdout)
129 a129376b 2019-03-28 stsp
130 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
131 a129376b 2019-03-28 stsp ret="$?"
132 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
133 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
134 a129376b 2019-03-28 stsp fi
135 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
136 a129376b 2019-03-28 stsp }
137 a129376b 2019-03-28 stsp
138 e20a8b6f 2019-06-04 stsp function test_revert_multiple {
139 e20a8b6f 2019-06-04 stsp local testroot=`test_init revert_multiple`
140 e20a8b6f 2019-06-04 stsp
141 e20a8b6f 2019-06-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
142 e20a8b6f 2019-06-04 stsp ret="$?"
143 e20a8b6f 2019-06-04 stsp if [ "$ret" != "0" ]; then
144 e20a8b6f 2019-06-04 stsp test_done "$testroot" "$ret"
145 e20a8b6f 2019-06-04 stsp return 1
146 e20a8b6f 2019-06-04 stsp fi
147 e20a8b6f 2019-06-04 stsp
148 e20a8b6f 2019-06-04 stsp echo "modified alpha" > $testroot/wt/alpha
149 e20a8b6f 2019-06-04 stsp echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
150 e20a8b6f 2019-06-04 stsp
151 e20a8b6f 2019-06-04 stsp echo 'R alpha' > $testroot/stdout.expected
152 e20a8b6f 2019-06-04 stsp echo 'R epsilon/zeta' >> $testroot/stdout.expected
153 e20a8b6f 2019-06-04 stsp
154 e20a8b6f 2019-06-04 stsp (cd $testroot/wt && got revert alpha epsilon/zeta > $testroot/stdout)
155 e20a8b6f 2019-06-04 stsp
156 e20a8b6f 2019-06-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
157 e20a8b6f 2019-06-04 stsp ret="$?"
158 e20a8b6f 2019-06-04 stsp if [ "$ret" != "0" ]; then
159 e20a8b6f 2019-06-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
160 e20a8b6f 2019-06-04 stsp test_done "$testroot" "$ret"
161 e20a8b6f 2019-06-04 stsp return 1
162 e20a8b6f 2019-06-04 stsp fi
163 e20a8b6f 2019-06-04 stsp
164 e20a8b6f 2019-06-04 stsp echo "alpha" > $testroot/content.expected
165 e20a8b6f 2019-06-04 stsp cat $testroot/wt/alpha > $testroot/content
166 e20a8b6f 2019-06-04 stsp
167 e20a8b6f 2019-06-04 stsp cmp -s $testroot/content.expected $testroot/content
168 e20a8b6f 2019-06-04 stsp ret="$?"
169 e20a8b6f 2019-06-04 stsp if [ "$ret" != "0" ]; then
170 e20a8b6f 2019-06-04 stsp diff -u $testroot/content.expected $testroot/content
171 e20a8b6f 2019-06-04 stsp test_done "$testroot" "$ret"
172 e20a8b6f 2019-06-04 stsp return 1
173 e20a8b6f 2019-06-04 stsp fi
174 e20a8b6f 2019-06-04 stsp
175 e20a8b6f 2019-06-04 stsp echo "zeta" > $testroot/content.expected
176 e20a8b6f 2019-06-04 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
177 e20a8b6f 2019-06-04 stsp
178 e20a8b6f 2019-06-04 stsp cmp -s $testroot/content.expected $testroot/content
179 e20a8b6f 2019-06-04 stsp ret="$?"
180 e20a8b6f 2019-06-04 stsp if [ "$ret" != "0" ]; then
181 e20a8b6f 2019-06-04 stsp diff -u $testroot/content.expected $testroot/content
182 e20a8b6f 2019-06-04 stsp fi
183 e20a8b6f 2019-06-04 stsp test_done "$testroot" "$ret"
184 e20a8b6f 2019-06-04 stsp }
185 e20a8b6f 2019-06-04 stsp
186 a9fa2909 2019-07-27 stsp function test_revert_file_in_new_subdir {
187 a9fa2909 2019-07-27 stsp local testroot=`test_init revert_file_in_new_subdir`
188 a9fa2909 2019-07-27 stsp
189 a9fa2909 2019-07-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
190 a9fa2909 2019-07-27 stsp ret="$?"
191 a9fa2909 2019-07-27 stsp if [ "$ret" != "0" ]; then
192 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
193 a9fa2909 2019-07-27 stsp return 1
194 a9fa2909 2019-07-27 stsp fi
195 a9fa2909 2019-07-27 stsp
196 a9fa2909 2019-07-27 stsp
197 a9fa2909 2019-07-27 stsp mkdir -p $testroot/wt/newdir
198 a9fa2909 2019-07-27 stsp echo new > $testroot/wt/newdir/new
199 a9fa2909 2019-07-27 stsp (cd $testroot/wt && got add newdir/new > /dev/null)
200 a9fa2909 2019-07-27 stsp
201 a9fa2909 2019-07-27 stsp (cd $testroot/wt && got revert newdir/new > $testroot/stdout)
202 a9fa2909 2019-07-27 stsp
203 a9fa2909 2019-07-27 stsp echo "R newdir/new" > $testroot/stdout.expected
204 a9fa2909 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
205 a9fa2909 2019-07-27 stsp ret="$?"
206 a9fa2909 2019-07-27 stsp if [ "$ret" != "0" ]; then
207 a9fa2909 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
208 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
209 a9fa2909 2019-07-27 stsp return 1
210 a9fa2909 2019-07-27 stsp fi
211 a9fa2909 2019-07-27 stsp
212 a9fa2909 2019-07-27 stsp (cd $testroot/wt && got status > $testroot/stdout)
213 a9fa2909 2019-07-27 stsp
214 a9fa2909 2019-07-27 stsp echo "? newdir/new" > $testroot/stdout.expected
215 a9fa2909 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
216 a9fa2909 2019-07-27 stsp ret="$?"
217 a9fa2909 2019-07-27 stsp if [ "$ret" != "0" ]; then
218 a9fa2909 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
219 a9fa2909 2019-07-27 stsp fi
220 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
221 a9fa2909 2019-07-27 stsp
222 a9fa2909 2019-07-27 stsp }
223 a9fa2909 2019-07-27 stsp
224 1f1abb7e 2019-08-08 stsp function test_revert_no_arguments {
225 1f1abb7e 2019-08-08 stsp local testroot=`test_init revert_no_arguments`
226 1f1abb7e 2019-08-08 stsp
227 1f1abb7e 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
228 1f1abb7e 2019-08-08 stsp ret="$?"
229 1f1abb7e 2019-08-08 stsp if [ "$ret" != "0" ]; then
230 1f1abb7e 2019-08-08 stsp test_done "$testroot" "$ret"
231 1f1abb7e 2019-08-08 stsp return 1
232 1f1abb7e 2019-08-08 stsp fi
233 1f1abb7e 2019-08-08 stsp
234 1f1abb7e 2019-08-08 stsp echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
235 1f1abb7e 2019-08-08 stsp
236 1f1abb7e 2019-08-08 stsp (cd $testroot/wt && got revert > $testroot/stdout 2> $testroot/stderr)
237 1f1abb7e 2019-08-08 stsp ret="$?"
238 1f1abb7e 2019-08-08 stsp if [ "$ret" == "0" ]; then
239 1f1abb7e 2019-08-08 stsp echo "revert command succeeded unexpectedly" >&2
240 1f1abb7e 2019-08-08 stsp test_done "$testroot" "1"
241 1f1abb7e 2019-08-08 stsp return 1
242 1f1abb7e 2019-08-08 stsp fi
243 1f1abb7e 2019-08-08 stsp
244 1f1abb7e 2019-08-08 stsp echo -n > $testroot/stdout.expected
245 1f1abb7e 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
246 1f1abb7e 2019-08-08 stsp ret="$?"
247 1f1abb7e 2019-08-08 stsp if [ "$ret" != "0" ]; then
248 1f1abb7e 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
249 1f1abb7e 2019-08-08 stsp test_done "$testroot" "$ret"
250 1f1abb7e 2019-08-08 stsp return 1
251 1f1abb7e 2019-08-08 stsp fi
252 1f1abb7e 2019-08-08 stsp
253 33aa809d 2019-08-08 stsp echo "usage: got revert [-p] [-F response-script] [-R] path ..." \
254 33aa809d 2019-08-08 stsp > $testroot/stderr.expected
255 0f6d7415 2019-08-08 stsp cmp -s $testroot/stderr.expected $testroot/stderr
256 0f6d7415 2019-08-08 stsp ret="$?"
257 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
258 0f6d7415 2019-08-08 stsp diff -u $testroot/stderr.expected $testroot/stderr
259 0f6d7415 2019-08-08 stsp fi
260 0f6d7415 2019-08-08 stsp test_done "$testroot" "$ret"
261 0f6d7415 2019-08-08 stsp }
262 0f6d7415 2019-08-08 stsp
263 0f6d7415 2019-08-08 stsp function test_revert_directory {
264 0f6d7415 2019-08-08 stsp local testroot=`test_init revert_directory`
265 0f6d7415 2019-08-08 stsp
266 0f6d7415 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
267 0f6d7415 2019-08-08 stsp ret="$?"
268 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
269 0f6d7415 2019-08-08 stsp test_done "$testroot" "$ret"
270 0f6d7415 2019-08-08 stsp return 1
271 0f6d7415 2019-08-08 stsp fi
272 0f6d7415 2019-08-08 stsp
273 0f6d7415 2019-08-08 stsp echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
274 0f6d7415 2019-08-08 stsp
275 0f6d7415 2019-08-08 stsp (cd $testroot/wt && got revert . > $testroot/stdout 2> $testroot/stderr)
276 0f6d7415 2019-08-08 stsp ret="$?"
277 0f6d7415 2019-08-08 stsp if [ "$ret" == "0" ]; then
278 0f6d7415 2019-08-08 stsp echo "got revert command succeeded unexpectedly" >&2
279 0f6d7415 2019-08-08 stsp test_done "$testroot" "1"
280 0f6d7415 2019-08-08 stsp return 1
281 0f6d7415 2019-08-08 stsp fi
282 0f6d7415 2019-08-08 stsp echo "got: reverting directories requires -R option" \
283 0f6d7415 2019-08-08 stsp > $testroot/stderr.expected
284 1f1abb7e 2019-08-08 stsp cmp -s $testroot/stderr.expected $testroot/stderr
285 1f1abb7e 2019-08-08 stsp ret="$?"
286 1f1abb7e 2019-08-08 stsp if [ "$ret" != "0" ]; then
287 1f1abb7e 2019-08-08 stsp diff -u $testroot/stderr.expected $testroot/stderr
288 0f6d7415 2019-08-08 stsp test_done "$testroot" "$ret"
289 0f6d7415 2019-08-08 stsp return 1
290 1f1abb7e 2019-08-08 stsp fi
291 0f6d7415 2019-08-08 stsp
292 0f6d7415 2019-08-08 stsp echo -n > $testroot/stdout.expected
293 0f6d7415 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
294 0f6d7415 2019-08-08 stsp ret="$?"
295 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
296 0f6d7415 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
297 0f6d7415 2019-08-08 stsp test_done "$testroot" "$ret"
298 0f6d7415 2019-08-08 stsp return 1
299 0f6d7415 2019-08-08 stsp fi
300 0f6d7415 2019-08-08 stsp
301 0f6d7415 2019-08-08 stsp (cd $testroot/wt && got revert -R . > $testroot/stdout)
302 0f6d7415 2019-08-08 stsp
303 0f6d7415 2019-08-08 stsp echo 'R epsilon/zeta' > $testroot/stdout.expected
304 0f6d7415 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
305 0f6d7415 2019-08-08 stsp ret="$?"
306 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
307 0f6d7415 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
308 0f6d7415 2019-08-08 stsp test_done "$testroot" "$ret"
309 0f6d7415 2019-08-08 stsp return 1
310 0f6d7415 2019-08-08 stsp fi
311 0f6d7415 2019-08-08 stsp
312 0f6d7415 2019-08-08 stsp echo "zeta" > $testroot/content.expected
313 0f6d7415 2019-08-08 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
314 0f6d7415 2019-08-08 stsp
315 0f6d7415 2019-08-08 stsp cmp -s $testroot/content.expected $testroot/content
316 0f6d7415 2019-08-08 stsp ret="$?"
317 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
318 0f6d7415 2019-08-08 stsp diff -u $testroot/content.expected $testroot/content
319 33aa809d 2019-08-08 stsp fi
320 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
321 3d69ad8d 2019-08-17 semarie }
322 3d69ad8d 2019-08-17 semarie
323 3d69ad8d 2019-08-17 semarie function test_revert_directory_unknown {
324 3d69ad8d 2019-08-17 semarie local testroot=`test_init revert_directory_unknown`
325 3d69ad8d 2019-08-17 semarie
326 3d69ad8d 2019-08-17 semarie got checkout $testroot/repo $testroot/wt > /dev/null
327 3d69ad8d 2019-08-17 semarie ret="$?"
328 3d69ad8d 2019-08-17 semarie if [ "$ret" != "0" ]; then
329 3d69ad8d 2019-08-17 semarie test_done "$testroot" "$ret"
330 3d69ad8d 2019-08-17 semarie return 1
331 3d69ad8d 2019-08-17 semarie fi
332 3d69ad8d 2019-08-17 semarie
333 3d69ad8d 2019-08-17 semarie echo "modified alpha" > $testroot/wt/alpha
334 3d69ad8d 2019-08-17 semarie echo "new untracked file" > $testroot/wt/epsilon/new_file
335 3d69ad8d 2019-08-17 semarie echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
336 3d69ad8d 2019-08-17 semarie
337 3d69ad8d 2019-08-17 semarie (cd $testroot/wt && got revert -R . > $testroot/stdout)
338 3d69ad8d 2019-08-17 semarie
339 3d69ad8d 2019-08-17 semarie echo 'R alpha' > $testroot/stdout.expected
340 3d69ad8d 2019-08-17 semarie echo '? epsilon/new_file' >> $testroot/stdout.expected
341 3d69ad8d 2019-08-17 semarie echo 'R epsilon/zeta' >> $testroot/stdout.expected
342 3d69ad8d 2019-08-17 semarie cmp -s $testroot/stdout.expected $testroot/stdout
343 3d69ad8d 2019-08-17 semarie ret="$?"
344 3d69ad8d 2019-08-17 semarie if [ "$ret" != "0" ]; then
345 3d69ad8d 2019-08-17 semarie diff -u $testroot/stdout.expected $testroot/stdout
346 3d69ad8d 2019-08-17 semarie test_done "$testroot" "$ret"
347 3d69ad8d 2019-08-17 semarie return 1
348 3d69ad8d 2019-08-17 semarie fi
349 3d69ad8d 2019-08-17 semarie
350 3d69ad8d 2019-08-17 semarie echo "new untracked file" > $testroot/content.expected
351 3d69ad8d 2019-08-17 semarie cat $testroot/wt/epsilon/new_file > $testroot/content
352 3d69ad8d 2019-08-17 semarie
353 3d69ad8d 2019-08-17 semarie cmp -s $testroot/content.expected $testroot/content
354 3d69ad8d 2019-08-17 semarie ret="$?"
355 3d69ad8d 2019-08-17 semarie if [ "$ret" != "0" ]; then
356 3d69ad8d 2019-08-17 semarie diff -u $testroot/content.expected $testroot/content
357 3d69ad8d 2019-08-17 semarie test_done "$testroot" "$ret"
358 3d69ad8d 2019-08-17 semarie return 1
359 3d69ad8d 2019-08-17 semarie fi
360 3d69ad8d 2019-08-17 semarie
361 3d69ad8d 2019-08-17 semarie echo "zeta" > $testroot/content.expected
362 3d69ad8d 2019-08-17 semarie cat $testroot/wt/epsilon/zeta > $testroot/content
363 33aa809d 2019-08-08 stsp
364 3d69ad8d 2019-08-17 semarie cmp -s $testroot/content.expected $testroot/content
365 3d69ad8d 2019-08-17 semarie ret="$?"
366 3d69ad8d 2019-08-17 semarie if [ "$ret" != "0" ]; then
367 3d69ad8d 2019-08-17 semarie diff -u $testroot/content.expected $testroot/content
368 3d69ad8d 2019-08-17 semarie fi
369 3d69ad8d 2019-08-17 semarie
370 3d69ad8d 2019-08-17 semarie test_done "$testroot" "$ret"
371 33aa809d 2019-08-08 stsp }
372 33aa809d 2019-08-08 stsp
373 33aa809d 2019-08-08 stsp function test_revert_patch {
374 33aa809d 2019-08-08 stsp local testroot=`test_init revert_patch`
375 33aa809d 2019-08-08 stsp
376 33aa809d 2019-08-08 stsp jot 16 > $testroot/repo/numbers
377 33aa809d 2019-08-08 stsp (cd $testroot/repo && git add numbers)
378 33aa809d 2019-08-08 stsp git_commit $testroot/repo -m "added numbers file"
379 33aa809d 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
380 33aa809d 2019-08-08 stsp
381 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
382 33aa809d 2019-08-08 stsp ret="$?"
383 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
384 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
385 33aa809d 2019-08-08 stsp return 1
386 33aa809d 2019-08-08 stsp fi
387 33aa809d 2019-08-08 stsp
388 33aa809d 2019-08-08 stsp sed -i -e 's/^2$/a/' $testroot/wt/numbers
389 33aa809d 2019-08-08 stsp sed -i -e 's/^7$/b/' $testroot/wt/numbers
390 33aa809d 2019-08-08 stsp sed -i -e 's/^16$/c/' $testroot/wt/numbers
391 33aa809d 2019-08-08 stsp
392 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/numbers.diff)
393 33aa809d 2019-08-08 stsp
394 33aa809d 2019-08-08 stsp # don't revert any hunks
395 33aa809d 2019-08-08 stsp printf "n\nn\nn\n" > $testroot/patchscript
396 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
397 33aa809d 2019-08-08 stsp numbers > $testroot/stdout)
398 33aa809d 2019-08-08 stsp ret="$?"
399 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
400 33aa809d 2019-08-08 stsp echo "got revert command failed unexpectedly" >&2
401 33aa809d 2019-08-08 stsp test_done "$testroot" "1"
402 33aa809d 2019-08-08 stsp return 1
403 33aa809d 2019-08-08 stsp fi
404 33aa809d 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
405 33aa809d 2019-08-08 stsp -----------------------------------------------
406 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
407 33aa809d 2019-08-08 stsp 1
408 33aa809d 2019-08-08 stsp -2
409 33aa809d 2019-08-08 stsp +a
410 33aa809d 2019-08-08 stsp 3
411 33aa809d 2019-08-08 stsp 4
412 33aa809d 2019-08-08 stsp 5
413 33aa809d 2019-08-08 stsp -----------------------------------------------
414 33aa809d 2019-08-08 stsp M numbers (change 1 of 3)
415 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
416 33aa809d 2019-08-08 stsp -----------------------------------------------
417 33aa809d 2019-08-08 stsp @@ -4,7 +4,7 @@
418 33aa809d 2019-08-08 stsp 4
419 33aa809d 2019-08-08 stsp 5
420 33aa809d 2019-08-08 stsp 6
421 33aa809d 2019-08-08 stsp -7
422 33aa809d 2019-08-08 stsp +b
423 33aa809d 2019-08-08 stsp 8
424 33aa809d 2019-08-08 stsp 9
425 33aa809d 2019-08-08 stsp 10
426 33aa809d 2019-08-08 stsp -----------------------------------------------
427 33aa809d 2019-08-08 stsp M numbers (change 2 of 3)
428 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
429 33aa809d 2019-08-08 stsp -----------------------------------------------
430 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
431 33aa809d 2019-08-08 stsp 13
432 33aa809d 2019-08-08 stsp 14
433 33aa809d 2019-08-08 stsp 15
434 33aa809d 2019-08-08 stsp -16
435 33aa809d 2019-08-08 stsp +c
436 33aa809d 2019-08-08 stsp -----------------------------------------------
437 33aa809d 2019-08-08 stsp M numbers (change 3 of 3)
438 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
439 33aa809d 2019-08-08 stsp EOF
440 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
441 33aa809d 2019-08-08 stsp ret="$?"
442 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
443 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
444 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
445 33aa809d 2019-08-08 stsp return 1
446 33aa809d 2019-08-08 stsp fi
447 33aa809d 2019-08-08 stsp
448 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
449 33aa809d 2019-08-08 stsp echo "M numbers" > $testroot/stdout.expected
450 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
451 33aa809d 2019-08-08 stsp ret="$?"
452 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
453 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
454 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
455 33aa809d 2019-08-08 stsp return 1
456 33aa809d 2019-08-08 stsp fi
457 33aa809d 2019-08-08 stsp
458 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
459 33aa809d 2019-08-08 stsp cmp -s $testroot/numbers.diff $testroot/stdout
460 33aa809d 2019-08-08 stsp ret="$?"
461 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
462 33aa809d 2019-08-08 stsp diff -u $testroot/numbers.diff $testroot/stdout
463 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
464 33aa809d 2019-08-08 stsp return 1
465 33aa809d 2019-08-08 stsp fi
466 33aa809d 2019-08-08 stsp
467 ce2b05c7 2019-08-10 stsp # revert first hunk
468 ce2b05c7 2019-08-10 stsp printf "y\nn\nn\n" > $testroot/patchscript
469 ce2b05c7 2019-08-10 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
470 ce2b05c7 2019-08-10 stsp numbers > $testroot/stdout)
471 ce2b05c7 2019-08-10 stsp ret="$?"
472 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
473 ce2b05c7 2019-08-10 stsp echo "got revert command failed unexpectedly" >&2
474 ce2b05c7 2019-08-10 stsp test_done "$testroot" "1"
475 ce2b05c7 2019-08-10 stsp return 1
476 ce2b05c7 2019-08-10 stsp fi
477 ce2b05c7 2019-08-10 stsp cat > $testroot/stdout.expected <<EOF
478 ce2b05c7 2019-08-10 stsp -----------------------------------------------
479 ce2b05c7 2019-08-10 stsp @@ -1,5 +1,5 @@
480 ce2b05c7 2019-08-10 stsp 1
481 ce2b05c7 2019-08-10 stsp -2
482 ce2b05c7 2019-08-10 stsp +a
483 ce2b05c7 2019-08-10 stsp 3
484 ce2b05c7 2019-08-10 stsp 4
485 ce2b05c7 2019-08-10 stsp 5
486 ce2b05c7 2019-08-10 stsp -----------------------------------------------
487 ce2b05c7 2019-08-10 stsp M numbers (change 1 of 3)
488 ce2b05c7 2019-08-10 stsp revert this change? [y/n/q] y
489 ce2b05c7 2019-08-10 stsp -----------------------------------------------
490 ce2b05c7 2019-08-10 stsp @@ -4,7 +4,7 @@
491 ce2b05c7 2019-08-10 stsp 4
492 ce2b05c7 2019-08-10 stsp 5
493 ce2b05c7 2019-08-10 stsp 6
494 ce2b05c7 2019-08-10 stsp -7
495 ce2b05c7 2019-08-10 stsp +b
496 ce2b05c7 2019-08-10 stsp 8
497 ce2b05c7 2019-08-10 stsp 9
498 ce2b05c7 2019-08-10 stsp 10
499 ce2b05c7 2019-08-10 stsp -----------------------------------------------
500 ce2b05c7 2019-08-10 stsp M numbers (change 2 of 3)
501 ce2b05c7 2019-08-10 stsp revert this change? [y/n/q] n
502 ce2b05c7 2019-08-10 stsp -----------------------------------------------
503 ce2b05c7 2019-08-10 stsp @@ -13,4 +13,4 @@
504 ce2b05c7 2019-08-10 stsp 13
505 ce2b05c7 2019-08-10 stsp 14
506 ce2b05c7 2019-08-10 stsp 15
507 ce2b05c7 2019-08-10 stsp -16
508 ce2b05c7 2019-08-10 stsp +c
509 ce2b05c7 2019-08-10 stsp -----------------------------------------------
510 ce2b05c7 2019-08-10 stsp M numbers (change 3 of 3)
511 ce2b05c7 2019-08-10 stsp revert this change? [y/n/q] n
512 ce2b05c7 2019-08-10 stsp EOF
513 ce2b05c7 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
514 ce2b05c7 2019-08-10 stsp ret="$?"
515 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
516 ce2b05c7 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
517 ce2b05c7 2019-08-10 stsp test_done "$testroot" "$ret"
518 ce2b05c7 2019-08-10 stsp return 1
519 ce2b05c7 2019-08-10 stsp fi
520 ce2b05c7 2019-08-10 stsp
521 ce2b05c7 2019-08-10 stsp (cd $testroot/wt && got status > $testroot/stdout)
522 ce2b05c7 2019-08-10 stsp echo "M numbers" > $testroot/stdout.expected
523 ce2b05c7 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
524 ce2b05c7 2019-08-10 stsp ret="$?"
525 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
526 ce2b05c7 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
527 ce2b05c7 2019-08-10 stsp test_done "$testroot" "$ret"
528 ce2b05c7 2019-08-10 stsp return 1
529 ce2b05c7 2019-08-10 stsp fi
530 ce2b05c7 2019-08-10 stsp
531 ce2b05c7 2019-08-10 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
532 ce2b05c7 2019-08-10 stsp echo -n 'blob - ' >> $testroot/stdout.expected
533 ce2b05c7 2019-08-10 stsp got tree -r $testroot/repo -i -c $commit_id \
534 ce2b05c7 2019-08-10 stsp | grep 'numbers$' | cut -d' ' -f 1 \
535 ce2b05c7 2019-08-10 stsp >> $testroot/stdout.expected
536 ce2b05c7 2019-08-10 stsp echo 'file + numbers' >> $testroot/stdout.expected
537 ce2b05c7 2019-08-10 stsp cat >> $testroot/stdout.expected <<EOF
538 ce2b05c7 2019-08-10 stsp --- numbers
539 ce2b05c7 2019-08-10 stsp +++ numbers
540 ce2b05c7 2019-08-10 stsp @@ -4,7 +4,7 @@
541 ce2b05c7 2019-08-10 stsp 4
542 ce2b05c7 2019-08-10 stsp 5
543 ce2b05c7 2019-08-10 stsp 6
544 ce2b05c7 2019-08-10 stsp -7
545 ce2b05c7 2019-08-10 stsp +b
546 ce2b05c7 2019-08-10 stsp 8
547 ce2b05c7 2019-08-10 stsp 9
548 ce2b05c7 2019-08-10 stsp 10
549 ce2b05c7 2019-08-10 stsp @@ -13,4 +13,4 @@
550 ce2b05c7 2019-08-10 stsp 13
551 ce2b05c7 2019-08-10 stsp 14
552 ce2b05c7 2019-08-10 stsp 15
553 ce2b05c7 2019-08-10 stsp -16
554 ce2b05c7 2019-08-10 stsp +c
555 ce2b05c7 2019-08-10 stsp EOF
556 ce2b05c7 2019-08-10 stsp (cd $testroot/wt && got diff > $testroot/stdout)
557 ce2b05c7 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
558 ce2b05c7 2019-08-10 stsp ret="$?"
559 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
560 ce2b05c7 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
561 ce2b05c7 2019-08-10 stsp test_done "$testroot" "$ret"
562 ce2b05c7 2019-08-10 stsp return 1
563 ce2b05c7 2019-08-10 stsp fi
564 ce2b05c7 2019-08-10 stsp
565 ce2b05c7 2019-08-10 stsp # put first hunk back
566 ce2b05c7 2019-08-10 stsp sed -i -e 's/^2$/a/' $testroot/wt/numbers
567 ce2b05c7 2019-08-10 stsp
568 33aa809d 2019-08-08 stsp # revert middle hunk
569 33aa809d 2019-08-08 stsp printf "n\ny\nn\n" > $testroot/patchscript
570 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
571 33aa809d 2019-08-08 stsp numbers > $testroot/stdout)
572 33aa809d 2019-08-08 stsp
573 33aa809d 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
574 33aa809d 2019-08-08 stsp -----------------------------------------------
575 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
576 33aa809d 2019-08-08 stsp 1
577 33aa809d 2019-08-08 stsp -2
578 33aa809d 2019-08-08 stsp +a
579 33aa809d 2019-08-08 stsp 3
580 33aa809d 2019-08-08 stsp 4
581 33aa809d 2019-08-08 stsp 5
582 33aa809d 2019-08-08 stsp -----------------------------------------------
583 33aa809d 2019-08-08 stsp M numbers (change 1 of 3)
584 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
585 33aa809d 2019-08-08 stsp -----------------------------------------------
586 33aa809d 2019-08-08 stsp @@ -4,7 +4,7 @@
587 33aa809d 2019-08-08 stsp 4
588 33aa809d 2019-08-08 stsp 5
589 33aa809d 2019-08-08 stsp 6
590 33aa809d 2019-08-08 stsp -7
591 33aa809d 2019-08-08 stsp +b
592 33aa809d 2019-08-08 stsp 8
593 33aa809d 2019-08-08 stsp 9
594 33aa809d 2019-08-08 stsp 10
595 33aa809d 2019-08-08 stsp -----------------------------------------------
596 33aa809d 2019-08-08 stsp M numbers (change 2 of 3)
597 33aa809d 2019-08-08 stsp revert this change? [y/n/q] y
598 33aa809d 2019-08-08 stsp -----------------------------------------------
599 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
600 33aa809d 2019-08-08 stsp 13
601 33aa809d 2019-08-08 stsp 14
602 33aa809d 2019-08-08 stsp 15
603 33aa809d 2019-08-08 stsp -16
604 33aa809d 2019-08-08 stsp +c
605 33aa809d 2019-08-08 stsp -----------------------------------------------
606 33aa809d 2019-08-08 stsp M numbers (change 3 of 3)
607 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
608 33aa809d 2019-08-08 stsp EOF
609 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
610 33aa809d 2019-08-08 stsp ret="$?"
611 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
612 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
613 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
614 33aa809d 2019-08-08 stsp return 1
615 33aa809d 2019-08-08 stsp fi
616 33aa809d 2019-08-08 stsp
617 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
618 33aa809d 2019-08-08 stsp echo "M numbers" > $testroot/stdout.expected
619 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
620 33aa809d 2019-08-08 stsp ret="$?"
621 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
622 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
623 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
624 33aa809d 2019-08-08 stsp return 1
625 33aa809d 2019-08-08 stsp fi
626 33aa809d 2019-08-08 stsp
627 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
628 33aa809d 2019-08-08 stsp
629 33aa809d 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
630 33aa809d 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
631 33aa809d 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
632 33aa809d 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
633 33aa809d 2019-08-08 stsp >> $testroot/stdout.expected
634 33aa809d 2019-08-08 stsp echo 'file + numbers' >> $testroot/stdout.expected
635 33aa809d 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
636 33aa809d 2019-08-08 stsp --- numbers
637 33aa809d 2019-08-08 stsp +++ numbers
638 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
639 33aa809d 2019-08-08 stsp 1
640 33aa809d 2019-08-08 stsp -2
641 33aa809d 2019-08-08 stsp +a
642 33aa809d 2019-08-08 stsp 3
643 33aa809d 2019-08-08 stsp 4
644 33aa809d 2019-08-08 stsp 5
645 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
646 33aa809d 2019-08-08 stsp 13
647 33aa809d 2019-08-08 stsp 14
648 33aa809d 2019-08-08 stsp 15
649 33aa809d 2019-08-08 stsp -16
650 33aa809d 2019-08-08 stsp +c
651 33aa809d 2019-08-08 stsp EOF
652 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
653 33aa809d 2019-08-08 stsp ret="$?"
654 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
655 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
656 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
657 33aa809d 2019-08-08 stsp return 1
658 0f6d7415 2019-08-08 stsp fi
659 33aa809d 2019-08-08 stsp
660 33aa809d 2019-08-08 stsp # revert last hunk
661 33aa809d 2019-08-08 stsp printf "n\ny\n" > $testroot/patchscript
662 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
663 33aa809d 2019-08-08 stsp numbers > $testroot/stdout)
664 33aa809d 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
665 33aa809d 2019-08-08 stsp -----------------------------------------------
666 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
667 33aa809d 2019-08-08 stsp 1
668 33aa809d 2019-08-08 stsp -2
669 33aa809d 2019-08-08 stsp +a
670 33aa809d 2019-08-08 stsp 3
671 33aa809d 2019-08-08 stsp 4
672 33aa809d 2019-08-08 stsp 5
673 33aa809d 2019-08-08 stsp -----------------------------------------------
674 33aa809d 2019-08-08 stsp M numbers (change 1 of 2)
675 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
676 33aa809d 2019-08-08 stsp -----------------------------------------------
677 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
678 33aa809d 2019-08-08 stsp 13
679 33aa809d 2019-08-08 stsp 14
680 33aa809d 2019-08-08 stsp 15
681 33aa809d 2019-08-08 stsp -16
682 33aa809d 2019-08-08 stsp +c
683 33aa809d 2019-08-08 stsp -----------------------------------------------
684 33aa809d 2019-08-08 stsp M numbers (change 2 of 2)
685 33aa809d 2019-08-08 stsp revert this change? [y/n/q] y
686 33aa809d 2019-08-08 stsp EOF
687 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
688 33aa809d 2019-08-08 stsp ret="$?"
689 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
690 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
691 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
692 33aa809d 2019-08-08 stsp return 1
693 33aa809d 2019-08-08 stsp fi
694 33aa809d 2019-08-08 stsp
695 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
696 33aa809d 2019-08-08 stsp
697 33aa809d 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
698 33aa809d 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
699 33aa809d 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
700 33aa809d 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
701 33aa809d 2019-08-08 stsp >> $testroot/stdout.expected
702 33aa809d 2019-08-08 stsp echo 'file + numbers' >> $testroot/stdout.expected
703 33aa809d 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
704 33aa809d 2019-08-08 stsp --- numbers
705 33aa809d 2019-08-08 stsp +++ numbers
706 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
707 33aa809d 2019-08-08 stsp 1
708 33aa809d 2019-08-08 stsp -2
709 33aa809d 2019-08-08 stsp +a
710 33aa809d 2019-08-08 stsp 3
711 33aa809d 2019-08-08 stsp 4
712 33aa809d 2019-08-08 stsp 5
713 33aa809d 2019-08-08 stsp EOF
714 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
715 33aa809d 2019-08-08 stsp ret="$?"
716 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
717 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
718 33aa809d 2019-08-08 stsp fi
719 1f1abb7e 2019-08-08 stsp test_done "$testroot" "$ret"
720 33aa809d 2019-08-08 stsp }
721 0f6d7415 2019-08-08 stsp
722 33aa809d 2019-08-08 stsp function test_revert_patch_added {
723 33aa809d 2019-08-08 stsp local testroot=`test_init revert_patch_added`
724 33aa809d 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
725 33aa809d 2019-08-08 stsp
726 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
727 33aa809d 2019-08-08 stsp ret="$?"
728 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
729 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
730 33aa809d 2019-08-08 stsp return 1
731 33aa809d 2019-08-08 stsp fi
732 33aa809d 2019-08-08 stsp
733 33aa809d 2019-08-08 stsp echo "new" > $testroot/wt/epsilon/new
734 33aa809d 2019-08-08 stsp (cd $testroot/wt && got add epsilon/new > /dev/null)
735 33aa809d 2019-08-08 stsp
736 33aa809d 2019-08-08 stsp printf "n\n" > $testroot/patchscript
737 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
738 33aa809d 2019-08-08 stsp epsilon/new > $testroot/stdout)
739 33aa809d 2019-08-08 stsp
740 33aa809d 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
741 33aa809d 2019-08-08 stsp echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
742 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
743 33aa809d 2019-08-08 stsp ret="$?"
744 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
745 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
746 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
747 33aa809d 2019-08-08 stsp return 1
748 33aa809d 2019-08-08 stsp fi
749 33aa809d 2019-08-08 stsp
750 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
751 33aa809d 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
752 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
753 33aa809d 2019-08-08 stsp ret="$?"
754 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
755 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
756 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
757 33aa809d 2019-08-08 stsp return 1
758 33aa809d 2019-08-08 stsp fi
759 33aa809d 2019-08-08 stsp
760 33aa809d 2019-08-08 stsp printf "y\n" > $testroot/patchscript
761 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
762 33aa809d 2019-08-08 stsp epsilon/new > $testroot/stdout)
763 33aa809d 2019-08-08 stsp
764 33aa809d 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
765 33aa809d 2019-08-08 stsp echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
766 33aa809d 2019-08-08 stsp echo "R epsilon/new" >> $testroot/stdout.expected
767 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
768 33aa809d 2019-08-08 stsp ret="$?"
769 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
770 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
771 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
772 33aa809d 2019-08-08 stsp return 1
773 33aa809d 2019-08-08 stsp fi
774 33aa809d 2019-08-08 stsp
775 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
776 33aa809d 2019-08-08 stsp echo "? epsilon/new" > $testroot/stdout.expected
777 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
778 33aa809d 2019-08-08 stsp ret="$?"
779 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
780 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
781 33aa809d 2019-08-08 stsp fi
782 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
783 1f1abb7e 2019-08-08 stsp }
784 1f1abb7e 2019-08-08 stsp
785 33aa809d 2019-08-08 stsp function test_revert_patch_removed {
786 33aa809d 2019-08-08 stsp local testroot=`test_init revert_patch_removed`
787 33aa809d 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
788 33aa809d 2019-08-08 stsp
789 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
790 33aa809d 2019-08-08 stsp ret="$?"
791 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
792 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
793 33aa809d 2019-08-08 stsp return 1
794 33aa809d 2019-08-08 stsp fi
795 33aa809d 2019-08-08 stsp
796 33aa809d 2019-08-08 stsp (cd $testroot/wt && got rm beta > /dev/null)
797 33aa809d 2019-08-08 stsp
798 33aa809d 2019-08-08 stsp printf "n\n" > $testroot/patchscript
799 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
800 33aa809d 2019-08-08 stsp beta > $testroot/stdout)
801 33aa809d 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
802 33aa809d 2019-08-08 stsp echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
803 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
804 33aa809d 2019-08-08 stsp ret="$?"
805 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
806 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
807 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
808 33aa809d 2019-08-08 stsp return 1
809 33aa809d 2019-08-08 stsp fi
810 33aa809d 2019-08-08 stsp
811 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
812 33aa809d 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
813 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
814 33aa809d 2019-08-08 stsp ret="$?"
815 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
816 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
817 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
818 33aa809d 2019-08-08 stsp return 1
819 33aa809d 2019-08-08 stsp fi
820 33aa809d 2019-08-08 stsp
821 33aa809d 2019-08-08 stsp printf "y\n" > $testroot/patchscript
822 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
823 33aa809d 2019-08-08 stsp beta > $testroot/stdout)
824 33aa809d 2019-08-08 stsp
825 33aa809d 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
826 33aa809d 2019-08-08 stsp echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
827 33aa809d 2019-08-08 stsp echo "R beta" >> $testroot/stdout.expected
828 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
829 33aa809d 2019-08-08 stsp ret="$?"
830 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
831 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
832 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
833 33aa809d 2019-08-08 stsp return 1
834 33aa809d 2019-08-08 stsp fi
835 33aa809d 2019-08-08 stsp
836 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
837 33aa809d 2019-08-08 stsp echo -n > $testroot/stdout.expected
838 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
839 33aa809d 2019-08-08 stsp ret="$?"
840 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
841 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
842 33aa809d 2019-08-08 stsp fi
843 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
844 33aa809d 2019-08-08 stsp }
845 f1e81a05 2019-08-10 stsp
846 f1e81a05 2019-08-10 stsp function test_revert_patch_one_change {
847 f1e81a05 2019-08-10 stsp local testroot=`test_init revert_patch_one_change`
848 f1e81a05 2019-08-10 stsp
849 f1e81a05 2019-08-10 stsp jot 16 > $testroot/repo/numbers
850 f1e81a05 2019-08-10 stsp (cd $testroot/repo && git add numbers)
851 f1e81a05 2019-08-10 stsp git_commit $testroot/repo -m "added numbers file"
852 f1e81a05 2019-08-10 stsp local commit_id=`git_show_head $testroot/repo`
853 f1e81a05 2019-08-10 stsp
854 f1e81a05 2019-08-10 stsp got checkout $testroot/repo $testroot/wt > /dev/null
855 f1e81a05 2019-08-10 stsp ret="$?"
856 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
857 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
858 f1e81a05 2019-08-10 stsp return 1
859 f1e81a05 2019-08-10 stsp fi
860 f1e81a05 2019-08-10 stsp
861 6c6b73bb 2019-08-10 stsp # Ensure file size is changed. Avoids race condition causing test
862 6c6b73bb 2019-08-10 stsp # failures where 'got revert' does not see changes to revert if
863 6c6b73bb 2019-08-10 stsp # timestamps and size in stat info remain unchanged.
864 6c6b73bb 2019-08-10 stsp sed -i -e 's/^2$/aa/' $testroot/wt/numbers
865 33aa809d 2019-08-08 stsp
866 f1e81a05 2019-08-10 stsp # revert change with -p
867 f1e81a05 2019-08-10 stsp printf "y\n" > $testroot/patchscript
868 f1e81a05 2019-08-10 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
869 f1e81a05 2019-08-10 stsp numbers > $testroot/stdout)
870 f1e81a05 2019-08-10 stsp ret="$?"
871 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
872 f1e81a05 2019-08-10 stsp echo "got revert command failed unexpectedly" >&2
873 f1e81a05 2019-08-10 stsp test_done "$testroot" "1"
874 f1e81a05 2019-08-10 stsp return 1
875 f1e81a05 2019-08-10 stsp fi
876 f1e81a05 2019-08-10 stsp cat > $testroot/stdout.expected <<EOF
877 f1e81a05 2019-08-10 stsp -----------------------------------------------
878 f1e81a05 2019-08-10 stsp @@ -1,5 +1,5 @@
879 f1e81a05 2019-08-10 stsp 1
880 f1e81a05 2019-08-10 stsp -2
881 6c6b73bb 2019-08-10 stsp +aa
882 f1e81a05 2019-08-10 stsp 3
883 f1e81a05 2019-08-10 stsp 4
884 f1e81a05 2019-08-10 stsp 5
885 f1e81a05 2019-08-10 stsp -----------------------------------------------
886 f1e81a05 2019-08-10 stsp M numbers (change 1 of 1)
887 f1e81a05 2019-08-10 stsp revert this change? [y/n/q] y
888 f1e81a05 2019-08-10 stsp EOF
889 6c6b73bb 2019-08-10 stsp ret="$?"
890 6c6b73bb 2019-08-10 stsp if [ "$ret" != "0" ]; then
891 6c6b73bb 2019-08-10 stsp echo "got revert command failed unexpectedly" >&2
892 6c6b73bb 2019-08-10 stsp test_done "$testroot" "1"
893 6c6b73bb 2019-08-10 stsp return 1
894 6c6b73bb 2019-08-10 stsp fi
895 6c6b73bb 2019-08-10 stsp
896 f1e81a05 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
897 f1e81a05 2019-08-10 stsp ret="$?"
898 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
899 f1e81a05 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
900 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
901 f1e81a05 2019-08-10 stsp return 1
902 f1e81a05 2019-08-10 stsp fi
903 f1e81a05 2019-08-10 stsp
904 f1e81a05 2019-08-10 stsp (cd $testroot/wt && got status > $testroot/stdout)
905 f1e81a05 2019-08-10 stsp echo -n > $testroot/stdout.expected
906 f1e81a05 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
907 f1e81a05 2019-08-10 stsp ret="$?"
908 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
909 f1e81a05 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
910 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
911 f1e81a05 2019-08-10 stsp return 1
912 f1e81a05 2019-08-10 stsp fi
913 f1e81a05 2019-08-10 stsp
914 f1e81a05 2019-08-10 stsp (cd $testroot/wt && got diff > $testroot/stdout)
915 f1e81a05 2019-08-10 stsp echo -n > $testroot/stdout.expected
916 f1e81a05 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
917 f1e81a05 2019-08-10 stsp ret="$?"
918 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
919 f1e81a05 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
920 f1e81a05 2019-08-10 stsp fi
921 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
922 f1e81a05 2019-08-10 stsp }
923 f1e81a05 2019-08-10 stsp
924 a129376b 2019-03-28 stsp run_test test_revert_basic
925 a129376b 2019-03-28 stsp run_test test_revert_rm
926 a129376b 2019-03-28 stsp run_test test_revert_add
927 e20a8b6f 2019-06-04 stsp run_test test_revert_multiple
928 a9fa2909 2019-07-27 stsp run_test test_revert_file_in_new_subdir
929 1f1abb7e 2019-08-08 stsp run_test test_revert_no_arguments
930 0f6d7415 2019-08-08 stsp run_test test_revert_directory
931 3d69ad8d 2019-08-17 semarie run_test test_revert_directory_unknown
932 33aa809d 2019-08-08 stsp run_test test_revert_patch
933 33aa809d 2019-08-08 stsp run_test test_revert_patch_added
934 33aa809d 2019-08-08 stsp run_test test_revert_patch_removed
935 f1e81a05 2019-08-10 stsp run_test test_revert_patch_one_change