3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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.
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 diff -r $testroot/repo $orig_commit $old_commit2 \
36 > $testroot/diff.expected
38 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
40 if [ "$ret" != "0" ]; then
41 test_done "$testroot" "$ret"
45 echo "pick $old_commit1" > $testroot/histedit-script
46 echo "pick $old_commit2" >> $testroot/histedit-script
48 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
51 local new_commit1=`git_show_parent_commit $testroot/repo`
52 local new_commit2=`git_show_head $testroot/repo`
54 local short_old_commit1=`trim_obj_id 28 $old_commit1`
55 local short_old_commit2=`trim_obj_id 28 $old_commit2`
56 local short_new_commit1=`trim_obj_id 28 $new_commit1`
57 local short_new_commit2=`trim_obj_id 28 $new_commit2`
59 echo "G alpha" > $testroot/stdout.expected
60 echo "D beta" >> $testroot/stdout.expected
61 echo "A epsilon/new" >> $testroot/stdout.expected
62 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
63 >> $testroot/stdout.expected
64 echo "G epsilon/zeta" >> $testroot/stdout.expected
65 echo -n "$short_old_commit2 -> $short_new_commit2: " \
66 >> $testroot/stdout.expected
67 echo "committing to zeta on master" >> $testroot/stdout.expected
68 echo "Switching work tree to refs/heads/master" \
69 >> $testroot/stdout.expected
71 cmp -s $testroot/stdout.expected $testroot/stdout
73 if [ "$ret" != "0" ]; then
74 diff -u $testroot/stdout.expected $testroot/stdout
75 test_done "$testroot" "$ret"
79 echo "modified alpha on master" > $testroot/content.expected
80 cat $testroot/wt/alpha > $testroot/content
81 cmp -s $testroot/content.expected $testroot/content
83 if [ "$ret" != "0" ]; then
84 diff -u $testroot/content.expected $testroot/content
85 test_done "$testroot" "$ret"
89 if [ -e $testroot/wt/beta ]; then
90 echo "removed file beta still exists on disk" >&2
91 test_done "$testroot" "1"
95 echo "new file on master" > $testroot/content.expected
96 cat $testroot/wt/epsilon/new > $testroot/content
97 cmp -s $testroot/content.expected $testroot/content
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/content.expected $testroot/content
101 test_done "$testroot" "$ret"
105 (cd $testroot/wt && got status > $testroot/stdout)
107 echo -n > $testroot/stdout.expected
108 cmp -s $testroot/stdout.expected $testroot/stdout
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/stdout.expected $testroot/stdout
112 test_done "$testroot" "$ret"
116 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
117 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
118 echo "commit $new_commit1" >> $testroot/stdout.expected
119 echo "commit $orig_commit" >> $testroot/stdout.expected
120 cmp -s $testroot/stdout.expected $testroot/stdout
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/stdout.expected $testroot/stdout
124 test_done "$testroot" "$ret"
128 got diff -r $testroot/repo $orig_commit $new_commit2 \
130 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
131 cmp -s $testroot/diff.expected $testroot/diff
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/diff.expected $testroot/diff
136 test_done "$testroot" "$ret"
139 function test_histedit_swap {
140 local testroot=`test_init histedit_swap`
142 local orig_commit=`git_show_head $testroot/repo`
144 echo "modified alpha on master" > $testroot/repo/alpha
145 (cd $testroot/repo && git rm -q beta)
146 echo "new file on master" > $testroot/repo/epsilon/new
147 (cd $testroot/repo && git add epsilon/new)
148 git_commit $testroot/repo -m "committing changes"
149 local old_commit1=`git_show_head $testroot/repo`
151 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
152 git_commit $testroot/repo -m "committing to zeta on master"
153 local old_commit2=`git_show_head $testroot/repo`
155 got diff -r $testroot/repo $orig_commit $old_commit2 \
156 > $testroot/diff.expected
158 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
160 if [ "$ret" != "0" ]; then
161 test_done "$testroot" "$ret"
165 echo "pick $old_commit2" > $testroot/histedit-script
166 echo "pick $old_commit1" >> $testroot/histedit-script
168 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
171 local new_commit2=`git_show_parent_commit $testroot/repo`
172 local new_commit1=`git_show_head $testroot/repo`
174 local short_old_commit1=`trim_obj_id 28 $old_commit1`
175 local short_old_commit2=`trim_obj_id 28 $old_commit2`
176 local short_new_commit1=`trim_obj_id 28 $new_commit1`
177 local short_new_commit2=`trim_obj_id 28 $new_commit2`
179 echo "G epsilon/zeta" > $testroot/stdout.expected
180 echo -n "$short_old_commit2 -> $short_new_commit2: " \
181 >> $testroot/stdout.expected
182 echo "committing to zeta on master" >> $testroot/stdout.expected
183 echo "G alpha" >> $testroot/stdout.expected
184 echo "D beta" >> $testroot/stdout.expected
185 echo "A epsilon/new" >> $testroot/stdout.expected
186 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
187 >> $testroot/stdout.expected
188 echo "Switching work tree to refs/heads/master" \
189 >> $testroot/stdout.expected
191 cmp -s $testroot/stdout.expected $testroot/stdout
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stdout.expected $testroot/stdout
195 test_done "$testroot" "$ret"
199 echo "modified alpha on master" > $testroot/content.expected
200 cat $testroot/wt/alpha > $testroot/content
201 cmp -s $testroot/content.expected $testroot/content
203 if [ "$ret" != "0" ]; then
204 diff -u $testroot/content.expected $testroot/content
205 test_done "$testroot" "$ret"
209 if [ -e $testroot/wt/beta ]; then
210 echo "removed file beta still exists on disk" >&2
211 test_done "$testroot" "1"
215 echo "new file on master" > $testroot/content.expected
216 cat $testroot/wt/epsilon/new > $testroot/content
217 cmp -s $testroot/content.expected $testroot/content
219 if [ "$ret" != "0" ]; then
220 diff -u $testroot/content.expected $testroot/content
221 test_done "$testroot" "$ret"
225 (cd $testroot/wt && got status > $testroot/stdout)
227 echo -n > $testroot/stdout.expected
228 cmp -s $testroot/stdout.expected $testroot/stdout
230 if [ "$ret" != "0" ]; then
231 diff -u $testroot/stdout.expected $testroot/stdout
232 test_done "$testroot" "$ret"
236 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
237 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
238 echo "commit $new_commit2" >> $testroot/stdout.expected
239 echo "commit $orig_commit" >> $testroot/stdout.expected
240 cmp -s $testroot/stdout.expected $testroot/stdout
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stdout.expected $testroot/stdout
244 test_done "$testroot" "$ret"
248 got diff -r $testroot/repo $orig_commit $new_commit1 \
250 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
251 cmp -s $testroot/diff.expected $testroot/diff
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/diff.expected $testroot/diff
256 test_done "$testroot" "$ret"
259 function test_histedit_drop {
260 local testroot=`test_init histedit_drop`
261 local orig_commit=`git_show_head $testroot/repo`
263 echo "modified alpha on master" > $testroot/repo/alpha
264 (cd $testroot/repo && git rm -q beta)
265 echo "new file on master" > $testroot/repo/epsilon/new
266 (cd $testroot/repo && git add epsilon/new)
267 git_commit $testroot/repo -m "committing changes"
268 local old_commit1=`git_show_head $testroot/repo`
270 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
271 git_commit $testroot/repo -m "committing to zeta on master"
272 local old_commit2=`git_show_head $testroot/repo`
274 got diff -r $testroot/repo $old_commit1 $old_commit2 \
275 > $testroot/diff.expected
277 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
279 if [ "$ret" != "0" ]; then
280 test_done "$testroot" "$ret"
284 echo "drop $old_commit1" > $testroot/histedit-script
285 echo "pick $old_commit2" >> $testroot/histedit-script
287 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
290 local new_commit2=`git_show_head $testroot/repo`
292 local short_old_commit1=`trim_obj_id 28 $old_commit1`
293 local short_old_commit2=`trim_obj_id 28 $old_commit2`
294 local short_new_commit2=`trim_obj_id 28 $new_commit2`
296 echo "$short_old_commit1 -> drop commit: committing changes" \
297 > $testroot/stdout.expected
298 echo "G epsilon/zeta" >> $testroot/stdout.expected
299 echo -n "$short_old_commit2 -> $short_new_commit2: " \
300 >> $testroot/stdout.expected
301 echo "committing to zeta on master" >> $testroot/stdout.expected
302 echo "Switching work tree to refs/heads/master" \
303 >> $testroot/stdout.expected
305 cmp -s $testroot/stdout.expected $testroot/stdout
307 if [ "$ret" != "0" ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
313 for f in alpha beta; do
314 echo "$f" > $testroot/content.expected
315 cat $testroot/wt/$f > $testroot/content
316 cmp -s $testroot/content.expected $testroot/content
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/content.expected $testroot/content
320 test_done "$testroot" "$ret"
325 if [ -e $testroot/wt/new ]; then
326 echo "file new exists on disk but should not" >&2
327 test_done "$testroot" "1"
331 (cd $testroot/wt && got status > $testroot/stdout)
333 echo -n > $testroot/stdout.expected
334 cmp -s $testroot/stdout.expected $testroot/stdout
336 if [ "$ret" != "0" ]; then
337 diff -u $testroot/stdout.expected $testroot/stdout
338 test_done "$testroot" "$ret"
342 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
343 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
344 echo "commit $orig_commit" >> $testroot/stdout.expected
345 cmp -s $testroot/stdout.expected $testroot/stdout
347 if [ "$ret" != "0" ]; then
348 diff -u $testroot/stdout.expected $testroot/stdout
349 test_done "$testroot" "$ret"
353 got diff -r $testroot/repo $orig_commit $new_commit2 \
355 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
356 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
357 cmp -s $testroot/diff.expected $testroot/diff
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/diff.expected $testroot/diff
362 test_done "$testroot" "$ret"
365 function test_histedit_fold {
366 local testroot=`test_init histedit_fold`
368 local orig_commit=`git_show_head $testroot/repo`
370 echo "modified alpha on master" > $testroot/repo/alpha
371 (cd $testroot/repo && git rm -q beta)
372 echo "new file on master" > $testroot/repo/epsilon/new
373 (cd $testroot/repo && git add epsilon/new)
374 git_commit $testroot/repo -m "committing changes"
375 local old_commit1=`git_show_head $testroot/repo`
377 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
378 git_commit $testroot/repo -m "committing to zeta on master"
379 local old_commit2=`git_show_head $testroot/repo`
381 echo "modified delta on master" > $testroot/repo/gamma/delta
382 git_commit $testroot/repo -m "committing to delta on master"
383 local old_commit3=`git_show_head $testroot/repo`
385 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
387 if [ "$ret" != "0" ]; then
388 test_done "$testroot" "$ret"
392 echo "fold $old_commit1" > $testroot/histedit-script
393 echo "drop $old_commit2" >> $testroot/histedit-script
394 echo "pick $old_commit3" >> $testroot/histedit-script
395 echo "mesg committing folded changes" >> $testroot/histedit-script
397 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
400 local new_commit1=`git_show_parent_commit $testroot/repo`
401 local new_commit2=`git_show_head $testroot/repo`
403 local short_old_commit1=`trim_obj_id 28 $old_commit1`
404 local short_old_commit2=`trim_obj_id 28 $old_commit2`
405 local short_old_commit3=`trim_obj_id 28 $old_commit3`
406 local short_new_commit1=`trim_obj_id 28 $new_commit1`
407 local short_new_commit2=`trim_obj_id 28 $new_commit2`
409 echo "G alpha" > $testroot/stdout.expected
410 echo "D beta" >> $testroot/stdout.expected
411 echo "A epsilon/new" >> $testroot/stdout.expected
412 echo "$short_old_commit1 -> fold commit: committing changes" \
413 >> $testroot/stdout.expected
414 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
415 echo "drop commit: committing to zeta on master" \
416 >> $testroot/stdout.expected
417 echo "G gamma/delta" >> $testroot/stdout.expected
418 echo -n "$short_old_commit3 -> $short_new_commit2: " \
419 >> $testroot/stdout.expected
420 echo "committing folded changes" >> $testroot/stdout.expected
421 echo "Switching work tree to refs/heads/master" \
422 >> $testroot/stdout.expected
424 cmp -s $testroot/stdout.expected $testroot/stdout
426 if [ "$ret" != "0" ]; then
427 diff -u $testroot/stdout.expected $testroot/stdout
428 test_done "$testroot" "$ret"
432 echo "modified alpha on master" > $testroot/content.expected
433 cat $testroot/wt/alpha > $testroot/content
434 cmp -s $testroot/content.expected $testroot/content
436 if [ "$ret" != "0" ]; then
437 diff -u $testroot/content.expected $testroot/content
438 test_done "$testroot" "$ret"
442 if [ -e $testroot/wt/beta ]; then
443 echo "removed file beta still exists on disk" >&2
444 test_done "$testroot" "1"
448 echo "new file on master" > $testroot/content.expected
449 cat $testroot/wt/epsilon/new > $testroot/content
450 cmp -s $testroot/content.expected $testroot/content
452 if [ "$ret" != "0" ]; then
453 diff -u $testroot/content.expected $testroot/content
454 test_done "$testroot" "$ret"
458 (cd $testroot/wt && got status > $testroot/stdout)
460 echo -n > $testroot/stdout.expected
461 cmp -s $testroot/stdout.expected $testroot/stdout
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/stdout.expected $testroot/stdout
465 test_done "$testroot" "$ret"
469 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
470 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
471 echo "commit $orig_commit" >> $testroot/stdout.expected
472 cmp -s $testroot/stdout.expected $testroot/stdout
474 if [ "$ret" != "0" ]; then
475 diff -u $testroot/stdout.expected $testroot/stdout
477 test_done "$testroot" "$ret"
480 function test_histedit_edit {
481 local testroot=`test_init histedit_edit`
483 local orig_commit=`git_show_head $testroot/repo`
485 echo "modified alpha on master" > $testroot/repo/alpha
486 (cd $testroot/repo && git rm -q beta)
487 echo "new file on master" > $testroot/repo/epsilon/new
488 (cd $testroot/repo && git add epsilon/new)
489 git_commit $testroot/repo -m "committing changes"
490 local old_commit1=`git_show_head $testroot/repo`
492 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
493 git_commit $testroot/repo -m "committing to zeta on master"
494 local old_commit2=`git_show_head $testroot/repo`
496 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
498 if [ "$ret" != "0" ]; then
499 test_done "$testroot" "$ret"
503 echo "edit $old_commit1" > $testroot/histedit-script
504 echo "mesg committing changes" >> $testroot/histedit-script
505 echo "pick $old_commit2" >> $testroot/histedit-script
507 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
510 local short_old_commit1=`trim_obj_id 28 $old_commit1`
511 local short_old_commit2=`trim_obj_id 28 $old_commit2`
513 echo "G alpha" > $testroot/stdout.expected
514 echo "D beta" >> $testroot/stdout.expected
515 echo "A epsilon/new" >> $testroot/stdout.expected
516 echo "Stopping histedit for amending commit $old_commit1" \
517 >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected $testroot/stdout
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
526 echo "edited modified alpha on master" > $testroot/wt/alpha
528 (cd $testroot/wt && got histedit -c > $testroot/stdout)
530 local new_commit1=`git_show_parent_commit $testroot/repo`
531 local new_commit2=`git_show_head $testroot/repo`
533 local short_new_commit1=`trim_obj_id 28 $new_commit1`
534 local short_new_commit2=`trim_obj_id 28 $new_commit2`
536 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
537 > $testroot/stdout.expected
538 echo "G epsilon/zeta" >> $testroot/stdout.expected
539 echo -n "$short_old_commit2 -> $short_new_commit2: " \
540 >> $testroot/stdout.expected
541 echo "committing to zeta on master" >> $testroot/stdout.expected
542 echo "Switching work tree to refs/heads/master" \
543 >> $testroot/stdout.expected
545 cmp -s $testroot/stdout.expected $testroot/stdout
547 if [ "$ret" != "0" ]; then
548 diff -u $testroot/stdout.expected $testroot/stdout
549 test_done "$testroot" "$ret"
553 echo "edited modified alpha on master" > $testroot/content.expected
554 cat $testroot/wt/alpha > $testroot/content
555 cmp -s $testroot/content.expected $testroot/content
557 if [ "$ret" != "0" ]; then
558 diff -u $testroot/content.expected $testroot/content
559 test_done "$testroot" "$ret"
563 if [ -e $testroot/wt/beta ]; then
564 echo "removed file beta still exists on disk" >&2
565 test_done "$testroot" "1"
569 echo "new file on master" > $testroot/content.expected
570 cat $testroot/wt/epsilon/new > $testroot/content
571 cmp -s $testroot/content.expected $testroot/content
573 if [ "$ret" != "0" ]; then
574 diff -u $testroot/content.expected $testroot/content
575 test_done "$testroot" "$ret"
579 (cd $testroot/wt && got status > $testroot/stdout)
581 echo -n > $testroot/stdout.expected
582 cmp -s $testroot/stdout.expected $testroot/stdout
584 if [ "$ret" != "0" ]; then
585 diff -u $testroot/stdout.expected $testroot/stdout
586 test_done "$testroot" "$ret"
590 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
591 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
592 echo "commit $new_commit1" >> $testroot/stdout.expected
593 echo "commit $orig_commit" >> $testroot/stdout.expected
594 cmp -s $testroot/stdout.expected $testroot/stdout
596 if [ "$ret" != "0" ]; then
597 diff -u $testroot/stdout.expected $testroot/stdout
599 test_done "$testroot" "$ret"
602 function test_histedit_fold_last_commit {
603 local testroot=`test_init histedit_fold_last_commit`
605 local orig_commit=`git_show_head $testroot/repo`
607 echo "modified alpha on master" > $testroot/repo/alpha
608 (cd $testroot/repo && git rm -q beta)
609 echo "new file on master" > $testroot/repo/epsilon/new
610 (cd $testroot/repo && git add epsilon/new)
611 git_commit $testroot/repo -m "committing changes"
612 local old_commit1=`git_show_head $testroot/repo`
614 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
615 git_commit $testroot/repo -m "committing to zeta on master"
616 local old_commit2=`git_show_head $testroot/repo`
618 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
620 if [ "$ret" != "0" ]; then
621 test_done "$testroot" "$ret"
625 echo "pick $old_commit1" > $testroot/histedit-script
626 echo "fold $old_commit2" >> $testroot/histedit-script
627 echo "mesg committing folded changes" >> $testroot/histedit-script
629 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
630 > $testroot/stdout 2> $testroot/stderr)
633 if [ "$ret" == "0" ]; then
634 echo "histedit succeeded unexpectedly" >&2
635 test_done "$testroot" "1"
639 echo "got: last commit in histedit script cannot be folded" \
640 > $testroot/stderr.expected
642 cmp -s $testroot/stderr.expected $testroot/stderr
644 if [ "$ret" != "0" ]; then
645 diff -u $testroot/stderr.expected $testroot/stderr
647 test_done "$testroot" "$ret"
650 function test_histedit_missing_commit {
651 local testroot=`test_init histedit_missing_commit`
653 local orig_commit=`git_show_head $testroot/repo`
655 echo "modified alpha on master" > $testroot/repo/alpha
656 (cd $testroot/repo && git rm -q beta)
657 echo "new file on master" > $testroot/repo/epsilon/new
658 (cd $testroot/repo && git add epsilon/new)
659 git_commit $testroot/repo -m "committing changes"
660 local old_commit1=`git_show_head $testroot/repo`
662 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
663 git_commit $testroot/repo -m "committing to zeta on master"
664 local old_commit2=`git_show_head $testroot/repo`
666 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
668 if [ "$ret" != "0" ]; then
669 test_done "$testroot" "$ret"
673 echo "pick $old_commit1" > $testroot/histedit-script
674 echo "mesg committing changes" >> $testroot/histedit-script
676 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
677 > $testroot/stdout 2> $testroot/stderr)
680 if [ "$ret" == "0" ]; then
681 echo "histedit succeeded unexpectedly" >&2
682 test_done "$testroot" "1"
686 echo "got: commit $old_commit2 missing from histedit script" \
687 > $testroot/stderr.expected
689 cmp -s $testroot/stderr.expected $testroot/stderr
691 if [ "$ret" != "0" ]; then
692 diff -u $testroot/stderr.expected $testroot/stderr
694 test_done "$testroot" "$ret"
697 function test_histedit_abort {
698 local testroot=`test_init histedit_abort`
700 local orig_commit=`git_show_head $testroot/repo`
702 echo "modified alpha on master" > $testroot/repo/alpha
703 (cd $testroot/repo && git rm -q beta)
704 echo "new file on master" > $testroot/repo/epsilon/new
705 (cd $testroot/repo && git add epsilon/new)
706 git_commit $testroot/repo -m "committing changes"
707 local old_commit1=`git_show_head $testroot/repo`
709 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
710 git_commit $testroot/repo -m "committing to zeta on master"
711 local old_commit2=`git_show_head $testroot/repo`
713 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
715 if [ "$ret" != "0" ]; then
716 test_done "$testroot" "$ret"
720 echo "edit $old_commit1" > $testroot/histedit-script
721 echo "mesg committing changes" >> $testroot/histedit-script
722 echo "pick $old_commit2" >> $testroot/histedit-script
724 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
727 local short_old_commit1=`trim_obj_id 28 $old_commit1`
728 local short_old_commit2=`trim_obj_id 28 $old_commit2`
730 echo "G alpha" > $testroot/stdout.expected
731 echo "D beta" >> $testroot/stdout.expected
732 echo "A epsilon/new" >> $testroot/stdout.expected
733 echo "Stopping histedit for amending commit $old_commit1" \
734 >> $testroot/stdout.expected
735 cmp -s $testroot/stdout.expected $testroot/stdout
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stdout.expected $testroot/stdout
739 test_done "$testroot" "$ret"
743 echo "edited modified alpha on master" > $testroot/wt/alpha
745 (cd $testroot/wt && got histedit -a > $testroot/stdout)
747 local new_commit1=`git_show_parent_commit $testroot/repo`
748 local new_commit2=`git_show_head $testroot/repo`
750 echo "Switching work tree to refs/heads/master" \
751 > $testroot/stdout.expected
752 echo "R alpha" >> $testroot/stdout.expected
753 echo "R beta" >> $testroot/stdout.expected
754 echo "R epsilon/new" >> $testroot/stdout.expected
755 echo "Histedit of refs/heads/master aborted" \
756 >> $testroot/stdout.expected
758 cmp -s $testroot/stdout.expected $testroot/stdout
760 if [ "$ret" != "0" ]; then
761 diff -u $testroot/stdout.expected $testroot/stdout
762 test_done "$testroot" "$ret"
766 for f in alpha beta; do
767 echo "$f" > $testroot/content.expected
768 cat $testroot/wt/$f > $testroot/content
769 cmp -s $testroot/content.expected $testroot/content
771 if [ "$ret" != "0" ]; then
772 diff -u $testroot/content.expected $testroot/content
773 test_done "$testroot" "$ret"
778 echo "new file on master" > $testroot/content.expected
779 cat $testroot/wt/epsilon/new > $testroot/content
780 cmp -s $testroot/content.expected $testroot/content
782 if [ "$ret" != "0" ]; then
783 diff -u $testroot/content.expected $testroot/content
784 test_done "$testroot" "$ret"
788 (cd $testroot/wt && got status > $testroot/stdout)
790 echo "? epsilon/new" > $testroot/stdout.expected
791 cmp -s $testroot/stdout.expected $testroot/stdout
793 if [ "$ret" != "0" ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
795 test_done "$testroot" "$ret"
799 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
800 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
801 echo "commit $new_commit1" >> $testroot/stdout.expected
802 echo "commit $orig_commit" >> $testroot/stdout.expected
803 cmp -s $testroot/stdout.expected $testroot/stdout
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/stdout.expected $testroot/stdout
808 test_done "$testroot" "$ret"
811 function test_histedit_path_prefix_drop {
812 local testroot=`test_init histedit_path_prefix_drop`
813 local orig_commit=`git_show_head $testroot/repo`
815 echo "modified zeta" > $testroot/repo/epsilon/zeta
816 git_commit $testroot/repo -m "changing zeta"
817 local old_commit1=`git_show_head $testroot/repo`
819 got checkout -c $orig_commit -p gamma $testroot/repo \
820 $testroot/wt > /dev/null
822 if [ "$ret" != "0" ]; then
823 test_done "$testroot" "$ret"
827 echo "drop $old_commit1" > $testroot/histedit-script
829 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
830 > $testroot/stdout 2> $testroot/stderr)
833 if [ "$ret" == "0" ]; then
834 echo "histedit succeeded unexpectedly" >&2
835 test_done "$testroot" "1"
839 echo -n "got: cannot edit branch history which contains changes " \
840 > $testroot/stderr.expected
841 echo "outside of this work tree's path prefix" \
842 >> $testroot/stderr.expected
844 cmp -s $testroot/stderr.expected $testroot/stderr
846 if [ "$ret" != "0" ]; then
847 diff -u $testroot/stderr.expected $testroot/stderr
848 test_done "$testroot" "$ret"
853 got checkout -c $orig_commit -p epsilon $testroot/repo \
854 $testroot/wt > /dev/null
856 if [ "$ret" != "0" ]; then
857 test_done "$testroot" "$ret"
860 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
863 local short_old_commit1=`trim_obj_id 28 $old_commit1`
864 local short_old_commit2=`trim_obj_id 28 $old_commit2`
866 echo "$short_old_commit1 -> drop commit: changing zeta" \
867 > $testroot/stdout.expected
868 echo "Switching work tree to refs/heads/master" \
869 >> $testroot/stdout.expected
871 cmp -s $testroot/stdout.expected $testroot/stdout
873 if [ "$ret" != "0" ]; then
874 diff -u $testroot/stdout.expected $testroot/stdout
875 test_done "$testroot" "$ret"
879 echo "zeta" > $testroot/content.expected
880 cat $testroot/wt/zeta > $testroot/content
881 cmp -s $testroot/content.expected $testroot/content
883 if [ "$ret" != "0" ]; then
884 diff -u $testroot/content.expected $testroot/content
885 test_done "$testroot" "$ret"
890 (cd $testroot/wt && got status > $testroot/stdout)
892 echo -n > $testroot/stdout.expected
893 cmp -s $testroot/stdout.expected $testroot/stdout
895 if [ "$ret" != "0" ]; then
896 diff -u $testroot/stdout.expected $testroot/stdout
897 test_done "$testroot" "$ret"
901 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
902 echo "commit $orig_commit (master)" > $testroot/stdout.expected
903 cmp -s $testroot/stdout.expected $testroot/stdout
905 if [ "$ret" != "0" ]; then
906 diff -u $testroot/stdout.expected $testroot/stdout
908 test_done "$testroot" "$ret"
911 function test_histedit_path_prefix_edit {
912 local testroot=`test_init histedit_path_prefix_edit`
913 local orig_commit=`git_show_head $testroot/repo`
915 echo "modified zeta" > $testroot/repo/epsilon/zeta
916 git_commit $testroot/repo -m "changing zeta"
917 local old_commit1=`git_show_head $testroot/repo`
919 got diff -r $testroot/repo $orig_commit $old_commit1 \
920 > $testroot/diff.expected
922 got checkout -c $orig_commit -p gamma $testroot/repo \
923 $testroot/wt > /dev/null
925 if [ "$ret" != "0" ]; then
926 test_done "$testroot" "$ret"
930 echo "edit $old_commit1" > $testroot/histedit-script
931 echo "mesg modified zeta" >> $testroot/histedit-script
933 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
934 > $testroot/stdout 2> $testroot/stderr)
937 if [ "$ret" == "0" ]; then
938 echo "histedit succeeded unexpectedly" >&2
939 test_done "$testroot" "1"
943 echo -n "got: cannot edit branch history which contains changes " \
944 > $testroot/stderr.expected
945 echo "outside of this work tree's path prefix" \
946 >> $testroot/stderr.expected
948 cmp -s $testroot/stderr.expected $testroot/stderr
950 if [ "$ret" != "0" ]; then
951 diff -u $testroot/stderr.expected $testroot/stderr
952 test_done "$testroot" "$ret"
957 got checkout -c $orig_commit -p epsilon $testroot/repo \
958 $testroot/wt > /dev/null
960 if [ "$ret" != "0" ]; then
961 test_done "$testroot" "$ret"
964 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
967 local short_old_commit1=`trim_obj_id 28 $old_commit1`
969 echo "G zeta" > $testroot/stdout.expected
970 echo "Stopping histedit for amending commit $old_commit1" \
971 >> $testroot/stdout.expected
972 cmp -s $testroot/stdout.expected $testroot/stdout
974 if [ "$ret" != "0" ]; then
975 diff -u $testroot/stdout.expected $testroot/stdout
976 test_done "$testroot" "$ret"
980 echo "modified zeta" > $testroot/content.expected
981 cat $testroot/wt/zeta > $testroot/content
982 cmp -s $testroot/content.expected $testroot/content
984 if [ "$ret" != "0" ]; then
985 diff -u $testroot/content.expected $testroot/content
986 test_done "$testroot" "$ret"
990 (cd $testroot/wt && got status > $testroot/stdout)
992 echo "M zeta"> $testroot/stdout.expected
993 cmp -s $testroot/stdout.expected $testroot/stdout
995 if [ "$ret" != "0" ]; then
996 diff -u $testroot/stdout.expected $testroot/stdout
997 test_done "$testroot" "$ret"
1001 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1003 local new_commit1=`git_show_head $testroot/repo`
1004 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1006 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1007 > $testroot/stdout.expected
1008 echo "modified zeta" >> $testroot/stdout.expected
1009 echo "Switching work tree to refs/heads/master" \
1010 >> $testroot/stdout.expected
1012 cmp -s $testroot/stdout.expected $testroot/stdout
1014 if [ "$ret" != "0" ]; then
1015 diff -u $testroot/stdout.expected $testroot/stdout
1016 test_done "$testroot" "$ret"
1020 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1021 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1022 echo "commit $orig_commit" >> $testroot/stdout.expected
1023 cmp -s $testroot/stdout.expected $testroot/stdout
1025 if [ "$ret" != "0" ]; then
1026 diff -u $testroot/stdout.expected $testroot/stdout
1027 test_done "$testroot" "$ret"
1031 got diff -r $testroot/repo $orig_commit $new_commit1 \
1033 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1034 cmp -s $testroot/diff.expected $testroot/diff
1036 if [ "$ret" != "0" ]; then
1037 diff -u $testroot/diff.expected $testroot/diff
1039 test_done "$testroot" "$ret"
1042 run_test test_histedit_no_op
1043 run_test test_histedit_swap
1044 run_test test_histedit_drop
1045 run_test test_histedit_fold
1046 run_test test_histedit_edit
1047 run_test test_histedit_fold_last_commit
1048 run_test test_histedit_missing_commit
1049 run_test test_histedit_abort
1050 run_test test_histedit_path_prefix_drop
1051 run_test test_histedit_path_prefix_edit