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`
32 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
33 git_commit $testroot/repo -m "committing to zeta on master"
34 local old_commit2=`git_show_head $testroot/repo`
35 local old_author_time2=`git_show_author_time $testroot/repo`
37 got diff -r $testroot/repo $orig_commit $old_commit2 \
38 > $testroot/diff.expected
40 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
42 if [ "$ret" != "0" ]; then
43 test_done "$testroot" "$ret"
47 echo "pick $old_commit1" > $testroot/histedit-script
48 echo "pick $old_commit2" >> $testroot/histedit-script
50 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
53 local new_commit1=`git_show_parent_commit $testroot/repo`
54 local new_commit2=`git_show_head $testroot/repo`
55 local new_author_time2=`git_show_author_time $testroot/repo`
57 local short_old_commit1=`trim_obj_id 28 $old_commit1`
58 local short_old_commit2=`trim_obj_id 28 $old_commit2`
59 local short_new_commit1=`trim_obj_id 28 $new_commit1`
60 local short_new_commit2=`trim_obj_id 28 $new_commit2`
62 echo "G alpha" > $testroot/stdout.expected
63 echo "D beta" >> $testroot/stdout.expected
64 echo "A epsilon/new" >> $testroot/stdout.expected
65 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
66 >> $testroot/stdout.expected
67 echo "G epsilon/zeta" >> $testroot/stdout.expected
68 echo -n "$short_old_commit2 -> $short_new_commit2: " \
69 >> $testroot/stdout.expected
70 echo "committing to zeta on master" >> $testroot/stdout.expected
71 echo "Switching work tree to refs/heads/master" \
72 >> $testroot/stdout.expected
74 cmp -s $testroot/stdout.expected $testroot/stdout
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 test_done "$testroot" "$ret"
82 echo "modified alpha on master" > $testroot/content.expected
83 cat $testroot/wt/alpha > $testroot/content
84 cmp -s $testroot/content.expected $testroot/content
86 if [ "$ret" != "0" ]; then
87 diff -u $testroot/content.expected $testroot/content
88 test_done "$testroot" "$ret"
92 if [ -e $testroot/wt/beta ]; then
93 echo "removed file beta still exists on disk" >&2
94 test_done "$testroot" "1"
98 echo "new file on master" > $testroot/content.expected
99 cat $testroot/wt/epsilon/new > $testroot/content
100 cmp -s $testroot/content.expected $testroot/content
102 if [ "$ret" != "0" ]; then
103 diff -u $testroot/content.expected $testroot/content
104 test_done "$testroot" "$ret"
108 (cd $testroot/wt && got status > $testroot/stdout)
110 echo -n > $testroot/stdout.expected
111 cmp -s $testroot/stdout.expected $testroot/stdout
113 if [ "$ret" != "0" ]; then
114 diff -u $testroot/stdout.expected $testroot/stdout
115 test_done "$testroot" "$ret"
119 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
120 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
121 echo "commit $new_commit1" >> $testroot/stdout.expected
122 echo "commit $orig_commit" >> $testroot/stdout.expected
123 cmp -s $testroot/stdout.expected $testroot/stdout
125 if [ "$ret" != "0" ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
131 got diff -r $testroot/repo $orig_commit $new_commit2 \
133 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
134 cmp -s $testroot/diff.expected $testroot/diff
136 if [ "$ret" != "0" ]; then
137 diff -u $testroot/diff.expected $testroot/diff
138 test_done "$testroot" "$ret"
142 (cd $testroot/wt && got update > $testroot/stdout)
144 echo 'Already up-to-date' > $testroot/stdout.expected
145 cmp -s $testroot/stdout.expected $testroot/stdout
147 if [ "$ret" != "0" ]; then
148 diff -u $testroot/stdout.expected $testroot/stdout
149 test_done "$testroot" "$ret"
152 # We should have a backup of old commits
153 (cd $testroot/repo && got histedit -l > $testroot/stdout)
154 d_orig2=`env TZ=UTC date -r $old_author_time2 +"%a %b %e %X %Y UTC"`
155 d_new2=`env TZ=UTC date -r $new_author_time2 +"%G-%m-%d"`
156 d_orig=`env TZ=UTC date -r $orig_author_time +"%G-%m-%d"`
157 cat > $testroot/stdout.expected <<EOF
158 -----------------------------------------------
159 commit $old_commit2 (formerly master)
163 committing to zeta on master
165 has become commit $new_commit2 (master)
166 $d_new2 $GOT_AUTHOR_11 committing to zeta on master
167 history forked at $orig_commit
168 $d_orig $GOT_AUTHOR_11 adding the test tree
170 cmp -s $testroot/stdout.expected $testroot/stdout
172 if [ "$ret" != "0" ]; then
173 diff -u $testroot/stdout.expected $testroot/stdout
175 test_done "$testroot" "$ret"
178 test_histedit_swap() {
179 local testroot=`test_init histedit_swap`
181 local orig_commit=`git_show_head $testroot/repo`
183 echo "modified alpha on master" > $testroot/repo/alpha
184 (cd $testroot/repo && git rm -q beta)
185 echo "new file on master" > $testroot/repo/epsilon/new
186 (cd $testroot/repo && git add epsilon/new)
187 git_commit $testroot/repo -m "committing changes"
188 local old_commit1=`git_show_head $testroot/repo`
190 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
191 git_commit $testroot/repo -m "committing to zeta on master"
192 local old_commit2=`git_show_head $testroot/repo`
194 got diff -r $testroot/repo $orig_commit $old_commit2 \
195 > $testroot/diff.expected
197 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
199 if [ "$ret" != "0" ]; then
200 test_done "$testroot" "$ret"
204 echo "pick $old_commit2" > $testroot/histedit-script
205 echo "pick $old_commit1" >> $testroot/histedit-script
207 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
210 local new_commit2=`git_show_parent_commit $testroot/repo`
211 local new_commit1=`git_show_head $testroot/repo`
213 local short_old_commit1=`trim_obj_id 28 $old_commit1`
214 local short_old_commit2=`trim_obj_id 28 $old_commit2`
215 local short_new_commit1=`trim_obj_id 28 $new_commit1`
216 local short_new_commit2=`trim_obj_id 28 $new_commit2`
218 echo "G epsilon/zeta" > $testroot/stdout.expected
219 echo -n "$short_old_commit2 -> $short_new_commit2: " \
220 >> $testroot/stdout.expected
221 echo "committing to zeta on master" >> $testroot/stdout.expected
222 echo "G alpha" >> $testroot/stdout.expected
223 echo "D beta" >> $testroot/stdout.expected
224 echo "A epsilon/new" >> $testroot/stdout.expected
225 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
226 >> $testroot/stdout.expected
227 echo "Switching work tree to refs/heads/master" \
228 >> $testroot/stdout.expected
230 cmp -s $testroot/stdout.expected $testroot/stdout
232 if [ "$ret" != "0" ]; then
233 diff -u $testroot/stdout.expected $testroot/stdout
234 test_done "$testroot" "$ret"
238 echo "modified alpha on master" > $testroot/content.expected
239 cat $testroot/wt/alpha > $testroot/content
240 cmp -s $testroot/content.expected $testroot/content
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/content.expected $testroot/content
244 test_done "$testroot" "$ret"
248 if [ -e $testroot/wt/beta ]; then
249 echo "removed file beta still exists on disk" >&2
250 test_done "$testroot" "1"
254 echo "new file on master" > $testroot/content.expected
255 cat $testroot/wt/epsilon/new > $testroot/content
256 cmp -s $testroot/content.expected $testroot/content
258 if [ "$ret" != "0" ]; then
259 diff -u $testroot/content.expected $testroot/content
260 test_done "$testroot" "$ret"
264 (cd $testroot/wt && got status > $testroot/stdout)
266 echo -n > $testroot/stdout.expected
267 cmp -s $testroot/stdout.expected $testroot/stdout
269 if [ "$ret" != "0" ]; then
270 diff -u $testroot/stdout.expected $testroot/stdout
271 test_done "$testroot" "$ret"
275 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
276 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
277 echo "commit $new_commit2" >> $testroot/stdout.expected
278 echo "commit $orig_commit" >> $testroot/stdout.expected
279 cmp -s $testroot/stdout.expected $testroot/stdout
281 if [ "$ret" != "0" ]; then
282 diff -u $testroot/stdout.expected $testroot/stdout
283 test_done "$testroot" "$ret"
287 got diff -r $testroot/repo $orig_commit $new_commit1 \
289 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
290 cmp -s $testroot/diff.expected $testroot/diff
292 if [ "$ret" != "0" ]; then
293 diff -u $testroot/diff.expected $testroot/diff
295 test_done "$testroot" "$ret"
298 test_histedit_drop() {
299 local testroot=`test_init histedit_drop`
300 local orig_commit=`git_show_head $testroot/repo`
302 echo "modified alpha on master" > $testroot/repo/alpha
303 (cd $testroot/repo && git rm -q beta)
304 echo "new file on master" > $testroot/repo/epsilon/new
305 (cd $testroot/repo && git add epsilon/new)
306 git_commit $testroot/repo -m "committing changes"
307 local old_commit1=`git_show_head $testroot/repo`
309 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
310 git_commit $testroot/repo -m "committing to zeta on master"
311 local old_commit2=`git_show_head $testroot/repo`
313 got diff -r $testroot/repo $old_commit1 $old_commit2 \
314 > $testroot/diff.expected
316 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
318 if [ "$ret" != "0" ]; then
319 test_done "$testroot" "$ret"
323 echo "drop $old_commit1" > $testroot/histedit-script
324 echo "pick $old_commit2" >> $testroot/histedit-script
326 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
329 local new_commit2=`git_show_head $testroot/repo`
331 local short_old_commit1=`trim_obj_id 28 $old_commit1`
332 local short_old_commit2=`trim_obj_id 28 $old_commit2`
333 local short_new_commit2=`trim_obj_id 28 $new_commit2`
335 echo "$short_old_commit1 -> drop commit: committing changes" \
336 > $testroot/stdout.expected
337 echo "G epsilon/zeta" >> $testroot/stdout.expected
338 echo -n "$short_old_commit2 -> $short_new_commit2: " \
339 >> $testroot/stdout.expected
340 echo "committing to zeta on master" >> $testroot/stdout.expected
341 echo "Switching work tree to refs/heads/master" \
342 >> $testroot/stdout.expected
344 cmp -s $testroot/stdout.expected $testroot/stdout
346 if [ "$ret" != "0" ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
352 for f in alpha beta; do
353 echo "$f" > $testroot/content.expected
354 cat $testroot/wt/$f > $testroot/content
355 cmp -s $testroot/content.expected $testroot/content
357 if [ "$ret" != "0" ]; then
358 diff -u $testroot/content.expected $testroot/content
359 test_done "$testroot" "$ret"
364 if [ -e $testroot/wt/new ]; then
365 echo "file new exists on disk but should not" >&2
366 test_done "$testroot" "1"
370 (cd $testroot/wt && got status > $testroot/stdout)
372 echo -n > $testroot/stdout.expected
373 cmp -s $testroot/stdout.expected $testroot/stdout
375 if [ "$ret" != "0" ]; then
376 diff -u $testroot/stdout.expected $testroot/stdout
377 test_done "$testroot" "$ret"
381 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
382 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
383 echo "commit $orig_commit" >> $testroot/stdout.expected
384 cmp -s $testroot/stdout.expected $testroot/stdout
386 if [ "$ret" != "0" ]; then
387 diff -u $testroot/stdout.expected $testroot/stdout
388 test_done "$testroot" "$ret"
392 got diff -r $testroot/repo $orig_commit $new_commit2 \
394 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
395 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
396 cmp -s $testroot/diff.expected $testroot/diff
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/diff.expected $testroot/diff
401 test_done "$testroot" "$ret"
404 test_histedit_fold() {
405 local testroot=`test_init histedit_fold`
407 local orig_commit=`git_show_head $testroot/repo`
409 echo "modified alpha on master" > $testroot/repo/alpha
410 (cd $testroot/repo && git rm -q beta)
411 echo "new file on master" > $testroot/repo/epsilon/new
412 (cd $testroot/repo && git add epsilon/new)
413 git_commit $testroot/repo -m "committing changes"
414 local old_commit1=`git_show_head $testroot/repo`
416 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
417 git_commit $testroot/repo -m "committing to zeta on master"
418 local old_commit2=`git_show_head $testroot/repo`
420 echo "modified delta on master" > $testroot/repo/gamma/delta
421 git_commit $testroot/repo -m "committing to delta on master"
422 local old_commit3=`git_show_head $testroot/repo`
424 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
426 if [ "$ret" != "0" ]; then
427 test_done "$testroot" "$ret"
431 echo "fold $old_commit1" > $testroot/histedit-script
432 echo "drop $old_commit2" >> $testroot/histedit-script
433 echo "pick $old_commit3" >> $testroot/histedit-script
434 echo "mesg committing folded changes" >> $testroot/histedit-script
436 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
439 local new_commit1=`git_show_parent_commit $testroot/repo`
440 local new_commit2=`git_show_head $testroot/repo`
442 local short_old_commit1=`trim_obj_id 28 $old_commit1`
443 local short_old_commit2=`trim_obj_id 28 $old_commit2`
444 local short_old_commit3=`trim_obj_id 28 $old_commit3`
445 local short_new_commit1=`trim_obj_id 28 $new_commit1`
446 local short_new_commit2=`trim_obj_id 28 $new_commit2`
448 echo "G alpha" > $testroot/stdout.expected
449 echo "D beta" >> $testroot/stdout.expected
450 echo "A epsilon/new" >> $testroot/stdout.expected
451 echo "$short_old_commit1 -> fold commit: committing changes" \
452 >> $testroot/stdout.expected
453 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
454 echo "drop commit: committing to zeta on master" \
455 >> $testroot/stdout.expected
456 echo "G gamma/delta" >> $testroot/stdout.expected
457 echo -n "$short_old_commit3 -> $short_new_commit2: " \
458 >> $testroot/stdout.expected
459 echo "committing folded changes" >> $testroot/stdout.expected
460 echo "Switching work tree to refs/heads/master" \
461 >> $testroot/stdout.expected
463 cmp -s $testroot/stdout.expected $testroot/stdout
465 if [ "$ret" != "0" ]; then
466 diff -u $testroot/stdout.expected $testroot/stdout
467 test_done "$testroot" "$ret"
471 echo "modified alpha on master" > $testroot/content.expected
472 cat $testroot/wt/alpha > $testroot/content
473 cmp -s $testroot/content.expected $testroot/content
475 if [ "$ret" != "0" ]; then
476 diff -u $testroot/content.expected $testroot/content
477 test_done "$testroot" "$ret"
481 if [ -e $testroot/wt/beta ]; then
482 echo "removed file beta still exists on disk" >&2
483 test_done "$testroot" "1"
487 echo "new file on master" > $testroot/content.expected
488 cat $testroot/wt/epsilon/new > $testroot/content
489 cmp -s $testroot/content.expected $testroot/content
491 if [ "$ret" != "0" ]; then
492 diff -u $testroot/content.expected $testroot/content
493 test_done "$testroot" "$ret"
497 (cd $testroot/wt && got status > $testroot/stdout)
499 echo -n > $testroot/stdout.expected
500 cmp -s $testroot/stdout.expected $testroot/stdout
502 if [ "$ret" != "0" ]; then
503 diff -u $testroot/stdout.expected $testroot/stdout
504 test_done "$testroot" "$ret"
508 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
509 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
510 echo "commit $orig_commit" >> $testroot/stdout.expected
511 cmp -s $testroot/stdout.expected $testroot/stdout
513 if [ "$ret" != "0" ]; then
514 diff -u $testroot/stdout.expected $testroot/stdout
516 test_done "$testroot" "$ret"
519 test_histedit_edit() {
520 local testroot=`test_init histedit_edit`
522 local orig_commit=`git_show_head $testroot/repo`
524 echo "modified alpha on master" > $testroot/repo/alpha
525 (cd $testroot/repo && git rm -q beta)
526 echo "new file on master" > $testroot/repo/epsilon/new
527 (cd $testroot/repo && git add epsilon/new)
528 git_commit $testroot/repo -m "committing changes"
529 local old_commit1=`git_show_head $testroot/repo`
531 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
532 git_commit $testroot/repo -m "committing to zeta on master"
533 local old_commit2=`git_show_head $testroot/repo`
535 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
537 if [ "$ret" != "0" ]; then
538 test_done "$testroot" "$ret"
542 echo "edit $old_commit1" > $testroot/histedit-script
543 echo "mesg committing changes" >> $testroot/histedit-script
544 echo "pick $old_commit2" >> $testroot/histedit-script
546 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
549 local short_old_commit1=`trim_obj_id 28 $old_commit1`
550 local short_old_commit2=`trim_obj_id 28 $old_commit2`
552 echo "G alpha" > $testroot/stdout.expected
553 echo "D beta" >> $testroot/stdout.expected
554 echo "A epsilon/new" >> $testroot/stdout.expected
555 echo "Stopping histedit for amending commit $old_commit1" \
556 >> $testroot/stdout.expected
557 cmp -s $testroot/stdout.expected $testroot/stdout
559 if [ "$ret" != "0" ]; then
560 diff -u $testroot/stdout.expected $testroot/stdout
561 test_done "$testroot" "$ret"
565 echo "edited modified alpha on master" > $testroot/wt/alpha
567 # test interaction of 'got stage' and histedit -c
568 (cd $testroot/wt && got stage alpha > /dev/null)
569 (cd $testroot/wt && got histedit -c > $testroot/stdout \
572 if [ "$ret" = "0" ]; then
573 echo "histedit succeeded unexpectedly" >&2
574 test_done "$testroot" "1"
577 echo -n "got: work tree contains files with staged changes; " \
578 > $testroot/stderr.expected
579 echo "these changes must be committed or unstaged first" \
580 >> $testroot/stderr.expected
581 cmp -s $testroot/stderr.expected $testroot/stderr
583 if [ "$ret" != "0" ]; then
584 diff -u $testroot/stderr.expected $testroot/stderr
585 test_done "$testroot" "$ret"
589 (cd $testroot/wt && got unstage alpha > /dev/null)
590 (cd $testroot/wt && got histedit -c > $testroot/stdout)
592 local new_commit1=`git_show_parent_commit $testroot/repo`
593 local new_commit2=`git_show_head $testroot/repo`
595 local short_new_commit1=`trim_obj_id 28 $new_commit1`
596 local short_new_commit2=`trim_obj_id 28 $new_commit2`
598 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
599 > $testroot/stdout.expected
600 echo "G epsilon/zeta" >> $testroot/stdout.expected
601 echo -n "$short_old_commit2 -> $short_new_commit2: " \
602 >> $testroot/stdout.expected
603 echo "committing to zeta on master" >> $testroot/stdout.expected
604 echo "Switching work tree to refs/heads/master" \
605 >> $testroot/stdout.expected
607 cmp -s $testroot/stdout.expected $testroot/stdout
609 if [ "$ret" != "0" ]; then
610 diff -u $testroot/stdout.expected $testroot/stdout
611 test_done "$testroot" "$ret"
615 echo "edited modified alpha on master" > $testroot/content.expected
616 cat $testroot/wt/alpha > $testroot/content
617 cmp -s $testroot/content.expected $testroot/content
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/content.expected $testroot/content
621 test_done "$testroot" "$ret"
625 if [ -e $testroot/wt/beta ]; then
626 echo "removed file beta still exists on disk" >&2
627 test_done "$testroot" "1"
631 echo "new file on master" > $testroot/content.expected
632 cat $testroot/wt/epsilon/new > $testroot/content
633 cmp -s $testroot/content.expected $testroot/content
635 if [ "$ret" != "0" ]; then
636 diff -u $testroot/content.expected $testroot/content
637 test_done "$testroot" "$ret"
641 (cd $testroot/wt && got status > $testroot/stdout)
643 echo -n > $testroot/stdout.expected
644 cmp -s $testroot/stdout.expected $testroot/stdout
646 if [ "$ret" != "0" ]; then
647 diff -u $testroot/stdout.expected $testroot/stdout
648 test_done "$testroot" "$ret"
652 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
653 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
654 echo "commit $new_commit1" >> $testroot/stdout.expected
655 echo "commit $orig_commit" >> $testroot/stdout.expected
656 cmp -s $testroot/stdout.expected $testroot/stdout
658 if [ "$ret" != "0" ]; then
659 diff -u $testroot/stdout.expected $testroot/stdout
661 test_done "$testroot" "$ret"
664 test_histedit_fold_last_commit() {
665 local testroot=`test_init histedit_fold_last_commit`
667 local orig_commit=`git_show_head $testroot/repo`
669 echo "modified alpha on master" > $testroot/repo/alpha
670 (cd $testroot/repo && git rm -q beta)
671 echo "new file on master" > $testroot/repo/epsilon/new
672 (cd $testroot/repo && git add epsilon/new)
673 git_commit $testroot/repo -m "committing changes"
674 local old_commit1=`git_show_head $testroot/repo`
676 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
677 git_commit $testroot/repo -m "committing to zeta on master"
678 local old_commit2=`git_show_head $testroot/repo`
680 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
682 if [ "$ret" != "0" ]; then
683 test_done "$testroot" "$ret"
687 echo "pick $old_commit1" > $testroot/histedit-script
688 echo "fold $old_commit2" >> $testroot/histedit-script
689 echo "mesg committing folded changes" >> $testroot/histedit-script
691 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
692 > $testroot/stdout 2> $testroot/stderr)
695 if [ "$ret" = "0" ]; then
696 echo "histedit succeeded unexpectedly" >&2
697 test_done "$testroot" "1"
701 echo "got: last commit in histedit script cannot be folded" \
702 > $testroot/stderr.expected
704 cmp -s $testroot/stderr.expected $testroot/stderr
706 if [ "$ret" != "0" ]; then
707 diff -u $testroot/stderr.expected $testroot/stderr
709 test_done "$testroot" "$ret"
712 test_histedit_missing_commit() {
713 local testroot=`test_init histedit_missing_commit`
715 local orig_commit=`git_show_head $testroot/repo`
717 echo "modified alpha on master" > $testroot/repo/alpha
718 (cd $testroot/repo && git rm -q beta)
719 echo "new file on master" > $testroot/repo/epsilon/new
720 (cd $testroot/repo && git add epsilon/new)
721 git_commit $testroot/repo -m "committing changes"
722 local old_commit1=`git_show_head $testroot/repo`
724 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
725 git_commit $testroot/repo -m "committing to zeta on master"
726 local old_commit2=`git_show_head $testroot/repo`
728 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
730 if [ "$ret" != "0" ]; then
731 test_done "$testroot" "$ret"
735 echo "pick $old_commit1" > $testroot/histedit-script
736 echo "mesg committing changes" >> $testroot/histedit-script
738 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
739 > $testroot/stdout 2> $testroot/stderr)
742 if [ "$ret" = "0" ]; then
743 echo "histedit succeeded unexpectedly" >&2
744 test_done "$testroot" "1"
748 echo "got: commit $old_commit2 missing from histedit script" \
749 > $testroot/stderr.expected
751 cmp -s $testroot/stderr.expected $testroot/stderr
753 if [ "$ret" != "0" ]; then
754 diff -u $testroot/stderr.expected $testroot/stderr
756 test_done "$testroot" "$ret"
759 test_histedit_abort() {
760 local testroot=`test_init histedit_abort`
762 local orig_commit=`git_show_head $testroot/repo`
764 echo "modified alpha on master" > $testroot/repo/alpha
765 (cd $testroot/repo && git rm -q beta)
766 echo "new file on master" > $testroot/repo/epsilon/new
767 (cd $testroot/repo && git add epsilon/new)
768 git_commit $testroot/repo -m "committing changes"
769 local old_commit1=`git_show_head $testroot/repo`
771 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
772 git_commit $testroot/repo -m "committing to zeta on master"
773 local old_commit2=`git_show_head $testroot/repo`
775 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
777 if [ "$ret" != "0" ]; then
778 test_done "$testroot" "$ret"
782 echo "edit $old_commit1" > $testroot/histedit-script
783 echo "mesg committing changes" >> $testroot/histedit-script
784 echo "pick $old_commit2" >> $testroot/histedit-script
786 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
789 local short_old_commit1=`trim_obj_id 28 $old_commit1`
790 local short_old_commit2=`trim_obj_id 28 $old_commit2`
792 echo "G alpha" > $testroot/stdout.expected
793 echo "D beta" >> $testroot/stdout.expected
794 echo "A epsilon/new" >> $testroot/stdout.expected
795 echo "Stopping histedit for amending commit $old_commit1" \
796 >> $testroot/stdout.expected
797 cmp -s $testroot/stdout.expected $testroot/stdout
799 if [ "$ret" != "0" ]; then
800 diff -u $testroot/stdout.expected $testroot/stdout
801 test_done "$testroot" "$ret"
805 echo "edited modified alpha on master" > $testroot/wt/alpha
807 (cd $testroot/wt && got histedit -a > $testroot/stdout)
809 local new_commit1=`git_show_parent_commit $testroot/repo`
810 local new_commit2=`git_show_head $testroot/repo`
812 echo "Switching work tree to refs/heads/master" \
813 > $testroot/stdout.expected
814 echo "R alpha" >> $testroot/stdout.expected
815 echo "R beta" >> $testroot/stdout.expected
816 echo "R epsilon/new" >> $testroot/stdout.expected
817 echo "Histedit of refs/heads/master aborted" \
818 >> $testroot/stdout.expected
820 cmp -s $testroot/stdout.expected $testroot/stdout
822 if [ "$ret" != "0" ]; then
823 diff -u $testroot/stdout.expected $testroot/stdout
824 test_done "$testroot" "$ret"
828 for f in alpha beta; do
829 echo "$f" > $testroot/content.expected
830 cat $testroot/wt/$f > $testroot/content
831 cmp -s $testroot/content.expected $testroot/content
833 if [ "$ret" != "0" ]; then
834 diff -u $testroot/content.expected $testroot/content
835 test_done "$testroot" "$ret"
840 echo "new file on master" > $testroot/content.expected
841 cat $testroot/wt/epsilon/new > $testroot/content
842 cmp -s $testroot/content.expected $testroot/content
844 if [ "$ret" != "0" ]; then
845 diff -u $testroot/content.expected $testroot/content
846 test_done "$testroot" "$ret"
850 (cd $testroot/wt && got status > $testroot/stdout)
852 echo "? epsilon/new" > $testroot/stdout.expected
853 cmp -s $testroot/stdout.expected $testroot/stdout
855 if [ "$ret" != "0" ]; then
856 diff -u $testroot/stdout.expected $testroot/stdout
857 test_done "$testroot" "$ret"
861 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
862 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
863 echo "commit $new_commit1" >> $testroot/stdout.expected
864 echo "commit $orig_commit" >> $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
867 if [ "$ret" != "0" ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
870 test_done "$testroot" "$ret"
873 test_histedit_path_prefix_drop() {
874 local testroot=`test_init histedit_path_prefix_drop`
875 local orig_commit=`git_show_head $testroot/repo`
877 echo "modified zeta" > $testroot/repo/epsilon/zeta
878 git_commit $testroot/repo -m "changing zeta"
879 local old_commit1=`git_show_head $testroot/repo`
881 got checkout -c $orig_commit -p gamma $testroot/repo \
882 $testroot/wt > /dev/null
884 if [ "$ret" != "0" ]; then
885 test_done "$testroot" "$ret"
889 echo "drop $old_commit1" > $testroot/histedit-script
891 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
892 > $testroot/stdout 2> $testroot/stderr)
895 if [ "$ret" = "0" ]; then
896 echo "histedit succeeded unexpectedly" >&2
897 test_done "$testroot" "1"
901 echo -n "got: cannot edit branch history which contains changes " \
902 > $testroot/stderr.expected
903 echo "outside of this work tree's path prefix" \
904 >> $testroot/stderr.expected
906 cmp -s $testroot/stderr.expected $testroot/stderr
908 if [ "$ret" != "0" ]; then
909 diff -u $testroot/stderr.expected $testroot/stderr
910 test_done "$testroot" "$ret"
915 got checkout -c $orig_commit -p epsilon $testroot/repo \
916 $testroot/wt > /dev/null
918 if [ "$ret" != "0" ]; then
919 test_done "$testroot" "$ret"
922 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
925 local short_old_commit1=`trim_obj_id 28 $old_commit1`
926 local short_old_commit2=`trim_obj_id 28 $old_commit2`
928 echo "$short_old_commit1 -> drop commit: changing zeta" \
929 > $testroot/stdout.expected
930 echo "Switching work tree to refs/heads/master" \
931 >> $testroot/stdout.expected
933 cmp -s $testroot/stdout.expected $testroot/stdout
935 if [ "$ret" != "0" ]; then
936 diff -u $testroot/stdout.expected $testroot/stdout
937 test_done "$testroot" "$ret"
941 echo "zeta" > $testroot/content.expected
942 cat $testroot/wt/zeta > $testroot/content
943 cmp -s $testroot/content.expected $testroot/content
945 if [ "$ret" != "0" ]; then
946 diff -u $testroot/content.expected $testroot/content
947 test_done "$testroot" "$ret"
952 (cd $testroot/wt && got status > $testroot/stdout)
954 echo -n > $testroot/stdout.expected
955 cmp -s $testroot/stdout.expected $testroot/stdout
957 if [ "$ret" != "0" ]; then
958 diff -u $testroot/stdout.expected $testroot/stdout
959 test_done "$testroot" "$ret"
963 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
964 echo "commit $orig_commit (master)" > $testroot/stdout.expected
965 cmp -s $testroot/stdout.expected $testroot/stdout
967 if [ "$ret" != "0" ]; then
968 diff -u $testroot/stdout.expected $testroot/stdout
970 test_done "$testroot" "$ret"
973 test_histedit_path_prefix_edit() {
974 local testroot=`test_init histedit_path_prefix_edit`
975 local orig_commit=`git_show_head $testroot/repo`
977 echo "modified zeta" > $testroot/repo/epsilon/zeta
978 git_commit $testroot/repo -m "changing zeta"
979 local old_commit1=`git_show_head $testroot/repo`
981 got diff -r $testroot/repo $orig_commit $old_commit1 \
982 > $testroot/diff.expected
984 got checkout -c $orig_commit -p gamma $testroot/repo \
985 $testroot/wt > /dev/null
987 if [ "$ret" != "0" ]; then
988 test_done "$testroot" "$ret"
992 echo "edit $old_commit1" > $testroot/histedit-script
993 echo "mesg modified zeta" >> $testroot/histedit-script
995 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
996 > $testroot/stdout 2> $testroot/stderr)
999 if [ "$ret" = "0" ]; then
1000 echo "histedit succeeded unexpectedly" >&2
1001 test_done "$testroot" "1"
1005 echo -n "got: cannot edit branch history which contains changes " \
1006 > $testroot/stderr.expected
1007 echo "outside of this work tree's path prefix" \
1008 >> $testroot/stderr.expected
1010 cmp -s $testroot/stderr.expected $testroot/stderr
1012 if [ "$ret" != "0" ]; then
1013 diff -u $testroot/stderr.expected $testroot/stderr
1014 test_done "$testroot" "$ret"
1019 got checkout -c $orig_commit -p epsilon $testroot/repo \
1020 $testroot/wt > /dev/null
1022 if [ "$ret" != "0" ]; then
1023 test_done "$testroot" "$ret"
1026 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1029 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1031 echo "G zeta" > $testroot/stdout.expected
1032 echo "Stopping histedit for amending commit $old_commit1" \
1033 >> $testroot/stdout.expected
1034 cmp -s $testroot/stdout.expected $testroot/stdout
1036 if [ "$ret" != "0" ]; then
1037 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1042 echo "modified zeta" > $testroot/content.expected
1043 cat $testroot/wt/zeta > $testroot/content
1044 cmp -s $testroot/content.expected $testroot/content
1046 if [ "$ret" != "0" ]; then
1047 diff -u $testroot/content.expected $testroot/content
1048 test_done "$testroot" "$ret"
1052 (cd $testroot/wt && got status > $testroot/stdout)
1054 echo "M zeta"> $testroot/stdout.expected
1055 cmp -s $testroot/stdout.expected $testroot/stdout
1057 if [ "$ret" != "0" ]; then
1058 diff -u $testroot/stdout.expected $testroot/stdout
1059 test_done "$testroot" "$ret"
1063 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1065 local new_commit1=`git_show_head $testroot/repo`
1066 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1068 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1069 > $testroot/stdout.expected
1070 echo "modified zeta" >> $testroot/stdout.expected
1071 echo "Switching work tree to refs/heads/master" \
1072 >> $testroot/stdout.expected
1074 cmp -s $testroot/stdout.expected $testroot/stdout
1076 if [ "$ret" != "0" ]; then
1077 diff -u $testroot/stdout.expected $testroot/stdout
1078 test_done "$testroot" "$ret"
1082 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1083 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1084 echo "commit $orig_commit" >> $testroot/stdout.expected
1085 cmp -s $testroot/stdout.expected $testroot/stdout
1087 if [ "$ret" != "0" ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1089 test_done "$testroot" "$ret"
1093 got diff -r $testroot/repo $orig_commit $new_commit1 \
1095 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1096 cmp -s $testroot/diff.expected $testroot/diff
1098 if [ "$ret" != "0" ]; then
1099 diff -u $testroot/diff.expected $testroot/diff
1101 test_done "$testroot" "$ret"
1104 test_histedit_outside_refs_heads() {
1105 local testroot=`test_init histedit_outside_refs_heads`
1106 local commit1=`git_show_head $testroot/repo`
1108 got checkout $testroot/repo $testroot/wt > /dev/null
1110 if [ "$ret" != "0" ]; then
1111 echo "got checkout failed unexpectedly"
1112 test_done "$testroot" "$ret"
1116 echo "modified alpha" > $testroot/wt/alpha
1118 (cd $testroot/wt && got commit -m 'change alpha' \
1119 > $testroot/stdout 2> $testroot/stderr)
1121 if [ "$ret" != "0" ]; then
1122 echo "got commit failed unexpectedly" >&2
1123 test_done "$testroot" "1"
1126 local commit2=`git_show_head $testroot/repo`
1128 got ref -r $testroot/repo -c master refs/remotes/origin/master
1130 if [ "$ret" != "0" ]; then
1131 echo "got ref failed unexpectedly" >&2
1132 test_done "$testroot" "1"
1136 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1138 if [ "$ret" != "0" ]; then
1139 echo "got update failed unexpectedly"
1140 test_done "$testroot" "$ret"
1144 echo "edit $commit2" > $testroot/histedit-script
1145 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1146 2> $testroot/stderr)
1148 echo -n "got: will not edit commit history of a branch outside the " \
1149 > $testroot/stderr.expected
1150 echo '"refs/heads/" reference namespace' \
1151 >> $testroot/stderr.expected
1152 cmp -s $testroot/stderr.expected $testroot/stderr
1154 if [ "$ret" != "0" ]; then
1155 diff -u $testroot/stderr.expected $testroot/stderr
1157 test_done "$testroot" "$ret"
1160 test_histedit_fold_last_commit_swap() {
1161 local testroot=`test_init histedit_fold_last_commit_swap`
1163 local orig_commit=`git_show_head $testroot/repo`
1165 echo "modified alpha on master" > $testroot/repo/alpha
1166 (cd $testroot/repo && git rm -q beta)
1167 echo "new file on master" > $testroot/repo/epsilon/new
1168 (cd $testroot/repo && git add epsilon/new)
1169 git_commit $testroot/repo -m "committing changes"
1170 local old_commit1=`git_show_head $testroot/repo`
1172 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1173 git_commit $testroot/repo -m "committing to zeta on master"
1174 local old_commit2=`git_show_head $testroot/repo`
1176 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1178 if [ "$ret" != "0" ]; then
1179 test_done "$testroot" "$ret"
1183 # fold commit2 into commit1 (requires swapping commits)
1184 echo "fold $old_commit2" > $testroot/histedit-script
1185 echo "pick $old_commit1" >> $testroot/histedit-script
1186 echo "mesg committing folded changes" >> $testroot/histedit-script
1188 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1189 > $testroot/stdout 2> $testroot/stderr)
1192 if [ "$ret" != "0" ]; then
1193 echo "histedit failed unexpectedly" >&2
1194 test_done "$testroot" "$ret"
1198 local new_commit=`git_show_head $testroot/repo`
1200 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1201 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1202 local short_new_commit=`trim_obj_id 28 $new_commit`
1204 echo "G epsilon/zeta" >> $testroot/stdout.expected
1205 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1206 >> $testroot/stdout.expected
1207 echo "on master" >> $testroot/stdout.expected
1208 echo "G alpha" >> $testroot/stdout.expected
1209 echo "D beta" >> $testroot/stdout.expected
1210 echo "A epsilon/new" >> $testroot/stdout.expected
1211 echo -n "$short_old_commit1 -> $short_new_commit: " \
1212 >> $testroot/stdout.expected
1213 echo "committing folded changes" >> $testroot/stdout.expected
1214 echo "Switching work tree to refs/heads/master" \
1215 >> $testroot/stdout.expected
1217 cmp -s $testroot/stdout.expected $testroot/stdout
1219 if [ "$ret" != "0" ]; then
1220 diff -u $testroot/stdout.expected $testroot/stdout
1222 test_done "$testroot" "$ret"
1225 test_histedit_split_commit() {
1226 local testroot=`test_init histedit_split_commit`
1228 local orig_commit=`git_show_head $testroot/repo`
1230 echo "modified alpha on master" > $testroot/repo/alpha
1231 (cd $testroot/repo && git rm -q beta)
1232 echo "new file on master" > $testroot/repo/epsilon/new
1233 (cd $testroot/repo && git add epsilon/new)
1234 git_commit $testroot/repo -m "committing changes 1"
1235 local old_commit1=`git_show_head $testroot/repo`
1236 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1238 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1239 git_commit $testroot/repo -m "committing changes 2"
1240 local old_commit2=`git_show_head $testroot/repo`
1241 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1243 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1245 if [ "$ret" != "0" ]; then
1246 test_done "$testroot" "$ret"
1250 # split commit1 into commitA and commitB and commitC
1251 echo "e $old_commit1" > $testroot/histedit-script
1252 echo "p $old_commit2" >> $testroot/histedit-script
1254 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1255 > $testroot/stdout 2> $testroot/stderr)
1257 if [ "$ret" != "0" ]; then
1258 echo "histedit failed unexpectedly:" >&2
1259 cat $testroot/stderr >&2
1260 test_done "$testroot" "$ret"
1264 echo "G alpha" > $testroot/stdout.expected
1265 echo "D beta" >> $testroot/stdout.expected
1266 echo "A epsilon/new" >> $testroot/stdout.expected
1267 echo "Stopping histedit for amending commit $old_commit1" \
1268 >> $testroot/stdout.expected
1270 cmp -s $testroot/stdout.expected $testroot/stdout
1272 if [ "$ret" != "0" ]; then
1273 diff -u $testroot/stdout.expected $testroot/stdout
1274 test_done "$testroot" "$ret"
1278 (cd $testroot/wt && got ci -m "commitA" alpha >/dev/null)
1280 if [ "$ret" != "0" ]; then
1281 echo "commit failed unexpectedly" >&2
1282 test_done "$testroot" "$ret"
1286 (cd $testroot/wt && got ci -m "commitB" beta >/dev/null)
1288 if [ "$ret" != "0" ]; then
1289 echo "commit failed unexpectedly" >&2
1290 test_done "$testroot" "$ret"
1294 (cd $testroot/wt && got ci -m "commitC" epsilon/new >/dev/null)
1296 if [ "$ret" != "0" ]; then
1297 echo "commit failed unexpectedly" >&2
1298 test_done "$testroot" "$ret"
1302 (cd $testroot/wt && got histedit -c \
1303 > $testroot/stdout 2> $testroot/stderr)
1305 if [ "$ret" != "0" ]; then
1306 echo "histedit failed unexpectedly:" >&2
1307 cat $testroot/stderr >&2
1308 test_done "$testroot" "$ret"
1311 local new_commit2=`git_show_head $testroot/repo`
1312 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1314 echo "$short_old_commit1 -> no-op change: committing changes 1" \
1315 > $testroot/stdout.expected
1316 echo "G epsilon/zeta" >> $testroot/stdout.expected
1317 echo "$short_old_commit2 -> $short_new_commit2: committing changes 2" \
1318 >> $testroot/stdout.expected
1319 echo "Switching work tree to refs/heads/master" \
1320 >> $testroot/stdout.expected
1322 cmp -s $testroot/stdout.expected $testroot/stdout
1324 if [ "$ret" != "0" ]; then
1325 diff -u $testroot/stdout.expected $testroot/stdout
1327 test_done "$testroot" "$ret"
1331 test_histedit_duplicate_commit_in_script() {
1332 local testroot=`test_init histedit_duplicate_commit_in_script`
1334 local orig_commit=`git_show_head $testroot/repo`
1336 echo "modified alpha on master" > $testroot/repo/alpha
1337 (cd $testroot/repo && git rm -q beta)
1338 echo "new file on master" > $testroot/repo/epsilon/new
1339 (cd $testroot/repo && git add epsilon/new)
1340 git_commit $testroot/repo -m "committing changes 1"
1341 local old_commit1=`git_show_head $testroot/repo`
1343 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1344 git_commit $testroot/repo -m "committing changes 2"
1345 local old_commit2=`git_show_head $testroot/repo`
1347 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1349 if [ "$ret" != "0" ]; then
1350 test_done "$testroot" "$ret"
1354 # This histedit script lists commit1 more than once
1355 echo "p $old_commit1" > $testroot/histedit-script
1356 echo "p $old_commit1" >> $testroot/histedit-script
1357 echo "p $old_commit2" >> $testroot/histedit-script
1359 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1360 > $testroot/stdout 2> $testroot/stderr)
1362 if [ "$ret" = "0" ]; then
1363 echo "histedit succeeded unexpectedly:" >&2
1364 cat $testroot/stdout >&2
1365 test_done "$testroot" "$ret"
1369 echo -n "got: commit $old_commit1 is listed more than once " \
1370 > $testroot/stderr.expected
1371 echo "in histedit script" >> $testroot/stderr.expected
1373 cmp -s $testroot/stderr.expected $testroot/stderr
1375 if [ "$ret" != "0" ]; then
1376 diff -u $testroot/stderr.expected $testroot/stderr
1378 test_done "$testroot" "$ret"
1382 # if a previous commit introduces a new file, and it is folded into a commit
1383 # that deletes the same file, the file still exists after the histedit
1384 test_histedit_fold_add_delete() {
1385 local testroot=`test_init histedit_fold`
1387 local orig_commit=`git_show_head $testroot/repo`
1389 echo "added new file epsilon/psi" > $testroot/repo/epsilon/psi
1390 (cd $testroot/repo && git add epsilon/psi)
1391 git_commit $testroot/repo -m "committing changes"
1392 local old_commit1=`git_show_head $testroot/repo`
1394 echo "modified epsilon/psi" > $testroot/repo/epsilon/psi
1395 git_commit $testroot/repo -m "editing psi"
1396 local old_commit2=`git_show_head $testroot/repo`
1398 (cd $testroot/repo && git rm -q epsilon/psi)
1399 git_commit $testroot/repo -m "removing psi"
1400 local old_commit3=`git_show_head $testroot/repo`
1402 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1404 if [ "$ret" != "0" ]; then
1405 test_done "$testroot" "$ret"
1409 echo "fold $old_commit1" > $testroot/histedit-script
1410 echo "fold $old_commit2" >> $testroot/histedit-script
1411 echo "pick $old_commit3" >> $testroot/histedit-script
1412 echo "mesg folded changes" >> $testroot/histedit-script
1414 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1417 local new_commit1=`git_show_head $testroot/repo`
1419 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1420 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1421 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1422 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1424 echo "A epsilon/psi" >> $testroot/stdout.expected
1425 echo "$short_old_commit1 -> fold commit: committing changes" \
1426 >> $testroot/stdout.expected
1427 echo "G epsilon/psi" >> $testroot/stdout.expected
1428 echo "$short_old_commit2 -> fold commit: editing psi" \
1429 >> $testroot/stdout.expected
1430 echo "D epsilon/psi" >> $testroot/stdout.expected
1431 echo "$short_old_commit3 -> no-op change: folded changes" \
1432 >> $testroot/stdout.expected
1433 echo "Switching work tree to refs/heads/master" \
1434 >> $testroot/stdout.expected
1436 cmp -s $testroot/stdout.expected $testroot/stdout
1438 if [ "$ret" != "0" ]; then
1439 diff -u $testroot/stdout.expected $testroot/stdout
1440 test_done "$testroot" "$ret"
1444 if [ -e $testroot/wt/epsilon/psi ]; then
1445 echo "removed file psi still exists on disk" >&2
1446 test_done "$testroot" "1"
1450 (cd $testroot/wt && got status > $testroot/stdout)
1452 echo -n > $testroot/stdout.expected
1453 cmp -s $testroot/stdout.expected $testroot/stdout
1455 if [ "$ret" != "0" ]; then
1456 diff -u $testroot/stdout.expected $testroot/stdout
1457 test_done "$testroot" "$ret"
1461 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1462 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1463 cmp -s $testroot/stdout.expected $testroot/stdout
1465 if [ "$ret" != "0" ]; then
1466 diff -u $testroot/stdout.expected $testroot/stdout
1467 test_done "$testroot" "$ret"
1471 got tree -r $testroot/repo epsilon > $testroot/stdout
1472 echo "zeta" > $testroot/stdout.expected
1473 cmp -s $testroot/stdout.expected $testroot/stdout
1475 if [ "$ret" != "0" ]; then
1476 diff -u $testroot/stdout.expected $testroot/stdout
1478 test_done "$testroot" "$ret"
1481 test_histedit_fold_only() {
1482 local testroot=`test_init histedit_fold_only`
1484 local orig_commit=`git_show_head $testroot/repo`
1486 echo "modified alpha on master" > $testroot/repo/alpha
1487 (cd $testroot/repo && git rm -q beta)
1488 echo "new file on master" > $testroot/repo/epsilon/new
1489 (cd $testroot/repo && git add epsilon/new)
1490 git_commit $testroot/repo -m "committing changes"
1491 local old_commit1=`git_show_head $testroot/repo`
1493 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1494 git_commit $testroot/repo -m "committing to zeta on master"
1495 local old_commit2=`git_show_head $testroot/repo`
1497 echo "modified delta on master" > $testroot/repo/gamma/delta
1498 git_commit $testroot/repo -m "committing to delta on master"
1499 local old_commit3=`git_show_head $testroot/repo`
1501 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1503 if [ "$ret" != "0" ]; then
1504 test_done "$testroot" "$ret"
1508 cat > $testroot/editor.sh <<EOF
1510 sed -i 's/.*/committing folded changes/' "\$1"
1512 chmod +x $testroot/editor.sh
1514 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1515 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1517 local new_commit1=`git_show_head $testroot/repo`
1519 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1520 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1521 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1522 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1523 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1525 echo "G alpha" > $testroot/stdout.expected
1526 echo "D beta" >> $testroot/stdout.expected
1527 echo "A epsilon/new" >> $testroot/stdout.expected
1528 echo "$short_old_commit1 -> fold commit: committing changes" \
1529 >> $testroot/stdout.expected
1530 echo "G epsilon/zeta" >> $testroot/stdout.expected
1531 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1532 echo "fold commit: committing to zeta on master" \
1533 >> $testroot/stdout.expected
1534 echo "G gamma/delta" >> $testroot/stdout.expected
1535 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1536 >> $testroot/stdout.expected
1537 echo "committing folded changes" >> $testroot/stdout.expected
1538 echo "Switching work tree to refs/heads/master" \
1539 >> $testroot/stdout.expected
1541 cmp -s $testroot/stdout.expected $testroot/stdout
1543 if [ "$ret" != "0" ]; then
1544 diff -u $testroot/stdout.expected $testroot/stdout
1545 test_done "$testroot" "$ret"
1549 echo "modified alpha on master" > $testroot/content.expected
1550 cat $testroot/wt/alpha > $testroot/content
1551 cmp -s $testroot/content.expected $testroot/content
1553 if [ "$ret" != "0" ]; then
1554 diff -u $testroot/content.expected $testroot/content
1555 test_done "$testroot" "$ret"
1559 if [ -e $testroot/wt/beta ]; then
1560 echo "removed file beta still exists on disk" >&2
1561 test_done "$testroot" "1"
1565 echo "new file on master" > $testroot/content.expected
1566 cat $testroot/wt/epsilon/new > $testroot/content
1567 cmp -s $testroot/content.expected $testroot/content
1569 if [ "$ret" != "0" ]; then
1570 diff -u $testroot/content.expected $testroot/content
1571 test_done "$testroot" "$ret"
1575 (cd $testroot/wt && got status > $testroot/stdout)
1577 echo -n > $testroot/stdout.expected
1578 cmp -s $testroot/stdout.expected $testroot/stdout
1580 if [ "$ret" != "0" ]; then
1581 diff -u $testroot/stdout.expected $testroot/stdout
1582 test_done "$testroot" "$ret"
1586 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1587 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1588 echo "commit $orig_commit" >> $testroot/stdout.expected
1589 cmp -s $testroot/stdout.expected $testroot/stdout
1591 if [ "$ret" != "0" ]; then
1592 diff -u $testroot/stdout.expected $testroot/stdout
1594 test_done "$testroot" "$ret"
1597 test_histedit_fold_only_empty_logmsg() {
1598 local testroot=`test_init histedit_fold_only_empty_logmsg`
1600 local orig_commit=`git_show_head $testroot/repo`
1602 echo "modified alpha on master" > $testroot/repo/alpha
1603 (cd $testroot/repo && git rm -q beta)
1604 echo "new file on master" > $testroot/repo/epsilon/new
1605 (cd $testroot/repo && git add epsilon/new)
1606 git_commit $testroot/repo -m "committing changes"
1607 local old_commit1=`git_show_head $testroot/repo`
1609 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1610 git_commit $testroot/repo -m "committing to zeta on master"
1611 local old_commit2=`git_show_head $testroot/repo`
1613 echo "modified delta on master" > $testroot/repo/gamma/delta
1614 git_commit $testroot/repo -m "committing to delta on master"
1615 local old_commit3=`git_show_head $testroot/repo`
1617 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1619 if [ "$ret" != "0" ]; then
1620 test_done "$testroot" "$ret"
1624 cat > $testroot/editor.sh <<EOF
1628 chmod +x $testroot/editor.sh
1630 (cd $testroot/wt && env EDITOR="$testroot/editor.sh" \
1631 VISUAL="$testroot/editor.sh" got histedit -f > $testroot/stdout)
1633 local new_commit1=`git_show_head $testroot/repo`
1635 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1636 local very_short_old_commit1=`trim_obj_id 29 $old_commit1`
1637 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1638 local short_old_commit3=`trim_obj_id 28 $old_commit3`
1639 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1640 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1642 echo "G alpha" > $testroot/stdout.expected
1643 echo "D beta" >> $testroot/stdout.expected
1644 echo "A epsilon/new" >> $testroot/stdout.expected
1645 echo "$short_old_commit1 -> fold commit: committing changes" \
1646 >> $testroot/stdout.expected
1647 echo "G epsilon/zeta" >> $testroot/stdout.expected
1648 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
1649 echo "fold commit: committing to zeta on master" \
1650 >> $testroot/stdout.expected
1651 echo "G gamma/delta" >> $testroot/stdout.expected
1652 echo -n "$short_old_commit3 -> $short_new_commit1: " \
1653 >> $testroot/stdout.expected
1654 echo "# log message of folded commit $very_short_old_commit1" \
1655 >> $testroot/stdout.expected
1656 echo "Switching work tree to refs/heads/master" \
1657 >> $testroot/stdout.expected
1659 cmp -s $testroot/stdout.expected $testroot/stdout
1661 if [ "$ret" != "0" ]; then
1662 diff -u $testroot/stdout.expected $testroot/stdout
1663 test_done "$testroot" "$ret"
1667 echo "modified alpha on master" > $testroot/content.expected
1668 cat $testroot/wt/alpha > $testroot/content
1669 cmp -s $testroot/content.expected $testroot/content
1671 if [ "$ret" != "0" ]; then
1672 diff -u $testroot/content.expected $testroot/content
1673 test_done "$testroot" "$ret"
1677 if [ -e $testroot/wt/beta ]; then
1678 echo "removed file beta still exists on disk" >&2
1679 test_done "$testroot" "1"
1683 echo "new file on master" > $testroot/content.expected
1684 cat $testroot/wt/epsilon/new > $testroot/content
1685 cmp -s $testroot/content.expected $testroot/content
1687 if [ "$ret" != "0" ]; then
1688 diff -u $testroot/content.expected $testroot/content
1689 test_done "$testroot" "$ret"
1693 (cd $testroot/wt && got status > $testroot/stdout)
1695 echo -n > $testroot/stdout.expected
1696 cmp -s $testroot/stdout.expected $testroot/stdout
1698 if [ "$ret" != "0" ]; then
1699 diff -u $testroot/stdout.expected $testroot/stdout
1700 test_done "$testroot" "$ret"
1704 (cd $testroot/wt && got log | grep ^commit > $testroot/stdout)
1705 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1706 echo "commit $orig_commit" >> $testroot/stdout.expected
1707 cmp -s $testroot/stdout.expected $testroot/stdout
1709 if [ "$ret" != "0" ]; then
1710 diff -u $testroot/stdout.expected $testroot/stdout
1712 test_done "$testroot" "$ret"
1716 run_test test_histedit_no_op
1717 run_test test_histedit_swap
1718 run_test test_histedit_drop
1719 run_test test_histedit_fold
1720 run_test test_histedit_edit
1721 run_test test_histedit_fold_last_commit
1722 run_test test_histedit_missing_commit
1723 run_test test_histedit_abort
1724 run_test test_histedit_path_prefix_drop
1725 run_test test_histedit_path_prefix_edit
1726 run_test test_histedit_outside_refs_heads
1727 run_test test_histedit_fold_last_commit_swap
1728 run_test test_histedit_split_commit
1729 run_test test_histedit_duplicate_commit_in_script
1730 run_test test_histedit_fold_add_delete
1731 run_test test_histedit_fold_only
1732 run_test test_histedit_fold_only_empty_logmsg