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.
19 function test_rebase_basic {
20 local testroot=`test_init rebase_basic`
22 (cd $testroot/repo && git checkout -q -b newbranch)
23 echo "modified delta on branch" > $testroot/repo/gamma/delta
24 git_commit $testroot/repo -m "committing to delta on newbranch"
26 echo "modified alpha on branch" > $testroot/repo/alpha
27 (cd $testroot/repo && git rm -q beta)
28 echo "new file on branch" > $testroot/repo/epsilon/new
29 (cd $testroot/repo && git add epsilon/new)
30 git_commit $testroot/repo -m "committing more changes on newbranch"
32 local orig_commit1=`git_show_parent_commit $testroot/repo`
33 local orig_commit2=`git_show_head $testroot/repo`
35 (cd $testroot/repo && git checkout -q master)
36 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
37 git_commit $testroot/repo -m "committing to zeta on master"
38 local master_commit=`git_show_head $testroot/repo`
40 got checkout $testroot/repo $testroot/wt > /dev/null
42 if [ "$ret" != "0" ]; then
43 test_done "$testroot" "$ret"
47 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
49 (cd $testroot/repo && git checkout -q newbranch)
50 local new_commit1=`git_show_parent_commit $testroot/repo`
51 local new_commit2=`git_show_head $testroot/repo`
53 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
54 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
55 local short_new_commit1=`trim_obj_id 28 $new_commit1`
56 local short_new_commit2=`trim_obj_id 28 $new_commit2`
58 echo "G gamma/delta" >> $testroot/stdout.expected
59 echo -n "$short_orig_commit1 -> $short_new_commit1" \
60 >> $testroot/stdout.expected
61 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
62 echo "G alpha" >> $testroot/stdout.expected
63 echo "D beta" >> $testroot/stdout.expected
64 echo "A epsilon/new" >> $testroot/stdout.expected
65 echo -n "$short_orig_commit2 -> $short_new_commit2" \
66 >> $testroot/stdout.expected
67 echo ": committing more changes on newbranch" \
68 >> $testroot/stdout.expected
69 echo "Switching work tree to refs/heads/newbranch" \
70 >> $testroot/stdout.expected
72 cmp -s $testroot/stdout.expected $testroot/stdout
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stdout.expected $testroot/stdout
76 test_done "$testroot" "$ret"
80 echo "modified delta on branch" > $testroot/content.expected
81 cat $testroot/wt/gamma/delta > $testroot/content
82 cmp -s $testroot/content.expected $testroot/content
84 if [ "$ret" != "0" ]; then
85 diff -u $testroot/content.expected $testroot/content
86 test_done "$testroot" "$ret"
90 echo "modified alpha on branch" > $testroot/content.expected
91 cat $testroot/wt/alpha > $testroot/content
92 cmp -s $testroot/content.expected $testroot/content
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/content.expected $testroot/content
96 test_done "$testroot" "$ret"
100 if [ -e $testroot/wt/beta ]; then
101 echo "removed file beta still exists on disk" >&2
102 test_done "$testroot" "1"
106 echo "new file on branch" > $testroot/content.expected
107 cat $testroot/wt/epsilon/new > $testroot/content
108 cmp -s $testroot/content.expected $testroot/content
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/content.expected $testroot/content
112 test_done "$testroot" "$ret"
116 (cd $testroot/wt && got status > $testroot/stdout)
118 echo -n > $testroot/stdout.expected
119 cmp -s $testroot/stdout.expected $testroot/stdout
121 if [ "$ret" != "0" ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 test_done "$testroot" "$ret"
127 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
128 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
129 echo "commit $new_commit1" >> $testroot/stdout.expected
130 echo "commit $master_commit (master)" >> $testroot/stdout.expected
131 cmp -s $testroot/stdout.expected $testroot/stdout
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stdout.expected $testroot/stdout
136 test_done "$testroot" "$ret"
139 function test_rebase_ancestry_check {
140 local testroot=`test_init rebase_ancestry_check`
142 got checkout $testroot/repo $testroot/wt > /dev/null
144 if [ "$ret" != "0" ]; then
145 test_done "$testroot" "$ret"
149 (cd $testroot/repo && git checkout -q -b newbranch)
150 echo "modified delta on branch" > $testroot/repo/gamma/delta
151 git_commit $testroot/repo -m "committing to delta on newbranch"
153 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
156 echo -n > $testroot/stdout.expected
157 cmp -s $testroot/stdout.expected $testroot/stdout
159 if [ "$ret" != "0" ]; then
160 diff -u $testroot/stdout.expected $testroot/stdout
161 test_done "$testroot" "$ret"
165 echo -n "got: specified branch resolves to a commit " \
166 > $testroot/stderr.expected
167 echo "which is already contained in work tree's branch" \
168 >> $testroot/stderr.expected
169 cmp -s $testroot/stderr.expected $testroot/stderr
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
174 test_done "$testroot" "$ret"
177 function test_rebase_continue {
178 local testroot=`test_init rebase_continue`
179 local init_commit=`git_show_head $testroot/repo`
181 (cd $testroot/repo && git checkout -q -b newbranch)
182 echo "modified alpha on branch" > $testroot/repo/alpha
183 git_commit $testroot/repo -m "committing to alpha on newbranch"
184 local orig_commit1=`git_show_head $testroot/repo`
185 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
187 (cd $testroot/repo && git checkout -q master)
188 echo "modified alpha on master" > $testroot/repo/alpha
189 git_commit $testroot/repo -m "committing to alpha on master"
190 local master_commit=`git_show_head $testroot/repo`
192 got checkout $testroot/repo $testroot/wt > /dev/null
194 if [ "$ret" != "0" ]; then
195 test_done "$testroot" "$ret"
199 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
202 echo "C alpha" > $testroot/stdout.expected
203 echo -n "$short_orig_commit1 -> merge conflict" \
204 >> $testroot/stdout.expected
205 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
206 cmp -s $testroot/stdout.expected $testroot/stdout
208 if [ "$ret" != "0" ]; then
209 diff -u $testroot/stdout.expected $testroot/stdout
210 test_done "$testroot" "$ret"
214 echo "got: conflicts must be resolved before rebasing can continue" \
215 > $testroot/stderr.expected
216 cmp -s $testroot/stderr.expected $testroot/stderr
218 if [ "$ret" != "0" ]; then
219 diff -u $testroot/stderr.expected $testroot/stderr
220 test_done "$testroot" "$ret"
224 echo "<<<<<<< merged change: commit $orig_commit1" \
225 > $testroot/content.expected
226 echo "modified alpha on branch" >> $testroot/content.expected
227 echo "||||||| 3-way merge base: commit $init_commit" \
228 >> $testroot/content.expected
229 echo "alpha" >> $testroot/content.expected
230 echo "=======" >> $testroot/content.expected
231 echo "modified alpha on master" >> $testroot/content.expected
232 echo '>>>>>>>' >> $testroot/content.expected
233 cat $testroot/wt/alpha > $testroot/content
234 cmp -s $testroot/content.expected $testroot/content
236 if [ "$ret" != "0" ]; then
237 diff -u $testroot/content.expected $testroot/content
238 test_done "$testroot" "$ret"
242 (cd $testroot/wt && got status > $testroot/stdout)
244 echo "C alpha" > $testroot/stdout.expected
245 cmp -s $testroot/stdout.expected $testroot/stdout
247 if [ "$ret" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
253 # resolve the conflict
254 echo "modified alpha on branch and master" > $testroot/wt/alpha
256 # test interaction of 'got stage' and rebase -c
257 (cd $testroot/wt && got stage alpha > /dev/null)
258 (cd $testroot/wt && got rebase -c > $testroot/stdout \
261 if [ "$ret" == "0" ]; then
262 echo "rebase succeeded unexpectedly" >&2
263 test_done "$testroot" "1"
266 echo -n "got: work tree contains files with staged changes; " \
267 > $testroot/stderr.expected
268 echo "these changes must be committed or unstaged first" \
269 >> $testroot/stderr.expected
270 cmp -s $testroot/stderr.expected $testroot/stderr
272 if [ "$ret" != "0" ]; then
273 diff -u $testroot/stderr.expected $testroot/stderr
274 test_done "$testroot" "$ret"
278 (cd $testroot/wt && got unstage alpha > /dev/null)
279 (cd $testroot/wt && got rebase -c > $testroot/stdout)
281 (cd $testroot/repo && git checkout -q newbranch)
282 local new_commit1=`git_show_head $testroot/repo`
283 local short_new_commit1=`trim_obj_id 28 $new_commit1`
285 echo -n "$short_orig_commit1 -> $short_new_commit1" \
286 > $testroot/stdout.expected
287 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
288 echo "Switching work tree to refs/heads/newbranch" \
289 >> $testroot/stdout.expected
291 cmp -s $testroot/stdout.expected $testroot/stdout
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/stdout.expected $testroot/stdout
295 test_done "$testroot" "$ret"
300 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
301 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
302 echo "commit $master_commit (master)" >> $testroot/stdout.expected
303 cmp -s $testroot/stdout.expected $testroot/stdout
305 if [ "$ret" != "0" ]; then
306 diff -u $testroot/stdout.expected $testroot/stdout
308 test_done "$testroot" "$ret"
311 function test_rebase_abort {
312 local testroot=`test_init rebase_abort`
314 local init_commit=`git_show_head $testroot/repo`
316 (cd $testroot/repo && git checkout -q -b newbranch)
317 echo "modified alpha on branch" > $testroot/repo/alpha
318 git_commit $testroot/repo -m "committing to alpha on newbranch"
319 local orig_commit1=`git_show_head $testroot/repo`
320 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
322 (cd $testroot/repo && git checkout -q master)
323 echo "modified alpha on master" > $testroot/repo/alpha
324 git_commit $testroot/repo -m "committing to alpha on master"
325 local master_commit=`git_show_head $testroot/repo`
327 got checkout $testroot/repo $testroot/wt > /dev/null
329 if [ "$ret" != "0" ]; then
330 test_done "$testroot" "$ret"
334 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
337 echo "C alpha" > $testroot/stdout.expected
338 echo -n "$short_orig_commit1 -> merge conflict" \
339 >> $testroot/stdout.expected
340 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
341 cmp -s $testroot/stdout.expected $testroot/stdout
343 if [ "$ret" != "0" ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
349 echo "got: conflicts must be resolved before rebasing can continue" \
350 > $testroot/stderr.expected
351 cmp -s $testroot/stderr.expected $testroot/stderr
353 if [ "$ret" != "0" ]; then
354 diff -u $testroot/stderr.expected $testroot/stderr
355 test_done "$testroot" "$ret"
359 echo "<<<<<<< merged change: commit $orig_commit1" \
360 > $testroot/content.expected
361 echo "modified alpha on branch" >> $testroot/content.expected
362 echo "||||||| 3-way merge base: commit $init_commit" \
363 >> $testroot/content.expected
364 echo "alpha" >> $testroot/content.expected
365 echo "=======" >> $testroot/content.expected
366 echo "modified alpha on master" >> $testroot/content.expected
367 echo '>>>>>>>' >> $testroot/content.expected
368 cat $testroot/wt/alpha > $testroot/content
369 cmp -s $testroot/content.expected $testroot/content
371 if [ "$ret" != "0" ]; then
372 diff -u $testroot/content.expected $testroot/content
373 test_done "$testroot" "$ret"
377 (cd $testroot/wt && got status > $testroot/stdout)
379 echo "C alpha" > $testroot/stdout.expected
380 cmp -s $testroot/stdout.expected $testroot/stdout
382 if [ "$ret" != "0" ]; then
383 diff -u $testroot/stdout.expected $testroot/stdout
384 test_done "$testroot" "$ret"
388 (cd $testroot/wt && got rebase -a > $testroot/stdout)
390 (cd $testroot/repo && git checkout -q newbranch)
392 echo "Switching work tree to refs/heads/master" \
393 > $testroot/stdout.expected
394 echo 'R alpha' >> $testroot/stdout.expected
395 echo "Rebase of refs/heads/newbranch aborted" \
396 >> $testroot/stdout.expected
398 cmp -s $testroot/stdout.expected $testroot/stdout
400 if [ "$ret" != "0" ]; then
401 diff -u $testroot/stdout.expected $testroot/stdout
402 test_done "$testroot" "$ret"
406 echo "modified alpha on master" > $testroot/content.expected
407 cat $testroot/wt/alpha > $testroot/content
408 cmp -s $testroot/content.expected $testroot/content
410 if [ "$ret" != "0" ]; then
411 diff -u $testroot/content.expected $testroot/content
412 test_done "$testroot" "$ret"
416 (cd $testroot/wt && got log -l3 -c newbranch \
417 | grep ^commit > $testroot/stdout)
418 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
419 echo "commit $init_commit" >> $testroot/stdout.expected
420 cmp -s $testroot/stdout.expected $testroot/stdout
422 if [ "$ret" != "0" ]; then
423 diff -u $testroot/stdout.expected $testroot/stdout
425 test_done "$testroot" "$ret"
428 function test_rebase_no_op_change {
429 local testroot=`test_init rebase_no_op_change`
430 local init_commit=`git_show_head $testroot/repo`
432 (cd $testroot/repo && git checkout -q -b newbranch)
433 echo "modified alpha on branch" > $testroot/repo/alpha
434 git_commit $testroot/repo -m "committing to alpha on newbranch"
435 local orig_commit1=`git_show_head $testroot/repo`
436 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
438 (cd $testroot/repo && git checkout -q master)
439 echo "modified alpha on master" > $testroot/repo/alpha
440 git_commit $testroot/repo -m "committing to alpha on master"
441 local master_commit=`git_show_head $testroot/repo`
443 got checkout $testroot/repo $testroot/wt > /dev/null
445 if [ "$ret" != "0" ]; then
446 test_done "$testroot" "$ret"
450 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
453 echo "C alpha" > $testroot/stdout.expected
454 echo -n "$short_orig_commit1 -> merge conflict" \
455 >> $testroot/stdout.expected
456 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
457 cmp -s $testroot/stdout.expected $testroot/stdout
459 if [ "$ret" != "0" ]; then
460 diff -u $testroot/stdout.expected $testroot/stdout
461 test_done "$testroot" "$ret"
465 echo "got: conflicts must be resolved before rebasing can continue" \
466 > $testroot/stderr.expected
467 cmp -s $testroot/stderr.expected $testroot/stderr
469 if [ "$ret" != "0" ]; then
470 diff -u $testroot/stderr.expected $testroot/stderr
471 test_done "$testroot" "$ret"
475 echo "<<<<<<< merged change: commit $orig_commit1" \
476 > $testroot/content.expected
477 echo "modified alpha on branch" >> $testroot/content.expected
478 echo "||||||| 3-way merge base: commit $init_commit" \
479 >> $testroot/content.expected
480 echo "alpha" >> $testroot/content.expected
481 echo "=======" >> $testroot/content.expected
482 echo "modified alpha on master" >> $testroot/content.expected
483 echo '>>>>>>>' >> $testroot/content.expected
484 cat $testroot/wt/alpha > $testroot/content
485 cmp -s $testroot/content.expected $testroot/content
487 if [ "$ret" != "0" ]; then
488 diff -u $testroot/content.expected $testroot/content
489 test_done "$testroot" "$ret"
493 (cd $testroot/wt && got status > $testroot/stdout)
495 echo "C alpha" > $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 # resolve the conflict
505 echo "modified alpha on master" > $testroot/wt/alpha
507 (cd $testroot/wt && got rebase -c > $testroot/stdout)
509 (cd $testroot/repo && git checkout -q newbranch)
510 local new_commit1=`git_show_head $testroot/repo`
512 echo -n "$short_orig_commit1 -> no-op change" \
513 > $testroot/stdout.expected
514 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
515 echo "Switching work tree to refs/heads/newbranch" \
516 >> $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"
527 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
528 echo "commit $master_commit (master, newbranch)" \
529 > $testroot/stdout.expected
530 echo "commit $init_commit" >> $testroot/stdout.expected
531 cmp -s $testroot/stdout.expected $testroot/stdout
533 if [ "$ret" != "0" ]; then
534 diff -u $testroot/stdout.expected $testroot/stdout
536 test_done "$testroot" "$ret"
539 function test_rebase_in_progress {
540 local testroot=`test_init rebase_in_progress`
541 local init_commit=`git_show_head $testroot/repo`
543 (cd $testroot/repo && git checkout -q -b newbranch)
544 echo "modified alpha on branch" > $testroot/repo/alpha
545 git_commit $testroot/repo -m "committing to alpha on newbranch"
546 local orig_commit1=`git_show_head $testroot/repo`
547 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
549 (cd $testroot/repo && git checkout -q master)
550 echo "modified alpha on master" > $testroot/repo/alpha
551 git_commit $testroot/repo -m "committing to alpha on master"
552 local master_commit=`git_show_head $testroot/repo`
554 got checkout $testroot/repo $testroot/wt > /dev/null
556 if [ "$ret" != "0" ]; then
557 test_done "$testroot" "$ret"
561 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
564 echo "C alpha" > $testroot/stdout.expected
565 echo -n "$short_orig_commit1 -> merge conflict" \
566 >> $testroot/stdout.expected
567 echo ": committing to alpha on newbranch" >> $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 "got: conflicts must be resolved before rebasing can continue" \
577 > $testroot/stderr.expected
578 cmp -s $testroot/stderr.expected $testroot/stderr
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/stderr.expected $testroot/stderr
582 test_done "$testroot" "$ret"
586 echo "<<<<<<< merged change: commit $orig_commit1" \
587 > $testroot/content.expected
588 echo "modified alpha on branch" >> $testroot/content.expected
589 echo "||||||| 3-way merge base: commit $init_commit" \
590 >> $testroot/content.expected
591 echo "alpha" >> $testroot/content.expected
592 echo "=======" >> $testroot/content.expected
593 echo "modified alpha on master" >> $testroot/content.expected
594 echo '>>>>>>>' >> $testroot/content.expected
595 cat $testroot/wt/alpha > $testroot/content
596 cmp -s $testroot/content.expected $testroot/content
598 if [ "$ret" != "0" ]; then
599 diff -u $testroot/content.expected $testroot/content
600 test_done "$testroot" "$ret"
604 (cd $testroot/wt && got status > $testroot/stdout)
606 echo "C alpha" > $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 for cmd in update commit; do
616 (cd $testroot/wt && got $cmd > $testroot/stdout \
619 echo -n > $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
622 if [ "$ret" != "0" ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
628 echo -n "got: a rebase operation is in progress in this " \
629 > $testroot/stderr.expected
630 echo "work tree and must be continued or aborted first" \
631 >> $testroot/stderr.expected
632 cmp -s $testroot/stderr.expected $testroot/stderr
634 if [ "$ret" != "0" ]; then
635 diff -u $testroot/stderr.expected $testroot/stderr
636 test_done "$testroot" "$ret"
641 test_done "$testroot" "$ret"
644 function test_rebase_path_prefix {
645 local testroot=`test_init rebase_path_prefix`
647 (cd $testroot/repo && git checkout -q -b newbranch)
648 echo "modified delta on branch" > $testroot/repo/gamma/delta
649 git_commit $testroot/repo -m "committing to delta on newbranch"
651 local orig_commit1=`git_show_parent_commit $testroot/repo`
652 local orig_commit2=`git_show_head $testroot/repo`
654 (cd $testroot/repo && git checkout -q master)
655 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
656 git_commit $testroot/repo -m "committing to zeta on master"
657 local master_commit=`git_show_head $testroot/repo`
659 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
661 if [ "$ret" != "0" ]; then
662 test_done "$testroot" "$ret"
666 (cd $testroot/wt && got rebase newbranch \
667 > $testroot/stdout 2> $testroot/stderr)
669 echo -n > $testroot/stdout.expected
670 cmp -s $testroot/stdout.expected $testroot/stdout
672 if [ "$ret" != "0" ]; then
673 diff -u $testroot/stdout.expected $testroot/stdout
674 test_done "$testroot" "$ret"
678 echo -n "got: cannot rebase branch which contains changes outside " \
679 > $testroot/stderr.expected
680 echo "of this work tree's path prefix" >> $testroot/stderr.expected
681 cmp -s $testroot/stderr.expected $testroot/stderr
683 if [ "$ret" != "0" ]; then
684 diff -u $testroot/stderr.expected $testroot/stderr
686 test_done "$testroot" "$ret"
689 function test_rebase_preserves_logmsg {
690 local testroot=`test_init rebase_preserves_logmsg`
692 (cd $testroot/repo && git checkout -q -b newbranch)
693 echo "modified delta on branch" > $testroot/repo/gamma/delta
694 git_commit $testroot/repo -m "modified delta on newbranch"
696 echo "modified alpha on branch" > $testroot/repo/alpha
697 git_commit $testroot/repo -m "modified alpha on newbranch"
699 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
700 > $testroot/log.expected)
702 local orig_commit1=`git_show_parent_commit $testroot/repo`
703 local orig_commit2=`git_show_head $testroot/repo`
705 (cd $testroot/repo && git checkout -q master)
706 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
707 git_commit $testroot/repo -m "committing to zeta on master"
708 local master_commit=`git_show_head $testroot/repo`
710 got checkout $testroot/repo $testroot/wt > /dev/null
712 if [ "$ret" != "0" ]; then
713 test_done "$testroot" "$ret"
717 (cd $testroot/wt && got rebase newbranch > /dev/null \
720 (cd $testroot/repo && git checkout -q newbranch)
721 local new_commit1=`git_show_parent_commit $testroot/repo`
722 local new_commit2=`git_show_head $testroot/repo`
724 echo -n > $testroot/stderr.expected
725 cmp -s $testroot/stderr.expected $testroot/stderr
727 if [ "$ret" != "0" ]; then
728 diff -u $testroot/stderr.expected $testroot/stderr
729 test_done "$testroot" "$ret"
733 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
735 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
736 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
737 cmp -s $testroot/log.expected $testroot/log
739 if [ "$ret" != "0" ]; then
740 diff -u $testroot/log.expected $testroot/log
743 test_done "$testroot" "$ret"
746 function test_rebase_no_commits_to_rebase {
747 local testroot=`test_init rebase_no_commits_to_rebase`
749 got checkout $testroot/repo $testroot/wt > /dev/null
751 if [ "$ret" != "0" ]; then
752 test_done "$testroot" "$ret"
756 (cd $testroot/wt && got branch -n newbranch)
758 echo "modified alpha on master" > $testroot/wt/alpha
759 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
761 (cd $testroot/wt && got update > /dev/null)
763 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
766 echo "got: no commits to rebase" > $testroot/stderr.expected
767 cmp -s $testroot/stderr.expected $testroot/stderr
769 if [ "$ret" != "0" ]; then
770 diff -u $testroot/stderr.expected $testroot/stderr
771 test_done "$testroot" "$ret"
775 echo "Rebase of refs/heads/newbranch aborted" \
776 > $testroot/stdout.expected
777 cmp -s $testroot/stdout.expected $testroot/stdout
779 if [ "$ret" != "0" ]; then
780 diff -u $testroot/stdout.expected $testroot/stdout
781 test_done "$testroot" "$ret"
785 (cd $testroot/wt && got update > $testroot/stdout)
786 echo "Already up-to-date" > $testroot/stdout.expected
787 cmp -s $testroot/stdout.expected $testroot/stdout
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stdout.expected $testroot/stdout
792 test_done "$testroot" "$ret"
795 function test_rebase_forward {
796 local testroot=`test_init rebase_forward`
797 local commit0=`git_show_head $testroot/repo`
799 got checkout $testroot/repo $testroot/wt > /dev/null
801 if [ "$ret" != "0" ]; then
802 test_done "$testroot" "$ret"
806 echo "change alpha 1" > $testroot/wt/alpha
807 (cd $testroot/wt && got commit -m 'test rebase_forward' \
809 local commit1=`git_show_head $testroot/repo`
811 echo "change alpha 2" > $testroot/wt/alpha
812 (cd $testroot/wt && got commit -m 'test rebase_forward' \
814 local commit2=`git_show_head $testroot/repo`
816 # Simulate a situation where fast-forward is required.
817 # We want to fast-forward master to origin/master:
818 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
819 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
820 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
821 (cd $testroot/repo && got ref -d master)
822 (cd $testroot/repo && got ref refs/heads/master $commit1)
823 (cd $testroot/repo && got ref refs/remotes/origin/master $commit2)
826 (cd $testroot/wt && got up -b origin/master > /dev/null)
828 (cd $testroot/wt && got rebase master \
829 > $testroot/stdout 2> $testroot/stderr)
831 echo "Forwarding refs/heads/master to commit $commit2" \
832 > $testroot/stdout.expected
833 echo "Switching work tree to refs/heads/master" \
834 >> $testroot/stdout.expected
835 cmp -s $testroot/stdout.expected $testroot/stdout
837 if [ "$ret" != "0" ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
843 # Ensure that rebase operation was completed correctly
844 (cd $testroot/wt && got rebase -a \
845 > $testroot/stdout 2> $testroot/stderr)
846 echo -n "" > $testroot/stdout.expected
847 cmp -s $testroot/stdout.expected $testroot/stdout
849 if [ "$ret" != "0" ]; then
850 diff -u $testroot/stdout.expected $testroot/stdout
851 test_done "$testroot" "$ret"
854 echo "got: rebase operation not in progress" > $testroot/stderr.expected
855 cmp -s $testroot/stderr.expected $testroot/stderr
857 if [ "$ret" != "0" ]; then
858 diff -u $testroot/stderr.expected $testroot/stderr
859 test_done "$testroot" "$ret"
863 (cd $testroot/wt && got branch -n > $testroot/stdout)
864 echo "master" > $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
867 if [ "$ret" != "0" ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 test_done "$testroot" "$ret"
873 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
874 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
875 echo "commit $commit1" >> $testroot/stdout.expected
876 echo "commit $commit0" >> $testroot/stdout.expected
877 cmp -s $testroot/stdout.expected $testroot/stdout
879 if [ "$ret" != "0" ]; then
880 diff -u $testroot/stdout.expected $testroot/stdout
882 test_done "$testroot" "$ret"
885 function test_rebase_out_of_date {
886 local testroot=`test_init rebase_out_of_date`
887 local initial_commit=`git_show_head $testroot/repo`
889 (cd $testroot/repo && git checkout -q -b newbranch)
890 echo "modified delta on branch" > $testroot/repo/gamma/delta
891 git_commit $testroot/repo -m "committing to delta on newbranch"
893 echo "modified alpha on branch" > $testroot/repo/alpha
894 (cd $testroot/repo && git rm -q beta)
895 echo "new file on branch" > $testroot/repo/epsilon/new
896 (cd $testroot/repo && git add epsilon/new)
897 git_commit $testroot/repo -m "committing more changes on newbranch"
899 local orig_commit1=`git_show_parent_commit $testroot/repo`
900 local orig_commit2=`git_show_head $testroot/repo`
902 (cd $testroot/repo && git checkout -q master)
903 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
904 git_commit $testroot/repo -m "committing to zeta on master"
905 local master_commit1=`git_show_head $testroot/repo`
907 (cd $testroot/repo && git checkout -q master)
908 echo "modified beta on master" > $testroot/repo/beta
909 git_commit $testroot/repo -m "committing to beta on master"
910 local master_commit2=`git_show_head $testroot/repo`
912 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
915 if [ "$ret" != "0" ]; then
916 test_done "$testroot" "$ret"
920 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
923 echo -n > $testroot/stdout.expected
924 cmp -s $testroot/stdout.expected $testroot/stdout
926 if [ "$ret" != "0" ]; then
927 diff -u $testroot/stdout.expected $testroot/stdout
928 test_done "$testroot" "$ret"
932 echo -n "got: work tree must be updated before it can be " \
933 > $testroot/stderr.expected
934 echo "used to rebase a branch" >> $testroot/stderr.expected
935 cmp -s $testroot/stderr.expected $testroot/stderr
937 if [ "$ret" != "0" ]; then
938 diff -u $testroot/stderr.expected $testroot/stderr
939 test_done "$testroot" "$ret"
943 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
944 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
945 echo "commit $master_commit1" >> $testroot/stdout.expected
946 echo "commit $initial_commit" >> $testroot/stdout.expected
947 cmp -s $testroot/stdout.expected $testroot/stdout
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
952 test_done "$testroot" "$ret"
955 function test_rebase_trims_empty_dir {
956 local testroot=`test_init rebase_trims_empty_dir`
958 (cd $testroot/repo && git checkout -q -b newbranch)
959 echo "modified delta on branch" > $testroot/repo/gamma/delta
960 git_commit $testroot/repo -m "committing to delta on newbranch"
962 (cd $testroot/repo && git rm -q epsilon/zeta)
963 git_commit $testroot/repo -m "removing zeta on newbranch"
965 local orig_commit1=`git_show_parent_commit $testroot/repo`
966 local orig_commit2=`git_show_head $testroot/repo`
968 (cd $testroot/repo && git checkout -q master)
969 echo "modified alpha on master" > $testroot/repo/alpha
970 git_commit $testroot/repo -m "committing to alpha on master"
971 local master_commit=`git_show_head $testroot/repo`
973 got checkout $testroot/repo $testroot/wt > /dev/null
975 if [ "$ret" != "0" ]; then
976 test_done "$testroot" "$ret"
980 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
982 (cd $testroot/repo && git checkout -q newbranch)
983 local new_commit1=`git_show_parent_commit $testroot/repo`
984 local new_commit2=`git_show_head $testroot/repo`
986 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
987 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
988 local short_new_commit1=`trim_obj_id 28 $new_commit1`
989 local short_new_commit2=`trim_obj_id 28 $new_commit2`
991 echo "G gamma/delta" >> $testroot/stdout.expected
992 echo -n "$short_orig_commit1 -> $short_new_commit1" \
993 >> $testroot/stdout.expected
994 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
995 echo "D epsilon/zeta" >> $testroot/stdout.expected
996 echo -n "$short_orig_commit2 -> $short_new_commit2" \
997 >> $testroot/stdout.expected
998 echo ": removing zeta on newbranch" \
999 >> $testroot/stdout.expected
1000 echo "Switching work tree to refs/heads/newbranch" \
1001 >> $testroot/stdout.expected
1003 cmp -s $testroot/stdout.expected $testroot/stdout
1005 if [ "$ret" != "0" ]; then
1006 diff -u $testroot/stdout.expected $testroot/stdout
1007 test_done "$testroot" "$ret"
1011 echo "modified delta on branch" > $testroot/content.expected
1012 cat $testroot/wt/gamma/delta > $testroot/content
1013 cmp -s $testroot/content.expected $testroot/content
1015 if [ "$ret" != "0" ]; then
1016 diff -u $testroot/content.expected $testroot/content
1017 test_done "$testroot" "$ret"
1021 echo "modified alpha on master" > $testroot/content.expected
1022 cat $testroot/wt/alpha > $testroot/content
1023 cmp -s $testroot/content.expected $testroot/content
1025 if [ "$ret" != "0" ]; then
1026 diff -u $testroot/content.expected $testroot/content
1027 test_done "$testroot" "$ret"
1031 if [ -e $testroot/wt/epsilon ]; then
1032 echo "parent of removed zeta still exists on disk" >&2
1033 test_done "$testroot" "1"
1037 (cd $testroot/wt && got status > $testroot/stdout)
1039 echo -n > $testroot/stdout.expected
1040 cmp -s $testroot/stdout.expected $testroot/stdout
1042 if [ "$ret" != "0" ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1048 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1049 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1050 echo "commit $new_commit1" >> $testroot/stdout.expected
1051 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1052 cmp -s $testroot/stdout.expected $testroot/stdout
1054 if [ "$ret" != "0" ]; then
1055 diff -u $testroot/stdout.expected $testroot/stdout
1057 test_done "$testroot" "$ret"
1060 run_test test_rebase_basic
1061 run_test test_rebase_ancestry_check
1062 run_test test_rebase_continue
1063 run_test test_rebase_abort
1064 run_test test_rebase_no_op_change
1065 run_test test_rebase_in_progress
1066 run_test test_rebase_path_prefix
1067 run_test test_rebase_preserves_logmsg
1068 run_test test_rebase_no_commits_to_rebase
1069 run_test test_rebase_forward
1070 run_test test_rebase_out_of_date
1071 run_test test_rebase_trims_empty_dir