3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 function test_histedit_no_op {
20 local testroot=`test_init histedit_no_op`
22 local orig_commit=`git_show_head $testroot/repo`
24 echo "modified alpha on master" > $testroot/repo/alpha
25 (cd $testroot/repo && git rm -q beta)
26 echo "new file on master" > $testroot/repo/epsilon/new
27 (cd $testroot/repo && git add epsilon/new)
28 git_commit $testroot/repo -m "committing changes"
29 local old_commit1=`git_show_head $testroot/repo`
31 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
32 git_commit $testroot/repo -m "committing to zeta on master"
33 local old_commit2=`git_show_head $testroot/repo`
35 got diff -r $testroot/repo $orig_commit $old_commit2 \
36 > $testroot/diff.expected
38 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
40 if [ "$ret" != "0" ]; then
41 test_done "$testroot" "$ret"
45 echo "pick $old_commit1" > $testroot/histedit-script
46 echo "pick $old_commit2" >> $testroot/histedit-script
48 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
51 local new_commit1=`git_show_parent_commit $testroot/repo`
52 local new_commit2=`git_show_head $testroot/repo`
54 local short_old_commit1=`trim_obj_id 28 $old_commit1`
55 local short_old_commit2=`trim_obj_id 28 $old_commit2`
56 local short_new_commit1=`trim_obj_id 28 $new_commit1`
57 local short_new_commit2=`trim_obj_id 28 $new_commit2`
59 echo "G alpha" > $testroot/stdout.expected
60 echo "D beta" >> $testroot/stdout.expected
61 echo "A epsilon/new" >> $testroot/stdout.expected
62 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
63 >> $testroot/stdout.expected
64 echo "G epsilon/zeta" >> $testroot/stdout.expected
65 echo -n "$short_old_commit2 -> $short_new_commit2: " \
66 >> $testroot/stdout.expected
67 echo "committing to zeta on master" >> $testroot/stdout.expected
68 echo "Switching work tree to refs/heads/master" \
69 >> $testroot/stdout.expected
71 cmp -s $testroot/stdout.expected $testroot/stdout
73 if [ "$ret" != "0" ]; then
74 diff -u $testroot/stdout.expected $testroot/stdout
75 test_done "$testroot" "$ret"
79 echo "modified alpha on master" > $testroot/content.expected
80 cat $testroot/wt/alpha > $testroot/content
81 cmp -s $testroot/content.expected $testroot/content
83 if [ "$ret" != "0" ]; then
84 diff -u $testroot/content.expected $testroot/content
85 test_done "$testroot" "$ret"
89 if [ -e $testroot/wt/beta ]; then
90 echo "removed file beta still exists on disk" >&2
91 test_done "$testroot" "1"
95 echo "new file on master" > $testroot/content.expected
96 cat $testroot/wt/epsilon/new > $testroot/content
97 cmp -s $testroot/content.expected $testroot/content
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/content.expected $testroot/content
101 test_done "$testroot" "$ret"
105 (cd $testroot/wt && got status > $testroot/stdout)
107 echo -n > $testroot/stdout.expected
108 cmp -s $testroot/stdout.expected $testroot/stdout
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/stdout.expected $testroot/stdout
112 test_done "$testroot" "$ret"
116 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
117 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
118 echo "commit $new_commit1" >> $testroot/stdout.expected
119 echo "commit $orig_commit" >> $testroot/stdout.expected
120 cmp -s $testroot/stdout.expected $testroot/stdout
122 if [ "$ret" != "0" ]; then
123 diff -u $testroot/stdout.expected $testroot/stdout
124 test_done "$testroot" "$ret"
128 got diff -r $testroot/repo $orig_commit $new_commit2 \
130 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
131 cmp -s $testroot/diff.expected $testroot/diff
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/diff.expected $testroot/diff
136 test_done "$testroot" "$ret"
139 function test_histedit_swap {
140 local testroot=`test_init histedit_swap`
142 local orig_commit=`git_show_head $testroot/repo`
144 echo "modified alpha on master" > $testroot/repo/alpha
145 (cd $testroot/repo && git rm -q beta)
146 echo "new file on master" > $testroot/repo/epsilon/new
147 (cd $testroot/repo && git add epsilon/new)
148 git_commit $testroot/repo -m "committing changes"
149 local old_commit1=`git_show_head $testroot/repo`
151 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
152 git_commit $testroot/repo -m "committing to zeta on master"
153 local old_commit2=`git_show_head $testroot/repo`
155 got diff -r $testroot/repo $orig_commit $old_commit2 \
156 > $testroot/diff.expected
158 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
160 if [ "$ret" != "0" ]; then
161 test_done "$testroot" "$ret"
165 echo "pick $old_commit2" > $testroot/histedit-script
166 echo "pick $old_commit1" >> $testroot/histedit-script
168 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
171 local new_commit2=`git_show_parent_commit $testroot/repo`
172 local new_commit1=`git_show_head $testroot/repo`
174 local short_old_commit1=`trim_obj_id 28 $old_commit1`
175 local short_old_commit2=`trim_obj_id 28 $old_commit2`
176 local short_new_commit1=`trim_obj_id 28 $new_commit1`
177 local short_new_commit2=`trim_obj_id 28 $new_commit2`
179 echo "G epsilon/zeta" > $testroot/stdout.expected
180 echo -n "$short_old_commit2 -> $short_new_commit2: " \
181 >> $testroot/stdout.expected
182 echo "committing to zeta on master" >> $testroot/stdout.expected
183 echo "G alpha" >> $testroot/stdout.expected
184 echo "D beta" >> $testroot/stdout.expected
185 echo "A epsilon/new" >> $testroot/stdout.expected
186 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
187 >> $testroot/stdout.expected
188 echo "Switching work tree to refs/heads/master" \
189 >> $testroot/stdout.expected
191 cmp -s $testroot/stdout.expected $testroot/stdout
193 if [ "$ret" != "0" ]; then
194 diff -u $testroot/stdout.expected $testroot/stdout
195 test_done "$testroot" "$ret"
199 echo "modified alpha on master" > $testroot/content.expected
200 cat $testroot/wt/alpha > $testroot/content
201 cmp -s $testroot/content.expected $testroot/content
203 if [ "$ret" != "0" ]; then
204 diff -u $testroot/content.expected $testroot/content
205 test_done "$testroot" "$ret"
209 if [ -e $testroot/wt/beta ]; then
210 echo "removed file beta still exists on disk" >&2
211 test_done "$testroot" "1"
215 echo "new file on master" > $testroot/content.expected
216 cat $testroot/wt/epsilon/new > $testroot/content
217 cmp -s $testroot/content.expected $testroot/content
219 if [ "$ret" != "0" ]; then
220 diff -u $testroot/content.expected $testroot/content
221 test_done "$testroot" "$ret"
225 (cd $testroot/wt && got status > $testroot/stdout)
227 echo -n > $testroot/stdout.expected
228 cmp -s $testroot/stdout.expected $testroot/stdout
230 if [ "$ret" != "0" ]; then
231 diff -u $testroot/stdout.expected $testroot/stdout
232 test_done "$testroot" "$ret"
236 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
237 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
238 echo "commit $new_commit2" >> $testroot/stdout.expected
239 echo "commit $orig_commit" >> $testroot/stdout.expected
240 cmp -s $testroot/stdout.expected $testroot/stdout
242 if [ "$ret" != "0" ]; then
243 diff -u $testroot/stdout.expected $testroot/stdout
244 test_done "$testroot" "$ret"
248 got diff -r $testroot/repo $orig_commit $new_commit1 \
250 sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected
251 cmp -s $testroot/diff.expected $testroot/diff
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/diff.expected $testroot/diff
256 test_done "$testroot" "$ret"
259 function test_histedit_drop {
260 local testroot=`test_init histedit_drop`
261 local orig_commit=`git_show_head $testroot/repo`
263 echo "modified alpha on master" > $testroot/repo/alpha
264 (cd $testroot/repo && git rm -q beta)
265 echo "new file on master" > $testroot/repo/epsilon/new
266 (cd $testroot/repo && git add epsilon/new)
267 git_commit $testroot/repo -m "committing changes"
268 local old_commit1=`git_show_head $testroot/repo`
270 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
271 git_commit $testroot/repo -m "committing to zeta on master"
272 local old_commit2=`git_show_head $testroot/repo`
274 got diff -r $testroot/repo $old_commit1 $old_commit2 \
275 > $testroot/diff.expected
277 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
279 if [ "$ret" != "0" ]; then
280 test_done "$testroot" "$ret"
284 echo "drop $old_commit1" > $testroot/histedit-script
285 echo "pick $old_commit2" >> $testroot/histedit-script
287 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
290 local new_commit2=`git_show_head $testroot/repo`
292 local short_old_commit1=`trim_obj_id 28 $old_commit1`
293 local short_old_commit2=`trim_obj_id 28 $old_commit2`
294 local short_new_commit2=`trim_obj_id 28 $new_commit2`
296 echo "$short_old_commit1 -> drop commit: committing changes" \
297 > $testroot/stdout.expected
298 echo "G epsilon/zeta" >> $testroot/stdout.expected
299 echo -n "$short_old_commit2 -> $short_new_commit2: " \
300 >> $testroot/stdout.expected
301 echo "committing to zeta on master" >> $testroot/stdout.expected
302 echo "Switching work tree to refs/heads/master" \
303 >> $testroot/stdout.expected
305 cmp -s $testroot/stdout.expected $testroot/stdout
307 if [ "$ret" != "0" ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
313 for f in alpha beta; do
314 echo "$f" > $testroot/content.expected
315 cat $testroot/wt/$f > $testroot/content
316 cmp -s $testroot/content.expected $testroot/content
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/content.expected $testroot/content
320 test_done "$testroot" "$ret"
325 if [ -e $testroot/wt/new ]; then
326 echo "file new exists on disk but should not" >&2
327 test_done "$testroot" "1"
331 (cd $testroot/wt && got status > $testroot/stdout)
333 echo -n > $testroot/stdout.expected
334 cmp -s $testroot/stdout.expected $testroot/stdout
336 if [ "$ret" != "0" ]; then
337 diff -u $testroot/stdout.expected $testroot/stdout
338 test_done "$testroot" "$ret"
342 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
343 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
344 echo "commit $orig_commit" >> $testroot/stdout.expected
345 cmp -s $testroot/stdout.expected $testroot/stdout
347 if [ "$ret" != "0" ]; then
348 diff -u $testroot/stdout.expected $testroot/stdout
349 test_done "$testroot" "$ret"
353 got diff -r $testroot/repo $orig_commit $new_commit2 \
355 sed -i -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected
356 sed -i -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected
357 cmp -s $testroot/diff.expected $testroot/diff
359 if [ "$ret" != "0" ]; then
360 diff -u $testroot/diff.expected $testroot/diff
362 test_done "$testroot" "$ret"
365 function test_histedit_fold {
366 local testroot=`test_init histedit_fold`
368 local orig_commit=`git_show_head $testroot/repo`
370 echo "modified alpha on master" > $testroot/repo/alpha
371 (cd $testroot/repo && git rm -q beta)
372 echo "new file on master" > $testroot/repo/epsilon/new
373 (cd $testroot/repo && git add epsilon/new)
374 git_commit $testroot/repo -m "committing changes"
375 local old_commit1=`git_show_head $testroot/repo`
377 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
378 git_commit $testroot/repo -m "committing to zeta on master"
379 local old_commit2=`git_show_head $testroot/repo`
381 echo "modified delta on master" > $testroot/repo/gamma/delta
382 git_commit $testroot/repo -m "committing to delta on master"
383 local old_commit3=`git_show_head $testroot/repo`
385 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
387 if [ "$ret" != "0" ]; then
388 test_done "$testroot" "$ret"
392 echo "fold $old_commit1" > $testroot/histedit-script
393 echo "drop $old_commit2" >> $testroot/histedit-script
394 echo "pick $old_commit3" >> $testroot/histedit-script
395 echo "mesg committing folded changes" >> $testroot/histedit-script
397 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
400 local new_commit1=`git_show_parent_commit $testroot/repo`
401 local new_commit2=`git_show_head $testroot/repo`
403 local short_old_commit1=`trim_obj_id 28 $old_commit1`
404 local short_old_commit2=`trim_obj_id 28 $old_commit2`
405 local short_old_commit3=`trim_obj_id 28 $old_commit3`
406 local short_new_commit1=`trim_obj_id 28 $new_commit1`
407 local short_new_commit2=`trim_obj_id 28 $new_commit2`
409 echo "G alpha" > $testroot/stdout.expected
410 echo "D beta" >> $testroot/stdout.expected
411 echo "A epsilon/new" >> $testroot/stdout.expected
412 echo "$short_old_commit1 -> fold commit: committing changes" \
413 >> $testroot/stdout.expected
414 echo -n "$short_old_commit2 -> " >> $testroot/stdout.expected
415 echo "drop commit: committing to zeta on master" \
416 >> $testroot/stdout.expected
417 echo "G gamma/delta" >> $testroot/stdout.expected
418 echo -n "$short_old_commit3 -> $short_new_commit2: " \
419 >> $testroot/stdout.expected
420 echo "committing folded changes" >> $testroot/stdout.expected
421 echo "Switching work tree to refs/heads/master" \
422 >> $testroot/stdout.expected
424 cmp -s $testroot/stdout.expected $testroot/stdout
426 if [ "$ret" != "0" ]; then
427 diff -u $testroot/stdout.expected $testroot/stdout
428 test_done "$testroot" "$ret"
432 echo "modified alpha on master" > $testroot/content.expected
433 cat $testroot/wt/alpha > $testroot/content
434 cmp -s $testroot/content.expected $testroot/content
436 if [ "$ret" != "0" ]; then
437 diff -u $testroot/content.expected $testroot/content
438 test_done "$testroot" "$ret"
442 if [ -e $testroot/wt/beta ]; then
443 echo "removed file beta still exists on disk" >&2
444 test_done "$testroot" "1"
448 echo "new file on master" > $testroot/content.expected
449 cat $testroot/wt/epsilon/new > $testroot/content
450 cmp -s $testroot/content.expected $testroot/content
452 if [ "$ret" != "0" ]; then
453 diff -u $testroot/content.expected $testroot/content
454 test_done "$testroot" "$ret"
458 (cd $testroot/wt && got status > $testroot/stdout)
460 echo -n > $testroot/stdout.expected
461 cmp -s $testroot/stdout.expected $testroot/stdout
463 if [ "$ret" != "0" ]; then
464 diff -u $testroot/stdout.expected $testroot/stdout
465 test_done "$testroot" "$ret"
469 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
470 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
471 echo "commit $orig_commit" >> $testroot/stdout.expected
472 cmp -s $testroot/stdout.expected $testroot/stdout
474 if [ "$ret" != "0" ]; then
475 diff -u $testroot/stdout.expected $testroot/stdout
477 test_done "$testroot" "$ret"
480 function test_histedit_edit {
481 local testroot=`test_init histedit_edit`
483 local orig_commit=`git_show_head $testroot/repo`
485 echo "modified alpha on master" > $testroot/repo/alpha
486 (cd $testroot/repo && git rm -q beta)
487 echo "new file on master" > $testroot/repo/epsilon/new
488 (cd $testroot/repo && git add epsilon/new)
489 git_commit $testroot/repo -m "committing changes"
490 local old_commit1=`git_show_head $testroot/repo`
492 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
493 git_commit $testroot/repo -m "committing to zeta on master"
494 local old_commit2=`git_show_head $testroot/repo`
496 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
498 if [ "$ret" != "0" ]; then
499 test_done "$testroot" "$ret"
503 echo "edit $old_commit1" > $testroot/histedit-script
504 echo "mesg committing changes" >> $testroot/histedit-script
505 echo "pick $old_commit2" >> $testroot/histedit-script
507 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
510 local short_old_commit1=`trim_obj_id 28 $old_commit1`
511 local short_old_commit2=`trim_obj_id 28 $old_commit2`
513 echo "G alpha" > $testroot/stdout.expected
514 echo "D beta" >> $testroot/stdout.expected
515 echo "A epsilon/new" >> $testroot/stdout.expected
516 echo "Stopping histedit for amending commit $old_commit1" \
517 >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected $testroot/stdout
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
526 echo "edited modified alpha on master" > $testroot/wt/alpha
528 # test interaction of 'got stage' and histedit -c
529 (cd $testroot/wt && got stage alpha > /dev/null)
530 (cd $testroot/wt && got histedit -c > $testroot/stdout \
533 if [ "$ret" == "0" ]; then
534 echo "histedit succeeded unexpectedly" >&2
535 test_done "$testroot" "1"
538 echo -n "got: work tree contains files with staged changes; " \
539 > $testroot/stderr.expected
540 echo "these changes must be committed or unstaged first" \
541 >> $testroot/stderr.expected
542 cmp -s $testroot/stderr.expected $testroot/stderr
544 if [ "$ret" != "0" ]; then
545 diff -u $testroot/stderr.expected $testroot/stderr
546 test_done "$testroot" "$ret"
550 (cd $testroot/wt && got unstage alpha > /dev/null)
551 (cd $testroot/wt && got histedit -c > $testroot/stdout)
553 local new_commit1=`git_show_parent_commit $testroot/repo`
554 local new_commit2=`git_show_head $testroot/repo`
556 local short_new_commit1=`trim_obj_id 28 $new_commit1`
557 local short_new_commit2=`trim_obj_id 28 $new_commit2`
559 echo "$short_old_commit1 -> $short_new_commit1: committing changes" \
560 > $testroot/stdout.expected
561 echo "G epsilon/zeta" >> $testroot/stdout.expected
562 echo -n "$short_old_commit2 -> $short_new_commit2: " \
563 >> $testroot/stdout.expected
564 echo "committing to zeta on master" >> $testroot/stdout.expected
565 echo "Switching work tree to refs/heads/master" \
566 >> $testroot/stdout.expected
568 cmp -s $testroot/stdout.expected $testroot/stdout
570 if [ "$ret" != "0" ]; then
571 diff -u $testroot/stdout.expected $testroot/stdout
572 test_done "$testroot" "$ret"
576 echo "edited modified alpha on master" > $testroot/content.expected
577 cat $testroot/wt/alpha > $testroot/content
578 cmp -s $testroot/content.expected $testroot/content
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/content.expected $testroot/content
582 test_done "$testroot" "$ret"
586 if [ -e $testroot/wt/beta ]; then
587 echo "removed file beta still exists on disk" >&2
588 test_done "$testroot" "1"
592 echo "new file on master" > $testroot/content.expected
593 cat $testroot/wt/epsilon/new > $testroot/content
594 cmp -s $testroot/content.expected $testroot/content
596 if [ "$ret" != "0" ]; then
597 diff -u $testroot/content.expected $testroot/content
598 test_done "$testroot" "$ret"
602 (cd $testroot/wt && got status > $testroot/stdout)
604 echo -n > $testroot/stdout.expected
605 cmp -s $testroot/stdout.expected $testroot/stdout
607 if [ "$ret" != "0" ]; then
608 diff -u $testroot/stdout.expected $testroot/stdout
609 test_done "$testroot" "$ret"
613 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
614 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
615 echo "commit $new_commit1" >> $testroot/stdout.expected
616 echo "commit $orig_commit" >> $testroot/stdout.expected
617 cmp -s $testroot/stdout.expected $testroot/stdout
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/stdout.expected $testroot/stdout
622 test_done "$testroot" "$ret"
625 function test_histedit_fold_last_commit {
626 local testroot=`test_init histedit_fold_last_commit`
628 local orig_commit=`git_show_head $testroot/repo`
630 echo "modified alpha on master" > $testroot/repo/alpha
631 (cd $testroot/repo && git rm -q beta)
632 echo "new file on master" > $testroot/repo/epsilon/new
633 (cd $testroot/repo && git add epsilon/new)
634 git_commit $testroot/repo -m "committing changes"
635 local old_commit1=`git_show_head $testroot/repo`
637 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
638 git_commit $testroot/repo -m "committing to zeta on master"
639 local old_commit2=`git_show_head $testroot/repo`
641 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
643 if [ "$ret" != "0" ]; then
644 test_done "$testroot" "$ret"
648 echo "pick $old_commit1" > $testroot/histedit-script
649 echo "fold $old_commit2" >> $testroot/histedit-script
650 echo "mesg committing folded changes" >> $testroot/histedit-script
652 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
653 > $testroot/stdout 2> $testroot/stderr)
656 if [ "$ret" == "0" ]; then
657 echo "histedit succeeded unexpectedly" >&2
658 test_done "$testroot" "1"
662 echo "got: last commit in histedit script cannot be folded" \
663 > $testroot/stderr.expected
665 cmp -s $testroot/stderr.expected $testroot/stderr
667 if [ "$ret" != "0" ]; then
668 diff -u $testroot/stderr.expected $testroot/stderr
670 test_done "$testroot" "$ret"
673 function test_histedit_missing_commit {
674 local testroot=`test_init histedit_missing_commit`
676 local orig_commit=`git_show_head $testroot/repo`
678 echo "modified alpha on master" > $testroot/repo/alpha
679 (cd $testroot/repo && git rm -q beta)
680 echo "new file on master" > $testroot/repo/epsilon/new
681 (cd $testroot/repo && git add epsilon/new)
682 git_commit $testroot/repo -m "committing changes"
683 local old_commit1=`git_show_head $testroot/repo`
685 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
686 git_commit $testroot/repo -m "committing to zeta on master"
687 local old_commit2=`git_show_head $testroot/repo`
689 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
691 if [ "$ret" != "0" ]; then
692 test_done "$testroot" "$ret"
696 echo "pick $old_commit1" > $testroot/histedit-script
697 echo "mesg committing changes" >> $testroot/histedit-script
699 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
700 > $testroot/stdout 2> $testroot/stderr)
703 if [ "$ret" == "0" ]; then
704 echo "histedit succeeded unexpectedly" >&2
705 test_done "$testroot" "1"
709 echo "got: commit $old_commit2 missing from histedit script" \
710 > $testroot/stderr.expected
712 cmp -s $testroot/stderr.expected $testroot/stderr
714 if [ "$ret" != "0" ]; then
715 diff -u $testroot/stderr.expected $testroot/stderr
717 test_done "$testroot" "$ret"
720 function test_histedit_abort {
721 local testroot=`test_init histedit_abort`
723 local orig_commit=`git_show_head $testroot/repo`
725 echo "modified alpha on master" > $testroot/repo/alpha
726 (cd $testroot/repo && git rm -q beta)
727 echo "new file on master" > $testroot/repo/epsilon/new
728 (cd $testroot/repo && git add epsilon/new)
729 git_commit $testroot/repo -m "committing changes"
730 local old_commit1=`git_show_head $testroot/repo`
732 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
733 git_commit $testroot/repo -m "committing to zeta on master"
734 local old_commit2=`git_show_head $testroot/repo`
736 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
738 if [ "$ret" != "0" ]; then
739 test_done "$testroot" "$ret"
743 echo "edit $old_commit1" > $testroot/histedit-script
744 echo "mesg committing changes" >> $testroot/histedit-script
745 echo "pick $old_commit2" >> $testroot/histedit-script
747 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
750 local short_old_commit1=`trim_obj_id 28 $old_commit1`
751 local short_old_commit2=`trim_obj_id 28 $old_commit2`
753 echo "G alpha" > $testroot/stdout.expected
754 echo "D beta" >> $testroot/stdout.expected
755 echo "A epsilon/new" >> $testroot/stdout.expected
756 echo "Stopping histedit for amending commit $old_commit1" \
757 >> $testroot/stdout.expected
758 cmp -s $testroot/stdout.expected $testroot/stdout
760 if [ "$ret" != "0" ]; then
761 diff -u $testroot/stdout.expected $testroot/stdout
762 test_done "$testroot" "$ret"
766 echo "edited modified alpha on master" > $testroot/wt/alpha
768 (cd $testroot/wt && got histedit -a > $testroot/stdout)
770 local new_commit1=`git_show_parent_commit $testroot/repo`
771 local new_commit2=`git_show_head $testroot/repo`
773 echo "Switching work tree to refs/heads/master" \
774 > $testroot/stdout.expected
775 echo "R alpha" >> $testroot/stdout.expected
776 echo "R beta" >> $testroot/stdout.expected
777 echo "R epsilon/new" >> $testroot/stdout.expected
778 echo "Histedit of refs/heads/master aborted" \
779 >> $testroot/stdout.expected
781 cmp -s $testroot/stdout.expected $testroot/stdout
783 if [ "$ret" != "0" ]; then
784 diff -u $testroot/stdout.expected $testroot/stdout
785 test_done "$testroot" "$ret"
789 for f in alpha beta; do
790 echo "$f" > $testroot/content.expected
791 cat $testroot/wt/$f > $testroot/content
792 cmp -s $testroot/content.expected $testroot/content
794 if [ "$ret" != "0" ]; then
795 diff -u $testroot/content.expected $testroot/content
796 test_done "$testroot" "$ret"
801 echo "new file on master" > $testroot/content.expected
802 cat $testroot/wt/epsilon/new > $testroot/content
803 cmp -s $testroot/content.expected $testroot/content
805 if [ "$ret" != "0" ]; then
806 diff -u $testroot/content.expected $testroot/content
807 test_done "$testroot" "$ret"
811 (cd $testroot/wt && got status > $testroot/stdout)
813 echo "? epsilon/new" > $testroot/stdout.expected
814 cmp -s $testroot/stdout.expected $testroot/stdout
816 if [ "$ret" != "0" ]; then
817 diff -u $testroot/stdout.expected $testroot/stdout
818 test_done "$testroot" "$ret"
822 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
823 echo "commit $new_commit2 (master)" > $testroot/stdout.expected
824 echo "commit $new_commit1" >> $testroot/stdout.expected
825 echo "commit $orig_commit" >> $testroot/stdout.expected
826 cmp -s $testroot/stdout.expected $testroot/stdout
828 if [ "$ret" != "0" ]; then
829 diff -u $testroot/stdout.expected $testroot/stdout
831 test_done "$testroot" "$ret"
834 function test_histedit_path_prefix_drop {
835 local testroot=`test_init histedit_path_prefix_drop`
836 local orig_commit=`git_show_head $testroot/repo`
838 echo "modified zeta" > $testroot/repo/epsilon/zeta
839 git_commit $testroot/repo -m "changing zeta"
840 local old_commit1=`git_show_head $testroot/repo`
842 got checkout -c $orig_commit -p gamma $testroot/repo \
843 $testroot/wt > /dev/null
845 if [ "$ret" != "0" ]; then
846 test_done "$testroot" "$ret"
850 echo "drop $old_commit1" > $testroot/histedit-script
852 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
853 > $testroot/stdout 2> $testroot/stderr)
856 if [ "$ret" == "0" ]; then
857 echo "histedit succeeded unexpectedly" >&2
858 test_done "$testroot" "1"
862 echo -n "got: cannot edit branch history which contains changes " \
863 > $testroot/stderr.expected
864 echo "outside of this work tree's path prefix" \
865 >> $testroot/stderr.expected
867 cmp -s $testroot/stderr.expected $testroot/stderr
869 if [ "$ret" != "0" ]; then
870 diff -u $testroot/stderr.expected $testroot/stderr
871 test_done "$testroot" "$ret"
876 got checkout -c $orig_commit -p epsilon $testroot/repo \
877 $testroot/wt > /dev/null
879 if [ "$ret" != "0" ]; then
880 test_done "$testroot" "$ret"
883 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
886 local short_old_commit1=`trim_obj_id 28 $old_commit1`
887 local short_old_commit2=`trim_obj_id 28 $old_commit2`
889 echo "$short_old_commit1 -> drop commit: changing zeta" \
890 > $testroot/stdout.expected
891 echo "Switching work tree to refs/heads/master" \
892 >> $testroot/stdout.expected
894 cmp -s $testroot/stdout.expected $testroot/stdout
896 if [ "$ret" != "0" ]; then
897 diff -u $testroot/stdout.expected $testroot/stdout
898 test_done "$testroot" "$ret"
902 echo "zeta" > $testroot/content.expected
903 cat $testroot/wt/zeta > $testroot/content
904 cmp -s $testroot/content.expected $testroot/content
906 if [ "$ret" != "0" ]; then
907 diff -u $testroot/content.expected $testroot/content
908 test_done "$testroot" "$ret"
913 (cd $testroot/wt && got status > $testroot/stdout)
915 echo -n > $testroot/stdout.expected
916 cmp -s $testroot/stdout.expected $testroot/stdout
918 if [ "$ret" != "0" ]; then
919 diff -u $testroot/stdout.expected $testroot/stdout
920 test_done "$testroot" "$ret"
924 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
925 echo "commit $orig_commit (master)" > $testroot/stdout.expected
926 cmp -s $testroot/stdout.expected $testroot/stdout
928 if [ "$ret" != "0" ]; then
929 diff -u $testroot/stdout.expected $testroot/stdout
931 test_done "$testroot" "$ret"
934 function test_histedit_path_prefix_edit {
935 local testroot=`test_init histedit_path_prefix_edit`
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 diff -r $testroot/repo $orig_commit $old_commit1 \
943 > $testroot/diff.expected
945 got checkout -c $orig_commit -p gamma $testroot/repo \
946 $testroot/wt > /dev/null
948 if [ "$ret" != "0" ]; then
949 test_done "$testroot" "$ret"
953 echo "edit $old_commit1" > $testroot/histedit-script
954 echo "mesg modified zeta" >> $testroot/histedit-script
956 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
957 > $testroot/stdout 2> $testroot/stderr)
960 if [ "$ret" == "0" ]; then
961 echo "histedit succeeded unexpectedly" >&2
962 test_done "$testroot" "1"
966 echo -n "got: cannot edit branch history which contains changes " \
967 > $testroot/stderr.expected
968 echo "outside of this work tree's path prefix" \
969 >> $testroot/stderr.expected
971 cmp -s $testroot/stderr.expected $testroot/stderr
973 if [ "$ret" != "0" ]; then
974 diff -u $testroot/stderr.expected $testroot/stderr
975 test_done "$testroot" "$ret"
980 got checkout -c $orig_commit -p epsilon $testroot/repo \
981 $testroot/wt > /dev/null
983 if [ "$ret" != "0" ]; then
984 test_done "$testroot" "$ret"
987 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
990 local short_old_commit1=`trim_obj_id 28 $old_commit1`
992 echo "G zeta" > $testroot/stdout.expected
993 echo "Stopping histedit for amending commit $old_commit1" \
994 >> $testroot/stdout.expected
995 cmp -s $testroot/stdout.expected $testroot/stdout
997 if [ "$ret" != "0" ]; then
998 diff -u $testroot/stdout.expected $testroot/stdout
999 test_done "$testroot" "$ret"
1003 echo "modified zeta" > $testroot/content.expected
1004 cat $testroot/wt/zeta > $testroot/content
1005 cmp -s $testroot/content.expected $testroot/content
1007 if [ "$ret" != "0" ]; then
1008 diff -u $testroot/content.expected $testroot/content
1009 test_done "$testroot" "$ret"
1013 (cd $testroot/wt && got status > $testroot/stdout)
1015 echo "M zeta"> $testroot/stdout.expected
1016 cmp -s $testroot/stdout.expected $testroot/stdout
1018 if [ "$ret" != "0" ]; then
1019 diff -u $testroot/stdout.expected $testroot/stdout
1020 test_done "$testroot" "$ret"
1024 (cd $testroot/wt && got histedit -c > $testroot/stdout)
1026 local new_commit1=`git_show_head $testroot/repo`
1027 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1029 echo -n "$short_old_commit1 -> $short_new_commit1: " \
1030 > $testroot/stdout.expected
1031 echo "modified zeta" >> $testroot/stdout.expected
1032 echo "Switching work tree to refs/heads/master" \
1033 >> $testroot/stdout.expected
1035 cmp -s $testroot/stdout.expected $testroot/stdout
1037 if [ "$ret" != "0" ]; then
1038 diff -u $testroot/stdout.expected $testroot/stdout
1039 test_done "$testroot" "$ret"
1043 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1044 echo "commit $new_commit1 (master)" > $testroot/stdout.expected
1045 echo "commit $orig_commit" >> $testroot/stdout.expected
1046 cmp -s $testroot/stdout.expected $testroot/stdout
1048 if [ "$ret" != "0" ]; then
1049 diff -u $testroot/stdout.expected $testroot/stdout
1050 test_done "$testroot" "$ret"
1054 got diff -r $testroot/repo $orig_commit $new_commit1 \
1056 sed -i -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected
1057 cmp -s $testroot/diff.expected $testroot/diff
1059 if [ "$ret" != "0" ]; then
1060 diff -u $testroot/diff.expected $testroot/diff
1062 test_done "$testroot" "$ret"
1065 function test_histedit_outside_refs_heads {
1066 local testroot=`test_init histedit_outside_refs_heads`
1067 local commit1=`git_show_head $testroot/repo`
1069 got checkout $testroot/repo $testroot/wt > /dev/null
1071 if [ "$ret" != "0" ]; then
1072 echo "got checkout failed unexpectedly"
1073 test_done "$testroot" "$ret"
1077 echo "modified alpha" > $testroot/wt/alpha
1079 (cd $testroot/wt && got commit -m 'change alpha' \
1080 > $testroot/stdout 2> $testroot/stderr)
1082 if [ "$ret" != "0" ]; then
1083 echo "got commit failed unexpectedly" >&2
1084 test_done "$testroot" "1"
1087 local commit2=`git_show_head $testroot/repo`
1089 got ref -r $testroot/repo refs/remotes/origin/master master
1091 if [ "$ret" != "0" ]; then
1092 echo "got ref failed unexpectedly" >&2
1093 test_done "$testroot" "1"
1097 (cd $testroot/wt && got update -b origin/master -c $commit1 >/dev/null)
1099 if [ "$ret" != "0" ]; then
1100 echo "got update failed unexpectedly"
1101 test_done "$testroot" "$ret"
1105 echo "edit $commit2" > $testroot/histedit-script
1106 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1107 2> $testroot/stderr)
1109 echo -n "got: will not edit commit history of a branch outside the " \
1110 > $testroot/stderr.expected
1111 echo '"refs/heads/" reference namespace' \
1112 >> $testroot/stderr.expected
1113 cmp -s $testroot/stderr.expected $testroot/stderr
1115 if [ "$ret" != "0" ]; then
1116 diff -u $testroot/stderr.expected $testroot/stderr
1118 test_done "$testroot" "$ret"
1121 function test_histedit_fold_last_commit_swap {
1122 local testroot=`test_init histedit_fold_last_commit_swap`
1124 local orig_commit=`git_show_head $testroot/repo`
1126 echo "modified alpha on master" > $testroot/repo/alpha
1127 (cd $testroot/repo && git rm -q beta)
1128 echo "new file on master" > $testroot/repo/epsilon/new
1129 (cd $testroot/repo && git add epsilon/new)
1130 git_commit $testroot/repo -m "committing changes"
1131 local old_commit1=`git_show_head $testroot/repo`
1133 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1134 git_commit $testroot/repo -m "committing to zeta on master"
1135 local old_commit2=`git_show_head $testroot/repo`
1137 got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
1139 if [ "$ret" != "0" ]; then
1140 test_done "$testroot" "$ret"
1144 # fold commit2 into commit1 (requires swapping commits)
1145 echo "fold $old_commit2" > $testroot/histedit-script
1146 echo "pick $old_commit1" >> $testroot/histedit-script
1147 echo "mesg committing folded changes" >> $testroot/histedit-script
1149 (cd $testroot/wt && got histedit -F $testroot/histedit-script \
1150 > $testroot/stdout 2> $testroot/stderr)
1153 if [ "$ret" != "0" ]; then
1154 echo "histedit failed unexpectedly" >&2
1155 test_done "$testroot" "$ret"
1159 local new_commit=`git_show_head $testroot/repo`
1161 local short_old_commit1=`trim_obj_id 28 $old_commit1`
1162 local short_old_commit2=`trim_obj_id 28 $old_commit2`
1163 local short_new_commit=`trim_obj_id 28 $new_commit`
1165 echo "G epsilon/zeta" >> $testroot/stdout.expected
1166 echo -n "$short_old_commit2 -> fold commit: committing to zeta " \
1167 >> $testroot/stdout.expected
1168 echo "on master" >> $testroot/stdout.expected
1169 echo "G alpha" >> $testroot/stdout.expected
1170 echo "D beta" >> $testroot/stdout.expected
1171 echo "A epsilon/new" >> $testroot/stdout.expected
1172 echo -n "$short_old_commit1 -> $short_new_commit: " \
1173 >> $testroot/stdout.expected
1174 echo "committing folded changes" >> $testroot/stdout.expected
1175 echo "Switching work tree to refs/heads/master" \
1176 >> $testroot/stdout.expected
1178 cmp -s $testroot/stdout.expected $testroot/stdout
1180 if [ "$ret" != "0" ]; then
1181 diff -u $testroot/stdout.expected $testroot/stdout
1183 test_done "$testroot" "$ret"
1186 run_test test_histedit_no_op
1187 run_test test_histedit_swap
1188 run_test test_histedit_drop
1189 run_test test_histedit_fold
1190 run_test test_histedit_edit
1191 run_test test_histedit_fold_last_commit
1192 run_test test_histedit_missing_commit
1193 run_test test_histedit_abort
1194 run_test test_histedit_path_prefix_drop
1195 run_test test_histedit_path_prefix_edit
1196 run_test test_histedit_outside_refs_heads
1197 run_test test_histedit_fold_last_commit_swap