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 test_histedit_no_op() {
20 local testroot=`test_init histedit_no_op`
22 local orig_commit=`git_show_head $testroot/repo`
23 local orig_author_time=`git_show_author_time $testroot/repo`
25 echo "modified alpha on master" > $testroot/repo/alpha
26 (cd $testroot/repo && git rm -q beta)
27 echo "new file on master" > $testroot/repo/epsilon/new
28 (cd $testroot/repo && git add epsilon/new)
29 git_commit $testroot/repo -m "committing changes"
30 local old_commit1=`git_show_head $testroot/repo`
31 local old_author_time1=`git_show_author_time $testroot/repo`
33 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
34 git_commit $testroot/repo -m "committing to zeta on master"
35 local old_commit2=`git_show_head $testroot/repo`
36 local old_author_time2=`git_show_author_time $testroot/repo`
38 got diff -r $testroot/repo $orig_commit $old_commit2 \
39 > $testroot/diff.expected
41 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
43 if [ $ret -ne 0 ]; then
44 test_done "$testroot" "$ret"
48 echo "pick $old_commit1" > $testroot/histedit-script
49 echo "pick $old_commit2" >> $testroot/histedit-script
51 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
54 local new_commit1=`git_show_parent_commit $testroot/repo`
55 local new_commit2=`git_show_head $testroot/repo`
56 local new_author_time2=`git_show_author_time $testroot/repo`
58 local short_old_commit1=`trim_obj_id 28 $old_commit1`
59 local short_old_commit2=`trim_obj_id 28 $old_commit2`
60 local short_new_commit1=`trim_obj_id 28 $new_commit1`
61 local short_new_commit2=`trim_obj_id 28 $new_commit2`
63 echo "G alpha" > $testroot/stdout.expected
64 echo "D beta" >> $testroot/stdout.expected
65 echo "A epsilon/new" >> $testroot/stdout.expected
66 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
67 >> $testroot/stdout.expected
68 echo "G epsilon/zeta" >> $testroot/stdout.expected
69 echo -n "$short_old_commit2 -> $short_new_commit2: " \
70 >> $testroot/stdout.expected
71 echo "committing to zeta on master" >> $testroot/stdout.expected
72 echo "Switching work tree to refs/heads/master" \
73 >> $testroot/stdout.expected
75 cmp -s $testroot/stdout.expected $testroot/stdout
77 if [ $ret -ne 0 ]; then
78 diff -u $testroot/stdout.expected $testroot/stdout
79 test_done "$testroot" "$ret"
83 echo "modified alpha on master" > $testroot/content.expected
84 cat $testroot/wt/alpha > $testroot/content
85 cmp -s $testroot/content.expected $testroot/content
87 if [ $ret -ne 0 ]; then
88 diff -u $testroot/content.expected $testroot/content
89 test_done "$testroot" "$ret"
93 if [ -e $testroot/wt/beta ]; then
94 echo "removed file beta still exists on disk" >&2
95 test_done "$testroot" "1"
99 echo "new file on master" > $testroot/content.expected
100 cat $testroot/wt/epsilon/new > $testroot/content
101 cmp -s $testroot/content.expected $testroot/content
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/content.expected $testroot/content
105 test_done "$testroot" "$ret"
109 (cd $testroot/wt && got status > $testroot/stdout)
111 echo -n > $testroot/stdout.expected
112 cmp -s $testroot/stdout.expected $testroot/stdout
114 if [ $ret -ne 0 ]; then
115 diff -u $testroot/stdout.expected $testroot/stdout
116 test_done "$testroot" "$ret"
120 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
121 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
122 echo "commit $new_commit1" >> $testroot/stdout.expected
123 echo "commit $orig_commit" >> $testroot/stdout.expected
124 cmp -s $testroot/stdout.expected $testroot/stdout
126 if [ $ret -ne 0 ]; then
127 diff -u $testroot/stdout.expected $testroot/stdout
128 test_done "$testroot" "$ret"
132 got diff -r $testroot/repo $orig_commit $new_commit2 \
134 ed -s $testroot/diff.expected <<-EOF
135 ,s/$old_commit2/$new_commit2/
138 cmp -s $testroot/diff.expected $testroot/diff
140 if [ $ret -ne 0 ]; then
141 diff -u $testroot/diff.expected $testroot/diff
142 test_done "$testroot" "$ret"
146 (cd $testroot/wt && got update > $testroot/stdout)
148 echo 'Already up-to-date' > $testroot/stdout.expected
149 cmp -s $testroot/stdout.expected $testroot/stdout
151 if [ $ret -ne 0 ]; then
152 diff -u $testroot/stdout.expected $testroot/stdout
153 test_done "$testroot" "$ret"
157 # We should have a backup of old commits
158 (cd $testroot/repo && got histedit -l > $testroot/stdout)
159 d_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"`
160 d_orig2=`date -u -r $old_author_time2 +"%a %b %e %X %Y UTC"`
161 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
162 d_orig=`date -u -r $orig_author_time +"%G-%m-%d"`
163 cat > $testroot/stdout.expected <<EOF
164 -----------------------------------------------
165 commit $old_commit2 (formerly master)
169 committing to zeta on master
171 has become commit $new_commit2 (master)
172 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
175 local is_forked=true d_fork fork_commit fork_commit_msg
177 if [ "$old_commit1" = "$new_commit1" ]; then
178 if [ "$old_commit2" = "$new_commit2" ]; then
182 fork_commit=$new_commit1
183 fork_commit_msg="committing changes"
187 fork_commit=$orig_commit
188 fork_commit_msg="adding the test tree"
191 $is_forked && cat >> $testroot/stdout.expected <<EOF
192 history forked at $fork_commit
193 $d_fork $GOT_AUTHOR_11 $fork_commit_msg
196 cmp -s $testroot/stdout.expected $testroot/stdout
198 if [ $ret -ne 0 ]; then
199 diff -u $testroot/stdout.expected $testroot/stdout
200 test_done "$testroot" "$ret"
204 (cd $testroot/repo && got histedit -X master \
205 > $testroot/stdout 2> $testroot/stderr)
206 echo -n "Deleted refs/got/backup/histedit/master/$new_commit2: " \
207 > $testroot/stdout.expected
208 echo "$old_commit2" >> $testroot/stdout.expected
209 echo -n > $testroot/stderr.expected
210 cmp -s $testroot/stdout.expected $testroot/stdout
212 if [ $ret -ne 0 ]; then
213 diff -u $testroot/stdout.expected $testroot/stdout
214 test_done "$testroot" "$ret"
217 cmp -s $testroot/stderr.expected $testroot/stderr
219 if [ $ret -ne 0 ]; then
220 diff -u $testroot/stderr.expected $testroot/stderr
221 test_done "$testroot" "$ret"
225 (cd $testroot/repo && got histedit -l > $testroot/stdout)
226 echo -n > $testroot/stdout.expected
227 cmp -s $testroot/stdout.expected $testroot/stdout
229 if [ $ret -ne 0 ]; then
230 diff -u $testroot/stdout.expected $testroot/stdout
232 test_done "$testroot" "$ret"
235 test_histedit_swap() {
236 local testroot=`test_init histedit_swap`
238 local orig_commit=`git_show_head $testroot/repo`
240 echo "modified alpha on master" > $testroot/repo/alpha
241 (cd $testroot/repo && git rm -q beta)
242 echo "new file on master" > $testroot/repo/epsilon/new
243 (cd $testroot/repo && git add epsilon/new)
244 git_commit $testroot/repo -m "committing changes"
245 local old_commit1=`git_show_head $testroot/repo`
247 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
248 git_commit $testroot/repo -m "committing to zeta on master"
249 local old_commit2=`git_show_head $testroot/repo`
251 got diff -r $testroot/repo $orig_commit $old_commit2 \
252 > $testroot/diff.expected
254 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
256 if [ $ret -ne 0 ]; then
257 test_done "$testroot" "$ret"
261 echo "pick $old_commit2" > $testroot/histedit-script
262 echo "pick $old_commit1" >> $testroot/histedit-script
264 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
267 local new_commit2=`git_show_parent_commit $testroot/repo`
268 local new_commit1=`git_show_head $testroot/repo`
270 local short_old_commit1=`trim_obj_id 28 $old_commit1`
271 local short_old_commit2=`trim_obj_id 28 $old_commit2`
272 local short_new_commit1=`trim_obj_id 28 $new_commit1`
273 local short_new_commit2=`trim_obj_id 28 $new_commit2`
275 echo "G epsilon/zeta" > $testroot/stdout.expected
276 echo -n "$short_old_commit2 -> $short_new_commit2: " \
277 >> $testroot/stdout.expected
278 echo "committing to zeta on master" >> $testroot/stdout.expected
279 echo "G alpha" >> $testroot/stdout.expected
280 echo "D beta" >> $testroot/stdout.expected
281 echo "A epsilon/new" >> $testroot/stdout.expected
282 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
283 >> $testroot/stdout.expected
284 echo "Switching work tree to refs/heads/master" \
285 >> $testroot/stdout.expected
287 cmp -s $testroot/stdout.expected $testroot/stdout
289 if [ $ret -ne 0 ]; then
290 diff -u $testroot/stdout.expected $testroot/stdout
291 test_done "$testroot" "$ret"
295 echo "modified alpha on master" > $testroot/content.expected
296 cat $testroot/wt/alpha > $testroot/content
297 cmp -s $testroot/content.expected $testroot/content
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/content.expected $testroot/content
301 test_done "$testroot" "$ret"
305 if [ -e $testroot/wt/beta ]; then
306 echo "removed file beta still exists on disk" >&2
307 test_done "$testroot" "1"
311 echo "new file on master" > $testroot/content.expected
312 cat $testroot/wt/epsilon/new > $testroot/content
313 cmp -s $testroot/content.expected $testroot/content
315 if [ $ret -ne 0 ]; then
316 diff -u $testroot/content.expected $testroot/content
317 test_done "$testroot" "$ret"
321 (cd $testroot/wt && got status > $testroot/stdout)
323 echo -n > $testroot/stdout.expected
324 cmp -s $testroot/stdout.expected $testroot/stdout
326 if [ $ret -ne 0 ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout
328 test_done "$testroot" "$ret"
332 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
333 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
334 echo "commit $new_commit2" >> $testroot/stdout.expected
335 echo "commit $orig_commit" >> $testroot/stdout.expected
336 cmp -s $testroot/stdout.expected $testroot/stdout
338 if [ $ret -ne 0 ]; then
339 diff -u $testroot/stdout.expected $testroot/stdout
340 test_done "$testroot" "$ret"
344 got diff -r $testroot/repo $orig_commit $new_commit1 \
346 ed -s $testroot/diff.expected <<-EOF
347 ,s/$old_commit2/$new_commit1/
350 cmp -s $testroot/diff.expected $testroot/diff
352 if [ $ret -ne 0 ]; then
353 diff -u $testroot/diff.expected $testroot/diff
355 test_done "$testroot" "$ret"
358 test_histedit_drop() {
359 local testroot=`test_init histedit_drop`
360 local orig_commit=`git_show_head $testroot/repo`
362 echo "modified alpha on master" > $testroot/repo/alpha
363 (cd $testroot/repo && git rm -q beta)
364 echo "new file on master" > $testroot/repo/epsilon/new
365 (cd $testroot/repo && git add epsilon/new)
366 git_commit $testroot/repo -m "committing changes"
367 local old_commit1=`git_show_head $testroot/repo`
369 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
370 git_commit $testroot/repo -m "committing to zeta on master"
371 local old_commit2=`git_show_head $testroot/repo`
373 got diff -r $testroot/repo $old_commit1 $old_commit2 \
374 > $testroot/diff.expected
376 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
378 if [ $ret -ne 0 ]; then
379 test_done "$testroot" "$ret"
383 echo "drop $old_commit1" > $testroot/histedit-script
384 echo "pick $old_commit2" >> $testroot/histedit-script
386 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
389 local new_commit2=`git_show_head $testroot/repo`
391 local short_old_commit1=`trim_obj_id 28 $old_commit1`
392 local short_old_commit2=`trim_obj_id 28 $old_commit2`
393 local short_new_commit2=`trim_obj_id 28 $new_commit2`
395 echo "$short_old_commit1 -> drop commit: committing changes" \
396 > $testroot/stdout.expected
397 echo "G epsilon/zeta" >> $testroot/stdout.expected
398 echo -n "$short_old_commit2 -> $short_new_commit2: " \
399 >> $testroot/stdout.expected
400 echo "committing to zeta on master" >> $testroot/stdout.expected
401 echo "Switching work tree to refs/heads/master" \
402 >> $testroot/stdout.expected
404 cmp -s $testroot/stdout.expected $testroot/stdout
406 if [ $ret -ne 0 ]; then
407 diff -u $testroot/stdout.expected $testroot/stdout
408 test_done "$testroot" "$ret"
412 for f in alpha beta; do
413 echo "$f" > $testroot/content.expected
414 cat $testroot/wt/$f > $testroot/content
415 cmp -s $testroot/content.expected $testroot/content
417 if [ $ret -ne 0 ]; then
418 diff -u $testroot/content.expected $testroot/content
419 test_done "$testroot" "$ret"
424 if [ -e $testroot/wt/new ]; then
425 echo "file new exists on disk but should not" >&2
426 test_done "$testroot" "1"
430 (cd $testroot/wt && got status > $testroot/stdout)
432 echo -n > $testroot/stdout.expected
433 cmp -s $testroot/stdout.expected $testroot/stdout
435 if [ $ret -ne 0 ]; then
436 diff -u $testroot/stdout.expected $testroot/stdout
437 test_done "$testroot" "$ret"
441 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
442 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
443 echo "commit $orig_commit" >> $testroot/stdout.expected
444 cmp -s $testroot/stdout.expected $testroot/stdout
446 if [ $ret -ne 0 ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
452 got diff -r $testroot/repo $orig_commit $new_commit2 \
454 ed -s $testroot/diff.expected <<-EOF
455 ,s/$old_commit1/$orig_commit/
456 ,s/$old_commit2/$new_commit2/
459 cmp -s $testroot/diff.expected $testroot/diff
461 if [ $ret -ne 0 ]; then
462 diff -u $testroot/diff.expected $testroot/diff
464 test_done "$testroot" "$ret"
467 test_histedit_fold() {
468 local testroot=`test_init histedit_fold`
470 local orig_commit=`git_show_head $testroot/repo`
472 echo "modified alpha on master" > $testroot/repo/alpha
473 (cd $testroot/repo && git rm -q beta)
474 echo "new file on master" > $testroot/repo/epsilon/new
475 (cd $testroot/repo && git add epsilon/new)
476 git_commit $testroot/repo -m "committing changes"
477 local old_commit1=`git_show_head $testroot/repo`
479 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
480 git_commit $testroot/repo -m "committing to zeta on master"
481 local old_commit2=`git_show_head $testroot/repo`
483 echo "modified delta on master" > $testroot/repo/gamma/delta
484 git_commit $testroot/repo -m "committing to delta on master"
485 local old_commit3=`git_show_head $testroot/repo`
487 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
489 if [ $ret -ne 0 ]; then
490 test_done "$testroot" "$ret"
494 echo "fold $old_commit1" > $testroot/histedit-script
495 echo "drop $old_commit2" >> $testroot/histedit-script
496 echo "pick $old_commit3" >> $testroot/histedit-script
497 echo "mesg committing folded changes" >> $testroot/histedit-script
499 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
502 local new_commit1=`git_show_parent_commit $testroot/repo`
503 local new_commit2=`git_show_head $testroot/repo`
505 local short_old_commit1=`trim_obj_id 28 $old_commit1`
506 local short_old_commit2=`trim_obj_id 28 $old_commit2`
507 local short_old_commit3=`trim_obj_id 28 $old_commit3`
508 local short_new_commit1=`trim_obj_id 28 $new_commit1`
509 local short_new_commit2=`trim_obj_id 28 $new_commit2`
511 echo "G alpha" > $testroot/stdout.expected
512 echo "D beta" >> $testroot/stdout.expected
513 echo "A epsilon/new" >> $testroot/stdout.expected
514 echo "$short_old_commit1 -> fold commit: committing changes" \
515 >> $testroot/stdout.expected
516 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
517 echo "drop commit: committing to zeta on master" \
518 >> $testroot/stdout.expected
519 echo "G gamma/delta" >> $testroot/stdout.expected
520 echo -n "$short_old_commit3 -> $short_new_commit2: " \
521 >> $testroot/stdout.expected
522 echo "committing folded changes" >> $testroot/stdout.expected
523 echo "Switching work tree to refs/heads/master" \
524 >> $testroot/stdout.expected
526 cmp -s $testroot/stdout.expected $testroot/stdout
528 if [ $ret -ne 0 ]; then
529 diff -u $testroot/stdout.expected $testroot/stdout
530 test_done "$testroot" "$ret"
534 echo "modified alpha on master" > $testroot/content.expected
535 cat $testroot/wt/alpha > $testroot/content
536 cmp -s $testroot/content.expected $testroot/content
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/content.expected $testroot/content
540 test_done "$testroot" "$ret"
544 if [ -e $testroot/wt/beta ]; then
545 echo "removed file beta still exists on disk" >&2
546 test_done "$testroot" "1"
550 echo "new file on master" > $testroot/content.expected
551 cat $testroot/wt/epsilon/new > $testroot/content
552 cmp -s $testroot/content.expected $testroot/content
554 if [ $ret -ne 0 ]; then
555 diff -u $testroot/content.expected $testroot/content
556 test_done "$testroot" "$ret"
560 (cd $testroot/wt && got status > $testroot/stdout)
562 echo -n > $testroot/stdout.expected
563 cmp -s $testroot/stdout.expected $testroot/stdout
565 if [ $ret -ne 0 ]; then
566 diff -u $testroot/stdout.expected $testroot/stdout
567 test_done "$testroot" "$ret"
571 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
572 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
573 echo "commit $orig_commit" >> $testroot/stdout.expected
574 cmp -s $testroot/stdout.expected $testroot/stdout
576 if [ $ret -ne 0 ]; then
577 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done "$testroot" "$ret"
582 test_histedit_edit() {
583 local testroot=`test_init histedit_edit`
585 local orig_commit=`git_show_head $testroot/repo`
587 echo "modified alpha on master" > $testroot/repo/alpha
588 (cd $testroot/repo && git rm -q beta)
589 echo "new file on master" > $testroot/repo/epsilon/new
590 (cd $testroot/repo && git add epsilon/new)
591 git_commit $testroot/repo -m "committing changes"
592 local old_commit1=`git_show_head $testroot/repo`
594 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
595 git_commit $testroot/repo -m "committing to zeta on master"
596 local old_commit2=`git_show_head $testroot/repo`
598 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
600 if [ $ret -ne 0 ]; then
601 test_done "$testroot" "$ret"
605 echo "edit $old_commit1" > $testroot/histedit-script
606 echo "mesg committing changes" >> $testroot/histedit-script
607 echo "pick $old_commit2" >> $testroot/histedit-script
609 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
612 local short_old_commit1=`trim_obj_id 28 $old_commit1`
613 local short_old_commit2=`trim_obj_id 28 $old_commit2`
615 echo "G alpha" > $testroot/stdout.expected
616 echo "D beta" >> $testroot/stdout.expected
617 echo "A epsilon/new" >> $testroot/stdout.expected
618 echo "Stopping histedit for amending commit $old_commit1" \
619 >> $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
622 if [ $ret -ne 0 ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
628 echo "edited modified alpha on master" > $testroot/wt/alpha
630 # test interaction of 'got stage' and histedit -c
631 (cd $testroot/wt && got stage alpha > /dev/null)
632 (cd $testroot/wt && got histedit -c > $testroot/stdout \
635 if [ $ret -eq 0 ]; then
636 echo "histedit succeeded unexpectedly" >&2
637 test_done "$testroot" "1"
640 echo -n "got: work tree contains files with staged changes; " \
641 > $testroot/stderr.expected
642 echo "these changes must be committed or unstaged first" \
643 >> $testroot/stderr.expected
644 cmp -s $testroot/stderr.expected $testroot/stderr
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stderr.expected $testroot/stderr
648 test_done "$testroot" "$ret"
652 (cd $testroot/wt && got unstage alpha > /dev/null)
653 (cd $testroot/wt && got histedit -c > $testroot/stdout)
655 local new_commit1=`git_show_parent_commit $testroot/repo`
656 local new_commit2=`git_show_head $testroot/repo`
658 local short_new_commit1=`trim_obj_id 28 $new_commit1`
659 local short_new_commit2=`trim_obj_id 28 $new_commit2`
661 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
662 > $testroot/stdout.expected
663 echo "G epsilon/zeta" >> $testroot/stdout.expected
664 echo -n "$short_old_commit2 -> $short_new_commit2: " \
665 >> $testroot/stdout.expected
666 echo "committing to zeta on master" >> $testroot/stdout.expected
667 echo "Switching work tree to refs/heads/master" \
668 >> $testroot/stdout.expected
670 cmp -s $testroot/stdout.expected $testroot/stdout
672 if [ $ret -ne 0 ]; then
673 diff -u $testroot/stdout.expected $testroot/stdout
674 test_done "$testroot" "$ret"
678 echo "edited modified alpha on master" > $testroot/content.expected
679 cat $testroot/wt/alpha > $testroot/content
680 cmp -s $testroot/content.expected $testroot/content
682 if [ $ret -ne 0 ]; then
683 diff -u $testroot/content.expected $testroot/content
684 test_done "$testroot" "$ret"
688 if [ -e $testroot/wt/beta ]; then
689 echo "removed file beta still exists on disk" >&2
690 test_done "$testroot" "1"
694 echo "new file on master" > $testroot/content.expected
695 cat $testroot/wt/epsilon/new > $testroot/content
696 cmp -s $testroot/content.expected $testroot/content
698 if [ $ret -ne 0 ]; then
699 diff -u $testroot/content.expected $testroot/content
700 test_done "$testroot" "$ret"
704 (cd $testroot/wt && got status > $testroot/stdout)
706 echo -n > $testroot/stdout.expected
707 cmp -s $testroot/stdout.expected $testroot/stdout
709 if [ $ret -ne 0 ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 test_done "$testroot" "$ret"
715 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
716 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
717 echo "commit $new_commit1" >> $testroot/stdout.expected
718 echo "commit $orig_commit" >> $testroot/stdout.expected
719 cmp -s $testroot/stdout.expected $testroot/stdout
721 if [ $ret -ne 0 ]; then
722 diff -u $testroot/stdout.expected $testroot/stdout
724 test_done "$testroot" "$ret"
727 test_histedit_fold_last_commit() {
728 local testroot=`test_init histedit_fold_last_commit`
730 local orig_commit=`git_show_head $testroot/repo`
732 echo "modified alpha on master" > $testroot/repo/alpha
733 (cd $testroot/repo && git rm -q beta)
734 echo "new file on master" > $testroot/repo/epsilon/new
735 (cd $testroot/repo && git add epsilon/new)
736 git_commit $testroot/repo -m "committing changes"
737 local old_commit1=`git_show_head $testroot/repo`
739 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
740 git_commit $testroot/repo -m "committing to zeta on master"
741 local old_commit2=`git_show_head $testroot/repo`
743 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
745 if [ $ret -ne 0 ]; then
746 test_done "$testroot" "$ret"
750 echo "pick $old_commit1" > $testroot/histedit-script
751 echo "fold $old_commit2" >> $testroot/histedit-script
753 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
754 > $testroot/stdout 2> $testroot/stderr)
757 if [ $ret -eq 0 ]; then
758 echo "histedit succeeded unexpectedly" >&2
759 test_done "$testroot" "1"
763 echo "got: last commit in histedit script cannot be folded" \
764 > $testroot/stderr.expected
766 cmp -s $testroot/stderr.expected $testroot/stderr
768 if [ $ret -ne 0 ]; then
769 diff -u $testroot/stderr.expected $testroot/stderr
771 test_done "$testroot" "$ret"
774 test_histedit_missing_commit() {
775 local testroot=`test_init histedit_missing_commit`
777 local orig_commit=`git_show_head $testroot/repo`
779 echo "modified alpha on master" > $testroot/repo/alpha
780 (cd $testroot/repo && git rm -q beta)
781 echo "new file on master" > $testroot/repo/epsilon/new
782 (cd $testroot/repo && git add epsilon/new)
783 git_commit $testroot/repo -m "committing changes"
784 local old_commit1=`git_show_head $testroot/repo`
786 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
787 git_commit $testroot/repo -m "committing to zeta on master"
788 local old_commit2=`git_show_head $testroot/repo`
790 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
792 if [ $ret -ne 0 ]; then
793 test_done "$testroot" "$ret"
797 echo "pick $old_commit1" > $testroot/histedit-script
798 echo "mesg committing changes" >> $testroot/histedit-script
800 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
801 > $testroot/stdout 2> $testroot/stderr)
804 if [ $ret -eq 0 ]; then
805 echo "histedit succeeded unexpectedly" >&2
806 test_done "$testroot" "1"
810 echo "got: commit $old_commit2 missing from histedit script" \
811 > $testroot/stderr.expected
813 cmp -s $testroot/stderr.expected $testroot/stderr
815 if [ $ret -ne 0 ]; then
816 diff -u $testroot/stderr.expected $testroot/stderr
818 test_done "$testroot" "$ret"
821 test_histedit_abort() {
822 local testroot=`test_init histedit_abort`
824 local orig_commit=`git_show_head $testroot/repo`
826 echo "modified alpha on master" > $testroot/repo/alpha
827 (cd $testroot/repo && git rm -q beta)
828 echo "new file on master" > $testroot/repo/epsilon/new
829 (cd $testroot/repo && git add epsilon/new)
830 git_commit $testroot/repo -m "committing changes"
831 local old_commit1=`git_show_head $testroot/repo`
833 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
834 git_commit $testroot/repo -m "committing to zeta on master"
835 local old_commit2=`git_show_head $testroot/repo`
837 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
839 if [ $ret -ne 0 ]; then
840 test_done "$testroot" "$ret"
844 # unrelated unversioned file in work tree
845 touch $testroot/wt/unversioned-file
847 echo "edit $old_commit1" > $testroot/histedit-script
848 echo "mesg committing changes" >> $testroot/histedit-script
849 echo "pick $old_commit2" >> $testroot/histedit-script
851 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
854 local short_old_commit1=`trim_obj_id 28 $old_commit1`
855 local short_old_commit2=`trim_obj_id 28 $old_commit2`
857 echo "G alpha" > $testroot/stdout.expected
858 echo "D beta" >> $testroot/stdout.expected
859 echo "A epsilon/new" >> $testroot/stdout.expected
860 echo "Stopping histedit for amending commit $old_commit1" \
861 >> $testroot/stdout.expected
862 cmp -s $testroot/stdout.expected $testroot/stdout
864 if [ $ret -ne 0 ]; then
865 diff -u $testroot/stdout.expected $testroot/stdout
866 test_done "$testroot" "$ret"
870 echo "edited modified alpha on master" > $testroot/wt/alpha
872 (cd $testroot/wt && got histedit -a > $testroot/stdout)
874 local new_commit1=`git_show_parent_commit $testroot/repo`
875 local new_commit2=`git_show_head $testroot/repo`
877 echo "Switching work tree to refs/heads/master" \
878 > $testroot/stdout.expected
879 echo "R alpha" >> $testroot/stdout.expected
880 echo "R beta" >> $testroot/stdout.expected
881 echo "R epsilon/new" >> $testroot/stdout.expected
882 echo "Histedit of refs/heads/master aborted" \
883 >> $testroot/stdout.expected
885 cmp -s $testroot/stdout.expected $testroot/stdout
887 if [ $ret -ne 0 ]; then
888 diff -u $testroot/stdout.expected $testroot/stdout
889 test_done "$testroot" "$ret"
893 for f in alpha beta; do
894 echo "$f" > $testroot/content.expected
895 cat $testroot/wt/$f > $testroot/content
896 cmp -s $testroot/content.expected $testroot/content
898 if [ $ret -ne 0 ]; then
899 diff -u $testroot/content.expected $testroot/content
900 test_done "$testroot" "$ret"
905 echo "new file on master" > $testroot/content.expected
906 cat $testroot/wt/epsilon/new > $testroot/content
907 cmp -s $testroot/content.expected $testroot/content
909 if [ $ret -ne 0 ]; then
910 diff -u $testroot/content.expected $testroot/content
911 test_done "$testroot" "$ret"
915 (cd $testroot/wt && got status > $testroot/stdout)
917 echo "? epsilon/new" > $testroot/stdout.expected
918 echo "? unversioned-file" >> $testroot/stdout.expected
919 cmp -s $testroot/stdout.expected $testroot/stdout
921 if [ $ret -ne 0 ]; then
922 diff -u $testroot/stdout.expected $testroot/stdout
923 test_done "$testroot" "$ret"
927 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
928 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
929 echo "commit $new_commit1" >> $testroot/stdout.expected
930 echo "commit $orig_commit" >> $testroot/stdout.expected
931 cmp -s $testroot/stdout.expected $testroot/stdout
933 if [ $ret -ne 0 ]; then
934 diff -u $testroot/stdout.expected $testroot/stdout
936 test_done "$testroot" "$ret"
939 test_histedit_path_prefix_drop() {
940 local testroot=`test_init histedit_path_prefix_drop`
941 local orig_commit=`git_show_head $testroot/repo`
943 echo "modified zeta" > $testroot/repo/epsilon/zeta
944 git_commit $testroot/repo -m "changing zeta"
945 local old_commit1=`git_show_head $testroot/repo`
947 got checkout -c $orig_commit -p gamma $testroot/repo \
948 $testroot/wt > /dev/null
950 if [ $ret -ne 0 ]; then
951 test_done "$testroot" "$ret"
955 echo "drop $old_commit1" > $testroot/histedit-script
957 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
958 > $testroot/stdout 2> $testroot/stderr)
961 if [ $ret -eq 0 ]; then
962 echo "histedit succeeded unexpectedly" >&2
963 test_done "$testroot" "1"
967 echo -n "got: cannot edit branch history which contains changes " \
968 > $testroot/stderr.expected
969 echo "outside of this work tree's path prefix" \
970 >> $testroot/stderr.expected
972 cmp -s $testroot/stderr.expected $testroot/stderr
974 if [ $ret -ne 0 ]; then
975 diff -u $testroot/stderr.expected $testroot/stderr
976 test_done "$testroot" "$ret"
981 got checkout -c $orig_commit -p epsilon $testroot/repo \
982 $testroot/wt > /dev/null
984 if [ $ret -ne 0 ]; then
985 test_done "$testroot" "$ret"
988 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
991 local short_old_commit1=`trim_obj_id 28 $old_commit1`
992 local short_old_commit2=`trim_obj_id 28 $old_commit2`
994 echo "$short_old_commit1 -> drop commit: changing zeta" \
995 > $testroot/stdout.expected
996 echo "Switching work tree to refs/heads/master" \
997 >> $testroot/stdout.expected
999 cmp -s $testroot/stdout.expected $testroot/stdout
1001 if [ $ret -ne 0 ]; then
1002 diff -u $testroot/stdout.expected $testroot/stdout
1003 test_done "$testroot" "$ret"
1007 echo "zeta" > $testroot/content.expected
1008 cat $testroot/wt/zeta > $testroot/content
1009 cmp -s $testroot/content.expected $testroot/content
1011 if [ $ret -ne 0 ]; then
1012 diff -u $testroot/content.expected $testroot/content
1013 test_done "$testroot" "$ret"
1018 (cd $testroot/wt && got status > $testroot/stdout)
1020 echo -n > $testroot/stdout.expected
1021 cmp -s $testroot/stdout.expected $testroot/stdout
1023 if [ $ret -ne 0 ]; then
1024 diff -u $testroot/stdout.expected $testroot/stdout
1025 test_done "$testroot" "$ret"
1029 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1030 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1031 cmp -s $testroot/stdout.expected $testroot/stdout
1033 if [ $ret -ne 0 ]; then
1034 diff -u $testroot/stdout.expected $testroot/stdout
1036 test_done "$testroot" "$ret"
1039 test_histedit_path_prefix_edit() {
1040 local testroot=`test_init histedit_path_prefix_edit`
1041 local orig_commit=`git_show_head $testroot/repo`
1043 echo "modified zeta" > $testroot/repo/epsilon/zeta
1044 git_commit $testroot/repo -m "changing zeta"
1045 local old_commit1=`git_show_head $testroot/repo`
1047 got diff -r $testroot/repo $orig_commit $old_commit1 \
1048 > $testroot/diff.expected
1050 got checkout -c $orig_commit -p gamma $testroot/repo \
1051 $testroot/wt > /dev/null
1053 if [ $ret -ne 0 ]; then
1054 test_done "$testroot" "$ret"
1058 echo "edit $old_commit1" > $testroot/histedit-script
1059 echo "mesg modified zeta" >> $testroot/histedit-script
1061 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1062 > $testroot/stdout 2> $testroot/stderr)
1065 if [ $ret -eq 0 ]; then
1066 echo "histedit succeeded unexpectedly" >&2
1067 test_done "$testroot" "1"
1071 echo -n "got: cannot edit branch history which contains changes " \
1072 > $testroot/stderr.expected
1073 echo "outside of this work tree's path prefix" \
1074 >> $testroot/stderr.expected
1076 cmp -s $testroot/stderr.expected $testroot/stderr
1078 if [ $ret -ne 0 ]; then
1079 diff -u $testroot/stderr.expected $testroot/stderr
1080 test_done "$testroot" "$ret"
1085 got checkout -c $orig_commit -p epsilon $testroot/repo \
1086 $testroot/wt > /dev/null
1088 if [ $ret -ne 0 ]; then
1089 test_done "$testroot" "$ret"
1092 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1095 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1097 echo "G zeta" > $testroot/stdout.expected
1098 echo "Stopping histedit for amending commit $old_commit1" \
1099 >> $testroot/stdout.expected
1100 cmp -s $testroot/stdout.expected $testroot/stdout
1102 if [ $ret -ne 0 ]; then
1103 diff -u $testroot/stdout.expected $testroot/stdout
1104 test_done "$testroot" "$ret"
1108 echo "modified zeta" > $testroot/content.expected
1109 cat $testroot/wt/zeta > $testroot/content
1110 cmp -s $testroot/content.expected $testroot/content
1112 if [ $ret -ne 0 ]; then
1113 diff -u $testroot/content.expected $testroot/content
1114 test_done "$testroot" "$ret"
1118 (cd $testroot/wt && got status > $testroot/stdout)
1120 echo "M zeta"> $testroot/stdout.expected
1121 cmp -s $testroot/stdout.expected $testroot/stdout
1123 if [ $ret -ne 0 ]; then
1124 diff -u $testroot/stdout.expected $testroot/stdout
1125 test_done "$testroot" "$ret"
1129 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1131 local new_commit1=`git_show_head $testroot/repo`
1132 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1134 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1135 > $testroot/stdout.expected
1136 echo "modified zeta" >> $testroot/stdout.expected
1137 echo "Switching work tree to refs/heads/master" \
1138 >> $testroot/stdout.expected
1140 cmp -s $testroot/stdout.expected $testroot/stdout
1142 if [ $ret -ne 0 ]; then
1143 diff -u $testroot/stdout.expected $testroot/stdout
1144 test_done "$testroot" "$ret"
1148 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1149 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1150 echo "commit $orig_commit" >> $testroot/stdout.expected
1151 cmp -s $testroot/stdout.expected $testroot/stdout
1153 if [ $ret -ne 0 ]; then
1154 diff -u $testroot/stdout.expected $testroot/stdout
1155 test_done "$testroot" "$ret"
1159 got diff -r $testroot/repo $orig_commit $new_commit1 \
1161 ed -s $testroot/diff.expected <<-EOF
1162 ,s/$old_commit1/$new_commit1/
1165 cmp -s $testroot/diff.expected $testroot/diff
1167 if [ $ret -ne 0 ]; then
1168 diff -u $testroot/diff.expected $testroot/diff
1170 test_done "$testroot" "$ret"
1173 test_histedit_outside_refs_heads() {
1174 local testroot=`test_init histedit_outside_refs_heads`
1175 local commit1=`git_show_head $testroot/repo`
1177 got checkout $testroot/repo $testroot/wt > /dev/null
1179 if [ $ret -ne 0 ]; then
1180 echo "got checkout failed unexpectedly"
1181 test_done "$testroot" "$ret"
1185 echo "modified alpha" > $testroot/wt/alpha
1187 (cd $testroot/wt && got commit -m 'change alpha' \
1188 > $testroot/stdout 2> $testroot/stderr)
1190 if [ $ret -ne 0 ]; then
1191 echo "got commit failed unexpectedly" >&2
1192 test_done "$testroot" "1"
1195 local commit2=`git_show_head $testroot/repo`
1197 got ref -r $testroot/repo -c master refs/remotes/origin/master
1199 if [ $ret -ne 0 ]; then
1200 echo "got ref failed unexpectedly" >&2
1201 test_done "$testroot" "1"
1205 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1207 if [ $ret -ne 0 ]; then
1208 echo "got update failed unexpectedly"
1209 test_done "$testroot" "$ret"
1213 echo "edit $commit2" > $testroot/histedit-script
1214 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1215 2> $testroot/stderr)
1217 echo -n "got: will not edit commit history of a branch outside the " \
1218 > $testroot/stderr.expected
1219 echo '"refs/heads/" reference namespace' \
1220 >> $testroot/stderr.expected
1221 cmp -s $testroot/stderr.expected $testroot/stderr
1223 if [ $ret -ne 0 ]; then
1224 diff -u $testroot/stderr.expected $testroot/stderr
1226 test_done "$testroot" "$ret"
1229 test_histedit_fold_last_commit_swap() {
1230 local testroot=`test_init histedit_fold_last_commit_swap`
1232 local orig_commit=`git_show_head $testroot/repo`
1234 echo "modified alpha on master" > $testroot/repo/alpha
1235 (cd $testroot/repo && git rm -q beta)
1236 echo "new file on master" > $testroot/repo/epsilon/new
1237 (cd $testroot/repo && git add epsilon/new)
1238 git_commit $testroot/repo -m "committing changes"
1239 local old_commit1=`git_show_head $testroot/repo`
1241 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1242 git_commit $testroot/repo -m "committing to zeta on master"
1243 local old_commit2=`git_show_head $testroot/repo`
1245 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1247 if [ $ret -ne 0 ]; then
1248 test_done "$testroot" "$ret"
1252 # fold commit2 into commit1 (requires swapping commits)
1253 echo "fold $old_commit2" > $testroot/histedit-script
1254 echo "pick $old_commit1" >> $testroot/histedit-script
1255 echo "mesg committing folded changes" >> $testroot/histedit-script
1257 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1258 > $testroot/stdout 2> $testroot/stderr)
1261 if [ $ret -ne 0 ]; then
1262 echo "histedit failed unexpectedly" >&2
1263 test_done "$testroot" "$ret"
1267 local new_commit=`git_show_head $testroot/repo`
1269 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1270 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1271 local short_new_commit=`trim_obj_id 28 $new_commit`
1273 echo "G epsilon/zeta" >> $testroot/stdout.expected
1274 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1275 >> $testroot/stdout.expected
1276 echo "on master" >> $testroot/stdout.expected
1277 echo "G alpha" >> $testroot/stdout.expected
1278 echo "D beta" >> $testroot/stdout.expected
1279 echo "A epsilon/new" >> $testroot/stdout.expected
1280 echo -n "$short_old_commit1 -> $short_new_commit: " \
1281 >> $testroot/stdout.expected
1282 echo "committing folded changes" >> $testroot/stdout.expected
1283 echo "Switching work tree to refs/heads/master" \
1284 >> $testroot/stdout.expected
1286 cmp -s $testroot/stdout.expected $testroot/stdout
1288 if [ $ret -ne 0 ]; then
1289 diff -u $testroot/stdout.expected $testroot/stdout
1291 test_done "$testroot" "$ret"
1294 test_histedit_split_commit() {
1295 local testroot=`test_init histedit_split_commit`
1297 local orig_commit=`git_show_head $testroot/repo`
1299 echo "modified alpha on master" > $testroot/repo/alpha
1300 (cd $testroot/repo && git rm -q beta)
1301 echo "new file on master" > $testroot/repo/epsilon/new
1302 (cd $testroot/repo && git add epsilon/new)
1303 git_commit $testroot/repo -m "committing changes 1"
1304 local old_commit1=`git_show_head $testroot/repo`
1305 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1307 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1308 git_commit $testroot/repo -m "committing changes 2"
1309 local old_commit2=`git_show_head $testroot/repo`
1310 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1312 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1314 if [ $ret -ne 0 ]; then
1315 test_done "$testroot" "$ret"
1319 # split commit1 into commitA and commitB and commitC
1320 echo "e $old_commit1" > $testroot/histedit-script
1321 echo "p $old_commit2" >> $testroot/histedit-script
1323 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1324 > $testroot/stdout 2> $testroot/stderr)
1326 if [ $ret -ne 0 ]; then
1327 echo "histedit failed unexpectedly:" >&2
1328 cat $testroot/stderr >&2
1329 test_done "$testroot" "$ret"
1333 echo "G alpha" > $testroot/stdout.expected
1334 echo "D beta" >> $testroot/stdout.expected
1335 echo "A epsilon/new" >> $testroot/stdout.expected
1336 echo "Stopping histedit for amending commit $old_commit1" \
1337 >> $testroot/stdout.expected
1339 cmp -s $testroot/stdout.expected $testroot/stdout
1341 if [ $ret -ne 0 ]; then
1342 diff -u $testroot/stdout.expected $testroot/stdout
1343 test_done "$testroot" "$ret"
1347 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1349 if [ $ret -ne 0 ]; then
1350 echo "commit failed unexpectedly" >&2
1351 test_done "$testroot" "$ret"
1355 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1357 if [ $ret -ne 0 ]; then
1358 echo "commit failed unexpectedly" >&2
1359 test_done "$testroot" "$ret"
1363 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1365 if [ $ret -ne 0 ]; then
1366 echo "commit failed unexpectedly" >&2
1367 test_done "$testroot" "$ret"
1371 (cd $testroot/wt && got histedit -c \
1372 > $testroot/stdout 2> $testroot/stderr)
1374 if [ $ret -ne 0 ]; then
1375 echo "histedit failed unexpectedly:" >&2
1376 cat $testroot/stderr >&2
1377 test_done "$testroot" "$ret"
1380 local new_commit2=`git_show_head $testroot/repo`
1381 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1383 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1384 > $testroot/stdout.expected
1385 echo "G epsilon/zeta" >> $testroot/stdout.expected
1386 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1387 >> $testroot/stdout.expected
1388 echo "Switching work tree to refs/heads/master" \
1389 >> $testroot/stdout.expected
1391 cmp -s $testroot/stdout.expected $testroot/stdout
1393 if [ $ret -ne 0 ]; then
1394 diff -u $testroot/stdout.expected $testroot/stdout
1396 test_done "$testroot" "$ret"
1400 test_histedit_duplicate_commit_in_script() {
1401 local testroot=`test_init histedit_duplicate_commit_in_script`
1403 local orig_commit=`git_show_head $testroot/repo`
1405 echo "modified alpha on master" > $testroot/repo/alpha
1406 (cd $testroot/repo && git rm -q beta)
1407 echo "new file on master" > $testroot/repo/epsilon/new
1408 (cd $testroot/repo && git add epsilon/new)
1409 git_commit $testroot/repo -m "committing changes 1"
1410 local old_commit1=`git_show_head $testroot/repo`
1412 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1413 git_commit $testroot/repo -m "committing changes 2"
1414 local old_commit2=`git_show_head $testroot/repo`
1416 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1418 if [ $ret -ne 0 ]; then
1419 test_done "$testroot" "$ret"
1423 # This histedit script lists commit1 more than once
1424 echo "p $old_commit1" > $testroot/histedit-script
1425 echo "p $old_commit1" >> $testroot/histedit-script
1426 echo "p $old_commit2" >> $testroot/histedit-script
1428 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1429 > $testroot/stdout 2> $testroot/stderr)
1431 if [ $ret -eq 0 ]; then
1432 echo "histedit succeeded unexpectedly:" >&2
1433 cat $testroot/stdout >&2
1434 test_done "$testroot" "$ret"
1438 echo -n "got: commit $old_commit1 is listed more than once " \
1439 > $testroot/stderr.expected
1440 echo "in histedit script" >> $testroot/stderr.expected
1442 cmp -s $testroot/stderr.expected $testroot/stderr
1444 if [ $ret -ne 0 ]; then
1445 diff -u $testroot/stderr.expected $testroot/stderr
1447 test_done "$testroot" "$ret"
1451 # if a previous commit introduces a new file, and it is folded into a commit
1452 # that deletes the same file, the file still exists after the histedit
1453 test_histedit_fold_add_delete() {
1454 local testroot=`test_init histedit_fold_add_delete`
1456 local orig_commit=`git_show_head $testroot/repo`
1458 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1459 (cd $testroot/repo && git add epsilon/psi)
1460 git_commit $testroot/repo -m "committing changes"
1461 local old_commit1=`git_show_head $testroot/repo`
1463 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1464 git_commit $testroot/repo -m "editing psi"
1465 local old_commit2=`git_show_head $testroot/repo`
1467 (cd $testroot/repo && git rm -q epsilon/psi)
1468 git_commit $testroot/repo -m "removing psi"
1469 local old_commit3=`git_show_head $testroot/repo`
1471 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1473 if [ $ret -ne 0 ]; then
1474 test_done "$testroot" "$ret"
1478 echo "fold $old_commit1" > $testroot/histedit-script
1479 echo "fold $old_commit2" >> $testroot/histedit-script
1480 echo "pick $old_commit3" >> $testroot/histedit-script
1481 echo "mesg folded changes" >> $testroot/histedit-script
1483 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1486 local new_commit1=`git_show_head $testroot/repo`
1488 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1489 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1490 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1491 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1493 echo "A epsilon/psi" >> $testroot/stdout.expected
1494 echo "$short_old_commit1 -> fold commit: committing changes" \
1495 >> $testroot/stdout.expected
1496 echo "G epsilon/psi" >> $testroot/stdout.expected
1497 echo "$short_old_commit2 -> fold commit: editing psi" \
1498 >> $testroot/stdout.expected
1499 echo "D epsilon/psi" >> $testroot/stdout.expected
1500 echo "$short_old_commit3 -> no-op change: folded changes" \
1501 >> $testroot/stdout.expected
1502 echo "Switching work tree to refs/heads/master" \
1503 >> $testroot/stdout.expected
1505 cmp -s $testroot/stdout.expected $testroot/stdout
1507 if [ $ret -ne 0 ]; then
1508 diff -u $testroot/stdout.expected $testroot/stdout
1509 test_done "$testroot" "$ret"
1513 if [ -e $testroot/wt/epsilon/psi ]; then
1514 echo "removed file psi still exists on disk" >&2
1515 test_done "$testroot" "1"
1519 (cd $testroot/wt && got status > $testroot/stdout)
1521 echo -n > $testroot/stdout.expected
1522 cmp -s $testroot/stdout.expected $testroot/stdout
1524 if [ $ret -ne 0 ]; then
1525 diff -u $testroot/stdout.expected $testroot/stdout
1526 test_done "$testroot" "$ret"
1530 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1531 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1532 cmp -s $testroot/stdout.expected $testroot/stdout
1534 if [ $ret -ne 0 ]; then
1535 diff -u $testroot/stdout.expected $testroot/stdout
1536 test_done "$testroot" "$ret"
1540 got tree -r $testroot/repo epsilon > $testroot/stdout
1541 echo "zeta" > $testroot/stdout.expected
1542 cmp -s $testroot/stdout.expected $testroot/stdout
1544 if [ $ret -ne 0 ]; then
1545 diff -u $testroot/stdout.expected $testroot/stdout
1547 test_done "$testroot" "$ret"
1550 test_histedit_fold_delete_add() {
1551 local testroot=`test_init histedit_fold_delete_add`
1553 local orig_commit=`git_show_head $testroot/repo`
1555 (cd $testroot/repo && git rm -q alpha)
1556 git_commit $testroot/repo -m "removing alpha"
1557 local old_commit1=`git_show_head $testroot/repo`
1559 echo "modified alpha" >$testroot/repo/alpha
1560 (cd $testroot/repo && git add alpha)
1561 git_commit $testroot/repo -m "add back modified alpha"
1562 local old_commit2=`git_show_head $testroot/repo`
1564 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1566 if [ $ret -ne 0 ]; then
1567 test_done "$testroot" "$ret"
1571 echo "fold $old_commit1" > $testroot/histedit-script
1572 echo "pick $old_commit2" >> $testroot/histedit-script
1573 echo "mesg folded changes" >> $testroot/histedit-script
1575 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1578 local new_commit1=`git_show_head $testroot/repo`
1580 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1581 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1582 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1584 echo "D alpha" > $testroot/stdout.expected
1585 echo "$short_old_commit1 -> fold commit: removing alpha" \
1586 >> $testroot/stdout.expected
1587 echo "A alpha" >> $testroot/stdout.expected
1588 echo "$short_old_commit2 -> $short_new_commit1: folded changes" \
1589 >> $testroot/stdout.expected
1590 echo "Switching work tree to refs/heads/master" \
1591 >> $testroot/stdout.expected
1593 cmp -s $testroot/stdout.expected $testroot/stdout
1595 if [ $ret -ne 0 ]; then
1596 diff -u $testroot/stdout.expected $testroot/stdout
1597 test_done "$testroot" "$ret"
1601 if [ ! -e $testroot/wt/alpha ]; then
1602 echo "file alpha is missing on disk" >&2
1603 test_done "$testroot" "1"
1607 echo "modified alpha" > $testroot/content.expected
1608 cat $testroot/wt/alpha > $testroot/content
1609 cmp -s $testroot/content.expected $testroot/content
1611 if [ $ret -ne 0 ]; then
1612 diff -u $testroot/content.expected $testroot/content
1613 test_done "$testroot" "$ret"
1616 test_done "$testroot" "0"
1619 test_histedit_fold_only() {
1620 local testroot=`test_init histedit_fold_only`
1622 local orig_commit=`git_show_head $testroot/repo`
1624 echo "modified alpha on master" > $testroot/repo/alpha
1625 (cd $testroot/repo && git rm -q beta)
1626 echo "new file on master" > $testroot/repo/epsilon/new
1627 (cd $testroot/repo && git add epsilon/new)
1628 git_commit $testroot/repo -m "committing changes"
1629 local old_commit1=`git_show_head $testroot/repo`
1631 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1632 git_commit $testroot/repo -m "committing to zeta on master"
1633 local old_commit2=`git_show_head $testroot/repo`
1635 echo "modified delta on master" > $testroot/repo/gamma/delta
1636 git_commit $testroot/repo -m "committing to delta on master"
1637 local old_commit3=`git_show_head $testroot/repo`
1639 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1641 if [ $ret -ne 0 ]; then
1642 test_done "$testroot" "$ret"
1646 cat > $testroot/editor.sh <<EOF
1649 ,s/.*/committing folded changes/
1653 chmod +x $testroot/editor.sh
1655 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1656 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1658 local new_commit1=`git_show_head $testroot/repo`
1660 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1661 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1662 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1663 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1664 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1666 echo "G alpha" > $testroot/stdout.expected
1667 echo "D beta" >> $testroot/stdout.expected
1668 echo "A epsilon/new" >> $testroot/stdout.expected
1669 echo "$short_old_commit1 -> fold commit: committing changes" \
1670 >> $testroot/stdout.expected
1671 echo "G epsilon/zeta" >> $testroot/stdout.expected
1672 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1673 echo "fold commit: committing to zeta on master" \
1674 >> $testroot/stdout.expected
1675 echo "G gamma/delta" >> $testroot/stdout.expected
1676 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1677 >> $testroot/stdout.expected
1678 echo "committing folded changes" >> $testroot/stdout.expected
1679 echo "Switching work tree to refs/heads/master" \
1680 >> $testroot/stdout.expected
1682 cmp -s $testroot/stdout.expected $testroot/stdout
1684 if [ $ret -ne 0 ]; then
1685 diff -u $testroot/stdout.expected $testroot/stdout
1686 test_done "$testroot" "$ret"
1690 echo "modified alpha on master" > $testroot/content.expected
1691 cat $testroot/wt/alpha > $testroot/content
1692 cmp -s $testroot/content.expected $testroot/content
1694 if [ $ret -ne 0 ]; then
1695 diff -u $testroot/content.expected $testroot/content
1696 test_done "$testroot" "$ret"
1700 if [ -e $testroot/wt/beta ]; then
1701 echo "removed file beta still exists on disk" >&2
1702 test_done "$testroot" "1"
1706 echo "new file on master" > $testroot/content.expected
1707 cat $testroot/wt/epsilon/new > $testroot/content
1708 cmp -s $testroot/content.expected $testroot/content
1710 if [ $ret -ne 0 ]; then
1711 diff -u $testroot/content.expected $testroot/content
1712 test_done "$testroot" "$ret"
1716 (cd $testroot/wt && got status > $testroot/stdout)
1718 echo -n > $testroot/stdout.expected
1719 cmp -s $testroot/stdout.expected $testroot/stdout
1721 if [ $ret -ne 0 ]; then
1722 diff -u $testroot/stdout.expected $testroot/stdout
1723 test_done "$testroot" "$ret"
1727 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1728 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1729 echo "commit $orig_commit" >> $testroot/stdout.expected
1730 cmp -s $testroot/stdout.expected $testroot/stdout
1732 if [ $ret -ne 0 ]; then
1733 diff -u $testroot/stdout.expected $testroot/stdout
1735 test_done "$testroot" "$ret"
1738 test_histedit_fold_only_empty_logmsg() {
1739 local testroot=`test_init histedit_fold_only_empty_logmsg`
1741 local orig_commit=`git_show_head $testroot/repo`
1743 echo "modified alpha on master" > $testroot/repo/alpha
1744 (cd $testroot/repo && git rm -q beta)
1745 echo "new file on master" > $testroot/repo/epsilon/new
1746 (cd $testroot/repo && git add epsilon/new)
1747 git_commit $testroot/repo -m "committing changes"
1748 local old_commit1=`git_show_head $testroot/repo`
1750 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1751 git_commit $testroot/repo -m "committing to zeta on master"
1752 local old_commit2=`git_show_head $testroot/repo`
1754 echo "modified delta on master" > $testroot/repo/gamma/delta
1755 git_commit $testroot/repo -m "committing to delta on master"
1756 local old_commit3=`git_show_head $testroot/repo`
1758 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1760 if [ $ret -ne 0 ]; then
1761 test_done "$testroot" "$ret"
1765 cat > $testroot/editor.sh <<EOF
1772 chmod +x $testroot/editor.sh
1774 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1775 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1777 local new_commit1=`git_show_head $testroot/repo`
1779 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1780 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1781 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1782 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1783 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1784 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1786 echo "G alpha" > $testroot/stdout.expected
1787 echo "D beta" >> $testroot/stdout.expected
1788 echo "A epsilon/new" >> $testroot/stdout.expected
1789 echo "$short_old_commit1 -> fold commit: committing changes" \
1790 >> $testroot/stdout.expected
1791 echo "G epsilon/zeta" >> $testroot/stdout.expected
1792 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1793 echo "fold commit: committing to zeta on master" \
1794 >> $testroot/stdout.expected
1795 echo "G gamma/delta" >> $testroot/stdout.expected
1796 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1797 >> $testroot/stdout.expected
1798 echo "# log message of folded commit $very_short_old_commit1" \
1799 >> $testroot/stdout.expected
1800 echo "Switching work tree to refs/heads/master" \
1801 >> $testroot/stdout.expected
1803 cmp -s $testroot/stdout.expected $testroot/stdout
1805 if [ $ret -ne 0 ]; then
1806 diff -u $testroot/stdout.expected $testroot/stdout
1807 test_done "$testroot" "$ret"
1811 echo "modified alpha on master" > $testroot/content.expected
1812 cat $testroot/wt/alpha > $testroot/content
1813 cmp -s $testroot/content.expected $testroot/content
1815 if [ $ret -ne 0 ]; then
1816 diff -u $testroot/content.expected $testroot/content
1817 test_done "$testroot" "$ret"
1821 if [ -e $testroot/wt/beta ]; then
1822 echo "removed file beta still exists on disk" >&2
1823 test_done "$testroot" "1"
1827 echo "new file on master" > $testroot/content.expected
1828 cat $testroot/wt/epsilon/new > $testroot/content
1829 cmp -s $testroot/content.expected $testroot/content
1831 if [ $ret -ne 0 ]; then
1832 diff -u $testroot/content.expected $testroot/content
1833 test_done "$testroot" "$ret"
1837 (cd $testroot/wt && got status > $testroot/stdout)
1839 echo -n > $testroot/stdout.expected
1840 cmp -s $testroot/stdout.expected $testroot/stdout
1842 if [ $ret -ne 0 ]; then
1843 diff -u $testroot/stdout.expected $testroot/stdout
1844 test_done "$testroot" "$ret"
1848 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1849 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1850 echo "commit $orig_commit" >> $testroot/stdout.expected
1851 cmp -s $testroot/stdout.expected $testroot/stdout
1853 if [ $ret -ne 0 ]; then
1854 diff -u $testroot/stdout.expected $testroot/stdout
1856 test_done "$testroot" "$ret"
1859 test_histedit_edit_only() {
1860 local testroot=`test_init histedit_edit_only`
1862 local orig_commit=`git_show_head $testroot/repo`
1864 echo "modified alpha on master" > $testroot/repo/alpha
1865 (cd $testroot/repo && git rm -q beta)
1866 echo "new file on master" > $testroot/repo/epsilon/new
1867 (cd $testroot/repo && git add epsilon/new)
1868 git_commit $testroot/repo -m "committing changes"
1869 local old_commit1=`git_show_head $testroot/repo`
1871 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1872 git_commit $testroot/repo -m "committing to zeta on master"
1873 local old_commit2=`git_show_head $testroot/repo`
1875 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1877 if [ $ret -ne 0 ]; then
1878 test_done "$testroot" "$ret"
1882 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1884 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1885 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1887 echo "G alpha" > $testroot/stdout.expected
1888 echo "D beta" >> $testroot/stdout.expected
1889 echo "A epsilon/new" >> $testroot/stdout.expected
1890 echo "Stopping histedit for amending commit $old_commit1" \
1891 >> $testroot/stdout.expected
1892 cmp -s $testroot/stdout.expected $testroot/stdout
1894 if [ $ret -ne 0 ]; then
1895 diff -u $testroot/stdout.expected $testroot/stdout
1896 test_done "$testroot" "$ret"
1900 echo "edited modified alpha on master" > $testroot/wt/alpha
1902 cat > $testroot/editor.sh <<EOF
1905 ,s/.*/committing edited changes 1/
1909 chmod +x $testroot/editor.sh
1911 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1912 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1914 local new_commit1=$(cd $testroot/wt && got info | \
1915 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1916 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1918 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1919 > $testroot/stdout.expected
1920 echo "committing edited changes 1" >> $testroot/stdout.expected
1921 echo "G epsilon/zeta" >> $testroot/stdout.expected
1922 echo "Stopping histedit for amending commit $old_commit2" \
1923 >> $testroot/stdout.expected
1924 cmp -s $testroot/stdout.expected $testroot/stdout
1926 if [ $ret -ne 0 ]; then
1927 diff -u $testroot/stdout.expected $testroot/stdout
1928 test_done "$testroot" "$ret"
1932 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1934 cat > $testroot/editor.sh <<EOF
1937 ,s/.*/committing edited changes 2/
1941 chmod +x $testroot/editor.sh
1943 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1944 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1946 local new_commit2=`git_show_head $testroot/repo`
1947 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1949 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1950 > $testroot/stdout.expected
1951 echo "committing edited changes 2" >> $testroot/stdout.expected
1952 echo "Switching work tree to refs/heads/master" \
1953 >> $testroot/stdout.expected
1955 cmp -s $testroot/stdout.expected $testroot/stdout
1957 if [ $ret -ne 0 ]; then
1958 diff -u $testroot/stdout.expected $testroot/stdout
1959 test_done "$testroot" "$ret"
1963 echo "edited modified alpha on master" > $testroot/content.expected
1964 cat $testroot/wt/alpha > $testroot/content
1965 cmp -s $testroot/content.expected $testroot/content
1967 if [ $ret -ne 0 ]; then
1968 diff -u $testroot/content.expected $testroot/content
1969 test_done "$testroot" "$ret"
1973 if [ -e $testroot/wt/beta ]; then
1974 echo "removed file beta still exists on disk" >&2
1975 test_done "$testroot" "1"
1979 echo "new file on master" > $testroot/content.expected
1980 cat $testroot/wt/epsilon/new > $testroot/content
1981 cmp -s $testroot/content.expected $testroot/content
1983 if [ $ret -ne 0 ]; then
1984 diff -u $testroot/content.expected $testroot/content
1985 test_done "$testroot" "$ret"
1989 (cd $testroot/wt && got status > $testroot/stdout)
1991 echo -n > $testroot/stdout.expected
1992 cmp -s $testroot/stdout.expected $testroot/stdout
1994 if [ $ret -ne 0 ]; then
1995 diff -u $testroot/stdout.expected $testroot/stdout
1996 test_done "$testroot" "$ret"
2000 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
2001 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
2002 echo "commit $new_commit1" >> $testroot/stdout.expected
2003 echo "commit $orig_commit" >> $testroot/stdout.expected
2004 cmp -s $testroot/stdout.expected $testroot/stdout
2006 if [ $ret -ne 0 ]; then
2007 diff -u $testroot/stdout.expected $testroot/stdout
2009 test_done "$testroot" "$ret"
2012 test_histedit_prepend_line() {
2013 local testroot=`test_init histedit_prepend_line`
2014 local orig_commit=`git_show_head $testroot/repo`
2016 got checkout $testroot/repo $testroot/wt > /dev/null
2018 ed -s "$testroot/wt/alpha" <<EOF
2025 cp $testroot/wt/alpha $testroot/content.expected
2027 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2030 if [ "$?" != 0 ]; then
2031 echo "got commit failed unexpectedly" >&2
2032 test_done "$testroot" "$ret"
2036 local top_commit=`git_show_head $testroot/repo`
2037 echo "pick $top_commit" > "$testroot/histedit-script"
2039 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2041 if [ "$?" != 0 ]; then
2042 echo "got update failed unexpectedly" >&2
2043 test_done "$testroot" "$ret"
2047 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
2050 if [ "$?" != 0 ]; then
2051 echo "got histedit failed unexpectedly" >&2
2052 test_done "$testroot" "$ret"
2056 cp $testroot/wt/alpha $testroot/content
2057 cmp -s $testroot/content.expected $testroot/content
2059 if [ $ret -ne 0 ]; then
2060 diff -u $testroot/content.expected $testroot/content
2061 test_done "$testroot" "$ret"
2065 test_done "$testroot" $ret
2068 test_histedit_mesg_invalid() {
2069 local testroot=`test_init mesg_invalid`
2071 local orig_commit=`git_show_head $testroot/repo`
2073 echo "modified alpha on master" > $testroot/repo/alpha
2074 (cd $testroot/repo && git rm -q beta)
2075 echo "new file on master" > $testroot/repo/epsilon/new
2076 (cd $testroot/repo && git add epsilon/new)
2077 git_commit $testroot/repo -m 'committing changes'
2078 local old_commit1=`git_show_head $testroot/repo`
2080 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2081 git_commit $testroot/repo -m 'committing to zeto on master'
2082 local old_commit2=`git_show_head $testroot/repo`
2084 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2086 if [ $ret -ne 0 ]; then
2087 test_done "$testroot" $ret
2091 # try with a leading mesg
2093 echo "mesg something something" > $testroot/histedit-script
2094 echo "pick $old_commit1" >> $testroot/histedit-script
2095 echo "pick $old_commit2" >> $testroot/histedit-script
2097 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2098 > $testroot/stdout 2> $testroot/stderr)
2100 if [ $ret -eq 0 ]; then
2101 echo "histedit succeeded unexpectedly" >&2
2102 test_done "$testroot" 1
2106 echo "got: bad histedit command" > $testroot/stderr.expected
2107 cmp -s $testroot/stderr.expected $testroot/stderr
2109 if [ $ret -ne 0 ]; then
2110 diff -u $testroot/stderr.expected $testroot/stderr
2111 test_done "$testroot" $ret
2115 # try again with mesg -> mesg
2117 echo "pick $old_commit1" > $testroot/histedit-script
2118 echo "mesg something something" >> $testroot/histedit-script
2119 echo "mesg something something else" >> $testroot/histedit-script
2120 echo "pick $old_commit2" >> $testroot/histedit-script
2122 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2123 > $testroot/stdout 2> $testroot/stderr)
2125 if [ $ret -eq 0 ]; then
2126 echo "histedit succeeded unexpectedly" >&2
2127 test_done "$testroot" 1
2131 echo "got: bad histedit command" > $testroot/stderr.expected
2132 cmp -s $testroot/stderr.expected $testroot/stderr
2134 if [ $ret -ne 0 ]; then
2135 diff -u $testroot/stderr.expected $testroot/stderr
2136 test_done "$testroot" $ret
2140 # try again with drop -> mesg
2142 echo "drop $old_commit1" > $testroot/histedit-script
2143 echo "mesg something something" >> $testroot/histedit-script
2144 echo "pick $old_commit2" >> $testroot/histedit-script
2146 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2147 > $testroot/stdout 2> $testroot/stderr)
2149 if [ $ret -eq 0 ]; then
2150 echo "histedit succeeded unexpectedly" >&2
2151 test_done "$testroot" 1
2155 echo "got: bad histedit command" > $testroot/stderr.expected
2156 cmp -s $testroot/stderr.expected $testroot/stderr
2158 if [ $ret -ne 0 ]; then
2159 diff -u $testroot/stderr.expected $testroot/stderr
2160 test_done "$testroot" $ret
2164 # try again with fold -> mesg
2166 echo "fold $old_commit1" > $testroot/histedit-script
2167 echo "mesg something something" >> $testroot/histedit-script
2168 echo "pick $old_commit2" >> $testroot/histedit-script
2170 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2171 > $testroot/stdout 2> $testroot/stderr)
2173 if [ $ret -eq 0 ]; then
2174 echo "histedit succeeded unexpectedly" >&2
2175 test_done "$testroot" 1
2179 echo "got: bad histedit command" > $testroot/stderr.expected
2180 cmp -s $testroot/stderr.expected $testroot/stderr
2182 if [ $ret -ne 0 ]; then
2183 diff -u $testroot/stderr.expected $testroot/stderr
2185 test_done "$testroot" $ret
2188 test_histedit_resets_committer() {
2189 local testroot=`test_init histedit_resets_committer`
2190 local orig_commit=`git_show_head $testroot/repo`
2191 local committer="Flan Luck <flan_luck@openbsd.org>"
2193 got checkout $testroot/repo $testroot/wt > /dev/null
2195 echo "modified alpha" > $testroot/wt/alpha
2197 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2200 if [ "$?" != 0 ]; then
2201 echo "got commit failed unexpectedly" >&2
2202 test_done "$testroot" "$ret"
2206 local top_commit=`git_show_head $testroot/repo`
2207 echo "pick $top_commit" > "$testroot/histedit-script"
2209 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2211 if [ "$?" != 0 ]; then
2212 echo "got update failed unexpectedly" >&2
2213 test_done "$testroot" "$ret"
2217 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2218 got histedit -F "$testroot/histedit-script" > /dev/null)
2220 if [ "$?" != 0 ]; then
2221 echo "got histedit failed unexpectedly" >&2
2222 test_done "$testroot" "$ret"
2225 local edited_commit=`git_show_head $testroot/repo`
2227 # Original commit only had one author
2228 (cd $testroot/repo && got log -l1 -c $top_commit | \
2229 egrep '^(from|via):' > $testroot/stdout)
2230 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2231 cmp -s $testroot/stdout.expected $testroot/stdout
2233 if [ $ret -ne 0 ]; then
2234 diff -u $testroot/stdout.expected $testroot/stdout
2235 test_done "$testroot" "$ret"
2239 # Edited commit should have new committer name added
2240 (cd $testroot/repo && got log -l1 -c $edited_commit | \
2241 egrep '^(from|via):' > $testroot/stdout)
2242 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2243 echo "via: $committer" >> $testroot/stdout.expected
2245 cmp -s $testroot/stdout.expected $testroot/stdout
2247 if [ $ret -ne 0 ]; then
2248 diff -u $testroot/stdout.expected $testroot/stdout
2250 test_done "$testroot" "$ret"
2253 test_histedit_umask() {
2254 local testroot=`test_init histedit_umask`
2255 local orig_commit=`git_show_head "$testroot/repo"`
2257 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
2259 echo "modified alpha" > $testroot/wt/alpha
2260 (cd "$testroot/wt" && got commit -m 'edit #1') >/dev/null
2261 local commit1=`git_show_head "$testroot/repo"`
2263 echo "modified again" > $testroot/wt/alpha
2264 (cd "$testroot/wt" && got commit -m 'edit #2') >/dev/null
2265 local commit2=`git_show_head "$testroot/repo"`
2267 echo "modified again!" > $testroot/wt/alpha
2268 echo "modify beta too!" > $testroot/wt/beta
2269 (cd "$testroot/wt" && got commit -m 'edit #3') >/dev/null
2270 local commit3=`git_show_head "$testroot/repo"`
2272 (cd "$testroot/wt" && got update -c "$orig_commit") >/dev/null
2274 if [ $ret -ne 0 ]; then
2275 echo "update to $orig_commit failed!" >&2
2276 test_done "$testroot" 1
2280 echo fold $commit1 >$testroot/histedit-script
2281 echo fold $commit2 >>$testroot/histedit-script
2282 echo pick $commit3 >>$testroot/histedit-script
2283 echo mesg folding changes >>$testroot/histedit-script
2285 # using a subshell to avoid clobbering global umask
2286 (umask 077 && cd "$testroot/wt" && \
2287 got histedit -F "$testroot/histedit-script") >/dev/null
2290 if [ $ret -ne 0 ]; then
2291 echo "histedit operation failed" >&2
2292 test_done "$testroot" $ret
2296 for f in alpha beta; do
2297 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
2298 if [ $? -ne 0 ]; then
2299 echo "$f is not 0600 after histedi" >&2
2300 ls -l "$testroot/wt/$f" >&2
2301 test_done "$testroot" 1
2306 test_done "$testroot" 0
2309 test_histedit_mesg_filemode_change() {
2310 local testroot=`test_init histedit_mode_change`
2312 local orig_commit=`git_show_head $testroot/repo`
2313 local orig_author_time=`git_show_author_time $testroot/repo`
2315 chmod +x $testroot/repo/alpha
2316 git_commit $testroot/repo -m "set x bit on alpha"
2317 local old_commit1=`git_show_head $testroot/repo`
2318 local old_author_time1=`git_show_author_time $testroot/repo`
2320 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2322 if [ $ret -ne 0 ]; then
2323 test_done "$testroot" "$ret"
2327 if [ -x $testroot/wt/alpha ]; then
2328 echo "file alpha has unexpected executable bit" >&2
2329 test_done "$testroot" "1"
2333 cat > $testroot/editor.sh <<EOF
2336 ,s/ x bit / executable bit /
2341 chmod +x $testroot/editor.sh
2343 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2344 got histedit -m > $testroot/stdout)
2346 local new_commit1=`git_show_head $testroot/repo`
2347 local new_author_time1=`git_show_author_time $testroot/repo`
2349 local short_old_commit1=`trim_obj_id 28 $old_commit1`
2350 local short_new_commit1=`trim_obj_id 28 $new_commit1`
2352 echo "G alpha" > $testroot/stdout.expected
2353 echo "$short_old_commit1 -> $short_new_commit1: set executable bit on alpha" \
2354 >> $testroot/stdout.expected
2355 echo "Switching work tree to refs/heads/master" \
2356 >> $testroot/stdout.expected
2358 cmp -s $testroot/stdout.expected $testroot/stdout
2360 if [ $ret -ne 0 ]; then
2361 diff -u $testroot/stdout.expected $testroot/stdout
2362 test_done "$testroot" "$ret"
2366 echo "alpha" > $testroot/content.expected
2367 cmp -s $testroot/content.expected $testroot/wt/alpha
2369 if [ $ret -ne 0 ]; then
2370 diff -u $testroot/content.expected $testroot/wt/alpha
2371 test_done "$testroot" "$ret"
2375 if [ ! -x $testroot/wt/alpha ]; then
2376 echo "file alpha lost its executable bit" >&2
2377 test_done "$testroot" "1"
2381 (cd $testroot/wt && got status > $testroot/stdout)
2383 echo -n > $testroot/stdout.expected
2384 cmp -s $testroot/stdout.expected $testroot/stdout
2386 if [ $ret -ne 0 ]; then
2387 diff -u $testroot/stdout.expected $testroot/stdout
2388 test_done "$testroot" "$ret"
2392 (cd $testroot/wt && got log -l1 | grep ' set executable bit on alpha' \
2395 echo ' set executable bit on alpha' > $testroot/stdout.expected
2396 cmp -s $testroot/stdout.expected $testroot/stdout
2398 if [ $ret -ne 0 ]; then
2399 diff -u $testroot/stdout.expected $testroot/stdout
2400 test_done "$testroot" "$ret"
2404 test_done "$testroot" "$ret"
2407 test_histedit_drop_only() {
2408 local testroot=`test_init histedit_drop_only`
2410 local orig_commit=`git_show_head $testroot/repo`
2411 local drop="-> drop commit:"
2412 local dropmsg="commit changes to drop"
2414 echo "modified alpha on master" > $testroot/repo/alpha
2415 (cd $testroot/repo && git rm -q beta)
2416 echo "new file on master" > $testroot/repo/epsilon/new
2417 (cd $testroot/repo && git add epsilon/new)
2419 git_commit $testroot/repo -m "$dropmsg 1"
2420 local drop_commit1=`git_show_head $testroot/repo`
2422 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2424 git_commit $testroot/repo -m "$dropmsg 2"
2425 local drop_commit2=`git_show_head $testroot/repo`
2427 echo "modified delta on master" > $testroot/repo/gamma/delta
2429 git_commit $testroot/repo -m "$dropmsg 3"
2430 local drop_commit3=`git_show_head $testroot/repo`
2432 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2434 if [ $ret -ne 0 ]; then
2435 test_done "$testroot" "$ret"
2439 (cd $testroot/wt && got histedit -d > $testroot/stdout)
2440 local new_commit1=`git_show_head $testroot/repo`
2442 local short_commit1=`trim_obj_id 28 $drop_commit1`
2443 local short_commit2=`trim_obj_id 28 $drop_commit2`
2444 local short_commit3=`trim_obj_id 28 $drop_commit3`
2446 echo "$short_commit1 $drop $dropmsg 1" > $testroot/stdout.expected
2447 echo "$short_commit2 $drop $dropmsg 2" >> $testroot/stdout.expected
2448 echo "$short_commit3 $drop $dropmsg 3" >> $testroot/stdout.expected
2449 echo "Switching work tree to refs/heads/master" \
2450 >> $testroot/stdout.expected
2452 cmp -s $testroot/stdout.expected $testroot/stdout
2454 if [ $ret -ne 0 ]; then
2455 diff -u $testroot/stdout.expected $testroot/stdout
2456 test_done "$testroot" "$ret"
2460 echo "alpha" > $testroot/content.expected
2461 cat $testroot/wt/alpha > $testroot/content
2462 cmp -s $testroot/content.expected $testroot/content
2464 if [ $ret -ne 0 ]; then
2465 diff -u $testroot/content.expected $testroot/content
2466 test_done "$testroot" "$ret"
2470 echo "zeta" > $testroot/content.expected
2471 cat $testroot/wt/epsilon/zeta > $testroot/content
2472 cmp -s $testroot/content.expected $testroot/content
2474 if [ $ret -ne 0 ]; then
2475 diff -u $testroot/content.expected $testroot/content
2476 test_done "$testroot" "$ret"
2480 echo "delta" > $testroot/content.expected
2481 cat $testroot/wt/gamma/delta > $testroot/content
2482 cmp -s $testroot/content.expected $testroot/content
2484 if [ $ret -ne 0 ]; then
2485 diff -u $testroot/content.expected $testroot/content
2486 test_done "$testroot" "$ret"
2490 if [ ! -e $testroot/wt/beta ]; then
2491 echo "removed file beta should be restored" >&2
2492 test_done "$testroot" "1"
2496 if [ -e $testroot/wt/new ]; then
2497 echo "new file should no longer exist" >&2
2498 test_done "$testroot" "$ret"
2502 (cd $testroot/wt && got status > $testroot/stdout)
2504 echo -n > $testroot/stdout.expected
2505 cmp -s $testroot/stdout.expected $testroot/stdout
2507 if [ $ret -ne 0 ]; then
2508 diff -u $testroot/stdout.expected $testroot/stdout
2509 test_done "$testroot" "$ret"
2513 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2514 echo "commit $orig_commit (master)" > $testroot/stdout.expected
2515 cmp -s $testroot/stdout.expected $testroot/stdout
2517 if [ $ret -ne 0 ]; then
2518 diff -u $testroot/stdout.expected $testroot/stdout
2520 test_done "$testroot" "$ret"
2524 run_test test_histedit_no_op
2525 run_test test_histedit_swap
2526 run_test test_histedit_drop
2527 run_test test_histedit_fold
2528 run_test test_histedit_edit
2529 run_test test_histedit_fold_last_commit
2530 run_test test_histedit_missing_commit
2531 run_test test_histedit_abort
2532 run_test test_histedit_path_prefix_drop
2533 run_test test_histedit_path_prefix_edit
2534 run_test test_histedit_outside_refs_heads
2535 run_test test_histedit_fold_last_commit_swap
2536 run_test test_histedit_split_commit
2537 run_test test_histedit_duplicate_commit_in_script
2538 run_test test_histedit_fold_add_delete
2539 run_test test_histedit_fold_delete_add
2540 run_test test_histedit_fold_only
2541 run_test test_histedit_fold_only_empty_logmsg
2542 run_test test_histedit_edit_only
2543 run_test test_histedit_prepend_line
2544 run_test test_histedit_mesg_invalid
2545 run_test test_histedit_resets_committer
2546 run_test test_histedit_umask
2547 run_test test_histedit_mesg_filemode_change
2548 run_test test_histedit_drop_only