3 # Copyright (c) 2019, 2020 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.
20 local testroot=`test_init rebase_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 (cd $testroot/repo && git checkout -q -b newbranch)
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
28 echo "modified alpha on branch" > $testroot/repo/alpha
29 (cd $testroot/repo && git rm -q beta)
30 echo "new file on branch" > $testroot/repo/epsilon/new
31 (cd $testroot/repo && git add epsilon/new)
32 git_commit $testroot/repo -m "committing more changes on newbranch"
34 local orig_commit1=`git_show_parent_commit $testroot/repo`
35 local orig_commit2=`git_show_head $testroot/repo`
36 local orig_author_time2=`git_show_author_time $testroot/repo`
38 (cd $testroot/repo && git checkout -q master)
39 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
40 git_commit $testroot/repo -m "committing to zeta on master"
41 local master_commit=`git_show_head $testroot/repo`
43 got checkout $testroot/repo $testroot/wt > /dev/null
45 if [ "$ret" != "0" ]; then
46 test_done "$testroot" "$ret"
50 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
52 (cd $testroot/repo && git checkout -q newbranch)
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_orig_commit1=`trim_obj_id 28 $orig_commit1`
58 local short_orig_commit2=`trim_obj_id 28 $orig_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 gamma/delta" >> $testroot/stdout.expected
63 echo -n "$short_orig_commit1 -> $short_new_commit1" \
64 >> $testroot/stdout.expected
65 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
66 echo "G alpha" >> $testroot/stdout.expected
67 echo "D beta" >> $testroot/stdout.expected
68 echo "A epsilon/new" >> $testroot/stdout.expected
69 echo -n "$short_orig_commit2 -> $short_new_commit2" \
70 >> $testroot/stdout.expected
71 echo ": committing more changes on newbranch" \
72 >> $testroot/stdout.expected
73 echo "Switching work tree to refs/heads/newbranch" \
74 >> $testroot/stdout.expected
76 cmp -s $testroot/stdout.expected $testroot/stdout
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
84 echo "modified delta on branch" > $testroot/content.expected
85 cat $testroot/wt/gamma/delta > $testroot/content
86 cmp -s $testroot/content.expected $testroot/content
88 if [ "$ret" != "0" ]; then
89 diff -u $testroot/content.expected $testroot/content
90 test_done "$testroot" "$ret"
94 echo "modified alpha on branch" > $testroot/content.expected
95 cat $testroot/wt/alpha > $testroot/content
96 cmp -s $testroot/content.expected $testroot/content
98 if [ "$ret" != "0" ]; then
99 diff -u $testroot/content.expected $testroot/content
100 test_done "$testroot" "$ret"
104 if [ -e $testroot/wt/beta ]; then
105 echo "removed file beta still exists on disk" >&2
106 test_done "$testroot" "1"
110 echo "new file on branch" > $testroot/content.expected
111 cat $testroot/wt/epsilon/new > $testroot/content
112 cmp -s $testroot/content.expected $testroot/content
114 if [ "$ret" != "0" ]; then
115 diff -u $testroot/content.expected $testroot/content
116 test_done "$testroot" "$ret"
120 (cd $testroot/wt && got status > $testroot/stdout)
122 echo -n > $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 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
132 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
133 echo "commit $new_commit1" >> $testroot/stdout.expected
134 echo "commit $master_commit (master)" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected $testroot/stdout
137 if [ "$ret" != "0" ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 test_done "$testroot" "$ret"
143 (cd $testroot/wt && got update > $testroot/stdout)
145 echo 'Already up-to-date' > $testroot/stdout.expected
146 cmp -s $testroot/stdout.expected $testroot/stdout
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
154 # We should have a backup of old commits
155 (cd $testroot/repo && got rebase -l > $testroot/stdout)
156 d_orig2=`date -u -r $orig_author_time2 +"%a %b %e %X %Y UTC"`
157 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
158 d_0=`date -u -r $commit0_author_time +"%G-%m-%d"`
159 cat > $testroot/stdout.expected <<EOF
160 -----------------------------------------------
161 commit $orig_commit2 (formerly newbranch)
165 committing more changes on newbranch
167 has become commit $new_commit2 (newbranch)
168 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
169 history forked at $commit0
170 $d_0 $GOT_AUTHOR_11 adding the test tree
172 cmp -s $testroot/stdout.expected $testroot/stdout
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stdout.expected $testroot/stdout
176 test_done "$testroot" "$ret"
180 # Asking for backups of a branch which has none should yield an error
181 (cd $testroot/repo && got rebase -l master \
182 > $testroot/stdout 2> $testroot/stderr)
183 echo -n > $testroot/stdout.expected
184 echo "got: refs/got/backup/rebase/master/: no such reference found" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
193 cmp -s $testroot/stderr.expected $testroot/stderr
195 if [ "$ret" != "0" ]; then
196 diff -u $testroot/stderr.expected $testroot/stderr
197 test_done "$testroot" "$ret"
201 # Delete all backup refs
202 (cd $testroot/repo && got rebase -X \
203 > $testroot/stdout 2> $testroot/stderr)
204 echo -n "Deleted refs/got/backup/rebase/newbranch/$new_commit2: " \
205 > $testroot/stdout.expected
206 echo "$orig_commit2" >> $testroot/stdout.expected
207 echo -n > $testroot/stderr.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
215 cmp -s $testroot/stderr.expected $testroot/stderr
217 if [ "$ret" != "0" ]; then
218 diff -u $testroot/stderr.expected $testroot/stderr
219 test_done "$testroot" "$ret"
223 (cd $testroot/repo && got rebase -l > $testroot/stdout)
224 echo -n > $testroot/stdout.expected
225 cmp -s $testroot/stdout.expected $testroot/stdout
227 if [ "$ret" != "0" ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
230 test_done "$testroot" "$ret"
233 test_rebase_ancestry_check() {
234 local testroot=`test_init rebase_ancestry_check`
236 got checkout $testroot/repo $testroot/wt > /dev/null
238 if [ "$ret" != "0" ]; then
239 test_done "$testroot" "$ret"
243 (cd $testroot/repo && git checkout -q -b newbranch)
244 echo "modified delta on branch" > $testroot/repo/gamma/delta
245 git_commit $testroot/repo -m "committing to delta on newbranch"
247 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
250 echo -n > $testroot/stdout.expected
251 cmp -s $testroot/stdout.expected $testroot/stdout
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/stdout.expected $testroot/stdout
255 test_done "$testroot" "$ret"
259 echo "got: refs/heads/newbranch is already based on refs/heads/master" \
260 > $testroot/stderr.expected
261 cmp -s $testroot/stderr.expected $testroot/stderr
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stderr.expected $testroot/stderr
266 test_done "$testroot" "$ret"
269 test_rebase_continue() {
270 local testroot=`test_init rebase_continue`
271 local init_commit=`git_show_head $testroot/repo`
273 (cd $testroot/repo && git checkout -q -b newbranch)
274 echo "modified alpha on branch" > $testroot/repo/alpha
275 git_commit $testroot/repo -m "committing to alpha on newbranch"
276 local orig_commit1=`git_show_head $testroot/repo`
277 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
279 (cd $testroot/repo && git checkout -q master)
280 echo "modified alpha on master" > $testroot/repo/alpha
281 git_commit $testroot/repo -m "committing to alpha on master"
282 local master_commit=`git_show_head $testroot/repo`
284 got checkout $testroot/repo $testroot/wt > /dev/null
286 if [ "$ret" != "0" ]; then
287 test_done "$testroot" "$ret"
291 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
294 echo "C alpha" > $testroot/stdout.expected
295 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
296 echo -n "$short_orig_commit1 -> merge conflict" \
297 >> $testroot/stdout.expected
298 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
299 cmp -s $testroot/stdout.expected $testroot/stdout
301 if [ "$ret" != "0" ]; then
302 diff -u $testroot/stdout.expected $testroot/stdout
303 test_done "$testroot" "$ret"
307 echo "got: conflicts must be resolved before rebasing can continue" \
308 > $testroot/stderr.expected
309 cmp -s $testroot/stderr.expected $testroot/stderr
311 if [ "$ret" != "0" ]; then
312 diff -u $testroot/stderr.expected $testroot/stderr
313 test_done "$testroot" "$ret"
317 echo '<<<<<<<' > $testroot/content.expected
318 echo "modified alpha on master" >> $testroot/content.expected
319 echo "||||||| 3-way merge base: commit $init_commit" \
320 >> $testroot/content.expected
321 echo "alpha" >> $testroot/content.expected
322 echo "=======" >> $testroot/content.expected
323 echo "modified alpha on branch" >> $testroot/content.expected
324 echo ">>>>>>> merged change: commit $orig_commit1" \
325 >> $testroot/content.expected
326 cat $testroot/wt/alpha > $testroot/content
327 cmp -s $testroot/content.expected $testroot/content
329 if [ "$ret" != "0" ]; then
330 diff -u $testroot/content.expected $testroot/content
331 test_done "$testroot" "$ret"
335 (cd $testroot/wt && got status > $testroot/stdout)
337 echo "C alpha" > $testroot/stdout.expected
338 cmp -s $testroot/stdout.expected $testroot/stdout
340 if [ "$ret" != "0" ]; then
341 diff -u $testroot/stdout.expected $testroot/stdout
342 test_done "$testroot" "$ret"
346 # resolve the conflict
347 echo "modified alpha on branch and master" > $testroot/wt/alpha
349 # test interaction of 'got stage' and rebase -c
350 (cd $testroot/wt && got stage alpha > /dev/null)
351 (cd $testroot/wt && got rebase -c > $testroot/stdout \
354 if [ "$ret" = "0" ]; then
355 echo "rebase succeeded unexpectedly" >&2
356 test_done "$testroot" "1"
359 echo -n "got: work tree contains files with staged changes; " \
360 > $testroot/stderr.expected
361 echo "these changes must be committed or unstaged first" \
362 >> $testroot/stderr.expected
363 cmp -s $testroot/stderr.expected $testroot/stderr
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/stderr.expected $testroot/stderr
367 test_done "$testroot" "$ret"
371 (cd $testroot/wt && got unstage alpha > /dev/null)
372 (cd $testroot/wt && got rebase -c > $testroot/stdout)
374 (cd $testroot/repo && git checkout -q newbranch)
375 local new_commit1=`git_show_head $testroot/repo`
376 local short_new_commit1=`trim_obj_id 28 $new_commit1`
378 echo -n "$short_orig_commit1 -> $short_new_commit1" \
379 > $testroot/stdout.expected
380 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
381 echo "Switching work tree to refs/heads/newbranch" \
382 >> $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"
393 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
394 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
395 echo "commit $master_commit (master)" >> $testroot/stdout.expected
396 cmp -s $testroot/stdout.expected $testroot/stdout
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/stdout.expected $testroot/stdout
401 test_done "$testroot" "$ret"
404 test_rebase_abort() {
405 local testroot=`test_init rebase_abort`
407 local init_commit=`git_show_head $testroot/repo`
409 (cd $testroot/repo && git checkout -q -b newbranch)
410 echo "modified alpha on branch" > $testroot/repo/alpha
411 git_commit $testroot/repo -m "committing to alpha on newbranch"
412 local orig_commit1=`git_show_head $testroot/repo`
413 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
415 (cd $testroot/repo && git checkout -q master)
416 echo "modified alpha on master" > $testroot/repo/alpha
417 git_commit $testroot/repo -m "committing to alpha on master"
418 local master_commit=`git_show_head $testroot/repo`
420 got checkout $testroot/repo $testroot/wt > /dev/null
422 if [ "$ret" != "0" ]; then
423 test_done "$testroot" "$ret"
427 # unrelated unversioned file in work tree
428 touch $testroot/wt/unversioned-file
430 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
433 echo "C alpha" > $testroot/stdout.expected
434 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
435 echo -n "$short_orig_commit1 -> merge conflict" \
436 >> $testroot/stdout.expected
437 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
438 cmp -s $testroot/stdout.expected $testroot/stdout
440 if [ "$ret" != "0" ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
446 echo "got: conflicts must be resolved before rebasing can continue" \
447 > $testroot/stderr.expected
448 cmp -s $testroot/stderr.expected $testroot/stderr
450 if [ "$ret" != "0" ]; then
451 diff -u $testroot/stderr.expected $testroot/stderr
452 test_done "$testroot" "$ret"
456 echo '<<<<<<<' > $testroot/content.expected
457 echo "modified alpha on master" >> $testroot/content.expected
458 echo "||||||| 3-way merge base: commit $init_commit" \
459 >> $testroot/content.expected
460 echo "alpha" >> $testroot/content.expected
461 echo "=======" >> $testroot/content.expected
462 echo "modified alpha on branch" >> $testroot/content.expected
463 echo ">>>>>>> merged change: commit $orig_commit1" \
464 >> $testroot/content.expected
465 cat $testroot/wt/alpha > $testroot/content
466 cmp -s $testroot/content.expected $testroot/content
468 if [ "$ret" != "0" ]; then
469 diff -u $testroot/content.expected $testroot/content
470 test_done "$testroot" "$ret"
474 (cd $testroot/wt && got status > $testroot/stdout)
476 echo "C alpha" > $testroot/stdout.expected
477 echo "? unversioned-file" >> $testroot/stdout.expected
478 cmp -s $testroot/stdout.expected $testroot/stdout
480 if [ "$ret" != "0" ]; then
481 diff -u $testroot/stdout.expected $testroot/stdout
482 test_done "$testroot" "$ret"
486 (cd $testroot/wt && got rebase -a > $testroot/stdout)
488 (cd $testroot/repo && git checkout -q newbranch)
490 echo "Switching work tree to refs/heads/master" \
491 > $testroot/stdout.expected
492 echo 'R alpha' >> $testroot/stdout.expected
493 echo "Rebase of refs/heads/newbranch aborted" \
494 >> $testroot/stdout.expected
496 cmp -s $testroot/stdout.expected $testroot/stdout
498 if [ "$ret" != "0" ]; then
499 diff -u $testroot/stdout.expected $testroot/stdout
500 test_done "$testroot" "$ret"
504 echo "modified alpha on master" > $testroot/content.expected
505 cat $testroot/wt/alpha > $testroot/content
506 cmp -s $testroot/content.expected $testroot/content
508 if [ "$ret" != "0" ]; then
509 diff -u $testroot/content.expected $testroot/content
510 test_done "$testroot" "$ret"
514 (cd $testroot/wt && got log -l3 -c newbranch \
515 | grep ^commit > $testroot/stdout)
516 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
517 echo "commit $init_commit" >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected $testroot/stdout
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
523 test_done "$testroot" "$ret"
526 test_rebase_no_op_change() {
527 local testroot=`test_init rebase_no_op_change`
528 local init_commit=`git_show_head $testroot/repo`
530 (cd $testroot/repo && git checkout -q -b newbranch)
531 echo "modified alpha on branch" > $testroot/repo/alpha
532 git_commit $testroot/repo -m "committing to alpha on newbranch"
533 local orig_commit1=`git_show_head $testroot/repo`
534 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
536 (cd $testroot/repo && git checkout -q master)
537 echo "modified alpha on master" > $testroot/repo/alpha
538 git_commit $testroot/repo -m "committing to alpha on master"
539 local master_commit=`git_show_head $testroot/repo`
541 got checkout $testroot/repo $testroot/wt > /dev/null
543 if [ "$ret" != "0" ]; then
544 test_done "$testroot" "$ret"
548 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
551 echo "C alpha" > $testroot/stdout.expected
552 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
553 echo -n "$short_orig_commit1 -> merge conflict" \
554 >> $testroot/stdout.expected
555 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
556 cmp -s $testroot/stdout.expected $testroot/stdout
558 if [ "$ret" != "0" ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
564 echo "got: conflicts must be resolved before rebasing can continue" \
565 > $testroot/stderr.expected
566 cmp -s $testroot/stderr.expected $testroot/stderr
568 if [ "$ret" != "0" ]; then
569 diff -u $testroot/stderr.expected $testroot/stderr
570 test_done "$testroot" "$ret"
574 echo '<<<<<<<' > $testroot/content.expected
575 echo "modified alpha on master" >> $testroot/content.expected
576 echo "||||||| 3-way merge base: commit $init_commit" \
577 >> $testroot/content.expected
578 echo "alpha" >> $testroot/content.expected
579 echo "=======" >> $testroot/content.expected
580 echo "modified alpha on branch" >> $testroot/content.expected
581 echo ">>>>>>> merged change: commit $orig_commit1" \
582 >> $testroot/content.expected
583 cat $testroot/wt/alpha > $testroot/content
584 cmp -s $testroot/content.expected $testroot/content
586 if [ "$ret" != "0" ]; then
587 diff -u $testroot/content.expected $testroot/content
588 test_done "$testroot" "$ret"
592 (cd $testroot/wt && got status > $testroot/stdout)
594 echo "C alpha" > $testroot/stdout.expected
595 cmp -s $testroot/stdout.expected $testroot/stdout
597 if [ "$ret" != "0" ]; then
598 diff -u $testroot/stdout.expected $testroot/stdout
599 test_done "$testroot" "$ret"
603 # resolve the conflict
604 echo "modified alpha on master" > $testroot/wt/alpha
606 (cd $testroot/wt && got rebase -c > $testroot/stdout)
608 (cd $testroot/repo && git checkout -q newbranch)
609 local new_commit1=`git_show_head $testroot/repo`
611 echo -n "$short_orig_commit1 -> no-op change" \
612 > $testroot/stdout.expected
613 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
614 echo "Switching work tree to refs/heads/newbranch" \
615 >> $testroot/stdout.expected
617 cmp -s $testroot/stdout.expected $testroot/stdout
619 if [ "$ret" != "0" ]; then
620 diff -u $testroot/stdout.expected $testroot/stdout
621 test_done "$testroot" "$ret"
626 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
627 echo "commit $master_commit (master, newbranch)" \
628 > $testroot/stdout.expected
629 echo "commit $init_commit" >> $testroot/stdout.expected
630 cmp -s $testroot/stdout.expected $testroot/stdout
632 if [ "$ret" != "0" ]; then
633 diff -u $testroot/stdout.expected $testroot/stdout
635 test_done "$testroot" "$ret"
638 test_rebase_in_progress() {
639 local testroot=`test_init rebase_in_progress`
640 local init_commit=`git_show_head $testroot/repo`
642 (cd $testroot/repo && git checkout -q -b newbranch)
643 echo "modified alpha on branch" > $testroot/repo/alpha
644 git_commit $testroot/repo -m "committing to alpha on newbranch"
645 local orig_commit1=`git_show_head $testroot/repo`
646 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
648 (cd $testroot/repo && git checkout -q master)
649 echo "modified alpha on master" > $testroot/repo/alpha
650 git_commit $testroot/repo -m "committing to alpha on master"
651 local master_commit=`git_show_head $testroot/repo`
653 got checkout $testroot/repo $testroot/wt > /dev/null
655 if [ "$ret" != "0" ]; then
656 test_done "$testroot" "$ret"
660 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
663 echo "C alpha" > $testroot/stdout.expected
664 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
665 echo -n "$short_orig_commit1 -> merge conflict" \
666 >> $testroot/stdout.expected
667 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
668 cmp -s $testroot/stdout.expected $testroot/stdout
670 if [ "$ret" != "0" ]; then
671 diff -u $testroot/stdout.expected $testroot/stdout
672 test_done "$testroot" "$ret"
676 echo "got: conflicts must be resolved before rebasing can continue" \
677 > $testroot/stderr.expected
678 cmp -s $testroot/stderr.expected $testroot/stderr
680 if [ "$ret" != "0" ]; then
681 diff -u $testroot/stderr.expected $testroot/stderr
682 test_done "$testroot" "$ret"
686 echo '<<<<<<<' > $testroot/content.expected
687 echo "modified alpha on master" >> $testroot/content.expected
688 echo "||||||| 3-way merge base: commit $init_commit" \
689 >> $testroot/content.expected
690 echo "alpha" >> $testroot/content.expected
691 echo "=======" >> $testroot/content.expected
692 echo "modified alpha on branch" >> $testroot/content.expected
693 echo ">>>>>>> merged change: commit $orig_commit1" \
694 >> $testroot/content.expected
695 cat $testroot/wt/alpha > $testroot/content
696 cmp -s $testroot/content.expected $testroot/content
698 if [ "$ret" != "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 "C alpha" > $testroot/stdout.expected
707 cmp -s $testroot/stdout.expected $testroot/stdout
709 if [ "$ret" != "0" ]; then
710 diff -u $testroot/stdout.expected $testroot/stdout
711 test_done "$testroot" "$ret"
715 for cmd in update commit; do
716 (cd $testroot/wt && got $cmd > $testroot/stdout \
719 echo -n > $testroot/stdout.expected
720 cmp -s $testroot/stdout.expected $testroot/stdout
722 if [ "$ret" != "0" ]; then
723 diff -u $testroot/stdout.expected $testroot/stdout
724 test_done "$testroot" "$ret"
728 echo -n "got: a rebase operation is in progress in this " \
729 > $testroot/stderr.expected
730 echo "work tree and must be continued or aborted first" \
731 >> $testroot/stderr.expected
732 cmp -s $testroot/stderr.expected $testroot/stderr
734 if [ "$ret" != "0" ]; then
735 diff -u $testroot/stderr.expected $testroot/stderr
736 test_done "$testroot" "$ret"
741 test_done "$testroot" "$ret"
744 test_rebase_path_prefix() {
745 local testroot=`test_init rebase_path_prefix`
747 (cd $testroot/repo && git checkout -q -b newbranch)
748 echo "modified delta on branch" > $testroot/repo/gamma/delta
749 git_commit $testroot/repo -m "committing to delta on newbranch"
751 local orig_commit1=`git_show_parent_commit $testroot/repo`
752 local orig_commit2=`git_show_head $testroot/repo`
754 (cd $testroot/repo && git checkout -q master)
755 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
756 git_commit $testroot/repo -m "committing to zeta on master"
757 local master_commit=`git_show_head $testroot/repo`
759 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
761 if [ "$ret" != "0" ]; then
762 test_done "$testroot" "$ret"
766 (cd $testroot/wt && got rebase newbranch \
767 > $testroot/stdout 2> $testroot/stderr)
769 echo -n > $testroot/stdout.expected
770 cmp -s $testroot/stdout.expected $testroot/stdout
772 if [ "$ret" != "0" ]; then
773 diff -u $testroot/stdout.expected $testroot/stdout
774 test_done "$testroot" "$ret"
778 echo -n "got: cannot rebase branch which contains changes outside " \
779 > $testroot/stderr.expected
780 echo "of this work tree's path prefix" >> $testroot/stderr.expected
781 cmp -s $testroot/stderr.expected $testroot/stderr
783 if [ "$ret" != "0" ]; then
784 diff -u $testroot/stderr.expected $testroot/stderr
786 test_done "$testroot" "$ret"
789 test_rebase_preserves_logmsg() {
790 local testroot=`test_init rebase_preserves_logmsg`
792 (cd $testroot/repo && git checkout -q -b newbranch)
793 echo "modified delta on branch" > $testroot/repo/gamma/delta
794 git_commit $testroot/repo -m "modified delta on newbranch"
796 echo "modified alpha on branch" > $testroot/repo/alpha
797 git_commit $testroot/repo -m "modified alpha on newbranch"
799 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
800 > $testroot/log.expected)
802 local orig_commit1=`git_show_parent_commit $testroot/repo`
803 local orig_commit2=`git_show_head $testroot/repo`
805 (cd $testroot/repo && git checkout -q master)
806 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
807 git_commit $testroot/repo -m "committing to zeta on master"
808 local master_commit=`git_show_head $testroot/repo`
810 got checkout $testroot/repo $testroot/wt > /dev/null
812 if [ "$ret" != "0" ]; then
813 test_done "$testroot" "$ret"
817 (cd $testroot/wt && got rebase newbranch > /dev/null \
820 (cd $testroot/repo && git checkout -q newbranch)
821 local new_commit1=`git_show_parent_commit $testroot/repo`
822 local new_commit2=`git_show_head $testroot/repo`
824 echo -n > $testroot/stderr.expected
825 cmp -s $testroot/stderr.expected $testroot/stderr
827 if [ "$ret" != "0" ]; then
828 diff -u $testroot/stderr.expected $testroot/stderr
829 test_done "$testroot" "$ret"
833 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
835 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
836 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
837 cmp -s $testroot/log.expected $testroot/log
839 if [ "$ret" != "0" ]; then
840 diff -u $testroot/log.expected $testroot/log
843 test_done "$testroot" "$ret"
846 test_rebase_no_commits_to_rebase() {
847 local testroot=`test_init rebase_no_commits_to_rebase`
849 got checkout $testroot/repo $testroot/wt > /dev/null
851 if [ "$ret" != "0" ]; then
852 test_done "$testroot" "$ret"
856 (cd $testroot/wt && got branch -n newbranch)
858 echo "modified alpha on master" > $testroot/wt/alpha
859 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
861 (cd $testroot/wt && got update > /dev/null)
863 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
866 echo "got: no commits to rebase" > $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"
875 echo "Rebase of refs/heads/newbranch aborted" \
876 > $testroot/stdout.expected
877 cmp -s $testroot/stdout.expected $testroot/stdout
879 if [ "$ret" != "0" ]; then
880 diff -u $testroot/stdout.expected $testroot/stdout
881 test_done "$testroot" "$ret"
885 (cd $testroot/wt && got update > $testroot/stdout)
886 echo "Already up-to-date" > $testroot/stdout.expected
887 cmp -s $testroot/stdout.expected $testroot/stdout
889 if [ "$ret" != "0" ]; then
890 diff -u $testroot/stdout.expected $testroot/stdout
892 test_done "$testroot" "$ret"
895 test_rebase_forward() {
896 local testroot=`test_init rebase_forward`
897 local commit0=`git_show_head $testroot/repo`
899 got checkout $testroot/repo $testroot/wt > /dev/null
901 if [ "$ret" != "0" ]; then
902 test_done "$testroot" "$ret"
906 echo "change alpha 1" > $testroot/wt/alpha
907 (cd $testroot/wt && got commit -m 'test rebase_forward' \
909 local commit1=`git_show_head $testroot/repo`
911 echo "change alpha 2" > $testroot/wt/alpha
912 (cd $testroot/wt && got commit -m 'test rebase_forward' \
914 local commit2=`git_show_head $testroot/repo`
916 # Simulate a situation where fast-forward is required.
917 # We want to fast-forward master to origin/master:
918 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
919 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
920 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
921 (cd $testroot/repo && got ref -d master >/dev/null)
922 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
923 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
925 (cd $testroot/wt && got up -b origin/master > /dev/null)
927 (cd $testroot/wt && got rebase master \
928 > $testroot/stdout 2> $testroot/stderr)
930 echo "Forwarding refs/heads/master to commit $commit2" \
931 > $testroot/stdout.expected
932 echo "Switching work tree to refs/heads/master" \
933 >> $testroot/stdout.expected
934 cmp -s $testroot/stdout.expected $testroot/stdout
936 if [ "$ret" != "0" ]; then
937 diff -u $testroot/stdout.expected $testroot/stdout
938 test_done "$testroot" "$ret"
942 # Ensure that rebase operation was completed correctly
943 (cd $testroot/wt && got rebase -a \
944 > $testroot/stdout 2> $testroot/stderr)
945 echo -n "" > $testroot/stdout.expected
946 cmp -s $testroot/stdout.expected $testroot/stdout
948 if [ "$ret" != "0" ]; then
949 diff -u $testroot/stdout.expected $testroot/stdout
950 test_done "$testroot" "$ret"
953 echo "got: rebase operation not in progress" > $testroot/stderr.expected
954 cmp -s $testroot/stderr.expected $testroot/stderr
956 if [ "$ret" != "0" ]; then
957 diff -u $testroot/stderr.expected $testroot/stderr
958 test_done "$testroot" "$ret"
962 (cd $testroot/wt && got branch -n > $testroot/stdout)
963 echo "master" > $testroot/stdout.expected
964 cmp -s $testroot/stdout.expected $testroot/stdout
966 if [ "$ret" != "0" ]; then
967 diff -u $testroot/stdout.expected $testroot/stdout
968 test_done "$testroot" "$ret"
972 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
973 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
974 echo "commit $commit1" >> $testroot/stdout.expected
975 echo "commit $commit0" >> $testroot/stdout.expected
976 cmp -s $testroot/stdout.expected $testroot/stdout
978 if [ "$ret" != "0" ]; then
979 diff -u $testroot/stdout.expected $testroot/stdout
980 test_done "$testroot" "$ret"
984 # Forward-only rebase operations should not be backed up
985 (cd $testroot/repo && got rebase -l > $testroot/stdout)
986 echo -n > $testroot/stdout.expected
987 cmp -s $testroot/stdout.expected $testroot/stdout
989 if [ "$ret" != "0" ]; then
990 diff -u $testroot/stdout.expected $testroot/stdout
992 test_done "$testroot" "$ret"
995 test_rebase_out_of_date() {
996 local testroot=`test_init rebase_out_of_date`
997 local initial_commit=`git_show_head $testroot/repo`
999 (cd $testroot/repo && git checkout -q -b newbranch)
1000 echo "modified delta on branch" > $testroot/repo/gamma/delta
1001 git_commit $testroot/repo -m "committing to delta on newbranch"
1003 echo "modified alpha on branch" > $testroot/repo/alpha
1004 (cd $testroot/repo && git rm -q beta)
1005 echo "new file on branch" > $testroot/repo/epsilon/new
1006 (cd $testroot/repo && git add epsilon/new)
1007 git_commit $testroot/repo -m "committing more changes on newbranch"
1009 local orig_commit1=`git_show_parent_commit $testroot/repo`
1010 local orig_commit2=`git_show_head $testroot/repo`
1012 (cd $testroot/repo && git checkout -q master)
1013 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1014 git_commit $testroot/repo -m "committing to zeta on master"
1015 local master_commit1=`git_show_head $testroot/repo`
1017 (cd $testroot/repo && git checkout -q master)
1018 echo "modified beta on master" > $testroot/repo/beta
1019 git_commit $testroot/repo -m "committing to beta on master"
1020 local master_commit2=`git_show_head $testroot/repo`
1022 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1025 if [ "$ret" != "0" ]; then
1026 test_done "$testroot" "$ret"
1030 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1031 2> $testroot/stderr)
1033 echo -n > $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 -n "got: work tree must be updated before it can be " \
1043 > $testroot/stderr.expected
1044 echo "used to rebase a branch" >> $testroot/stderr.expected
1045 cmp -s $testroot/stderr.expected $testroot/stderr
1047 if [ "$ret" != "0" ]; then
1048 diff -u $testroot/stderr.expected $testroot/stderr
1049 test_done "$testroot" "$ret"
1053 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1054 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1055 echo "commit $master_commit1" >> $testroot/stdout.expected
1056 echo "commit $initial_commit" >> $testroot/stdout.expected
1057 cmp -s $testroot/stdout.expected $testroot/stdout
1059 if [ "$ret" != "0" ]; then
1060 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1065 test_rebase_trims_empty_dir() {
1066 local testroot=`test_init rebase_trims_empty_dir`
1068 (cd $testroot/repo && git checkout -q -b newbranch)
1069 echo "modified delta on branch" > $testroot/repo/gamma/delta
1070 git_commit $testroot/repo -m "committing to delta on newbranch"
1072 (cd $testroot/repo && git rm -q epsilon/zeta)
1073 git_commit $testroot/repo -m "removing zeta on newbranch"
1075 local orig_commit1=`git_show_parent_commit $testroot/repo`
1076 local orig_commit2=`git_show_head $testroot/repo`
1078 (cd $testroot/repo && git checkout -q master)
1079 echo "modified alpha on master" > $testroot/repo/alpha
1080 git_commit $testroot/repo -m "committing to alpha on master"
1081 local master_commit=`git_show_head $testroot/repo`
1083 got checkout $testroot/repo $testroot/wt > /dev/null
1085 if [ "$ret" != "0" ]; then
1086 test_done "$testroot" "$ret"
1090 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1092 (cd $testroot/repo && git checkout -q newbranch)
1093 local new_commit1=`git_show_parent_commit $testroot/repo`
1094 local new_commit2=`git_show_head $testroot/repo`
1096 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1097 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1098 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1099 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1101 echo "G gamma/delta" >> $testroot/stdout.expected
1102 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1103 >> $testroot/stdout.expected
1104 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1105 echo "D epsilon/zeta" >> $testroot/stdout.expected
1106 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1107 >> $testroot/stdout.expected
1108 echo ": removing zeta on newbranch" \
1109 >> $testroot/stdout.expected
1110 echo "Switching work tree to refs/heads/newbranch" \
1111 >> $testroot/stdout.expected
1113 cmp -s $testroot/stdout.expected $testroot/stdout
1115 if [ "$ret" != "0" ]; then
1116 diff -u $testroot/stdout.expected $testroot/stdout
1117 test_done "$testroot" "$ret"
1121 echo "modified delta on branch" > $testroot/content.expected
1122 cat $testroot/wt/gamma/delta > $testroot/content
1123 cmp -s $testroot/content.expected $testroot/content
1125 if [ "$ret" != "0" ]; then
1126 diff -u $testroot/content.expected $testroot/content
1127 test_done "$testroot" "$ret"
1131 echo "modified alpha on master" > $testroot/content.expected
1132 cat $testroot/wt/alpha > $testroot/content
1133 cmp -s $testroot/content.expected $testroot/content
1135 if [ "$ret" != "0" ]; then
1136 diff -u $testroot/content.expected $testroot/content
1137 test_done "$testroot" "$ret"
1141 if [ -e $testroot/wt/epsilon ]; then
1142 echo "parent of removed zeta still exists on disk" >&2
1143 test_done "$testroot" "1"
1147 (cd $testroot/wt && got status > $testroot/stdout)
1149 echo -n > $testroot/stdout.expected
1150 cmp -s $testroot/stdout.expected $testroot/stdout
1152 if [ "$ret" != "0" ]; then
1153 diff -u $testroot/stdout.expected $testroot/stdout
1154 test_done "$testroot" "$ret"
1158 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1159 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1160 echo "commit $new_commit1" >> $testroot/stdout.expected
1161 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1162 cmp -s $testroot/stdout.expected $testroot/stdout
1164 if [ "$ret" != "0" ]; then
1165 diff -u $testroot/stdout.expected $testroot/stdout
1167 test_done "$testroot" "$ret"
1170 test_rebase_delete_missing_file() {
1171 local testroot=`test_init rebase_delete_missing_file`
1173 mkdir -p $testroot/repo/d/f/g
1174 echo "new file" > $testroot/repo/d/f/g/new
1175 (cd $testroot/repo && git add d/f/g/new)
1176 git_commit $testroot/repo -m "adding a subdir"
1177 local commit0=`git_show_head $testroot/repo`
1179 got br -r $testroot/repo -c master newbranch
1181 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1183 echo "modified delta on branch" > $testroot/wt/gamma/delta
1184 (cd $testroot/wt && got commit \
1185 -m "committing to delta on newbranch" > /dev/null)
1187 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1188 (cd $testroot/wt && got commit \
1189 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1191 (cd $testroot/repo && git checkout -q newbranch)
1192 local orig_commit1=`git_show_parent_commit $testroot/repo`
1193 local orig_commit2=`git_show_head $testroot/repo`
1195 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1196 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1198 (cd $testroot/wt && got update -b master > /dev/null)
1199 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1200 (cd $testroot/wt && got commit \
1201 -m "removing beta and d/f/g/new on master" > /dev/null)
1203 (cd $testroot/repo && git checkout -q master)
1204 local master_commit=`git_show_head $testroot/repo`
1206 (cd $testroot/wt && got update -b master > /dev/null)
1207 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1208 2> $testroot/stderr)
1210 if [ "$ret" = "0" ]; then
1211 echo "rebase succeeded unexpectedly" >&2
1212 test_done "$testroot" "1"
1216 local new_commit1=$(cd $testroot/wt && got info | \
1217 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1219 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1220 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1222 echo "G gamma/delta" >> $testroot/stdout.expected
1223 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1224 >> $testroot/stdout.expected
1225 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1226 echo "! beta" >> $testroot/stdout.expected
1227 echo "! d/f/g/new" >> $testroot/stdout.expected
1228 echo -n "Files which had incoming changes but could not be found " \
1229 >> $testroot/stdout.expected
1230 echo "in the work tree: 2" >> $testroot/stdout.expected
1231 cmp -s $testroot/stdout.expected $testroot/stdout
1233 if [ "$ret" != "0" ]; then
1234 diff -u $testroot/stdout.expected $testroot/stdout
1235 test_done "$testroot" "$ret"
1239 echo -n "got: changes destined for some files were not yet merged " \
1240 > $testroot/stderr.expected
1241 echo -n "and should be merged manually if required before the " \
1242 >> $testroot/stderr.expected
1243 echo "rebase operation is continued" >> $testroot/stderr.expected
1244 cmp -s $testroot/stderr.expected $testroot/stderr
1246 if [ "$ret" != "0" ]; then
1247 diff -u $testroot/stderr.expected $testroot/stderr
1248 test_done "$testroot" "$ret"
1252 # ignore the missing changes and continue
1253 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1255 if [ "$ret" != "0" ]; then
1256 echo "rebase failed unexpectedly" >&2
1257 test_done "$testroot" "1"
1260 echo -n "$short_orig_commit2 -> no-op change" \
1261 > $testroot/stdout.expected
1262 echo ": removing beta and d/f/g/new on newbranch" \
1263 >> $testroot/stdout.expected
1264 echo "Switching work tree to refs/heads/newbranch" \
1265 >> $testroot/stdout.expected
1267 cmp -s $testroot/stdout.expected $testroot/stdout
1269 if [ "$ret" != "0" ]; then
1270 diff -u $testroot/stdout.expected $testroot/stdout
1271 test_done "$testroot" "$ret"
1275 echo "modified delta on branch" > $testroot/content.expected
1276 cat $testroot/wt/gamma/delta > $testroot/content
1277 cmp -s $testroot/content.expected $testroot/content
1279 if [ "$ret" != "0" ]; then
1280 diff -u $testroot/content.expected $testroot/content
1281 test_done "$testroot" "$ret"
1285 if [ -e $testroot/wt/beta ]; then
1286 echo "removed file beta still exists on disk" >&2
1287 test_done "$testroot" "1"
1291 (cd $testroot/wt && got status > $testroot/stdout)
1293 echo -n > $testroot/stdout.expected
1294 cmp -s $testroot/stdout.expected $testroot/stdout
1296 if [ "$ret" != "0" ]; then
1297 diff -u $testroot/stdout.expected $testroot/stdout
1298 test_done "$testroot" "$ret"
1302 (cd $testroot/repo && git checkout -q newbranch)
1303 local new_commit1=`git_show_head $testroot/repo`
1304 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1306 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1307 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1308 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1309 echo "commit $commit0" >> $testroot/stdout.expected
1310 cmp -s $testroot/stdout.expected $testroot/stdout
1312 if [ "$ret" != "0" ]; then
1313 diff -u $testroot/stdout.expected $testroot/stdout
1315 test_done "$testroot" "$ret"
1318 test_rebase_rm_add_rm_file() {
1319 local testroot=`test_init rebase_rm_add_rm_file`
1321 (cd $testroot/repo && git checkout -q -b newbranch)
1322 (cd $testroot/repo && git rm -q beta)
1323 git_commit $testroot/repo -m "removing beta from newbranch"
1324 local orig_commit1=`git_show_head $testroot/repo`
1326 echo 'restored beta' > $testroot/repo/beta
1327 (cd $testroot/repo && git add beta)
1328 git_commit $testroot/repo -m "restoring beta on newbranch"
1329 local orig_commit2=`git_show_head $testroot/repo`
1331 (cd $testroot/repo && git rm -q beta)
1332 git_commit $testroot/repo -m "removing beta from newbranch again"
1333 local orig_commit3=`git_show_head $testroot/repo`
1335 (cd $testroot/repo && git checkout -q master)
1336 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1337 git_commit $testroot/repo -m "committing to zeta on master"
1338 local master_commit=`git_show_head $testroot/repo`
1340 got checkout $testroot/repo $testroot/wt > /dev/null
1342 if [ "$ret" != "0" ]; then
1343 test_done "$testroot" "$ret"
1347 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1349 # this would error out with 'got: file index is corrupt'
1350 (cd $testroot/wt && got status > /dev/null)
1352 if [ "$ret" != "0" ]; then
1353 echo "got status command failed unexpectedly" >&2
1354 test_done "$testroot" "$ret"
1358 (cd $testroot/repo && git checkout -q newbranch)
1359 local new_commit3=`git_show_head $testroot/repo`
1360 local new_commit2=`git_show_parent_commit $testroot/repo`
1361 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1363 (cd $testroot/repo && git checkout -q newbranch)
1365 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1366 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1367 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1368 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1369 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1370 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1372 echo "D beta" > $testroot/stdout.expected
1373 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1374 >> $testroot/stdout.expected
1375 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1376 echo "A beta" >> $testroot/stdout.expected
1377 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1378 >> $testroot/stdout.expected
1379 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1380 echo "D beta" >> $testroot/stdout.expected
1381 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1382 >> $testroot/stdout.expected
1383 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1384 echo "Switching work tree to refs/heads/newbranch" \
1385 >> $testroot/stdout.expected
1387 cmp -s $testroot/stdout.expected $testroot/stdout
1389 if [ "$ret" != "0" ]; then
1390 diff -u $testroot/stdout.expected $testroot/stdout
1391 test_done "$testroot" "$ret"
1395 (cd $testroot/wt && got status > $testroot/stdout)
1397 if [ "$ret" != "0" ]; then
1398 echo "got status command failed unexpectedly" >&2
1399 test_done "$testroot" "$ret"
1403 echo -n > $testroot/stdout.expected
1404 cmp -s $testroot/stdout.expected $testroot/stdout
1406 if [ "$ret" != "0" ]; then
1407 diff -u $testroot/stdout.expected $testroot/stdout
1408 test_done "$testroot" "$ret"
1412 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1413 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1414 echo "commit $new_commit2" >> $testroot/stdout.expected
1415 echo "commit $new_commit1" >> $testroot/stdout.expected
1416 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1417 cmp -s $testroot/stdout.expected $testroot/stdout
1419 if [ "$ret" != "0" ]; then
1420 diff -u $testroot/stdout.expected $testroot/stdout
1422 test_done "$testroot" "$ret"
1426 run_test test_rebase_basic
1427 run_test test_rebase_ancestry_check
1428 run_test test_rebase_continue
1429 run_test test_rebase_abort
1430 run_test test_rebase_no_op_change
1431 run_test test_rebase_in_progress
1432 run_test test_rebase_path_prefix
1433 run_test test_rebase_preserves_logmsg
1434 run_test test_rebase_no_commits_to_rebase
1435 run_test test_rebase_forward
1436 run_test test_rebase_out_of_date
1437 run_test test_rebase_trims_empty_dir
1438 run_test test_rebase_delete_missing_file
1439 run_test test_rebase_rm_add_rm_file