Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_histedit_no_op {
20 local testroot=`test_init histedit_no_op`
22 local orig_commit=`git_show_head $testroot/repo`
24 echo "modified alpha on master" > $testroot/repo/alpha
25 (cd $testroot/repo && git rm -q beta)
26 echo "new file on master" > $testroot/repo/epsilon/new
27 (cd $testroot/repo && git add epsilon/new)
28 git_commit $testroot/repo -m "committing changes"
29 local old_commit1=`git_show_head $testroot/repo`
31 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
32 git_commit $testroot/repo -m "committing to zeta on master"
33 local old_commit2=`git_show_head $testroot/repo`
35 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
36 ret="$?"
37 if [ "$ret" != "0" ]; then
38 test_done "$testroot" "$ret"
39 return 1
40 fi
42 echo "pick $old_commit1" > $testroot/histedit-script
43 echo "pick $old_commit2" >> $testroot/histedit-script
45 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
46 > $testroot/stdout)
48 local new_commit1=`git_show_parent_commit $testroot/repo`
49 local new_commit2=`git_show_head $testroot/repo`
51 local short_old_commit1=`trim_obj_id 28 $old_commit1`
52 local short_old_commit2=`trim_obj_id 28 $old_commit2`
53 local short_new_commit1=`trim_obj_id 28 $new_commit1`
54 local short_new_commit2=`trim_obj_id 28 $new_commit2`
56 echo "G alpha" > $testroot/stdout.expected
57 echo "D beta" >> $testroot/stdout.expected
58 echo "A epsilon/new" >> $testroot/stdout.expected
59 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
60 >> $testroot/stdout.expected
61 echo "G epsilon/zeta" >> $testroot/stdout.expected
62 echo -n "$short_old_commit2 -> $short_new_commit2: " \
63 >> $testroot/stdout.expected
64 echo "committing to zeta on master" >> $testroot/stdout.expected
65 echo "Switching work tree to refs/heads/master" \
66 >> $testroot/stdout.expected
68 cmp -s $testroot/stdout.expected $testroot/stdout
69 ret="$?"
70 if [ "$ret" != "0" ]; then
71 diff -u $testroot/stdout.expected $testroot/stdout
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 echo "modified alpha on master" > $testroot/content.expected
77 cat $testroot/wt/alpha > $testroot/content
78 cmp -s $testroot/content.expected $testroot/content
79 ret="$?"
80 if [ "$ret" != "0" ]; then
81 diff -u $testroot/content.expected $testroot/content
82 test_done "$testroot" "$ret"
83 return 1
84 fi
86 if [ -e $testroot/wt/beta ]; then
87 echo "removed file beta still exists on disk" >&2
88 test_done "$testroot" "1"
89 return 1
90 fi
92 echo "new file on master" > $testroot/content.expected
93 cat $testroot/wt/epsilon/new > $testroot/content
94 cmp -s $testroot/content.expected $testroot/content
95 ret="$?"
96 if [ "$ret" != "0" ]; then
97 diff -u $testroot/content.expected $testroot/content
98 test_done "$testroot" "$ret"
99 return 1
100 fi
102 (cd $testroot/wt && got status > $testroot/stdout)
104 echo -n > $testroot/stdout.expected
105 cmp -s $testroot/stdout.expected $testroot/stdout
106 ret="$?"
107 if [ "$ret" != "0" ]; then
108 diff -u $testroot/stdout.expected $testroot/stdout
109 test_done "$testroot" "$ret"
110 return 1
111 fi
113 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
114 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
115 echo "commit $new_commit1" >> $testroot/stdout.expected
116 echo "commit $orig_commit" >> $testroot/stdout.expected
117 cmp -s $testroot/stdout.expected $testroot/stdout
118 ret="$?"
119 if [ "$ret" != "0" ]; then
120 diff -u $testroot/stdout.expected $testroot/stdout
121 fi
122 test_done "$testroot" "$ret"
125 function test_histedit_swap {
126 local testroot=`test_init histedit_swap`
128 local orig_commit=`git_show_head $testroot/repo`
130 echo "modified alpha on master" > $testroot/repo/alpha
131 (cd $testroot/repo && git rm -q beta)
132 echo "new file on master" > $testroot/repo/epsilon/new
133 (cd $testroot/repo && git add epsilon/new)
134 git_commit $testroot/repo -m "committing changes"
135 local old_commit1=`git_show_head $testroot/repo`
137 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
138 git_commit $testroot/repo -m "committing to zeta on master"
139 local old_commit2=`git_show_head $testroot/repo`
141 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
142 ret="$?"
143 if [ "$ret" != "0" ]; then
144 test_done "$testroot" "$ret"
145 return 1
146 fi
148 echo "pick $old_commit2" > $testroot/histedit-script
149 echo "pick $old_commit1" >> $testroot/histedit-script
151 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
152 > $testroot/stdout)
154 local new_commit2=`git_show_parent_commit $testroot/repo`
155 local new_commit1=`git_show_head $testroot/repo`
157 local short_old_commit1=`trim_obj_id 28 $old_commit1`
158 local short_old_commit2=`trim_obj_id 28 $old_commit2`
159 local short_new_commit1=`trim_obj_id 28 $new_commit1`
160 local short_new_commit2=`trim_obj_id 28 $new_commit2`
162 echo "G epsilon/zeta" > $testroot/stdout.expected
163 echo -n "$short_old_commit2 -> $short_new_commit2: " \
164 >> $testroot/stdout.expected
165 echo "committing to zeta on master" >> $testroot/stdout.expected
166 echo "G alpha" >> $testroot/stdout.expected
167 echo "D beta" >> $testroot/stdout.expected
168 echo "A epsilon/new" >> $testroot/stdout.expected
169 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
170 >> $testroot/stdout.expected
171 echo "Switching work tree to refs/heads/master" \
172 >> $testroot/stdout.expected
174 cmp -s $testroot/stdout.expected $testroot/stdout
175 ret="$?"
176 if [ "$ret" != "0" ]; then
177 diff -u $testroot/stdout.expected $testroot/stdout
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 echo "modified alpha on master" > $testroot/content.expected
183 cat $testroot/wt/alpha > $testroot/content
184 cmp -s $testroot/content.expected $testroot/content
185 ret="$?"
186 if [ "$ret" != "0" ]; then
187 diff -u $testroot/content.expected $testroot/content
188 test_done "$testroot" "$ret"
189 return 1
190 fi
192 if [ -e $testroot/wt/beta ]; then
193 echo "removed file beta still exists on disk" >&2
194 test_done "$testroot" "1"
195 return 1
196 fi
198 echo "new file on master" > $testroot/content.expected
199 cat $testroot/wt/epsilon/new > $testroot/content
200 cmp -s $testroot/content.expected $testroot/content
201 ret="$?"
202 if [ "$ret" != "0" ]; then
203 diff -u $testroot/content.expected $testroot/content
204 test_done "$testroot" "$ret"
205 return 1
206 fi
208 (cd $testroot/wt && got status > $testroot/stdout)
210 echo -n > $testroot/stdout.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
216 return 1
217 fi
219 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
220 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
221 echo "commit $new_commit2" >> $testroot/stdout.expected
222 echo "commit $orig_commit" >> $testroot/stdout.expected
223 cmp -s $testroot/stdout.expected $testroot/stdout
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 diff -u $testroot/stdout.expected $testroot/stdout
227 fi
228 test_done "$testroot" "$ret"
231 function test_histedit_drop {
232 local testroot=`test_init histedit_drop`
234 local orig_commit=`git_show_head $testroot/repo`
236 echo "modified alpha on master" > $testroot/repo/alpha
237 (cd $testroot/repo && git rm -q beta)
238 echo "new file on master" > $testroot/repo/epsilon/new
239 (cd $testroot/repo && git add epsilon/new)
240 git_commit $testroot/repo -m "committing changes"
241 local old_commit1=`git_show_head $testroot/repo`
243 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
244 git_commit $testroot/repo -m "committing to zeta on master"
245 local old_commit2=`git_show_head $testroot/repo`
247 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
248 ret="$?"
249 if [ "$ret" != "0" ]; then
250 test_done "$testroot" "$ret"
251 return 1
252 fi
254 echo "drop $old_commit1" > $testroot/histedit-script
255 echo "pick $old_commit2" >> $testroot/histedit-script
257 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
258 > $testroot/stdout)
260 local new_commit1=`git_show_parent_commit $testroot/repo`
261 local new_commit2=`git_show_head $testroot/repo`
263 local short_old_commit1=`trim_obj_id 28 $old_commit1`
264 local short_old_commit2=`trim_obj_id 28 $old_commit2`
265 local short_new_commit1=`trim_obj_id 28 $new_commit1`
266 local short_new_commit2=`trim_obj_id 28 $new_commit2`
268 echo "$short_old_commit1 -> drop commit: committing changes" \
269 > $testroot/stdout.expected
270 echo "G epsilon/zeta" >> $testroot/stdout.expected
271 echo -n "$short_old_commit2 -> $short_new_commit2: " \
272 >> $testroot/stdout.expected
273 echo "committing to zeta on master" >> $testroot/stdout.expected
274 echo "Switching work tree to refs/heads/master" \
275 >> $testroot/stdout.expected
277 cmp -s $testroot/stdout.expected $testroot/stdout
278 ret="$?"
279 if [ "$ret" != "0" ]; then
280 diff -u $testroot/stdout.expected $testroot/stdout
281 test_done "$testroot" "$ret"
282 return 1
283 fi
285 for f in alpha beta; do
286 echo "$f" > $testroot/content.expected
287 cat $testroot/wt/$f > $testroot/content
288 cmp -s $testroot/content.expected $testroot/content
289 ret="$?"
290 if [ "$ret" != "0" ]; then
291 diff -u $testroot/content.expected $testroot/content
292 test_done "$testroot" "$ret"
293 return 1
294 fi
295 done
297 if [ -e $testroot/wt/new ]; then
298 echo "file new exists on disk but should not" >&2
299 test_done "$testroot" "1"
300 return 1
301 fi
303 (cd $testroot/wt && got status > $testroot/stdout)
305 echo -n > $testroot/stdout.expected
306 cmp -s $testroot/stdout.expected $testroot/stdout
307 ret="$?"
308 if [ "$ret" != "0" ]; then
309 diff -u $testroot/stdout.expected $testroot/stdout
310 test_done "$testroot" "$ret"
311 return 1
312 fi
314 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
315 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
316 echo "commit $orig_commit" >> $testroot/stdout.expected
317 cmp -s $testroot/stdout.expected $testroot/stdout
318 ret="$?"
319 if [ "$ret" != "0" ]; then
320 diff -u $testroot/stdout.expected $testroot/stdout
321 fi
322 test_done "$testroot" "$ret"
325 function test_histedit_fold {
326 local testroot=`test_init histedit_fold`
328 local orig_commit=`git_show_head $testroot/repo`
330 echo "modified alpha on master" > $testroot/repo/alpha
331 (cd $testroot/repo && git rm -q beta)
332 echo "new file on master" > $testroot/repo/epsilon/new
333 (cd $testroot/repo && git add epsilon/new)
334 git_commit $testroot/repo -m "committing changes"
335 local old_commit1=`git_show_head $testroot/repo`
337 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
338 git_commit $testroot/repo -m "committing to zeta on master"
339 local old_commit2=`git_show_head $testroot/repo`
341 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
342 ret="$?"
343 if [ "$ret" != "0" ]; then
344 test_done "$testroot" "$ret"
345 return 1
346 fi
348 echo "fold $old_commit1" > $testroot/histedit-script
349 echo "pick $old_commit2" >> $testroot/histedit-script
350 echo "mesg committing folded changes" >> $testroot/histedit-script
352 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
353 > $testroot/stdout)
355 local new_commit1=`git_show_parent_commit $testroot/repo`
356 local new_commit2=`git_show_head $testroot/repo`
358 local short_old_commit1=`trim_obj_id 28 $old_commit1`
359 local short_old_commit2=`trim_obj_id 28 $old_commit2`
360 local short_new_commit1=`trim_obj_id 28 $new_commit1`
361 local short_new_commit2=`trim_obj_id 28 $new_commit2`
363 echo "G alpha" > $testroot/stdout.expected
364 echo "D beta" >> $testroot/stdout.expected
365 echo "A epsilon/new" >> $testroot/stdout.expected
366 echo "$short_old_commit1 -> fold commit: committing changes" \
367 >> $testroot/stdout.expected
368 echo "G epsilon/zeta" >> $testroot/stdout.expected
369 echo -n "$short_old_commit2 -> $short_new_commit2: " \
370 >> $testroot/stdout.expected
371 echo "committing folded changes" >> $testroot/stdout.expected
372 echo "Switching work tree to refs/heads/master" \
373 >> $testroot/stdout.expected
375 cmp -s $testroot/stdout.expected $testroot/stdout
376 ret="$?"
377 if [ "$ret" != "0" ]; then
378 diff -u $testroot/stdout.expected $testroot/stdout
379 test_done "$testroot" "$ret"
380 return 1
381 fi
383 echo "modified alpha on master" > $testroot/content.expected
384 cat $testroot/wt/alpha > $testroot/content
385 cmp -s $testroot/content.expected $testroot/content
386 ret="$?"
387 if [ "$ret" != "0" ]; then
388 diff -u $testroot/content.expected $testroot/content
389 test_done "$testroot" "$ret"
390 return 1
391 fi
393 if [ -e $testroot/wt/beta ]; then
394 echo "removed file beta still exists on disk" >&2
395 test_done "$testroot" "1"
396 return 1
397 fi
399 echo "new file on master" > $testroot/content.expected
400 cat $testroot/wt/epsilon/new > $testroot/content
401 cmp -s $testroot/content.expected $testroot/content
402 ret="$?"
403 if [ "$ret" != "0" ]; then
404 diff -u $testroot/content.expected $testroot/content
405 test_done "$testroot" "$ret"
406 return 1
407 fi
409 (cd $testroot/wt && got status > $testroot/stdout)
411 echo -n > $testroot/stdout.expected
412 cmp -s $testroot/stdout.expected $testroot/stdout
413 ret="$?"
414 if [ "$ret" != "0" ]; then
415 diff -u $testroot/stdout.expected $testroot/stdout
416 test_done "$testroot" "$ret"
417 return 1
418 fi
420 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
421 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
422 echo "commit $orig_commit" >> $testroot/stdout.expected
423 cmp -s $testroot/stdout.expected $testroot/stdout
424 ret="$?"
425 if [ "$ret" != "0" ]; then
426 diff -u $testroot/stdout.expected $testroot/stdout
427 fi
428 test_done "$testroot" "$ret"
431 function test_histedit_edit {
432 local testroot=`test_init histedit_edit`
434 local orig_commit=`git_show_head $testroot/repo`
436 echo "modified alpha on master" > $testroot/repo/alpha
437 (cd $testroot/repo && git rm -q beta)
438 echo "new file on master" > $testroot/repo/epsilon/new
439 (cd $testroot/repo && git add epsilon/new)
440 git_commit $testroot/repo -m "committing changes"
441 local old_commit1=`git_show_head $testroot/repo`
443 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
444 git_commit $testroot/repo -m "committing to zeta on master"
445 local old_commit2=`git_show_head $testroot/repo`
447 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
448 ret="$?"
449 if [ "$ret" != "0" ]; then
450 test_done "$testroot" "$ret"
451 return 1
452 fi
454 echo "edit $old_commit1" > $testroot/histedit-script
455 echo "mesg committing changes" >> $testroot/histedit-script
456 echo "pick $old_commit2" >> $testroot/histedit-script
458 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
459 > $testroot/stdout)
461 local short_old_commit1=`trim_obj_id 28 $old_commit1`
462 local short_old_commit2=`trim_obj_id 28 $old_commit2`
464 echo "G alpha" > $testroot/stdout.expected
465 echo "D beta" >> $testroot/stdout.expected
466 echo "A epsilon/new" >> $testroot/stdout.expected
467 echo "Stopping histedit for amending commit $old_commit1" \
468 >> $testroot/stdout.expected
469 cmp -s $testroot/stdout.expected $testroot/stdout
470 ret="$?"
471 if [ "$ret" != "0" ]; then
472 diff -u $testroot/stdout.expected $testroot/stdout
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 echo "edited modified alpha on master" > $testroot/wt/alpha
479 (cd $testroot/wt && got histedit -c > $testroot/stdout)
481 local new_commit1=`git_show_parent_commit $testroot/repo`
482 local new_commit2=`git_show_head $testroot/repo`
484 local short_new_commit1=`trim_obj_id 28 $new_commit1`
485 local short_new_commit2=`trim_obj_id 28 $new_commit2`
487 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
488 > $testroot/stdout.expected
489 echo "G epsilon/zeta" >> $testroot/stdout.expected
490 echo -n "$short_old_commit2 -> $short_new_commit2: " \
491 >> $testroot/stdout.expected
492 echo "committing to zeta on master" >> $testroot/stdout.expected
493 echo "Switching work tree to refs/heads/master" \
494 >> $testroot/stdout.expected
496 cmp -s $testroot/stdout.expected $testroot/stdout
497 ret="$?"
498 if [ "$ret" != "0" ]; then
499 diff -u $testroot/stdout.expected $testroot/stdout
500 test_done "$testroot" "$ret"
501 return 1
502 fi
504 echo "edited modified alpha on master" > $testroot/content.expected
505 cat $testroot/wt/alpha > $testroot/content
506 cmp -s $testroot/content.expected $testroot/content
507 ret="$?"
508 if [ "$ret" != "0" ]; then
509 diff -u $testroot/content.expected $testroot/content
510 test_done "$testroot" "$ret"
511 return 1
512 fi
514 if [ -e $testroot/wt/beta ]; then
515 echo "removed file beta still exists on disk" >&2
516 test_done "$testroot" "1"
517 return 1
518 fi
520 echo "new file on master" > $testroot/content.expected
521 cat $testroot/wt/epsilon/new > $testroot/content
522 cmp -s $testroot/content.expected $testroot/content
523 ret="$?"
524 if [ "$ret" != "0" ]; then
525 diff -u $testroot/content.expected $testroot/content
526 test_done "$testroot" "$ret"
527 return 1
528 fi
530 (cd $testroot/wt && got status > $testroot/stdout)
532 echo -n > $testroot/stdout.expected
533 cmp -s $testroot/stdout.expected $testroot/stdout
534 ret="$?"
535 if [ "$ret" != "0" ]; then
536 diff -u $testroot/stdout.expected $testroot/stdout
537 test_done "$testroot" "$ret"
538 return 1
539 fi
541 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
542 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
543 echo "commit $new_commit1" >> $testroot/stdout.expected
544 echo "commit $orig_commit" >> $testroot/stdout.expected
545 cmp -s $testroot/stdout.expected $testroot/stdout
546 ret="$?"
547 if [ "$ret" != "0" ]; then
548 diff -u $testroot/stdout.expected $testroot/stdout
549 fi
550 test_done "$testroot" "$ret"
553 function test_histedit_fold_last_commit {
554 local testroot=`test_init histedit_fold_last_commit`
556 local orig_commit=`git_show_head $testroot/repo`
558 echo "modified alpha on master" > $testroot/repo/alpha
559 (cd $testroot/repo && git rm -q beta)
560 echo "new file on master" > $testroot/repo/epsilon/new
561 (cd $testroot/repo && git add epsilon/new)
562 git_commit $testroot/repo -m "committing changes"
563 local old_commit1=`git_show_head $testroot/repo`
565 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
566 git_commit $testroot/repo -m "committing to zeta on master"
567 local old_commit2=`git_show_head $testroot/repo`
569 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
570 ret="$?"
571 if [ "$ret" != "0" ]; then
572 test_done "$testroot" "$ret"
573 return 1
574 fi
576 echo "pick $old_commit1" > $testroot/histedit-script
577 echo "fold $old_commit2" >> $testroot/histedit-script
578 echo "mesg committing folded changes" >> $testroot/histedit-script
580 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
581 > $testroot/stdout 2> $testroot/stderr)
583 ret="$?"
584 if [ "$ret" == "0" ]; then
585 echo "histedit succeeded unexpectedly" >&2
586 test_done "$testroot" "1"
587 return 1
588 fi
590 echo "got: last commit in histedit script cannot be folded" \
591 > $testroot/stderr.expected
593 cmp -s $testroot/stderr.expected $testroot/stderr
594 ret="$?"
595 if [ "$ret" != "0" ]; then
596 diff -u $testroot/stderr.expected $testroot/stderr
597 fi
598 test_done "$testroot" "$ret"
601 function test_histedit_missing_commit {
602 local testroot=`test_init histedit_missing_commit`
604 local orig_commit=`git_show_head $testroot/repo`
606 echo "modified alpha on master" > $testroot/repo/alpha
607 (cd $testroot/repo && git rm -q beta)
608 echo "new file on master" > $testroot/repo/epsilon/new
609 (cd $testroot/repo && git add epsilon/new)
610 git_commit $testroot/repo -m "committing changes"
611 local old_commit1=`git_show_head $testroot/repo`
613 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
614 git_commit $testroot/repo -m "committing to zeta on master"
615 local old_commit2=`git_show_head $testroot/repo`
617 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
618 ret="$?"
619 if [ "$ret" != "0" ]; then
620 test_done "$testroot" "$ret"
621 return 1
622 fi
624 echo "pick $old_commit1" > $testroot/histedit-script
625 echo "mesg committing changes" >> $testroot/histedit-script
627 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
628 > $testroot/stdout 2> $testroot/stderr)
630 ret="$?"
631 if [ "$ret" == "0" ]; then
632 echo "histedit succeeded unexpectedly" >&2
633 test_done "$testroot" "1"
634 return 1
635 fi
637 echo "got: commit $old_commit2 missing from histedit script" \
638 > $testroot/stderr.expected
640 cmp -s $testroot/stderr.expected $testroot/stderr
641 ret="$?"
642 if [ "$ret" != "0" ]; then
643 diff -u $testroot/stderr.expected $testroot/stderr
644 fi
645 test_done "$testroot" "$ret"
648 function test_histedit_abort {
649 local testroot=`test_init histedit_abort`
651 local orig_commit=`git_show_head $testroot/repo`
653 echo "modified alpha on master" > $testroot/repo/alpha
654 (cd $testroot/repo && git rm -q beta)
655 echo "new file on master" > $testroot/repo/epsilon/new
656 (cd $testroot/repo && git add epsilon/new)
657 git_commit $testroot/repo -m "committing changes"
658 local old_commit1=`git_show_head $testroot/repo`
660 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
661 git_commit $testroot/repo -m "committing to zeta on master"
662 local old_commit2=`git_show_head $testroot/repo`
664 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
665 ret="$?"
666 if [ "$ret" != "0" ]; then
667 test_done "$testroot" "$ret"
668 return 1
669 fi
671 echo "edit $old_commit1" > $testroot/histedit-script
672 echo "mesg committing changes" >> $testroot/histedit-script
673 echo "pick $old_commit2" >> $testroot/histedit-script
675 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
676 > $testroot/stdout)
678 local short_old_commit1=`trim_obj_id 28 $old_commit1`
679 local short_old_commit2=`trim_obj_id 28 $old_commit2`
681 echo "G alpha" > $testroot/stdout.expected
682 echo "D beta" >> $testroot/stdout.expected
683 echo "A epsilon/new" >> $testroot/stdout.expected
684 echo "Stopping histedit for amending commit $old_commit1" \
685 >> $testroot/stdout.expected
686 cmp -s $testroot/stdout.expected $testroot/stdout
687 ret="$?"
688 if [ "$ret" != "0" ]; then
689 diff -u $testroot/stdout.expected $testroot/stdout
690 test_done "$testroot" "$ret"
691 return 1
692 fi
694 echo "edited modified alpha on master" > $testroot/wt/alpha
696 (cd $testroot/wt && got histedit -a > $testroot/stdout)
698 local new_commit1=`git_show_parent_commit $testroot/repo`
699 local new_commit2=`git_show_head $testroot/repo`
701 local short_new_commit1=`trim_obj_id 28 $new_commit1`
702 local short_new_commit2=`trim_obj_id 28 $new_commit2`
704 echo "Switching work tree to refs/heads/master" \
705 > $testroot/stdout.expected
706 echo "R alpha" >> $testroot/stdout.expected
707 echo "R beta" >> $testroot/stdout.expected
708 echo "R epsilon/new" >> $testroot/stdout.expected
709 echo "Histedit of refs/heads/master aborted" \
710 >> $testroot/stdout.expected
712 cmp -s $testroot/stdout.expected $testroot/stdout
713 ret="$?"
714 if [ "$ret" != "0" ]; then
715 diff -u $testroot/stdout.expected $testroot/stdout
716 test_done "$testroot" "$ret"
717 return 1
718 fi
720 for f in alpha beta; do
721 echo "$f" > $testroot/content.expected
722 cat $testroot/wt/$f > $testroot/content
723 cmp -s $testroot/content.expected $testroot/content
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 diff -u $testroot/content.expected $testroot/content
727 test_done "$testroot" "$ret"
728 return 1
729 fi
730 done
732 echo "new file on master" > $testroot/content.expected
733 cat $testroot/wt/epsilon/new > $testroot/content
734 cmp -s $testroot/content.expected $testroot/content
735 ret="$?"
736 if [ "$ret" != "0" ]; then
737 diff -u $testroot/content.expected $testroot/content
738 test_done "$testroot" "$ret"
739 return 1
740 fi
742 (cd $testroot/wt && got status > $testroot/stdout)
744 echo "? epsilon/new" > $testroot/stdout.expected
745 cmp -s $testroot/stdout.expected $testroot/stdout
746 ret="$?"
747 if [ "$ret" != "0" ]; then
748 diff -u $testroot/stdout.expected $testroot/stdout
749 test_done "$testroot" "$ret"
750 return 1
751 fi
753 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
754 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
755 echo "commit $new_commit1" >> $testroot/stdout.expected
756 echo "commit $orig_commit" >> $testroot/stdout.expected
757 cmp -s $testroot/stdout.expected $testroot/stdout
758 ret="$?"
759 if [ "$ret" != "0" ]; then
760 diff -u $testroot/stdout.expected $testroot/stdout
761 fi
762 test_done "$testroot" "$ret"
765 run_test test_histedit_no_op
766 run_test test_histedit_swap
767 run_test test_histedit_drop
768 run_test test_histedit_fold
769 run_test test_histedit_edit
770 run_test test_histedit_fold_last_commit
771 run_test test_histedit_missing_commit
772 run_test test_histedit_abort