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 ret="xfail fold deleted and added file"
1604 test_done "$testroot" "$ret"
1607 test_histedit_fold_only() {
1608 local testroot=`test_init histedit_fold_only`
1610 local orig_commit=`git_show_head $testroot/repo`
1612 echo "modified alpha on master" > $testroot/repo/alpha
1613 (cd $testroot/repo && git rm -q beta)
1614 echo "new file on master" > $testroot/repo/epsilon/new
1615 (cd $testroot/repo && git add epsilon/new)
1616 git_commit $testroot/repo -m "committing changes"
1617 local old_commit1=`git_show_head $testroot/repo`
1619 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1620 git_commit $testroot/repo -m "committing to zeta on master"
1621 local old_commit2=`git_show_head $testroot/repo`
1623 echo "modified delta on master" > $testroot/repo/gamma/delta
1624 git_commit $testroot/repo -m "committing to delta on master"
1625 local old_commit3=`git_show_head $testroot/repo`
1627 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1629 if [ $ret -ne 0 ]; then
1630 test_done "$testroot" "$ret"
1634 cat > $testroot/editor.sh <<EOF
1637 ,s/.*/committing folded changes/
1641 chmod +x $testroot/editor.sh
1643 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1644 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1646 local new_commit1=`git_show_head $testroot/repo`
1648 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1649 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1650 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1651 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1652 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1654 echo "G alpha" > $testroot/stdout.expected
1655 echo "D beta" >> $testroot/stdout.expected
1656 echo "A epsilon/new" >> $testroot/stdout.expected
1657 echo "$short_old_commit1 -> fold commit: committing changes" \
1658 >> $testroot/stdout.expected
1659 echo "G epsilon/zeta" >> $testroot/stdout.expected
1660 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1661 echo "fold commit: committing to zeta on master" \
1662 >> $testroot/stdout.expected
1663 echo "G gamma/delta" >> $testroot/stdout.expected
1664 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1665 >> $testroot/stdout.expected
1666 echo "committing folded changes" >> $testroot/stdout.expected
1667 echo "Switching work tree to refs/heads/master" \
1668 >> $testroot/stdout.expected
1670 cmp -s $testroot/stdout.expected $testroot/stdout
1672 if [ $ret -ne 0 ]; then
1673 diff -u $testroot/stdout.expected $testroot/stdout
1674 test_done "$testroot" "$ret"
1678 echo "modified alpha on master" > $testroot/content.expected
1679 cat $testroot/wt/alpha > $testroot/content
1680 cmp -s $testroot/content.expected $testroot/content
1682 if [ $ret -ne 0 ]; then
1683 diff -u $testroot/content.expected $testroot/content
1684 test_done "$testroot" "$ret"
1688 if [ -e $testroot/wt/beta ]; then
1689 echo "removed file beta still exists on disk" >&2
1690 test_done "$testroot" "1"
1694 echo "new file on master" > $testroot/content.expected
1695 cat $testroot/wt/epsilon/new > $testroot/content
1696 cmp -s $testroot/content.expected $testroot/content
1698 if [ $ret -ne 0 ]; then
1699 diff -u $testroot/content.expected $testroot/content
1700 test_done "$testroot" "$ret"
1704 (cd $testroot/wt && got status > $testroot/stdout)
1706 echo -n > $testroot/stdout.expected
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1709 if [ $ret -ne 0 ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1711 test_done "$testroot" "$ret"
1715 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1716 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1717 echo "commit $orig_commit" >> $testroot/stdout.expected
1718 cmp -s $testroot/stdout.expected $testroot/stdout
1720 if [ $ret -ne 0 ]; then
1721 diff -u $testroot/stdout.expected $testroot/stdout
1723 test_done "$testroot" "$ret"
1726 test_histedit_fold_only_empty_logmsg() {
1727 local testroot=`test_init histedit_fold_only_empty_logmsg`
1729 local orig_commit=`git_show_head $testroot/repo`
1731 echo "modified alpha on master" > $testroot/repo/alpha
1732 (cd $testroot/repo && git rm -q beta)
1733 echo "new file on master" > $testroot/repo/epsilon/new
1734 (cd $testroot/repo && git add epsilon/new)
1735 git_commit $testroot/repo -m "committing changes"
1736 local old_commit1=`git_show_head $testroot/repo`
1738 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1739 git_commit $testroot/repo -m "committing to zeta on master"
1740 local old_commit2=`git_show_head $testroot/repo`
1742 echo "modified delta on master" > $testroot/repo/gamma/delta
1743 git_commit $testroot/repo -m "committing to delta on master"
1744 local old_commit3=`git_show_head $testroot/repo`
1746 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1748 if [ $ret -ne 0 ]; then
1749 test_done "$testroot" "$ret"
1753 cat > $testroot/editor.sh <<EOF
1760 chmod +x $testroot/editor.sh
1762 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1763 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1765 local new_commit1=`git_show_head $testroot/repo`
1767 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1768 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1769 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1770 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1771 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1772 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1774 echo "G alpha" > $testroot/stdout.expected
1775 echo "D beta" >> $testroot/stdout.expected
1776 echo "A epsilon/new" >> $testroot/stdout.expected
1777 echo "$short_old_commit1 -> fold commit: committing changes" \
1778 >> $testroot/stdout.expected
1779 echo "G epsilon/zeta" >> $testroot/stdout.expected
1780 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1781 echo "fold commit: committing to zeta on master" \
1782 >> $testroot/stdout.expected
1783 echo "G gamma/delta" >> $testroot/stdout.expected
1784 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1785 >> $testroot/stdout.expected
1786 echo "# log message of folded commit $very_short_old_commit1" \
1787 >> $testroot/stdout.expected
1788 echo "Switching work tree to refs/heads/master" \
1789 >> $testroot/stdout.expected
1791 cmp -s $testroot/stdout.expected $testroot/stdout
1793 if [ $ret -ne 0 ]; then
1794 diff -u $testroot/stdout.expected $testroot/stdout
1795 test_done "$testroot" "$ret"
1799 echo "modified alpha on master" > $testroot/content.expected
1800 cat $testroot/wt/alpha > $testroot/content
1801 cmp -s $testroot/content.expected $testroot/content
1803 if [ $ret -ne 0 ]; then
1804 diff -u $testroot/content.expected $testroot/content
1805 test_done "$testroot" "$ret"
1809 if [ -e $testroot/wt/beta ]; then
1810 echo "removed file beta still exists on disk" >&2
1811 test_done "$testroot" "1"
1815 echo "new file on master" > $testroot/content.expected
1816 cat $testroot/wt/epsilon/new > $testroot/content
1817 cmp -s $testroot/content.expected $testroot/content
1819 if [ $ret -ne 0 ]; then
1820 diff -u $testroot/content.expected $testroot/content
1821 test_done "$testroot" "$ret"
1825 (cd $testroot/wt && got status > $testroot/stdout)
1827 echo -n > $testroot/stdout.expected
1828 cmp -s $testroot/stdout.expected $testroot/stdout
1830 if [ $ret -ne 0 ]; then
1831 diff -u $testroot/stdout.expected $testroot/stdout
1832 test_done "$testroot" "$ret"
1836 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1837 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1838 echo "commit $orig_commit" >> $testroot/stdout.expected
1839 cmp -s $testroot/stdout.expected $testroot/stdout
1841 if [ $ret -ne 0 ]; then
1842 diff -u $testroot/stdout.expected $testroot/stdout
1844 test_done "$testroot" "$ret"
1847 test_histedit_edit_only() {
1848 local testroot=`test_init histedit_edit_only`
1850 local orig_commit=`git_show_head $testroot/repo`
1852 echo "modified alpha on master" > $testroot/repo/alpha
1853 (cd $testroot/repo && git rm -q beta)
1854 echo "new file on master" > $testroot/repo/epsilon/new
1855 (cd $testroot/repo && git add epsilon/new)
1856 git_commit $testroot/repo -m "committing changes"
1857 local old_commit1=`git_show_head $testroot/repo`
1859 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1860 git_commit $testroot/repo -m "committing to zeta on master"
1861 local old_commit2=`git_show_head $testroot/repo`
1863 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1865 if [ $ret -ne 0 ]; then
1866 test_done "$testroot" "$ret"
1870 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1872 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1873 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1875 echo "G alpha" > $testroot/stdout.expected
1876 echo "D beta" >> $testroot/stdout.expected
1877 echo "A epsilon/new" >> $testroot/stdout.expected
1878 echo "Stopping histedit for amending commit $old_commit1" \
1879 >> $testroot/stdout.expected
1880 cmp -s $testroot/stdout.expected $testroot/stdout
1882 if [ $ret -ne 0 ]; then
1883 diff -u $testroot/stdout.expected $testroot/stdout
1884 test_done "$testroot" "$ret"
1888 echo "edited modified alpha on master" > $testroot/wt/alpha
1890 cat > $testroot/editor.sh <<EOF
1893 ,s/.*/committing edited changes 1/
1897 chmod +x $testroot/editor.sh
1899 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1900 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1902 local new_commit1=$(cd $testroot/wt && got info | \
1903 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1904 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1906 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1907 > $testroot/stdout.expected
1908 echo "committing edited changes 1" >> $testroot/stdout.expected
1909 echo "G epsilon/zeta" >> $testroot/stdout.expected
1910 echo "Stopping histedit for amending commit $old_commit2" \
1911 >> $testroot/stdout.expected
1912 cmp -s $testroot/stdout.expected $testroot/stdout
1914 if [ $ret -ne 0 ]; then
1915 diff -u $testroot/stdout.expected $testroot/stdout
1916 test_done "$testroot" "$ret"
1920 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1922 cat > $testroot/editor.sh <<EOF
1925 ,s/.*/committing edited changes 2/
1929 chmod +x $testroot/editor.sh
1931 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1932 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1934 local new_commit2=`git_show_head $testroot/repo`
1935 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1937 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1938 > $testroot/stdout.expected
1939 echo "committing edited changes 2" >> $testroot/stdout.expected
1940 echo "Switching work tree to refs/heads/master" \
1941 >> $testroot/stdout.expected
1943 cmp -s $testroot/stdout.expected $testroot/stdout
1945 if [ $ret -ne 0 ]; then
1946 diff -u $testroot/stdout.expected $testroot/stdout
1947 test_done "$testroot" "$ret"
1951 echo "edited modified alpha on master" > $testroot/content.expected
1952 cat $testroot/wt/alpha > $testroot/content
1953 cmp -s $testroot/content.expected $testroot/content
1955 if [ $ret -ne 0 ]; then
1956 diff -u $testroot/content.expected $testroot/content
1957 test_done "$testroot" "$ret"
1961 if [ -e $testroot/wt/beta ]; then
1962 echo "removed file beta still exists on disk" >&2
1963 test_done "$testroot" "1"
1967 echo "new file on master" > $testroot/content.expected
1968 cat $testroot/wt/epsilon/new > $testroot/content
1969 cmp -s $testroot/content.expected $testroot/content
1971 if [ $ret -ne 0 ]; then
1972 diff -u $testroot/content.expected $testroot/content
1973 test_done "$testroot" "$ret"
1977 (cd $testroot/wt && got status > $testroot/stdout)
1979 echo -n > $testroot/stdout.expected
1980 cmp -s $testroot/stdout.expected $testroot/stdout
1982 if [ $ret -ne 0 ]; then
1983 diff -u $testroot/stdout.expected $testroot/stdout
1984 test_done "$testroot" "$ret"
1988 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1989 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
1990 echo "commit $new_commit1" >> $testroot/stdout.expected
1991 echo "commit $orig_commit" >> $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
1997 test_done "$testroot" "$ret"
2000 test_histedit_prepend_line() {
2001 local testroot=`test_init histedit_prepend_line`
2002 local orig_commit=`git_show_head $testroot/repo`
2004 got checkout $testroot/repo $testroot/wt > /dev/null
2006 ed -s "$testroot/wt/alpha" <<EOF
2013 cp $testroot/wt/alpha $testroot/content.expected
2015 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2018 if [ "$?" != 0 ]; then
2019 echo "got commit failed unexpectedly" >&2
2020 test_done "$testroot" "$ret"
2024 local top_commit=`git_show_head $testroot/repo`
2025 echo "pick $top_commit" > "$testroot/histedit-script"
2027 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2029 if [ "$?" != 0 ]; then
2030 echo "got update failed unexpectedly" >&2
2031 test_done "$testroot" "$ret"
2035 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
2038 if [ "$?" != 0 ]; then
2039 echo "got histedit failed unexpectedly" >&2
2040 test_done "$testroot" "$ret"
2044 cp $testroot/wt/alpha $testroot/content
2045 cmp -s $testroot/content.expected $testroot/content
2047 if [ $ret -ne 0 ]; then
2048 diff -u $testroot/content.expected $testroot/content
2049 test_done "$testroot" "$ret"
2053 test_done "$testroot" $ret
2056 test_histedit_mesg_invalid() {
2057 local testroot=`test_init mesg_invalid`
2059 local orig_commit=`git_show_head $testroot/repo`
2061 echo "modified alpha on master" > $testroot/repo/alpha
2062 (cd $testroot/repo && git rm -q beta)
2063 echo "new file on master" > $testroot/repo/epsilon/new
2064 (cd $testroot/repo && git add epsilon/new)
2065 git_commit $testroot/repo -m 'committing changes'
2066 local old_commit1=`git_show_head $testroot/repo`
2068 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2069 git_commit $testroot/repo -m 'committing to zeto on master'
2070 local old_commit2=`git_show_head $testroot/repo`
2072 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2074 if [ $ret -ne 0 ]; then
2075 test_done "$testroot" $ret
2079 # try with a leading mesg
2081 echo "mesg something something" > $testroot/histedit-script
2082 echo "pick $old_commit1" >> $testroot/histedit-script
2083 echo "pick $old_commit2" >> $testroot/histedit-script
2085 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2086 > $testroot/stdout 2> $testroot/stderr)
2088 if [ $ret -eq 0 ]; then
2089 echo "histedit succeeded unexpectedly" >&2
2090 test_done "$testroot" 1
2094 echo "got: bad histedit command" > $testroot/stderr.expected
2095 cmp -s $testroot/stderr.expected $testroot/stderr
2097 if [ $ret -ne 0 ]; then
2098 diff -u $testroot/stderr.expected $testroot/stderr
2099 test_done "$testroot" $ret
2103 # try again with mesg -> mesg
2105 echo "pick $old_commit1" > $testroot/histedit-script
2106 echo "mesg something something" >> $testroot/histedit-script
2107 echo "mesg something something else" >> $testroot/histedit-script
2108 echo "pick $old_commit2" >> $testroot/histedit-script
2110 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2111 > $testroot/stdout 2> $testroot/stderr)
2113 if [ $ret -eq 0 ]; then
2114 echo "histedit succeeded unexpectedly" >&2
2115 test_done "$testroot" 1
2119 echo "got: bad histedit command" > $testroot/stderr.expected
2120 cmp -s $testroot/stderr.expected $testroot/stderr
2122 if [ $ret -ne 0 ]; then
2123 diff -u $testroot/stderr.expected $testroot/stderr
2124 test_done "$testroot" $ret
2128 # try again with drop -> mesg
2130 echo "drop $old_commit1" > $testroot/histedit-script
2131 echo "mesg something something" >> $testroot/histedit-script
2132 echo "pick $old_commit2" >> $testroot/histedit-script
2134 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2135 > $testroot/stdout 2> $testroot/stderr)
2137 if [ $ret -eq 0 ]; then
2138 echo "histedit succeeded unexpectedly" >&2
2139 test_done "$testroot" 1
2143 echo "got: bad histedit command" > $testroot/stderr.expected
2144 cmp -s $testroot/stderr.expected $testroot/stderr
2146 if [ $ret -ne 0 ]; then
2147 diff -u $testroot/stderr.expected $testroot/stderr
2148 test_done "$testroot" $ret
2152 # try again with fold -> mesg
2154 echo "fold $old_commit1" > $testroot/histedit-script
2155 echo "mesg something something" >> $testroot/histedit-script
2156 echo "pick $old_commit2" >> $testroot/histedit-script
2158 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2159 > $testroot/stdout 2> $testroot/stderr)
2161 if [ $ret -eq 0 ]; then
2162 echo "histedit succeeded unexpectedly" >&2
2163 test_done "$testroot" 1
2167 echo "got: bad histedit command" > $testroot/stderr.expected
2168 cmp -s $testroot/stderr.expected $testroot/stderr
2170 if [ $ret -ne 0 ]; then
2171 diff -u $testroot/stderr.expected $testroot/stderr
2173 test_done "$testroot" $ret
2176 test_histedit_resets_committer() {
2177 local testroot=`test_init histedit_resets_committer`
2178 local orig_commit=`git_show_head $testroot/repo`
2179 local committer="Flan Luck <flan_luck@openbsd.org>"
2181 got checkout $testroot/repo $testroot/wt > /dev/null
2183 echo "modified alpha" > $testroot/wt/alpha
2185 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2188 if [ "$?" != 0 ]; then
2189 echo "got commit failed unexpectedly" >&2
2190 test_done "$testroot" "$ret"
2194 local top_commit=`git_show_head $testroot/repo`
2195 echo "pick $top_commit" > "$testroot/histedit-script"
2197 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2199 if [ "$?" != 0 ]; then
2200 echo "got update failed unexpectedly" >&2
2201 test_done "$testroot" "$ret"
2205 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2206 got histedit -F "$testroot/histedit-script" > /dev/null)
2208 if [ "$?" != 0 ]; then
2209 echo "got histedit failed unexpectedly" >&2
2210 test_done "$testroot" "$ret"
2213 local edited_commit=`git_show_head $testroot/repo`
2215 # Original commit only had one author
2216 (cd $testroot/repo && got log -l1 -c $top_commit | \
2217 egrep '^(from|via):' > $testroot/stdout)
2218 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2219 cmp -s $testroot/stdout.expected $testroot/stdout
2221 if [ $ret -ne 0 ]; then
2222 diff -u $testroot/stdout.expected $testroot/stdout
2223 test_done "$testroot" "$ret"
2227 # Edited commit should have new committer name added
2228 (cd $testroot/repo && got log -l1 -c $edited_commit | \
2229 egrep '^(from|via):' > $testroot/stdout)
2230 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2231 echo "via: $committer" >> $testroot/stdout.expected
2233 cmp -s $testroot/stdout.expected $testroot/stdout
2235 if [ $ret -ne 0 ]; then
2236 diff -u $testroot/stdout.expected $testroot/stdout
2238 test_done "$testroot" "$ret"
2241 test_histedit_umask() {
2242 local testroot=`test_init histedit_umask`
2243 local orig_commit=`git_show_head "$testroot/repo"`
2245 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
2247 echo "modified alpha" > $testroot/wt/alpha
2248 (cd "$testroot/wt" && got commit -m 'edit #1') >/dev/null
2249 local commit1=`git_show_head "$testroot/repo"`
2251 echo "modified again" > $testroot/wt/alpha
2252 (cd "$testroot/wt" && got commit -m 'edit #2') >/dev/null
2253 local commit2=`git_show_head "$testroot/repo"`
2255 echo "modified again!" > $testroot/wt/alpha
2256 echo "modify beta too!" > $testroot/wt/beta
2257 (cd "$testroot/wt" && got commit -m 'edit #3') >/dev/null
2258 local commit3=`git_show_head "$testroot/repo"`
2260 (cd "$testroot/wt" && got update -c "$orig_commit") >/dev/null
2262 if [ $ret -ne 0 ]; then
2263 echo "update to $orig_commit failed!" >&2
2264 test_done "$testroot" 1
2268 echo fold $commit1 >$testroot/histedit-script
2269 echo fold $commit2 >>$testroot/histedit-script
2270 echo pick $commit3 >>$testroot/histedit-script
2271 echo mesg folding changes >>$testroot/histedit-script
2273 # using a subshell to avoid clobbering global umask
2274 (umask 077 && cd "$testroot/wt" && \
2275 got histedit -F "$testroot/histedit-script") >/dev/null
2278 if [ $ret -ne 0 ]; then
2279 echo "histedit operation failed" >&2
2280 test_done "$testroot" $ret
2284 for f in alpha beta; do
2285 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
2286 if [ $? -ne 0 ]; then
2287 echo "$f is not 0600 after histedi" >&2
2288 ls -l "$testroot/wt/$f" >&2
2289 test_done "$testroot" 1
2294 test_done "$testroot" 0
2297 test_histedit_mesg_filemode_change() {
2298 local testroot=`test_init histedit_mode_change`
2300 local orig_commit=`git_show_head $testroot/repo`
2301 local orig_author_time=`git_show_author_time $testroot/repo`
2303 chmod +x $testroot/repo/alpha
2304 git_commit $testroot/repo -m "set x bit on alpha"
2305 local old_commit1=`git_show_head $testroot/repo`
2306 local old_author_time1=`git_show_author_time $testroot/repo`
2308 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2310 if [ $ret -ne 0 ]; then
2311 test_done "$testroot" "$ret"
2315 if [ -x $testroot/wt/alpha ]; then
2316 echo "file alpha has unexpected executable bit" >&2
2317 test_done "$testroot" "1"
2321 cat > $testroot/editor.sh <<EOF
2324 ,s/ x bit / executable bit /
2329 chmod +x $testroot/editor.sh
2331 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2332 got histedit -m > $testroot/stdout)
2334 local new_commit1=`git_show_head $testroot/repo`
2335 local new_author_time1=`git_show_author_time $testroot/repo`
2337 local short_old_commit1=`trim_obj_id 28 $old_commit1`
2338 local short_new_commit1=`trim_obj_id 28 $new_commit1`
2340 echo "G alpha" > $testroot/stdout.expected
2341 echo "$short_old_commit1 -> $short_new_commit1: set executable bit on alpha" \
2342 >> $testroot/stdout.expected
2343 echo "Switching work tree to refs/heads/master" \
2344 >> $testroot/stdout.expected
2346 cmp -s $testroot/stdout.expected $testroot/stdout
2348 if [ $ret -ne 0 ]; then
2349 diff -u $testroot/stdout.expected $testroot/stdout
2350 test_done "$testroot" "$ret"
2354 echo "alpha" > $testroot/content.expected
2355 cmp -s $testroot/content.expected $testroot/wt/alpha
2357 if [ $ret -ne 0 ]; then
2358 diff -u $testroot/content.expected $testroot/wt/alpha
2359 test_done "$testroot" "$ret"
2363 if [ ! -x $testroot/wt/alpha ]; then
2364 echo "file alpha lost its executable bit" >&2
2365 test_done "$testroot" "1"
2369 (cd $testroot/wt && got status > $testroot/stdout)
2371 echo -n > $testroot/stdout.expected
2372 cmp -s $testroot/stdout.expected $testroot/stdout
2374 if [ $ret -ne 0 ]; then
2375 diff -u $testroot/stdout.expected $testroot/stdout
2376 test_done "$testroot" "$ret"
2380 (cd $testroot/wt && got log -l1 | grep ' set executable bit on alpha' \
2383 echo ' set executable bit on alpha' > $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 test_done "$testroot" "$ret"
2395 test_histedit_drop_only() {
2396 local testroot=`test_init histedit_drop_only`
2398 local orig_commit=`git_show_head $testroot/repo`
2399 local drop="-> drop commit:"
2400 local dropmsg="commit changes to drop"
2402 echo "modified alpha on master" > $testroot/repo/alpha
2403 (cd $testroot/repo && git rm -q beta)
2404 echo "new file on master" > $testroot/repo/epsilon/new
2405 (cd $testroot/repo && git add epsilon/new)
2407 git_commit $testroot/repo -m "$dropmsg 1"
2408 local drop_commit1=`git_show_head $testroot/repo`
2410 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2412 git_commit $testroot/repo -m "$dropmsg 2"
2413 local drop_commit2=`git_show_head $testroot/repo`
2415 echo "modified delta on master" > $testroot/repo/gamma/delta
2417 git_commit $testroot/repo -m "$dropmsg 3"
2418 local drop_commit3=`git_show_head $testroot/repo`
2420 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2422 if [ $ret -ne 0 ]; then
2423 test_done "$testroot" "$ret"
2427 (cd $testroot/wt && got histedit -d > $testroot/stdout)
2428 local new_commit1=`git_show_head $testroot/repo`
2430 local short_commit1=`trim_obj_id 28 $drop_commit1`
2431 local short_commit2=`trim_obj_id 28 $drop_commit2`
2432 local short_commit3=`trim_obj_id 28 $drop_commit3`
2434 echo "$short_commit1 $drop $dropmsg 1" > $testroot/stdout.expected
2435 echo "$short_commit2 $drop $dropmsg 2" >> $testroot/stdout.expected
2436 echo "$short_commit3 $drop $dropmsg 3" >> $testroot/stdout.expected
2437 echo "Switching work tree to refs/heads/master" \
2438 >> $testroot/stdout.expected
2440 cmp -s $testroot/stdout.expected $testroot/stdout
2442 if [ $ret -ne 0 ]; then
2443 diff -u $testroot/stdout.expected $testroot/stdout
2444 test_done "$testroot" "$ret"
2448 echo "alpha" > $testroot/content.expected
2449 cat $testroot/wt/alpha > $testroot/content
2450 cmp -s $testroot/content.expected $testroot/content
2452 if [ $ret -ne 0 ]; then
2453 diff -u $testroot/content.expected $testroot/content
2454 test_done "$testroot" "$ret"
2458 echo "zeta" > $testroot/content.expected
2459 cat $testroot/wt/epsilon/zeta > $testroot/content
2460 cmp -s $testroot/content.expected $testroot/content
2462 if [ $ret -ne 0 ]; then
2463 diff -u $testroot/content.expected $testroot/content
2464 test_done "$testroot" "$ret"
2468 echo "delta" > $testroot/content.expected
2469 cat $testroot/wt/gamma/delta > $testroot/content
2470 cmp -s $testroot/content.expected $testroot/content
2472 if [ $ret -ne 0 ]; then
2473 diff -u $testroot/content.expected $testroot/content
2474 test_done "$testroot" "$ret"
2478 if [ ! -e $testroot/wt/beta ]; then
2479 echo "removed file beta should be restored" >&2
2480 test_done "$testroot" "1"
2484 if [ -e $testroot/wt/new ]; then
2485 echo "new file should no longer exist" >&2
2486 test_done "$testroot" "$ret"
2490 (cd $testroot/wt && got status > $testroot/stdout)
2492 echo -n > $testroot/stdout.expected
2493 cmp -s $testroot/stdout.expected $testroot/stdout
2495 if [ $ret -ne 0 ]; then
2496 diff -u $testroot/stdout.expected $testroot/stdout
2497 test_done "$testroot" "$ret"
2501 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2502 echo "commit $orig_commit (master)" > $testroot/stdout.expected
2503 cmp -s $testroot/stdout.expected $testroot/stdout
2505 if [ $ret -ne 0 ]; then
2506 diff -u $testroot/stdout.expected $testroot/stdout
2508 test_done "$testroot" "$ret"
2512 run_test test_histedit_no_op
2513 run_test test_histedit_swap
2514 run_test test_histedit_drop
2515 run_test test_histedit_fold
2516 run_test test_histedit_edit
2517 run_test test_histedit_fold_last_commit
2518 run_test test_histedit_missing_commit
2519 run_test test_histedit_abort
2520 run_test test_histedit_path_prefix_drop
2521 run_test test_histedit_path_prefix_edit
2522 run_test test_histedit_outside_refs_heads
2523 run_test test_histedit_fold_last_commit_swap
2524 run_test test_histedit_split_commit
2525 run_test test_histedit_duplicate_commit_in_script
2526 run_test test_histedit_fold_add_delete
2527 run_test test_histedit_fold_delete_add
2528 run_test test_histedit_fold_only
2529 run_test test_histedit_fold_only_empty_logmsg
2530 run_test test_histedit_edit_only
2531 run_test test_histedit_prepend_line
2532 run_test test_histedit_mesg_invalid
2533 run_test test_histedit_resets_committer
2534 run_test test_histedit_umask
2535 run_test test_histedit_mesg_filemode_change
2536 run_test test_histedit_drop_only