3 a129376b 2019-03-28 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
17 a129376b 2019-03-28 stsp . ./common.sh
19 a129376b 2019-03-28 stsp function test_revert_basic {
20 a129376b 2019-03-28 stsp local testroot=`test_init revert_basic`
22 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
25 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
29 5e54fb30 2019-05-31 stsp echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
31 5e54fb30 2019-05-31 stsp echo 'R epsilon/zeta' > $testroot/stdout.expected
33 5e54fb30 2019-05-31 stsp (cd $testroot/wt && got revert epsilon/zeta > $testroot/stdout)
35 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
43 5e54fb30 2019-05-31 stsp echo "zeta" > $testroot/content.expected
44 5e54fb30 2019-05-31 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
46 8d301dd9 2019-05-14 stsp cmp -s $testroot/content.expected $testroot/content
48 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
49 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
51 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
55 a129376b 2019-03-28 stsp function test_revert_rm {
56 a129376b 2019-03-28 stsp local testroot=`test_init revert_rm`
58 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
60 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
61 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
65 a129376b 2019-03-28 stsp (cd $testroot/wt && got rm beta >/dev/null)
67 a129376b 2019-03-28 stsp echo 'R beta' > $testroot/stdout.expected
69 a129376b 2019-03-28 stsp (cd $testroot/wt && got revert beta > $testroot/stdout)
71 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
79 a129376b 2019-03-28 stsp echo "beta" > $testroot/content.expected
80 a129376b 2019-03-28 stsp cat $testroot/wt/beta > $testroot/content
82 8d301dd9 2019-05-14 stsp cmp -s $testroot/content.expected $testroot/content
84 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
85 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
87 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
90 a129376b 2019-03-28 stsp function test_revert_add {
91 a129376b 2019-03-28 stsp local testroot=`test_init revert_add`
93 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
95 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
96 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
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)
103 a129376b 2019-03-28 stsp echo 'R new' > $testroot/stdout.expected
105 a129376b 2019-03-28 stsp (cd $testroot/wt && got revert new > $testroot/stdout)
107 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
115 a129376b 2019-03-28 stsp echo "new file" > $testroot/content.expected
116 a129376b 2019-03-28 stsp cat $testroot/wt/new > $testroot/content
118 8d301dd9 2019-05-14 stsp cmp -s $testroot/content.expected $testroot/content
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"
126 a129376b 2019-03-28 stsp echo '? new' > $testroot/stdout.expected
128 a129376b 2019-03-28 stsp (cd $testroot/wt && got status > $testroot/stdout)
130 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
132 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
133 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
135 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
138 e20a8b6f 2019-06-04 stsp function test_revert_multiple {
139 e20a8b6f 2019-06-04 stsp local testroot=`test_init revert_multiple`
141 e20a8b6f 2019-06-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
143 e20a8b6f 2019-06-04 stsp if [ "$ret" != "0" ]; then
144 e20a8b6f 2019-06-04 stsp test_done "$testroot" "$ret"
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
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
154 e20a8b6f 2019-06-04 stsp (cd $testroot/wt && got revert alpha epsilon/zeta > $testroot/stdout)
156 e20a8b6f 2019-06-04 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
164 e20a8b6f 2019-06-04 stsp echo "alpha" > $testroot/content.expected
165 e20a8b6f 2019-06-04 stsp cat $testroot/wt/alpha > $testroot/content
167 e20a8b6f 2019-06-04 stsp cmp -s $testroot/content.expected $testroot/content
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"
175 e20a8b6f 2019-06-04 stsp echo "zeta" > $testroot/content.expected
176 e20a8b6f 2019-06-04 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
178 e20a8b6f 2019-06-04 stsp cmp -s $testroot/content.expected $testroot/content
180 e20a8b6f 2019-06-04 stsp if [ "$ret" != "0" ]; then
181 e20a8b6f 2019-06-04 stsp diff -u $testroot/content.expected $testroot/content
183 e20a8b6f 2019-06-04 stsp test_done "$testroot" "$ret"
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`
189 a9fa2909 2019-07-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
191 a9fa2909 2019-07-27 stsp if [ "$ret" != "0" ]; then
192 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
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)
201 a9fa2909 2019-07-27 stsp (cd $testroot/wt && got revert newdir/new > $testroot/stdout)
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
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"
212 a9fa2909 2019-07-27 stsp (cd $testroot/wt && got status > $testroot/stdout)
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
217 a9fa2909 2019-07-27 stsp if [ "$ret" != "0" ]; then
218 a9fa2909 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
220 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
224 1f1abb7e 2019-08-08 stsp function test_revert_no_arguments {
225 1f1abb7e 2019-08-08 stsp local testroot=`test_init revert_no_arguments`
227 1f1abb7e 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
229 1f1abb7e 2019-08-08 stsp if [ "$ret" != "0" ]; then
230 1f1abb7e 2019-08-08 stsp test_done "$testroot" "$ret"
234 1f1abb7e 2019-08-08 stsp echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
236 1f1abb7e 2019-08-08 stsp (cd $testroot/wt && got revert > $testroot/stdout 2> $testroot/stderr)
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"
244 1f1abb7e 2019-08-08 stsp echo -n > $testroot/stdout.expected
245 1f1abb7e 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
257 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
258 0f6d7415 2019-08-08 stsp diff -u $testroot/stderr.expected $testroot/stderr
260 0f6d7415 2019-08-08 stsp test_done "$testroot" "$ret"
263 0f6d7415 2019-08-08 stsp function test_revert_directory {
264 0f6d7415 2019-08-08 stsp local testroot=`test_init revert_directory`
266 0f6d7415 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
268 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
269 0f6d7415 2019-08-08 stsp test_done "$testroot" "$ret"
273 0f6d7415 2019-08-08 stsp echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta
275 0f6d7415 2019-08-08 stsp (cd $testroot/wt && got revert . > $testroot/stdout 2> $testroot/stderr)
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"
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
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"
292 0f6d7415 2019-08-08 stsp echo -n > $testroot/stdout.expected
293 0f6d7415 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
301 0f6d7415 2019-08-08 stsp (cd $testroot/wt && got revert -R . > $testroot/stdout)
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
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"
312 0f6d7415 2019-08-08 stsp echo "zeta" > $testroot/content.expected
313 0f6d7415 2019-08-08 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
315 0f6d7415 2019-08-08 stsp cmp -s $testroot/content.expected $testroot/content
317 0f6d7415 2019-08-08 stsp if [ "$ret" != "0" ]; then
318 0f6d7415 2019-08-08 stsp diff -u $testroot/content.expected $testroot/content
320 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
323 3d69ad8d 2019-08-17 semarie function test_revert_directory_unknown {
324 3d69ad8d 2019-08-17 semarie local testroot=`test_init revert_directory_unknown`
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
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
337 3d69ad8d 2019-08-17 semarie (cd $testroot/wt && got revert -R . > $testroot/stdout)
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
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
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
361 3d69ad8d 2019-08-17 semarie echo "zeta" > $testroot/content.expected
362 3d69ad8d 2019-08-17 semarie cat $testroot/wt/epsilon/zeta > $testroot/content
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
370 3d69ad8d 2019-08-17 semarie test_done "$testroot" "$ret"
373 33aa809d 2019-08-08 stsp function test_revert_patch {
374 33aa809d 2019-08-08 stsp local testroot=`test_init revert_patch`
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`
381 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
383 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
384 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
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
392 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/numbers.diff)
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)
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"
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 @@
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 @@
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 @@
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
440 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
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"
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
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"
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)
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"
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 @@
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 @@
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 @@
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
513 ce2b05c7 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
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"
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 @@
549 ce2b05c7 2019-08-10 stsp @@ -13,4 +13,4 @@
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
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"
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
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)
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 @@
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 @@
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 @@
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
609 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
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"
627 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
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 @@
645 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
652 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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 @@
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 @@
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
687 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
695 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
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 @@
714 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
716 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
717 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
719 1f1abb7e 2019-08-08 stsp test_done "$testroot" "$ret"
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`
726 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
728 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
729 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
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)
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)
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
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"
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
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"
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)
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
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"
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
779 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
780 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
782 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
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`
789 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
791 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
792 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
796 33aa809d 2019-08-08 stsp (cd $testroot/wt && got rm beta > /dev/null)
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
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"
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
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"
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)
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
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"
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
840 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
841 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
843 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
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`
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`
854 f1e81a05 2019-08-10 stsp got checkout $testroot/repo $testroot/wt > /dev/null
856 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
857 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
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
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)
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"
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 @@
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
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"
896 f1e81a05 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
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"
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
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"
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
918 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
919 f1e81a05 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
921 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
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