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 if [ -e $testroot/wt/epsilon/new ]; then
906 echo "removed file new still exists on disk" >&2
907 test_done "$testroot" "1"
911 (cd $testroot/wt && got status > $testroot/stdout)
913 echo "? unversioned-file" > $testroot/stdout.expected
914 cmp -s $testroot/stdout.expected $testroot/stdout
916 if [ $ret -ne 0 ]; then
917 diff -u $testroot/stdout.expected $testroot/stdout
918 test_done "$testroot" "$ret"
922 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
923 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
924 echo "commit $new_commit1" >> $testroot/stdout.expected
925 echo "commit $orig_commit" >> $testroot/stdout.expected
926 cmp -s $testroot/stdout.expected $testroot/stdout
928 if [ $ret -ne 0 ]; then
929 diff -u $testroot/stdout.expected $testroot/stdout
931 test_done "$testroot" "$ret"
934 test_histedit_path_prefix_drop() {
935 local testroot=`test_init histedit_path_prefix_drop`
936 local orig_commit=`git_show_head $testroot/repo`
938 echo "modified zeta" > $testroot/repo/epsilon/zeta
939 git_commit $testroot/repo -m "changing zeta"
940 local old_commit1=`git_show_head $testroot/repo`
942 got checkout -c $orig_commit -p gamma $testroot/repo \
943 $testroot/wt > /dev/null
945 if [ $ret -ne 0 ]; then
946 test_done "$testroot" "$ret"
950 echo "drop $old_commit1" > $testroot/histedit-script
952 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
953 > $testroot/stdout 2> $testroot/stderr)
956 if [ $ret -eq 0 ]; then
957 echo "histedit succeeded unexpectedly" >&2
958 test_done "$testroot" "1"
962 echo -n "got: cannot edit branch history which contains changes " \
963 > $testroot/stderr.expected
964 echo "outside of this work tree's path prefix" \
965 >> $testroot/stderr.expected
967 cmp -s $testroot/stderr.expected $testroot/stderr
969 if [ $ret -ne 0 ]; then
970 diff -u $testroot/stderr.expected $testroot/stderr
971 test_done "$testroot" "$ret"
976 got checkout -c $orig_commit -p epsilon $testroot/repo \
977 $testroot/wt > /dev/null
979 if [ $ret -ne 0 ]; then
980 test_done "$testroot" "$ret"
983 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
986 local short_old_commit1=`trim_obj_id 28 $old_commit1`
987 local short_old_commit2=`trim_obj_id 28 $old_commit2`
989 echo "$short_old_commit1 -> drop commit: changing zeta" \
990 > $testroot/stdout.expected
991 echo "Switching work tree to refs/heads/master" \
992 >> $testroot/stdout.expected
994 cmp -s $testroot/stdout.expected $testroot/stdout
996 if [ $ret -ne 0 ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 test_done "$testroot" "$ret"
1002 echo "zeta" > $testroot/content.expected
1003 cat $testroot/wt/zeta > $testroot/content
1004 cmp -s $testroot/content.expected $testroot/content
1006 if [ $ret -ne 0 ]; then
1007 diff -u $testroot/content.expected $testroot/content
1008 test_done "$testroot" "$ret"
1013 (cd $testroot/wt && got status > $testroot/stdout)
1015 echo -n > $testroot/stdout.expected
1016 cmp -s $testroot/stdout.expected $testroot/stdout
1018 if [ $ret -ne 0 ]; then
1019 diff -u $testroot/stdout.expected $testroot/stdout
1020 test_done "$testroot" "$ret"
1024 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1025 echo "commit $orig_commit (master)" > $testroot/stdout.expected
1026 cmp -s $testroot/stdout.expected $testroot/stdout
1028 if [ $ret -ne 0 ]; then
1029 diff -u $testroot/stdout.expected $testroot/stdout
1031 test_done "$testroot" "$ret"
1034 test_histedit_path_prefix_edit() {
1035 local testroot=`test_init histedit_path_prefix_edit`
1036 local orig_commit=`git_show_head $testroot/repo`
1038 echo "modified zeta" > $testroot/repo/epsilon/zeta
1039 git_commit $testroot/repo -m "changing zeta"
1040 local old_commit1=`git_show_head $testroot/repo`
1042 got diff -r $testroot/repo $orig_commit $old_commit1 \
1043 > $testroot/diff.expected
1045 got checkout -c $orig_commit -p gamma $testroot/repo \
1046 $testroot/wt > /dev/null
1048 if [ $ret -ne 0 ]; then
1049 test_done "$testroot" "$ret"
1053 echo "edit $old_commit1" > $testroot/histedit-script
1054 echo "mesg modified zeta" >> $testroot/histedit-script
1056 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1057 > $testroot/stdout 2> $testroot/stderr)
1060 if [ $ret -eq 0 ]; then
1061 echo "histedit succeeded unexpectedly" >&2
1062 test_done "$testroot" "1"
1066 echo -n "got: cannot edit branch history which contains changes " \
1067 > $testroot/stderr.expected
1068 echo "outside of this work tree's path prefix" \
1069 >> $testroot/stderr.expected
1071 cmp -s $testroot/stderr.expected $testroot/stderr
1073 if [ $ret -ne 0 ]; then
1074 diff -u $testroot/stderr.expected $testroot/stderr
1075 test_done "$testroot" "$ret"
1080 got checkout -c $orig_commit -p epsilon $testroot/repo \
1081 $testroot/wt > /dev/null
1083 if [ $ret -ne 0 ]; then
1084 test_done "$testroot" "$ret"
1087 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1090 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1092 echo "G zeta" > $testroot/stdout.expected
1093 echo "Stopping histedit for amending commit $old_commit1" \
1094 >> $testroot/stdout.expected
1095 cmp -s $testroot/stdout.expected $testroot/stdout
1097 if [ $ret -ne 0 ]; then
1098 diff -u $testroot/stdout.expected $testroot/stdout
1099 test_done "$testroot" "$ret"
1103 echo "modified zeta" > $testroot/content.expected
1104 cat $testroot/wt/zeta > $testroot/content
1105 cmp -s $testroot/content.expected $testroot/content
1107 if [ $ret -ne 0 ]; then
1108 diff -u $testroot/content.expected $testroot/content
1109 test_done "$testroot" "$ret"
1113 (cd $testroot/wt && got status > $testroot/stdout)
1115 echo "M zeta"> $testroot/stdout.expected
1116 cmp -s $testroot/stdout.expected $testroot/stdout
1118 if [ $ret -ne 0 ]; then
1119 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1124 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1126 local new_commit1=`git_show_head $testroot/repo`
1127 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1129 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1130 > $testroot/stdout.expected
1131 echo "modified zeta" >> $testroot/stdout.expected
1132 echo "Switching work tree to refs/heads/master" \
1133 >> $testroot/stdout.expected
1135 cmp -s $testroot/stdout.expected $testroot/stdout
1137 if [ $ret -ne 0 ]; then
1138 diff -u $testroot/stdout.expected $testroot/stdout
1139 test_done "$testroot" "$ret"
1143 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1144 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1145 echo "commit $orig_commit" >> $testroot/stdout.expected
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1148 if [ $ret -ne 0 ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1154 got diff -r $testroot/repo $orig_commit $new_commit1 \
1156 ed -s $testroot/diff.expected <<-EOF
1157 ,s/$old_commit1/$new_commit1/
1160 cmp -s $testroot/diff.expected $testroot/diff
1162 if [ $ret -ne 0 ]; then
1163 diff -u $testroot/diff.expected $testroot/diff
1165 test_done "$testroot" "$ret"
1168 test_histedit_outside_refs_heads() {
1169 local testroot=`test_init histedit_outside_refs_heads`
1170 local commit1=`git_show_head $testroot/repo`
1172 got checkout $testroot/repo $testroot/wt > /dev/null
1174 if [ $ret -ne 0 ]; then
1175 echo "got checkout failed unexpectedly"
1176 test_done "$testroot" "$ret"
1180 echo "modified alpha" > $testroot/wt/alpha
1182 (cd $testroot/wt && got commit -m 'change alpha' \
1183 > $testroot/stdout 2> $testroot/stderr)
1185 if [ $ret -ne 0 ]; then
1186 echo "got commit failed unexpectedly" >&2
1187 test_done "$testroot" "1"
1190 local commit2=`git_show_head $testroot/repo`
1192 got ref -r $testroot/repo -c master refs/remotes/origin/master
1194 if [ $ret -ne 0 ]; then
1195 echo "got ref failed unexpectedly" >&2
1196 test_done "$testroot" "1"
1200 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1202 if [ $ret -ne 0 ]; then
1203 echo "got update failed unexpectedly"
1204 test_done "$testroot" "$ret"
1208 echo "edit $commit2" > $testroot/histedit-script
1209 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1210 2> $testroot/stderr)
1212 echo -n "got: will not edit commit history of a branch outside the " \
1213 > $testroot/stderr.expected
1214 echo '"refs/heads/" reference namespace' \
1215 >> $testroot/stderr.expected
1216 cmp -s $testroot/stderr.expected $testroot/stderr
1218 if [ $ret -ne 0 ]; then
1219 diff -u $testroot/stderr.expected $testroot/stderr
1221 test_done "$testroot" "$ret"
1224 test_histedit_fold_last_commit_swap() {
1225 local testroot=`test_init histedit_fold_last_commit_swap`
1227 local orig_commit=`git_show_head $testroot/repo`
1229 echo "modified alpha on master" > $testroot/repo/alpha
1230 (cd $testroot/repo && git rm -q beta)
1231 echo "new file on master" > $testroot/repo/epsilon/new
1232 (cd $testroot/repo && git add epsilon/new)
1233 git_commit $testroot/repo -m "committing changes"
1234 local old_commit1=`git_show_head $testroot/repo`
1236 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1237 git_commit $testroot/repo -m "committing to zeta on master"
1238 local old_commit2=`git_show_head $testroot/repo`
1240 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1242 if [ $ret -ne 0 ]; then
1243 test_done "$testroot" "$ret"
1247 # fold commit2 into commit1 (requires swapping commits)
1248 echo "fold $old_commit2" > $testroot/histedit-script
1249 echo "pick $old_commit1" >> $testroot/histedit-script
1250 echo "mesg committing folded changes" >> $testroot/histedit-script
1252 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1253 > $testroot/stdout 2> $testroot/stderr)
1256 if [ $ret -ne 0 ]; then
1257 echo "histedit failed unexpectedly" >&2
1258 test_done "$testroot" "$ret"
1262 local new_commit=`git_show_head $testroot/repo`
1264 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1265 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1266 local short_new_commit=`trim_obj_id 28 $new_commit`
1268 echo "G epsilon/zeta" >> $testroot/stdout.expected
1269 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1270 >> $testroot/stdout.expected
1271 echo "on master" >> $testroot/stdout.expected
1272 echo "G alpha" >> $testroot/stdout.expected
1273 echo "D beta" >> $testroot/stdout.expected
1274 echo "A epsilon/new" >> $testroot/stdout.expected
1275 echo -n "$short_old_commit1 -> $short_new_commit: " \
1276 >> $testroot/stdout.expected
1277 echo "committing folded changes" >> $testroot/stdout.expected
1278 echo "Switching work tree to refs/heads/master" \
1279 >> $testroot/stdout.expected
1281 cmp -s $testroot/stdout.expected $testroot/stdout
1283 if [ $ret -ne 0 ]; then
1284 diff -u $testroot/stdout.expected $testroot/stdout
1286 test_done "$testroot" "$ret"
1289 test_histedit_split_commit() {
1290 local testroot=`test_init histedit_split_commit`
1292 local orig_commit=`git_show_head $testroot/repo`
1294 echo "modified alpha on master" > $testroot/repo/alpha
1295 (cd $testroot/repo && git rm -q beta)
1296 echo "new file on master" > $testroot/repo/epsilon/new
1297 (cd $testroot/repo && git add epsilon/new)
1298 git_commit $testroot/repo -m "committing changes 1"
1299 local old_commit1=`git_show_head $testroot/repo`
1300 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1302 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1303 git_commit $testroot/repo -m "committing changes 2"
1304 local old_commit2=`git_show_head $testroot/repo`
1305 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1307 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1309 if [ $ret -ne 0 ]; then
1310 test_done "$testroot" "$ret"
1314 # split commit1 into commitA and commitB and commitC
1315 echo "e $old_commit1" > $testroot/histedit-script
1316 echo "p $old_commit2" >> $testroot/histedit-script
1318 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1319 > $testroot/stdout 2> $testroot/stderr)
1321 if [ $ret -ne 0 ]; then
1322 echo "histedit failed unexpectedly:" >&2
1323 cat $testroot/stderr >&2
1324 test_done "$testroot" "$ret"
1328 echo "G alpha" > $testroot/stdout.expected
1329 echo "D beta" >> $testroot/stdout.expected
1330 echo "A epsilon/new" >> $testroot/stdout.expected
1331 echo "Stopping histedit for amending commit $old_commit1" \
1332 >> $testroot/stdout.expected
1334 cmp -s $testroot/stdout.expected $testroot/stdout
1336 if [ $ret -ne 0 ]; then
1337 diff -u $testroot/stdout.expected $testroot/stdout
1338 test_done "$testroot" "$ret"
1342 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1344 if [ $ret -ne 0 ]; then
1345 echo "commit failed unexpectedly" >&2
1346 test_done "$testroot" "$ret"
1350 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1352 if [ $ret -ne 0 ]; then
1353 echo "commit failed unexpectedly" >&2
1354 test_done "$testroot" "$ret"
1358 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1360 if [ $ret -ne 0 ]; then
1361 echo "commit failed unexpectedly" >&2
1362 test_done "$testroot" "$ret"
1366 (cd $testroot/wt && got histedit -c \
1367 > $testroot/stdout 2> $testroot/stderr)
1369 if [ $ret -ne 0 ]; then
1370 echo "histedit failed unexpectedly:" >&2
1371 cat $testroot/stderr >&2
1372 test_done "$testroot" "$ret"
1375 local new_commit2=`git_show_head $testroot/repo`
1376 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1378 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1379 > $testroot/stdout.expected
1380 echo "G epsilon/zeta" >> $testroot/stdout.expected
1381 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1382 >> $testroot/stdout.expected
1383 echo "Switching work tree to refs/heads/master" \
1384 >> $testroot/stdout.expected
1386 cmp -s $testroot/stdout.expected $testroot/stdout
1388 if [ $ret -ne 0 ]; then
1389 diff -u $testroot/stdout.expected $testroot/stdout
1391 test_done "$testroot" "$ret"
1395 test_histedit_duplicate_commit_in_script() {
1396 local testroot=`test_init histedit_duplicate_commit_in_script`
1398 local orig_commit=`git_show_head $testroot/repo`
1400 echo "modified alpha on master" > $testroot/repo/alpha
1401 (cd $testroot/repo && git rm -q beta)
1402 echo "new file on master" > $testroot/repo/epsilon/new
1403 (cd $testroot/repo && git add epsilon/new)
1404 git_commit $testroot/repo -m "committing changes 1"
1405 local old_commit1=`git_show_head $testroot/repo`
1407 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1408 git_commit $testroot/repo -m "committing changes 2"
1409 local old_commit2=`git_show_head $testroot/repo`
1411 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1413 if [ $ret -ne 0 ]; then
1414 test_done "$testroot" "$ret"
1418 # This histedit script lists commit1 more than once
1419 echo "p $old_commit1" > $testroot/histedit-script
1420 echo "p $old_commit1" >> $testroot/histedit-script
1421 echo "p $old_commit2" >> $testroot/histedit-script
1423 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1424 > $testroot/stdout 2> $testroot/stderr)
1426 if [ $ret -eq 0 ]; then
1427 echo "histedit succeeded unexpectedly:" >&2
1428 cat $testroot/stdout >&2
1429 test_done "$testroot" "$ret"
1433 echo -n "got: commit $old_commit1 is listed more than once " \
1434 > $testroot/stderr.expected
1435 echo "in histedit script" >> $testroot/stderr.expected
1437 cmp -s $testroot/stderr.expected $testroot/stderr
1439 if [ $ret -ne 0 ]; then
1440 diff -u $testroot/stderr.expected $testroot/stderr
1442 test_done "$testroot" "$ret"
1446 # if a previous commit introduces a new file, and it is folded into a commit
1447 # that deletes the same file, the file still exists after the histedit
1448 test_histedit_fold_add_delete() {
1449 local testroot=`test_init histedit_fold_add_delete`
1451 local orig_commit=`git_show_head $testroot/repo`
1453 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1454 (cd $testroot/repo && git add epsilon/psi)
1455 git_commit $testroot/repo -m "committing changes"
1456 local old_commit1=`git_show_head $testroot/repo`
1458 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1459 git_commit $testroot/repo -m "editing psi"
1460 local old_commit2=`git_show_head $testroot/repo`
1462 (cd $testroot/repo && git rm -q epsilon/psi)
1463 git_commit $testroot/repo -m "removing psi"
1464 local old_commit3=`git_show_head $testroot/repo`
1466 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1468 if [ $ret -ne 0 ]; then
1469 test_done "$testroot" "$ret"
1473 echo "fold $old_commit1" > $testroot/histedit-script
1474 echo "fold $old_commit2" >> $testroot/histedit-script
1475 echo "pick $old_commit3" >> $testroot/histedit-script
1476 echo "mesg folded changes" >> $testroot/histedit-script
1478 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1481 local new_commit1=`git_show_head $testroot/repo`
1483 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1484 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1485 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1486 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1488 echo "A epsilon/psi" >> $testroot/stdout.expected
1489 echo "$short_old_commit1 -> fold commit: committing changes" \
1490 >> $testroot/stdout.expected
1491 echo "G epsilon/psi" >> $testroot/stdout.expected
1492 echo "$short_old_commit2 -> fold commit: editing psi" \
1493 >> $testroot/stdout.expected
1494 echo "D epsilon/psi" >> $testroot/stdout.expected
1495 echo "$short_old_commit3 -> no-op change: folded changes" \
1496 >> $testroot/stdout.expected
1497 echo "Switching work tree to refs/heads/master" \
1498 >> $testroot/stdout.expected
1500 cmp -s $testroot/stdout.expected $testroot/stdout
1502 if [ $ret -ne 0 ]; then
1503 diff -u $testroot/stdout.expected $testroot/stdout
1504 test_done "$testroot" "$ret"
1508 if [ -e $testroot/wt/epsilon/psi ]; then
1509 echo "removed file psi still exists on disk" >&2
1510 test_done "$testroot" "1"
1514 (cd $testroot/wt && got status > $testroot/stdout)
1516 echo -n > $testroot/stdout.expected
1517 cmp -s $testroot/stdout.expected $testroot/stdout
1519 if [ $ret -ne 0 ]; then
1520 diff -u $testroot/stdout.expected $testroot/stdout
1521 test_done "$testroot" "$ret"
1525 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1526 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1527 cmp -s $testroot/stdout.expected $testroot/stdout
1529 if [ $ret -ne 0 ]; then
1530 diff -u $testroot/stdout.expected $testroot/stdout
1531 test_done "$testroot" "$ret"
1535 got tree -r $testroot/repo epsilon > $testroot/stdout
1536 echo "zeta" > $testroot/stdout.expected
1537 cmp -s $testroot/stdout.expected $testroot/stdout
1539 if [ $ret -ne 0 ]; then
1540 diff -u $testroot/stdout.expected $testroot/stdout
1542 test_done "$testroot" "$ret"
1545 test_histedit_fold_delete_add() {
1546 local testroot=`test_init histedit_fold_delete_add`
1548 local orig_commit=`git_show_head $testroot/repo`
1550 (cd $testroot/repo && git rm -q alpha)
1551 git_commit $testroot/repo -m "removing alpha"
1552 local old_commit1=`git_show_head $testroot/repo`
1554 echo "modified alpha" >$testroot/repo/alpha
1555 (cd $testroot/repo && git add alpha)
1556 git_commit $testroot/repo -m "add back modified alpha"
1557 local old_commit2=`git_show_head $testroot/repo`
1559 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1561 if [ $ret -ne 0 ]; then
1562 test_done "$testroot" "$ret"
1566 echo "fold $old_commit1" > $testroot/histedit-script
1567 echo "pick $old_commit2" >> $testroot/histedit-script
1568 echo "mesg folded changes" >> $testroot/histedit-script
1570 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1573 local new_commit1=`git_show_head $testroot/repo`
1575 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1576 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1577 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1579 echo "D alpha" > $testroot/stdout.expected
1580 echo "$short_old_commit1 -> fold commit: removing alpha" \
1581 >> $testroot/stdout.expected
1582 echo "A alpha" >> $testroot/stdout.expected
1583 echo "$short_old_commit2 -> $short_new_commit1: folded changes" \
1584 >> $testroot/stdout.expected
1585 echo "Switching work tree to refs/heads/master" \
1586 >> $testroot/stdout.expected
1588 cmp -s $testroot/stdout.expected $testroot/stdout
1590 if [ $ret -ne 0 ]; then
1591 diff -u $testroot/stdout.expected $testroot/stdout
1592 test_done "$testroot" "$ret"
1596 if [ ! -e $testroot/wt/alpha ]; then
1597 echo "file alpha is missing on disk" >&2
1598 test_done "$testroot" "1"
1602 echo "modified alpha" > $testroot/content.expected
1603 cat $testroot/wt/alpha > $testroot/content
1604 cmp -s $testroot/content.expected $testroot/content
1606 if [ $ret -ne 0 ]; then
1607 diff -u $testroot/content.expected $testroot/content
1608 test_done "$testroot" "$ret"
1611 test_done "$testroot" "0"
1614 test_histedit_fold_only() {
1615 local testroot=`test_init histedit_fold_only`
1617 local orig_commit=`git_show_head $testroot/repo`
1619 echo "modified alpha on master" > $testroot/repo/alpha
1620 (cd $testroot/repo && git rm -q beta)
1621 echo "new file on master" > $testroot/repo/epsilon/new
1622 (cd $testroot/repo && git add epsilon/new)
1623 git_commit $testroot/repo -m "committing changes"
1624 local old_commit1=`git_show_head $testroot/repo`
1626 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1627 git_commit $testroot/repo -m "committing to zeta on master"
1628 local old_commit2=`git_show_head $testroot/repo`
1630 echo "modified delta on master" > $testroot/repo/gamma/delta
1631 git_commit $testroot/repo -m "committing to delta on master"
1632 local old_commit3=`git_show_head $testroot/repo`
1634 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1636 if [ $ret -ne 0 ]; then
1637 test_done "$testroot" "$ret"
1641 cat > $testroot/editor.sh <<EOF
1644 ,s/.*/committing folded changes/
1648 chmod +x $testroot/editor.sh
1650 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1651 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1653 local new_commit1=`git_show_head $testroot/repo`
1655 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1656 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1657 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1658 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1659 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1661 echo "G alpha" > $testroot/stdout.expected
1662 echo "D beta" >> $testroot/stdout.expected
1663 echo "A epsilon/new" >> $testroot/stdout.expected
1664 echo "$short_old_commit1 -> fold commit: committing changes" \
1665 >> $testroot/stdout.expected
1666 echo "G epsilon/zeta" >> $testroot/stdout.expected
1667 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1668 echo "fold commit: committing to zeta on master" \
1669 >> $testroot/stdout.expected
1670 echo "G gamma/delta" >> $testroot/stdout.expected
1671 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1672 >> $testroot/stdout.expected
1673 echo "committing folded changes" >> $testroot/stdout.expected
1674 echo "Switching work tree to refs/heads/master" \
1675 >> $testroot/stdout.expected
1677 cmp -s $testroot/stdout.expected $testroot/stdout
1679 if [ $ret -ne 0 ]; then
1680 diff -u $testroot/stdout.expected $testroot/stdout
1681 test_done "$testroot" "$ret"
1685 echo "modified alpha on master" > $testroot/content.expected
1686 cat $testroot/wt/alpha > $testroot/content
1687 cmp -s $testroot/content.expected $testroot/content
1689 if [ $ret -ne 0 ]; then
1690 diff -u $testroot/content.expected $testroot/content
1691 test_done "$testroot" "$ret"
1695 if [ -e $testroot/wt/beta ]; then
1696 echo "removed file beta still exists on disk" >&2
1697 test_done "$testroot" "1"
1701 echo "new file on master" > $testroot/content.expected
1702 cat $testroot/wt/epsilon/new > $testroot/content
1703 cmp -s $testroot/content.expected $testroot/content
1705 if [ $ret -ne 0 ]; then
1706 diff -u $testroot/content.expected $testroot/content
1707 test_done "$testroot" "$ret"
1711 (cd $testroot/wt && got status > $testroot/stdout)
1713 echo -n > $testroot/stdout.expected
1714 cmp -s $testroot/stdout.expected $testroot/stdout
1716 if [ $ret -ne 0 ]; then
1717 diff -u $testroot/stdout.expected $testroot/stdout
1718 test_done "$testroot" "$ret"
1722 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1723 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1724 echo "commit $orig_commit" >> $testroot/stdout.expected
1725 cmp -s $testroot/stdout.expected $testroot/stdout
1727 if [ $ret -ne 0 ]; then
1728 diff -u $testroot/stdout.expected $testroot/stdout
1730 test_done "$testroot" "$ret"
1733 test_histedit_fold_only_empty_logmsg() {
1734 local testroot=`test_init histedit_fold_only_empty_logmsg`
1736 local orig_commit=`git_show_head $testroot/repo`
1738 echo "modified alpha on master" > $testroot/repo/alpha
1739 (cd $testroot/repo && git rm -q beta)
1740 echo "new file on master" > $testroot/repo/epsilon/new
1741 (cd $testroot/repo && git add epsilon/new)
1742 git_commit $testroot/repo -m "committing changes"
1743 local old_commit1=`git_show_head $testroot/repo`
1745 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1746 git_commit $testroot/repo -m "committing to zeta on master"
1747 local old_commit2=`git_show_head $testroot/repo`
1749 echo "modified delta on master" > $testroot/repo/gamma/delta
1750 git_commit $testroot/repo -m "committing to delta on master"
1751 local old_commit3=`git_show_head $testroot/repo`
1753 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1755 if [ $ret -ne 0 ]; then
1756 test_done "$testroot" "$ret"
1760 cat > $testroot/editor.sh <<EOF
1767 chmod +x $testroot/editor.sh
1769 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1770 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1772 local new_commit1=`git_show_head $testroot/repo`
1774 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1775 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1776 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1777 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1778 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1779 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1781 echo "G alpha" > $testroot/stdout.expected
1782 echo "D beta" >> $testroot/stdout.expected
1783 echo "A epsilon/new" >> $testroot/stdout.expected
1784 echo "$short_old_commit1 -> fold commit: committing changes" \
1785 >> $testroot/stdout.expected
1786 echo "G epsilon/zeta" >> $testroot/stdout.expected
1787 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1788 echo "fold commit: committing to zeta on master" \
1789 >> $testroot/stdout.expected
1790 echo "G gamma/delta" >> $testroot/stdout.expected
1791 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1792 >> $testroot/stdout.expected
1793 echo "# log message of folded commit $very_short_old_commit1" \
1794 >> $testroot/stdout.expected
1795 echo "Switching work tree to refs/heads/master" \
1796 >> $testroot/stdout.expected
1798 cmp -s $testroot/stdout.expected $testroot/stdout
1800 if [ $ret -ne 0 ]; then
1801 diff -u $testroot/stdout.expected $testroot/stdout
1802 test_done "$testroot" "$ret"
1806 echo "modified alpha on master" > $testroot/content.expected
1807 cat $testroot/wt/alpha > $testroot/content
1808 cmp -s $testroot/content.expected $testroot/content
1810 if [ $ret -ne 0 ]; then
1811 diff -u $testroot/content.expected $testroot/content
1812 test_done "$testroot" "$ret"
1816 if [ -e $testroot/wt/beta ]; then
1817 echo "removed file beta still exists on disk" >&2
1818 test_done "$testroot" "1"
1822 echo "new file on master" > $testroot/content.expected
1823 cat $testroot/wt/epsilon/new > $testroot/content
1824 cmp -s $testroot/content.expected $testroot/content
1826 if [ $ret -ne 0 ]; then
1827 diff -u $testroot/content.expected $testroot/content
1828 test_done "$testroot" "$ret"
1832 (cd $testroot/wt && got status > $testroot/stdout)
1834 echo -n > $testroot/stdout.expected
1835 cmp -s $testroot/stdout.expected $testroot/stdout
1837 if [ $ret -ne 0 ]; then
1838 diff -u $testroot/stdout.expected $testroot/stdout
1839 test_done "$testroot" "$ret"
1843 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1844 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1845 echo "commit $orig_commit" >> $testroot/stdout.expected
1846 cmp -s $testroot/stdout.expected $testroot/stdout
1848 if [ $ret -ne 0 ]; then
1849 diff -u $testroot/stdout.expected $testroot/stdout
1851 test_done "$testroot" "$ret"
1854 test_histedit_edit_only() {
1855 local testroot=`test_init histedit_edit_only`
1857 local orig_commit=`git_show_head $testroot/repo`
1859 echo "modified alpha on master" > $testroot/repo/alpha
1860 (cd $testroot/repo && git rm -q beta)
1861 echo "new file on master" > $testroot/repo/epsilon/new
1862 (cd $testroot/repo && git add epsilon/new)
1863 git_commit $testroot/repo -m "committing changes"
1864 local old_commit1=`git_show_head $testroot/repo`
1866 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1867 git_commit $testroot/repo -m "committing to zeta on master"
1868 local old_commit2=`git_show_head $testroot/repo`
1870 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1872 if [ $ret -ne 0 ]; then
1873 test_done "$testroot" "$ret"
1877 (cd $testroot/wt && got histedit -e > $testroot/stdout)
1879 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1880 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1882 echo "G alpha" > $testroot/stdout.expected
1883 echo "D beta" >> $testroot/stdout.expected
1884 echo "A epsilon/new" >> $testroot/stdout.expected
1885 echo "Stopping histedit for amending commit $old_commit1" \
1886 >> $testroot/stdout.expected
1887 cmp -s $testroot/stdout.expected $testroot/stdout
1889 if [ $ret -ne 0 ]; then
1890 diff -u $testroot/stdout.expected $testroot/stdout
1891 test_done "$testroot" "$ret"
1895 echo "edited modified alpha on master" > $testroot/wt/alpha
1897 cat > $testroot/editor.sh <<EOF
1900 ,s/.*/committing edited changes 1/
1904 chmod +x $testroot/editor.sh
1906 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1907 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1909 local new_commit1=$(cd $testroot/wt && got info | \
1910 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1911 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1913 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1914 > $testroot/stdout.expected
1915 echo "committing edited changes 1" >> $testroot/stdout.expected
1916 echo "G epsilon/zeta" >> $testroot/stdout.expected
1917 echo "Stopping histedit for amending commit $old_commit2" \
1918 >> $testroot/stdout.expected
1919 cmp -s $testroot/stdout.expected $testroot/stdout
1921 if [ $ret -ne 0 ]; then
1922 diff -u $testroot/stdout.expected $testroot/stdout
1923 test_done "$testroot" "$ret"
1927 echo "edited zeta on master" > $testroot/wt/epsilon/zeta
1929 cat > $testroot/editor.sh <<EOF
1932 ,s/.*/committing edited changes 2/
1936 chmod +x $testroot/editor.sh
1938 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1939 VISUAL="$testroot/editor.sh" got histedit -c > $testroot/stdout)
1941 local new_commit2=`git_show_head $testroot/repo`
1942 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1944 echo -n "$short_old_commit2 -> $short_new_commit2: " \
1945 > $testroot/stdout.expected
1946 echo "committing edited changes 2" >> $testroot/stdout.expected
1947 echo "Switching work tree to refs/heads/master" \
1948 >> $testroot/stdout.expected
1950 cmp -s $testroot/stdout.expected $testroot/stdout
1952 if [ $ret -ne 0 ]; then
1953 diff -u $testroot/stdout.expected $testroot/stdout
1954 test_done "$testroot" "$ret"
1958 echo "edited modified alpha on master" > $testroot/content.expected
1959 cat $testroot/wt/alpha > $testroot/content
1960 cmp -s $testroot/content.expected $testroot/content
1962 if [ $ret -ne 0 ]; then
1963 diff -u $testroot/content.expected $testroot/content
1964 test_done "$testroot" "$ret"
1968 if [ -e $testroot/wt/beta ]; then
1969 echo "removed file beta still exists on disk" >&2
1970 test_done "$testroot" "1"
1974 echo "new file on master" > $testroot/content.expected
1975 cat $testroot/wt/epsilon/new > $testroot/content
1976 cmp -s $testroot/content.expected $testroot/content
1978 if [ $ret -ne 0 ]; then
1979 diff -u $testroot/content.expected $testroot/content
1980 test_done "$testroot" "$ret"
1984 (cd $testroot/wt && got status > $testroot/stdout)
1986 echo -n > $testroot/stdout.expected
1987 cmp -s $testroot/stdout.expected $testroot/stdout
1989 if [ $ret -ne 0 ]; then
1990 diff -u $testroot/stdout.expected $testroot/stdout
1991 test_done "$testroot" "$ret"
1995 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1996 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
1997 echo "commit $new_commit1" >> $testroot/stdout.expected
1998 echo "commit $orig_commit" >> $testroot/stdout.expected
1999 cmp -s $testroot/stdout.expected $testroot/stdout
2001 if [ $ret -ne 0 ]; then
2002 diff -u $testroot/stdout.expected $testroot/stdout
2004 test_done "$testroot" "$ret"
2007 test_histedit_prepend_line() {
2008 local testroot=`test_init histedit_prepend_line`
2009 local orig_commit=`git_show_head $testroot/repo`
2011 got checkout $testroot/repo $testroot/wt > /dev/null
2013 ed -s "$testroot/wt/alpha" <<EOF
2020 cp $testroot/wt/alpha $testroot/content.expected
2022 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2025 if [ "$?" != 0 ]; then
2026 echo "got commit failed unexpectedly" >&2
2027 test_done "$testroot" "$ret"
2031 local top_commit=`git_show_head $testroot/repo`
2032 echo "pick $top_commit" > "$testroot/histedit-script"
2034 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2036 if [ "$?" != 0 ]; then
2037 echo "got update failed unexpectedly" >&2
2038 test_done "$testroot" "$ret"
2042 (cd $testroot/wt && got histedit -F "$testroot/histedit-script" \
2045 if [ "$?" != 0 ]; then
2046 echo "got histedit failed unexpectedly" >&2
2047 test_done "$testroot" "$ret"
2051 cp $testroot/wt/alpha $testroot/content
2052 cmp -s $testroot/content.expected $testroot/content
2054 if [ $ret -ne 0 ]; then
2055 diff -u $testroot/content.expected $testroot/content
2056 test_done "$testroot" "$ret"
2060 test_done "$testroot" $ret
2063 test_histedit_mesg_invalid() {
2064 local testroot=`test_init mesg_invalid`
2066 local orig_commit=`git_show_head $testroot/repo`
2068 echo "modified alpha on master" > $testroot/repo/alpha
2069 (cd $testroot/repo && git rm -q beta)
2070 echo "new file on master" > $testroot/repo/epsilon/new
2071 (cd $testroot/repo && git add epsilon/new)
2072 git_commit $testroot/repo -m 'committing changes'
2073 local old_commit1=`git_show_head $testroot/repo`
2075 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2076 git_commit $testroot/repo -m 'committing to zeto on master'
2077 local old_commit2=`git_show_head $testroot/repo`
2079 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2081 if [ $ret -ne 0 ]; then
2082 test_done "$testroot" $ret
2086 # try with a leading mesg
2088 echo "mesg something something" > $testroot/histedit-script
2089 echo "pick $old_commit1" >> $testroot/histedit-script
2090 echo "pick $old_commit2" >> $testroot/histedit-script
2092 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2093 > $testroot/stdout 2> $testroot/stderr)
2095 if [ $ret -eq 0 ]; then
2096 echo "histedit succeeded unexpectedly" >&2
2097 test_done "$testroot" 1
2101 echo "got: bad histedit command" > $testroot/stderr.expected
2102 cmp -s $testroot/stderr.expected $testroot/stderr
2104 if [ $ret -ne 0 ]; then
2105 diff -u $testroot/stderr.expected $testroot/stderr
2106 test_done "$testroot" $ret
2110 # try again with mesg -> mesg
2112 echo "pick $old_commit1" > $testroot/histedit-script
2113 echo "mesg something something" >> $testroot/histedit-script
2114 echo "mesg something something else" >> $testroot/histedit-script
2115 echo "pick $old_commit2" >> $testroot/histedit-script
2117 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2118 > $testroot/stdout 2> $testroot/stderr)
2120 if [ $ret -eq 0 ]; then
2121 echo "histedit succeeded unexpectedly" >&2
2122 test_done "$testroot" 1
2126 echo "got: bad histedit command" > $testroot/stderr.expected
2127 cmp -s $testroot/stderr.expected $testroot/stderr
2129 if [ $ret -ne 0 ]; then
2130 diff -u $testroot/stderr.expected $testroot/stderr
2131 test_done "$testroot" $ret
2135 # try again with drop -> mesg
2137 echo "drop $old_commit1" > $testroot/histedit-script
2138 echo "mesg something something" >> $testroot/histedit-script
2139 echo "pick $old_commit2" >> $testroot/histedit-script
2141 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2142 > $testroot/stdout 2> $testroot/stderr)
2144 if [ $ret -eq 0 ]; then
2145 echo "histedit succeeded unexpectedly" >&2
2146 test_done "$testroot" 1
2150 echo "got: bad histedit command" > $testroot/stderr.expected
2151 cmp -s $testroot/stderr.expected $testroot/stderr
2153 if [ $ret -ne 0 ]; then
2154 diff -u $testroot/stderr.expected $testroot/stderr
2155 test_done "$testroot" $ret
2159 # try again with fold -> mesg
2161 echo "fold $old_commit1" > $testroot/histedit-script
2162 echo "mesg something something" >> $testroot/histedit-script
2163 echo "pick $old_commit2" >> $testroot/histedit-script
2165 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
2166 > $testroot/stdout 2> $testroot/stderr)
2168 if [ $ret -eq 0 ]; then
2169 echo "histedit succeeded unexpectedly" >&2
2170 test_done "$testroot" 1
2174 echo "got: bad histedit command" > $testroot/stderr.expected
2175 cmp -s $testroot/stderr.expected $testroot/stderr
2177 if [ $ret -ne 0 ]; then
2178 diff -u $testroot/stderr.expected $testroot/stderr
2180 test_done "$testroot" $ret
2183 test_histedit_resets_committer() {
2184 local testroot=`test_init histedit_resets_committer`
2185 local orig_commit=`git_show_head $testroot/repo`
2186 local committer="Flan Luck <flan_luck@openbsd.org>"
2188 got checkout $testroot/repo $testroot/wt > /dev/null
2190 echo "modified alpha" > $testroot/wt/alpha
2192 (cd $testroot/wt/ && got commit -m 'modified alpha on master' \
2195 if [ "$?" != 0 ]; then
2196 echo "got commit failed unexpectedly" >&2
2197 test_done "$testroot" "$ret"
2201 local top_commit=`git_show_head $testroot/repo`
2202 echo "pick $top_commit" > "$testroot/histedit-script"
2204 (cd $testroot/wt/ && got update -c $orig_commit > /dev/null)
2206 if [ "$?" != 0 ]; then
2207 echo "got update failed unexpectedly" >&2
2208 test_done "$testroot" "$ret"
2212 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
2213 got histedit -F "$testroot/histedit-script" > /dev/null)
2215 if [ "$?" != 0 ]; then
2216 echo "got histedit failed unexpectedly" >&2
2217 test_done "$testroot" "$ret"
2220 local edited_commit=`git_show_head $testroot/repo`
2222 # Original commit only had one author
2223 (cd $testroot/repo && got log -l1 -c $top_commit | \
2224 egrep '^(from|via):' > $testroot/stdout)
2225 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2226 cmp -s $testroot/stdout.expected $testroot/stdout
2228 if [ $ret -ne 0 ]; then
2229 diff -u $testroot/stdout.expected $testroot/stdout
2230 test_done "$testroot" "$ret"
2234 # Edited commit should have new committer name added
2235 (cd $testroot/repo && got log -l1 -c $edited_commit | \
2236 egrep '^(from|via):' > $testroot/stdout)
2237 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
2238 echo "via: $committer" >> $testroot/stdout.expected
2240 cmp -s $testroot/stdout.expected $testroot/stdout
2242 if [ $ret -ne 0 ]; then
2243 diff -u $testroot/stdout.expected $testroot/stdout
2245 test_done "$testroot" "$ret"
2248 test_histedit_umask() {
2249 local testroot=`test_init histedit_umask`
2250 local orig_commit=`git_show_head "$testroot/repo"`
2252 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
2254 echo "modified alpha" > $testroot/wt/alpha
2255 (cd "$testroot/wt" && got commit -m 'edit #1') >/dev/null
2256 local commit1=`git_show_head "$testroot/repo"`
2258 echo "modified again" > $testroot/wt/alpha
2259 (cd "$testroot/wt" && got commit -m 'edit #2') >/dev/null
2260 local commit2=`git_show_head "$testroot/repo"`
2262 echo "modified again!" > $testroot/wt/alpha
2263 echo "modify beta too!" > $testroot/wt/beta
2264 (cd "$testroot/wt" && got commit -m 'edit #3') >/dev/null
2265 local commit3=`git_show_head "$testroot/repo"`
2267 (cd "$testroot/wt" && got update -c "$orig_commit") >/dev/null
2269 if [ $ret -ne 0 ]; then
2270 echo "update to $orig_commit failed!" >&2
2271 test_done "$testroot" 1
2275 echo fold $commit1 >$testroot/histedit-script
2276 echo fold $commit2 >>$testroot/histedit-script
2277 echo pick $commit3 >>$testroot/histedit-script
2278 echo mesg folding changes >>$testroot/histedit-script
2280 # using a subshell to avoid clobbering global umask
2281 (umask 077 && cd "$testroot/wt" && \
2282 got histedit -F "$testroot/histedit-script") >/dev/null
2285 if [ $ret -ne 0 ]; then
2286 echo "histedit operation failed" >&2
2287 test_done "$testroot" $ret
2291 for f in alpha beta; do
2292 ls -l "$testroot/wt/$f" | grep -q ^-rw-------
2293 if [ $? -ne 0 ]; then
2294 echo "$f is not 0600 after histedi" >&2
2295 ls -l "$testroot/wt/$f" >&2
2296 test_done "$testroot" 1
2301 test_done "$testroot" 0
2304 test_histedit_mesg_filemode_change() {
2305 local testroot=`test_init histedit_mode_change`
2307 local orig_commit=`git_show_head $testroot/repo`
2308 local orig_author_time=`git_show_author_time $testroot/repo`
2310 chmod +x $testroot/repo/alpha
2311 git_commit $testroot/repo -m "set x bit on alpha"
2312 local old_commit1=`git_show_head $testroot/repo`
2313 local old_author_time1=`git_show_author_time $testroot/repo`
2315 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2317 if [ $ret -ne 0 ]; then
2318 test_done "$testroot" "$ret"
2322 if [ -x $testroot/wt/alpha ]; then
2323 echo "file alpha has unexpected executable bit" >&2
2324 test_done "$testroot" "1"
2328 cat > $testroot/editor.sh <<EOF
2331 ,s/ x bit / executable bit /
2336 chmod +x $testroot/editor.sh
2338 (cd $testroot/wt && env VISUAL="$testroot/editor.sh" \
2339 got histedit -m > $testroot/stdout)
2341 local new_commit1=`git_show_head $testroot/repo`
2342 local new_author_time1=`git_show_author_time $testroot/repo`
2344 local short_old_commit1=`trim_obj_id 28 $old_commit1`
2345 local short_new_commit1=`trim_obj_id 28 $new_commit1`
2347 echo "G alpha" > $testroot/stdout.expected
2348 echo "$short_old_commit1 -> $short_new_commit1: set executable bit on alpha" \
2349 >> $testroot/stdout.expected
2350 echo "Switching work tree to refs/heads/master" \
2351 >> $testroot/stdout.expected
2353 cmp -s $testroot/stdout.expected $testroot/stdout
2355 if [ $ret -ne 0 ]; then
2356 diff -u $testroot/stdout.expected $testroot/stdout
2357 test_done "$testroot" "$ret"
2361 echo "alpha" > $testroot/content.expected
2362 cmp -s $testroot/content.expected $testroot/wt/alpha
2364 if [ $ret -ne 0 ]; then
2365 diff -u $testroot/content.expected $testroot/wt/alpha
2366 test_done "$testroot" "$ret"
2370 if [ ! -x $testroot/wt/alpha ]; then
2371 echo "file alpha lost its executable bit" >&2
2372 test_done "$testroot" "1"
2376 (cd $testroot/wt && got status > $testroot/stdout)
2378 echo -n > $testroot/stdout.expected
2379 cmp -s $testroot/stdout.expected $testroot/stdout
2381 if [ $ret -ne 0 ]; then
2382 diff -u $testroot/stdout.expected $testroot/stdout
2383 test_done "$testroot" "$ret"
2387 (cd $testroot/wt && got log -l1 | grep ' set executable bit on alpha' \
2390 echo ' set executable bit on alpha' > $testroot/stdout.expected
2391 cmp -s $testroot/stdout.expected $testroot/stdout
2393 if [ $ret -ne 0 ]; then
2394 diff -u $testroot/stdout.expected $testroot/stdout
2395 test_done "$testroot" "$ret"
2399 test_done "$testroot" "$ret"
2402 test_histedit_drop_only() {
2403 local testroot=`test_init histedit_drop_only`
2405 local orig_commit=`git_show_head $testroot/repo`
2406 local drop="-> drop commit:"
2407 local dropmsg="commit changes to drop"
2409 echo "modified alpha on master" > $testroot/repo/alpha
2410 (cd $testroot/repo && git rm -q beta)
2411 echo "new file on master" > $testroot/repo/epsilon/new
2412 (cd $testroot/repo && git add epsilon/new)
2414 git_commit $testroot/repo -m "$dropmsg 1"
2415 local drop_commit1=`git_show_head $testroot/repo`
2417 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
2419 git_commit $testroot/repo -m "$dropmsg 2"
2420 local drop_commit2=`git_show_head $testroot/repo`
2422 echo "modified delta on master" > $testroot/repo/gamma/delta
2424 git_commit $testroot/repo -m "$dropmsg 3"
2425 local drop_commit3=`git_show_head $testroot/repo`
2427 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
2429 if [ $ret -ne 0 ]; then
2430 test_done "$testroot" "$ret"
2434 (cd $testroot/wt && got histedit -d > $testroot/stdout)
2435 local new_commit1=`git_show_head $testroot/repo`
2437 local short_commit1=`trim_obj_id 28 $drop_commit1`
2438 local short_commit2=`trim_obj_id 28 $drop_commit2`
2439 local short_commit3=`trim_obj_id 28 $drop_commit3`
2441 echo "$short_commit1 $drop $dropmsg 1" > $testroot/stdout.expected
2442 echo "$short_commit2 $drop $dropmsg 2" >> $testroot/stdout.expected
2443 echo "$short_commit3 $drop $dropmsg 3" >> $testroot/stdout.expected
2444 echo "Switching work tree to refs/heads/master" \
2445 >> $testroot/stdout.expected
2447 cmp -s $testroot/stdout.expected $testroot/stdout
2449 if [ $ret -ne 0 ]; then
2450 diff -u $testroot/stdout.expected $testroot/stdout
2451 test_done "$testroot" "$ret"
2455 echo "alpha" > $testroot/content.expected
2456 cat $testroot/wt/alpha > $testroot/content
2457 cmp -s $testroot/content.expected $testroot/content
2459 if [ $ret -ne 0 ]; then
2460 diff -u $testroot/content.expected $testroot/content
2461 test_done "$testroot" "$ret"
2465 echo "zeta" > $testroot/content.expected
2466 cat $testroot/wt/epsilon/zeta > $testroot/content
2467 cmp -s $testroot/content.expected $testroot/content
2469 if [ $ret -ne 0 ]; then
2470 diff -u $testroot/content.expected $testroot/content
2471 test_done "$testroot" "$ret"
2475 echo "delta" > $testroot/content.expected
2476 cat $testroot/wt/gamma/delta > $testroot/content
2477 cmp -s $testroot/content.expected $testroot/content
2479 if [ $ret -ne 0 ]; then
2480 diff -u $testroot/content.expected $testroot/content
2481 test_done "$testroot" "$ret"
2485 if [ ! -e $testroot/wt/beta ]; then
2486 echo "removed file beta should be restored" >&2
2487 test_done "$testroot" "1"
2491 if [ -e $testroot/wt/new ]; then
2492 echo "new file should no longer exist" >&2
2493 test_done "$testroot" "$ret"
2497 (cd $testroot/wt && got status > $testroot/stdout)
2499 echo -n > $testroot/stdout.expected
2500 cmp -s $testroot/stdout.expected $testroot/stdout
2502 if [ $ret -ne 0 ]; then
2503 diff -u $testroot/stdout.expected $testroot/stdout
2504 test_done "$testroot" "$ret"
2508 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
2509 echo "commit $orig_commit (master)" > $testroot/stdout.expected
2510 cmp -s $testroot/stdout.expected $testroot/stdout
2512 if [ $ret -ne 0 ]; then
2513 diff -u $testroot/stdout.expected $testroot/stdout
2515 test_done "$testroot" "$ret"
2519 run_test test_histedit_no_op
2520 run_test test_histedit_swap
2521 run_test test_histedit_drop
2522 run_test test_histedit_fold
2523 run_test test_histedit_edit
2524 run_test test_histedit_fold_last_commit
2525 run_test test_histedit_missing_commit
2526 run_test test_histedit_abort
2527 run_test test_histedit_path_prefix_drop
2528 run_test test_histedit_path_prefix_edit
2529 run_test test_histedit_outside_refs_heads
2530 run_test test_histedit_fold_last_commit_swap
2531 run_test test_histedit_split_commit
2532 run_test test_histedit_duplicate_commit_in_script
2533 run_test test_histedit_fold_add_delete
2534 run_test test_histedit_fold_delete_add
2535 run_test test_histedit_fold_only
2536 run_test test_histedit_fold_only_empty_logmsg
2537 run_test test_histedit_edit_only
2538 run_test test_histedit_prepend_line
2539 run_test test_histedit_mesg_invalid
2540 run_test test_histedit_resets_committer
2541 run_test test_histedit_umask
2542 run_test test_histedit_mesg_filemode_change
2543 run_test test_histedit_drop_only