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"
324 33aa809d 2019-08-08 stsp function test_revert_patch {
325 33aa809d 2019-08-08 stsp local testroot=`test_init revert_patch`
327 33aa809d 2019-08-08 stsp jot 16 > $testroot/repo/numbers
328 33aa809d 2019-08-08 stsp (cd $testroot/repo && git add numbers)
329 33aa809d 2019-08-08 stsp git_commit $testroot/repo -m "added numbers file"
330 33aa809d 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
332 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
334 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
335 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
339 33aa809d 2019-08-08 stsp sed -i -e 's/^2$/a/' $testroot/wt/numbers
340 33aa809d 2019-08-08 stsp sed -i -e 's/^7$/b/' $testroot/wt/numbers
341 33aa809d 2019-08-08 stsp sed -i -e 's/^16$/c/' $testroot/wt/numbers
343 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/numbers.diff)
345 33aa809d 2019-08-08 stsp # don't revert any hunks
346 33aa809d 2019-08-08 stsp printf "n\nn\nn\n" > $testroot/patchscript
347 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
348 33aa809d 2019-08-08 stsp numbers > $testroot/stdout)
350 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
351 33aa809d 2019-08-08 stsp echo "got revert command failed unexpectedly" >&2
352 33aa809d 2019-08-08 stsp test_done "$testroot" "1"
355 33aa809d 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
356 33aa809d 2019-08-08 stsp -----------------------------------------------
357 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
364 33aa809d 2019-08-08 stsp -----------------------------------------------
365 33aa809d 2019-08-08 stsp M numbers (change 1 of 3)
366 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
367 33aa809d 2019-08-08 stsp -----------------------------------------------
368 33aa809d 2019-08-08 stsp @@ -4,7 +4,7 @@
377 33aa809d 2019-08-08 stsp -----------------------------------------------
378 33aa809d 2019-08-08 stsp M numbers (change 2 of 3)
379 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
380 33aa809d 2019-08-08 stsp -----------------------------------------------
381 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
387 33aa809d 2019-08-08 stsp -----------------------------------------------
388 33aa809d 2019-08-08 stsp M numbers (change 3 of 3)
389 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
391 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
393 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
394 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
395 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
399 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
400 33aa809d 2019-08-08 stsp echo "M numbers" > $testroot/stdout.expected
401 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
403 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
404 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
405 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
409 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
410 33aa809d 2019-08-08 stsp cmp -s $testroot/numbers.diff $testroot/stdout
412 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
413 33aa809d 2019-08-08 stsp diff -u $testroot/numbers.diff $testroot/stdout
414 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
418 ce2b05c7 2019-08-10 stsp # revert first hunk
419 ce2b05c7 2019-08-10 stsp printf "y\nn\nn\n" > $testroot/patchscript
420 ce2b05c7 2019-08-10 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
421 ce2b05c7 2019-08-10 stsp numbers > $testroot/stdout)
423 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
424 ce2b05c7 2019-08-10 stsp echo "got revert command failed unexpectedly" >&2
425 ce2b05c7 2019-08-10 stsp test_done "$testroot" "1"
428 ce2b05c7 2019-08-10 stsp cat > $testroot/stdout.expected <<EOF
429 ce2b05c7 2019-08-10 stsp -----------------------------------------------
430 ce2b05c7 2019-08-10 stsp @@ -1,5 +1,5 @@
437 ce2b05c7 2019-08-10 stsp -----------------------------------------------
438 ce2b05c7 2019-08-10 stsp M numbers (change 1 of 3)
439 ce2b05c7 2019-08-10 stsp revert this change? [y/n/q] y
440 ce2b05c7 2019-08-10 stsp -----------------------------------------------
441 ce2b05c7 2019-08-10 stsp @@ -4,7 +4,7 @@
450 ce2b05c7 2019-08-10 stsp -----------------------------------------------
451 ce2b05c7 2019-08-10 stsp M numbers (change 2 of 3)
452 ce2b05c7 2019-08-10 stsp revert this change? [y/n/q] n
453 ce2b05c7 2019-08-10 stsp -----------------------------------------------
454 ce2b05c7 2019-08-10 stsp @@ -13,4 +13,4 @@
460 ce2b05c7 2019-08-10 stsp -----------------------------------------------
461 ce2b05c7 2019-08-10 stsp M numbers (change 3 of 3)
462 ce2b05c7 2019-08-10 stsp revert this change? [y/n/q] n
464 ce2b05c7 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
466 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
467 ce2b05c7 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
468 ce2b05c7 2019-08-10 stsp test_done "$testroot" "$ret"
472 ce2b05c7 2019-08-10 stsp (cd $testroot/wt && got status > $testroot/stdout)
473 ce2b05c7 2019-08-10 stsp echo "M numbers" > $testroot/stdout.expected
474 ce2b05c7 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
476 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
477 ce2b05c7 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
478 ce2b05c7 2019-08-10 stsp test_done "$testroot" "$ret"
482 ce2b05c7 2019-08-10 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
483 ce2b05c7 2019-08-10 stsp echo -n 'blob - ' >> $testroot/stdout.expected
484 ce2b05c7 2019-08-10 stsp got tree -r $testroot/repo -i -c $commit_id \
485 ce2b05c7 2019-08-10 stsp | grep 'numbers$' | cut -d' ' -f 1 \
486 ce2b05c7 2019-08-10 stsp >> $testroot/stdout.expected
487 ce2b05c7 2019-08-10 stsp echo 'file + numbers' >> $testroot/stdout.expected
488 ce2b05c7 2019-08-10 stsp cat >> $testroot/stdout.expected <<EOF
489 ce2b05c7 2019-08-10 stsp --- numbers
490 ce2b05c7 2019-08-10 stsp +++ numbers
491 ce2b05c7 2019-08-10 stsp @@ -4,7 +4,7 @@
500 ce2b05c7 2019-08-10 stsp @@ -13,4 +13,4 @@
507 ce2b05c7 2019-08-10 stsp (cd $testroot/wt && got diff > $testroot/stdout)
508 ce2b05c7 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
510 ce2b05c7 2019-08-10 stsp if [ "$ret" != "0" ]; then
511 ce2b05c7 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
512 ce2b05c7 2019-08-10 stsp test_done "$testroot" "$ret"
516 ce2b05c7 2019-08-10 stsp # put first hunk back
517 ce2b05c7 2019-08-10 stsp sed -i -e 's/^2$/a/' $testroot/wt/numbers
519 33aa809d 2019-08-08 stsp # revert middle hunk
520 33aa809d 2019-08-08 stsp printf "n\ny\nn\n" > $testroot/patchscript
521 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
522 33aa809d 2019-08-08 stsp numbers > $testroot/stdout)
524 33aa809d 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
525 33aa809d 2019-08-08 stsp -----------------------------------------------
526 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
533 33aa809d 2019-08-08 stsp -----------------------------------------------
534 33aa809d 2019-08-08 stsp M numbers (change 1 of 3)
535 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
536 33aa809d 2019-08-08 stsp -----------------------------------------------
537 33aa809d 2019-08-08 stsp @@ -4,7 +4,7 @@
546 33aa809d 2019-08-08 stsp -----------------------------------------------
547 33aa809d 2019-08-08 stsp M numbers (change 2 of 3)
548 33aa809d 2019-08-08 stsp revert this change? [y/n/q] y
549 33aa809d 2019-08-08 stsp -----------------------------------------------
550 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
556 33aa809d 2019-08-08 stsp -----------------------------------------------
557 33aa809d 2019-08-08 stsp M numbers (change 3 of 3)
558 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
560 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
562 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
563 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
564 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
568 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
569 33aa809d 2019-08-08 stsp echo "M numbers" > $testroot/stdout.expected
570 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
572 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
573 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
574 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
578 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
580 33aa809d 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
581 33aa809d 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
582 33aa809d 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
583 33aa809d 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
584 33aa809d 2019-08-08 stsp >> $testroot/stdout.expected
585 33aa809d 2019-08-08 stsp echo 'file + numbers' >> $testroot/stdout.expected
586 33aa809d 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
587 33aa809d 2019-08-08 stsp --- numbers
588 33aa809d 2019-08-08 stsp +++ numbers
589 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
596 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
603 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
605 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
606 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
607 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
611 33aa809d 2019-08-08 stsp # revert last hunk
612 33aa809d 2019-08-08 stsp printf "n\ny\n" > $testroot/patchscript
613 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
614 33aa809d 2019-08-08 stsp numbers > $testroot/stdout)
615 33aa809d 2019-08-08 stsp cat > $testroot/stdout.expected <<EOF
616 33aa809d 2019-08-08 stsp -----------------------------------------------
617 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
624 33aa809d 2019-08-08 stsp -----------------------------------------------
625 33aa809d 2019-08-08 stsp M numbers (change 1 of 2)
626 33aa809d 2019-08-08 stsp revert this change? [y/n/q] n
627 33aa809d 2019-08-08 stsp -----------------------------------------------
628 33aa809d 2019-08-08 stsp @@ -13,4 +13,4 @@
634 33aa809d 2019-08-08 stsp -----------------------------------------------
635 33aa809d 2019-08-08 stsp M numbers (change 2 of 2)
636 33aa809d 2019-08-08 stsp revert this change? [y/n/q] y
638 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
640 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
641 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
642 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
646 33aa809d 2019-08-08 stsp (cd $testroot/wt && got diff > $testroot/stdout)
648 33aa809d 2019-08-08 stsp echo "diff $commit_id $testroot/wt" > $testroot/stdout.expected
649 33aa809d 2019-08-08 stsp echo -n 'blob - ' >> $testroot/stdout.expected
650 33aa809d 2019-08-08 stsp got tree -r $testroot/repo -i -c $commit_id \
651 33aa809d 2019-08-08 stsp | grep 'numbers$' | cut -d' ' -f 1 \
652 33aa809d 2019-08-08 stsp >> $testroot/stdout.expected
653 33aa809d 2019-08-08 stsp echo 'file + numbers' >> $testroot/stdout.expected
654 33aa809d 2019-08-08 stsp cat >> $testroot/stdout.expected <<EOF
655 33aa809d 2019-08-08 stsp --- numbers
656 33aa809d 2019-08-08 stsp +++ numbers
657 33aa809d 2019-08-08 stsp @@ -1,5 +1,5 @@
665 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
667 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
668 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
670 1f1abb7e 2019-08-08 stsp test_done "$testroot" "$ret"
673 33aa809d 2019-08-08 stsp function test_revert_patch_added {
674 33aa809d 2019-08-08 stsp local testroot=`test_init revert_patch_added`
675 33aa809d 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
677 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
679 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
680 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
684 33aa809d 2019-08-08 stsp echo "new" > $testroot/wt/epsilon/new
685 33aa809d 2019-08-08 stsp (cd $testroot/wt && got add epsilon/new > /dev/null)
687 33aa809d 2019-08-08 stsp printf "n\n" > $testroot/patchscript
688 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
689 33aa809d 2019-08-08 stsp epsilon/new > $testroot/stdout)
691 33aa809d 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
692 33aa809d 2019-08-08 stsp echo "revert this addition? [y/n] n" >> $testroot/stdout.expected
693 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
695 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
696 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
697 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
701 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
702 33aa809d 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
703 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
705 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
706 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
707 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
711 33aa809d 2019-08-08 stsp printf "y\n" > $testroot/patchscript
712 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
713 33aa809d 2019-08-08 stsp epsilon/new > $testroot/stdout)
715 33aa809d 2019-08-08 stsp echo "A epsilon/new" > $testroot/stdout.expected
716 33aa809d 2019-08-08 stsp echo "revert this addition? [y/n] y" >> $testroot/stdout.expected
717 33aa809d 2019-08-08 stsp echo "R epsilon/new" >> $testroot/stdout.expected
718 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
720 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
721 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
722 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
726 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
727 33aa809d 2019-08-08 stsp echo "? epsilon/new" > $testroot/stdout.expected
728 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
730 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
731 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
733 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
736 33aa809d 2019-08-08 stsp function test_revert_patch_removed {
737 33aa809d 2019-08-08 stsp local testroot=`test_init revert_patch_removed`
738 33aa809d 2019-08-08 stsp local commit_id=`git_show_head $testroot/repo`
740 33aa809d 2019-08-08 stsp got checkout $testroot/repo $testroot/wt > /dev/null
742 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
743 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
747 33aa809d 2019-08-08 stsp (cd $testroot/wt && got rm beta > /dev/null)
749 33aa809d 2019-08-08 stsp printf "n\n" > $testroot/patchscript
750 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
751 33aa809d 2019-08-08 stsp beta > $testroot/stdout)
752 33aa809d 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
753 33aa809d 2019-08-08 stsp echo "revert this deletion? [y/n] n" >> $testroot/stdout.expected
754 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
756 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
757 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
758 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
762 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
763 33aa809d 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
764 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
766 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
767 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
768 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
772 33aa809d 2019-08-08 stsp printf "y\n" > $testroot/patchscript
773 33aa809d 2019-08-08 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
774 33aa809d 2019-08-08 stsp beta > $testroot/stdout)
776 33aa809d 2019-08-08 stsp echo "D beta" > $testroot/stdout.expected
777 33aa809d 2019-08-08 stsp echo "revert this deletion? [y/n] y" >> $testroot/stdout.expected
778 33aa809d 2019-08-08 stsp echo "R beta" >> $testroot/stdout.expected
779 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
781 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
782 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
783 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
787 33aa809d 2019-08-08 stsp (cd $testroot/wt && got status > $testroot/stdout)
788 33aa809d 2019-08-08 stsp echo -n > $testroot/stdout.expected
789 33aa809d 2019-08-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
791 33aa809d 2019-08-08 stsp if [ "$ret" != "0" ]; then
792 33aa809d 2019-08-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
794 33aa809d 2019-08-08 stsp test_done "$testroot" "$ret"
797 f1e81a05 2019-08-10 stsp function test_revert_patch_one_change {
798 f1e81a05 2019-08-10 stsp local testroot=`test_init revert_patch_one_change`
800 f1e81a05 2019-08-10 stsp jot 16 > $testroot/repo/numbers
801 f1e81a05 2019-08-10 stsp (cd $testroot/repo && git add numbers)
802 f1e81a05 2019-08-10 stsp git_commit $testroot/repo -m "added numbers file"
803 f1e81a05 2019-08-10 stsp local commit_id=`git_show_head $testroot/repo`
805 f1e81a05 2019-08-10 stsp got checkout $testroot/repo $testroot/wt > /dev/null
807 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
808 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
812 6c6b73bb 2019-08-10 stsp # Ensure file size is changed. Avoids race condition causing test
813 6c6b73bb 2019-08-10 stsp # failures where 'got revert' does not see changes to revert if
814 6c6b73bb 2019-08-10 stsp # timestamps and size in stat info remain unchanged.
815 6c6b73bb 2019-08-10 stsp sed -i -e 's/^2$/aa/' $testroot/wt/numbers
817 f1e81a05 2019-08-10 stsp # revert change with -p
818 f1e81a05 2019-08-10 stsp printf "y\n" > $testroot/patchscript
819 f1e81a05 2019-08-10 stsp (cd $testroot/wt && got revert -F $testroot/patchscript -p \
820 f1e81a05 2019-08-10 stsp numbers > $testroot/stdout)
822 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
823 f1e81a05 2019-08-10 stsp echo "got revert command failed unexpectedly" >&2
824 f1e81a05 2019-08-10 stsp test_done "$testroot" "1"
827 f1e81a05 2019-08-10 stsp cat > $testroot/stdout.expected <<EOF
828 f1e81a05 2019-08-10 stsp -----------------------------------------------
829 f1e81a05 2019-08-10 stsp @@ -1,5 +1,5 @@
836 f1e81a05 2019-08-10 stsp -----------------------------------------------
837 f1e81a05 2019-08-10 stsp M numbers (change 1 of 1)
838 f1e81a05 2019-08-10 stsp revert this change? [y/n/q] y
841 6c6b73bb 2019-08-10 stsp if [ "$ret" != "0" ]; then
842 6c6b73bb 2019-08-10 stsp echo "got revert command failed unexpectedly" >&2
843 6c6b73bb 2019-08-10 stsp test_done "$testroot" "1"
847 f1e81a05 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
849 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
850 f1e81a05 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
851 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
855 f1e81a05 2019-08-10 stsp (cd $testroot/wt && got status > $testroot/stdout)
856 f1e81a05 2019-08-10 stsp echo -n > $testroot/stdout.expected
857 f1e81a05 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
859 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
860 f1e81a05 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
861 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
865 f1e81a05 2019-08-10 stsp (cd $testroot/wt && got diff > $testroot/stdout)
866 f1e81a05 2019-08-10 stsp echo -n > $testroot/stdout.expected
867 f1e81a05 2019-08-10 stsp cmp -s $testroot/stdout.expected $testroot/stdout
869 f1e81a05 2019-08-10 stsp if [ "$ret" != "0" ]; then
870 f1e81a05 2019-08-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
872 f1e81a05 2019-08-10 stsp test_done "$testroot" "$ret"
875 a129376b 2019-03-28 stsp run_test test_revert_basic
876 a129376b 2019-03-28 stsp run_test test_revert_rm
877 a129376b 2019-03-28 stsp run_test test_revert_add
878 e20a8b6f 2019-06-04 stsp run_test test_revert_multiple
879 a9fa2909 2019-07-27 stsp run_test test_revert_file_in_new_subdir
880 1f1abb7e 2019-08-08 stsp run_test test_revert_no_arguments
881 0f6d7415 2019-08-08 stsp run_test test_revert_directory
882 33aa809d 2019-08-08 stsp run_test test_revert_patch
883 33aa809d 2019-08-08 stsp run_test test_revert_patch_added
884 33aa809d 2019-08-08 stsp run_test test_revert_patch_removed
885 f1e81a05 2019-08-10 stsp run_test test_revert_patch_one_change