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 git -C $testroot/repo 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 git -C $testroot/repo rm -q beta
30 echo "new file on branch" > $testroot/repo/epsilon/new
31 git -C $testroot/repo 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 git -C $testroot/repo 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 -ne 0 ]; then
46 test_done "$testroot" "$ret"
50 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
52 git -C $testroot/repo 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 +"%F"`
158 d_0=`date -u -r $commit0_author_time +"%F"`
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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 0 ]; then
239 test_done "$testroot" "$ret"
243 git -C $testroot/repo 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"
246 local newbranch_id=`git_show_head $testroot/repo`
248 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
251 echo "refs/heads/newbranch is already based on refs/heads/master" \
252 > $testroot/stdout.expected
253 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
254 >> $testroot/stdout.expected
255 echo "U gamma/delta" >> $testroot/stdout.expected
256 echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
257 >> $testroot/stdout.expected
258 cmp -s $testroot/stdout.expected $testroot/stdout
260 if [ $ret -ne 0 ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
266 echo -n > $testroot/stderr.expected
267 cmp -s $testroot/stderr.expected $testroot/stderr
269 if [ $ret -ne 0 ]; then
270 diff -u $testroot/stderr.expected $testroot/stderr
272 test_done "$testroot" "$ret"
275 test_rebase_continue() {
276 local testroot=`test_init rebase_continue`
277 local init_commit=`git_show_head $testroot/repo`
279 git -C $testroot/repo checkout -q -b newbranch
280 echo "modified alpha on branch" > $testroot/repo/alpha
281 git_commit $testroot/repo -m "committing to alpha on newbranch"
282 local orig_commit1=`git_show_head $testroot/repo`
283 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
285 git -C $testroot/repo checkout -q master
286 echo "modified alpha on master" > $testroot/repo/alpha
287 git_commit $testroot/repo -m "committing to alpha on master"
288 local master_commit=`git_show_head $testroot/repo`
290 got checkout $testroot/repo $testroot/wt > /dev/null
292 if [ $ret -ne 0 ]; then
293 test_done "$testroot" "$ret"
297 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
300 echo "C alpha" > $testroot/stdout.expected
301 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
302 echo -n "$short_orig_commit1 -> merge conflict" \
303 >> $testroot/stdout.expected
304 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
305 cmp -s $testroot/stdout.expected $testroot/stdout
307 if [ $ret -ne 0 ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
313 echo "got: conflicts must be resolved before rebasing can continue" \
314 > $testroot/stderr.expected
315 cmp -s $testroot/stderr.expected $testroot/stderr
317 if [ $ret -ne 0 ]; then
318 diff -u $testroot/stderr.expected $testroot/stderr
319 test_done "$testroot" "$ret"
323 echo '<<<<<<<' > $testroot/content.expected
324 echo "modified alpha on master" >> $testroot/content.expected
325 echo "||||||| 3-way merge base: commit $init_commit" \
326 >> $testroot/content.expected
327 echo "alpha" >> $testroot/content.expected
328 echo "=======" >> $testroot/content.expected
329 echo "modified alpha on branch" >> $testroot/content.expected
330 echo ">>>>>>> merged change: commit $orig_commit1" \
331 >> $testroot/content.expected
332 cat $testroot/wt/alpha > $testroot/content
333 cmp -s $testroot/content.expected $testroot/content
335 if [ $ret -ne 0 ]; then
336 diff -u $testroot/content.expected $testroot/content
337 test_done "$testroot" "$ret"
341 (cd $testroot/wt && got status > $testroot/stdout)
343 cat > $testroot/stdout.expected <<EOF
345 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
347 cmp -s $testroot/stdout.expected $testroot/stdout
349 if [ $ret -ne 0 ]; then
350 diff -u $testroot/stdout.expected $testroot/stdout
351 test_done "$testroot" "$ret"
355 # resolve the conflict
356 echo "modified alpha on branch and master" > $testroot/wt/alpha
358 # test interaction of 'got stage' and rebase -c
359 (cd $testroot/wt && got stage alpha > /dev/null)
360 (cd $testroot/wt && got rebase -c > $testroot/stdout \
363 if [ $ret -eq 0 ]; then
364 echo "rebase succeeded unexpectedly" >&2
365 test_done "$testroot" "1"
368 echo -n "got: work tree contains files with staged changes; " \
369 > $testroot/stderr.expected
370 echo "these changes must be committed or unstaged first" \
371 >> $testroot/stderr.expected
372 cmp -s $testroot/stderr.expected $testroot/stderr
374 if [ $ret -ne 0 ]; then
375 diff -u $testroot/stderr.expected $testroot/stderr
376 test_done "$testroot" "$ret"
380 (cd $testroot/wt && got unstage alpha > /dev/null)
381 (cd $testroot/wt && got rebase -c > $testroot/stdout)
383 git -C $testroot/repo checkout -q newbranch
384 local new_commit1=`git_show_head $testroot/repo`
385 local short_new_commit1=`trim_obj_id 28 $new_commit1`
387 echo -n "$short_orig_commit1 -> $short_new_commit1" \
388 > $testroot/stdout.expected
389 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
390 echo "Switching work tree to refs/heads/newbranch" \
391 >> $testroot/stdout.expected
393 cmp -s $testroot/stdout.expected $testroot/stdout
395 if [ $ret -ne 0 ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
402 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
403 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
404 echo "commit $master_commit (master)" >> $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected $testroot/stdout
407 if [ $ret -ne 0 ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
413 test_rebase_abort() {
414 local testroot=`test_init rebase_abort`
416 local init_commit=`git_show_head $testroot/repo`
418 git -C $testroot/repo checkout -q -b newbranch
419 echo "modified beta on branch" > $testroot/repo/beta
420 git_commit $testroot/repo -m "committing to beta on newbranch"
421 local orig_commit1=`git_show_head $testroot/repo`
422 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
424 echo "modified alpha on branch" > $testroot/repo/alpha
425 echo "new file on branch" > $testroot/repo/epsilon/new
426 git -C $testroot/repo add epsilon/new
427 git_commit $testroot/repo \
428 -m "changing alpha and adding new on newbranch"
429 local orig_commit2=`git_show_head $testroot/repo`
430 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
432 git -C $testroot/repo checkout -q master
433 echo "modified alpha on master" > $testroot/repo/alpha
434 git_commit $testroot/repo -m "committing to alpha on master"
435 local master_commit=`git_show_head $testroot/repo`
437 got checkout $testroot/repo $testroot/wt > /dev/null
439 if [ $ret -ne 0 ]; then
440 test_done "$testroot" "$ret"
444 # unrelated unversioned file in work tree
445 touch $testroot/wt/unversioned-file
447 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
450 new_commit1=$(cd $testroot/wt && got info beta | \
451 grep '^based on commit:' | cut -d' ' -f4)
452 local short_new_commit1=`trim_obj_id 28 $new_commit1`
454 echo "G beta" > $testroot/stdout.expected
455 echo -n "$short_orig_commit1 -> $short_new_commit1" \
456 >> $testroot/stdout.expected
457 echo ": committing to beta on newbranch" >> $testroot/stdout.expected
458 echo "C alpha" >> $testroot/stdout.expected
459 echo "A epsilon/new" >> $testroot/stdout.expected
460 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
461 echo -n "$short_orig_commit2 -> merge conflict" \
462 >> $testroot/stdout.expected
463 echo ": changing alpha and adding new on newbranch" \
464 >> $testroot/stdout.expected
465 cmp -s $testroot/stdout.expected $testroot/stdout
467 if [ $ret -ne 0 ]; then
468 diff -u $testroot/stdout.expected $testroot/stdout
469 test_done "$testroot" "$ret"
473 echo "got: conflicts must be resolved before rebasing can continue" \
474 > $testroot/stderr.expected
475 cmp -s $testroot/stderr.expected $testroot/stderr
477 if [ $ret -ne 0 ]; then
478 diff -u $testroot/stderr.expected $testroot/stderr
479 test_done "$testroot" "$ret"
483 echo '<<<<<<<' > $testroot/content.expected
484 echo "modified alpha on master" >> $testroot/content.expected
485 echo "||||||| 3-way merge base: commit $orig_commit1" \
486 >> $testroot/content.expected
487 echo "alpha" >> $testroot/content.expected
488 echo "=======" >> $testroot/content.expected
489 echo "modified alpha on branch" >> $testroot/content.expected
490 echo ">>>>>>> merged change: commit $orig_commit2" \
491 >> $testroot/content.expected
492 cat $testroot/wt/alpha > $testroot/content
493 cmp -s $testroot/content.expected $testroot/content
495 if [ $ret -ne 0 ]; then
496 diff -u $testroot/content.expected $testroot/content
497 test_done "$testroot" "$ret"
501 # unrelated file in work tree added during conflict resolution
502 touch $testroot/wt/added-file
503 (cd $testroot/wt && got add added-file > /dev/null)
505 (cd $testroot/wt && got status > $testroot/stdout)
507 cat > $testroot/stdout.expected <<EOF
512 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
514 cmp -s $testroot/stdout.expected $testroot/stdout
516 if [ $ret -ne 0 ]; then
517 diff -u $testroot/stdout.expected $testroot/stdout
518 test_done "$testroot" "$ret"
522 (cd $testroot/wt && got rebase -a > $testroot/stdout)
524 git -C $testroot/repo checkout -q newbranch
526 echo "Switching work tree to refs/heads/master" \
527 > $testroot/stdout.expected
528 echo 'R added-file' >> $testroot/stdout.expected
529 echo 'R alpha' >> $testroot/stdout.expected
530 echo 'R epsilon/new' >> $testroot/stdout.expected
531 echo 'G added-file' >> $testroot/stdout.expected
532 echo 'U beta' >> $testroot/stdout.expected
533 echo "Rebase of refs/heads/newbranch aborted" \
534 >> $testroot/stdout.expected
536 cmp -s $testroot/stdout.expected $testroot/stdout
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 test_done "$testroot" "$ret"
544 echo "modified alpha on master" > $testroot/content.expected
545 cat $testroot/wt/alpha > $testroot/content
546 cmp -s $testroot/content.expected $testroot/content
548 if [ $ret -ne 0 ]; then
549 diff -u $testroot/content.expected $testroot/content
550 test_done "$testroot" "$ret"
554 (cd $testroot/wt && got log -l3 -c newbranch \
555 | grep ^commit > $testroot/stdout)
556 echo "commit $orig_commit2 (newbranch)" > $testroot/stdout.expected
557 echo "commit $orig_commit1" >> $testroot/stdout.expected
558 echo "commit $init_commit" >> $testroot/stdout.expected
559 cmp -s $testroot/stdout.expected $testroot/stdout
561 if [ $ret -ne 0 ]; then
562 diff -u $testroot/stdout.expected $testroot/stdout
563 test_done "$testroot" "$ret"
567 (cd $testroot/wt && got info .| \
568 grep '^based on commit:' | sort | uniq > $testroot/stdout)
569 echo "based on commit: $master_commit" > $testroot/stdout.expected
570 cmp -s $testroot/stdout.expected $testroot/stdout
572 if [ $ret -ne 0 ]; then
573 diff -u $testroot/stdout.expected $testroot/stdout
574 test_done "$testroot" "$ret"
578 (cd $testroot/wt && got status > $testroot/stdout)
579 echo "? added-file" > $testroot/stdout.expected
580 echo "? unversioned-file" >> $testroot/stdout.expected
581 cmp -s $testroot/stdout.expected $testroot/stdout
583 if [ $ret -ne 0 ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 test_done "$testroot" "$ret"
589 cat $testroot/wt/beta > $testroot/content
590 echo 'beta' > $testroot/content.expected
591 cmp -s $testroot/content.expected $testroot/content
593 if [ $ret -ne 0 ]; then
594 diff -u $testroot/content.expected $testroot/content
595 test_done "$testroot" "$ret"
599 # A subsequent update should be a no-op.
600 (cd $testroot/wt && got update > $testroot/stdout)
601 echo 'Already up-to-date' > $testroot/stdout.expected
602 cmp -s $testroot/stdout.expected $testroot/stdout
604 if [ $ret -ne 0 ]; then
605 diff -u $testroot/stdout.expected $testroot/stdout
607 test_done "$testroot" "$ret"
610 test_rebase_no_op_change() {
611 local testroot=`test_init rebase_no_op_change`
612 local init_commit=`git_show_head $testroot/repo`
614 git -C $testroot/repo checkout -q -b newbranch
615 echo "modified alpha on branch" > $testroot/repo/alpha
616 git_commit $testroot/repo -m "committing to alpha on newbranch"
617 local orig_commit1=`git_show_head $testroot/repo`
618 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
620 git -C $testroot/repo checkout -q master
621 echo "modified alpha on master" > $testroot/repo/alpha
622 git_commit $testroot/repo -m "committing to alpha on master"
623 local master_commit=`git_show_head $testroot/repo`
625 got checkout $testroot/repo $testroot/wt > /dev/null
627 if [ $ret -ne 0 ]; then
628 test_done "$testroot" "$ret"
632 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
635 echo "C alpha" > $testroot/stdout.expected
636 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
637 echo -n "$short_orig_commit1 -> merge conflict" \
638 >> $testroot/stdout.expected
639 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
640 cmp -s $testroot/stdout.expected $testroot/stdout
642 if [ $ret -ne 0 ]; then
643 diff -u $testroot/stdout.expected $testroot/stdout
644 test_done "$testroot" "$ret"
648 echo "got: conflicts must be resolved before rebasing can continue" \
649 > $testroot/stderr.expected
650 cmp -s $testroot/stderr.expected $testroot/stderr
652 if [ $ret -ne 0 ]; then
653 diff -u $testroot/stderr.expected $testroot/stderr
654 test_done "$testroot" "$ret"
658 echo '<<<<<<<' > $testroot/content.expected
659 echo "modified alpha on master" >> $testroot/content.expected
660 echo "||||||| 3-way merge base: commit $init_commit" \
661 >> $testroot/content.expected
662 echo "alpha" >> $testroot/content.expected
663 echo "=======" >> $testroot/content.expected
664 echo "modified alpha on branch" >> $testroot/content.expected
665 echo ">>>>>>> merged change: commit $orig_commit1" \
666 >> $testroot/content.expected
667 cat $testroot/wt/alpha > $testroot/content
668 cmp -s $testroot/content.expected $testroot/content
670 if [ $ret -ne 0 ]; then
671 diff -u $testroot/content.expected $testroot/content
672 test_done "$testroot" "$ret"
676 (cd $testroot/wt && got status > $testroot/stdout)
678 cat > $testroot/stdout.expected <<EOF
680 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
682 cmp -s $testroot/stdout.expected $testroot/stdout
684 if [ $ret -ne 0 ]; then
685 diff -u $testroot/stdout.expected $testroot/stdout
686 test_done "$testroot" "$ret"
690 # resolve the conflict
691 echo "modified alpha on master" > $testroot/wt/alpha
693 (cd $testroot/wt && got rebase -c > $testroot/stdout)
695 git -C $testroot/repo checkout -q newbranch
696 local new_commit1=`git_show_head $testroot/repo`
698 echo -n "$short_orig_commit1 -> no-op change" \
699 > $testroot/stdout.expected
700 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
701 echo "Switching work tree to refs/heads/newbranch" \
702 >> $testroot/stdout.expected
704 cmp -s $testroot/stdout.expected $testroot/stdout
706 if [ $ret -ne 0 ]; then
707 diff -u $testroot/stdout.expected $testroot/stdout
708 test_done "$testroot" "$ret"
713 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
714 echo "commit $master_commit (master, newbranch)" \
715 > $testroot/stdout.expected
716 echo "commit $init_commit" >> $testroot/stdout.expected
717 cmp -s $testroot/stdout.expected $testroot/stdout
719 if [ $ret -ne 0 ]; then
720 diff -u $testroot/stdout.expected $testroot/stdout
722 test_done "$testroot" "$ret"
725 test_rebase_in_progress() {
726 local testroot=`test_init rebase_in_progress`
727 local init_commit=`git_show_head $testroot/repo`
729 git -C $testroot/repo checkout -q -b newbranch
730 echo "modified alpha on branch" > $testroot/repo/alpha
731 git_commit $testroot/repo -m "committing to alpha on newbranch"
732 local orig_commit1=`git_show_head $testroot/repo`
733 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
735 git -C $testroot/repo checkout -q master
736 echo "modified alpha on master" > $testroot/repo/alpha
737 git_commit $testroot/repo -m "committing to alpha on master"
738 local master_commit=`git_show_head $testroot/repo`
740 got checkout $testroot/repo $testroot/wt > /dev/null
742 if [ $ret -ne 0 ]; then
743 test_done "$testroot" "$ret"
747 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
750 echo "C alpha" > $testroot/stdout.expected
751 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
752 echo -n "$short_orig_commit1 -> merge conflict" \
753 >> $testroot/stdout.expected
754 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
755 cmp -s $testroot/stdout.expected $testroot/stdout
757 if [ $ret -ne 0 ]; then
758 diff -u $testroot/stdout.expected $testroot/stdout
759 test_done "$testroot" "$ret"
763 echo "got: conflicts must be resolved before rebasing can continue" \
764 > $testroot/stderr.expected
765 cmp -s $testroot/stderr.expected $testroot/stderr
767 if [ $ret -ne 0 ]; then
768 diff -u $testroot/stderr.expected $testroot/stderr
769 test_done "$testroot" "$ret"
773 echo '<<<<<<<' > $testroot/content.expected
774 echo "modified alpha on master" >> $testroot/content.expected
775 echo "||||||| 3-way merge base: commit $init_commit" \
776 >> $testroot/content.expected
777 echo "alpha" >> $testroot/content.expected
778 echo "=======" >> $testroot/content.expected
779 echo "modified alpha on branch" >> $testroot/content.expected
780 echo ">>>>>>> merged change: commit $orig_commit1" \
781 >> $testroot/content.expected
782 cat $testroot/wt/alpha > $testroot/content
783 cmp -s $testroot/content.expected $testroot/content
785 if [ $ret -ne 0 ]; then
786 diff -u $testroot/content.expected $testroot/content
787 test_done "$testroot" "$ret"
791 (cd $testroot/wt && got status > $testroot/stdout)
793 cat > $testroot/stdout.expected <<EOF
795 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
797 cmp -s $testroot/stdout.expected $testroot/stdout
799 if [ $ret -ne 0 ]; then
800 diff -u $testroot/stdout.expected $testroot/stdout
801 test_done "$testroot" "$ret"
805 for cmd in update commit; do
806 (cd $testroot/wt && got $cmd > $testroot/stdout \
809 echo -n > $testroot/stdout.expected
810 cmp -s $testroot/stdout.expected $testroot/stdout
812 if [ $ret -ne 0 ]; then
813 diff -u $testroot/stdout.expected $testroot/stdout
814 test_done "$testroot" "$ret"
818 echo -n "got: a rebase operation is in progress in this " \
819 > $testroot/stderr.expected
820 echo "work tree and must be continued or aborted first" \
821 >> $testroot/stderr.expected
822 cmp -s $testroot/stderr.expected $testroot/stderr
824 if [ $ret -ne 0 ]; then
825 diff -u $testroot/stderr.expected $testroot/stderr
826 test_done "$testroot" "$ret"
831 test_done "$testroot" "$ret"
834 test_rebase_path_prefix() {
835 local testroot=`test_init rebase_path_prefix`
837 git -C $testroot/repo checkout -q -b newbranch
838 echo "modified delta on branch" > $testroot/repo/gamma/delta
839 git_commit $testroot/repo -m "committing to delta on newbranch"
841 local orig_commit1=`git_show_parent_commit $testroot/repo`
842 local orig_commit2=`git_show_head $testroot/repo`
844 git -C $testroot/repo checkout -q master
845 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
846 git_commit $testroot/repo -m "committing to zeta on master"
847 local master_commit=`git_show_head $testroot/repo`
849 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
851 if [ $ret -ne 0 ]; then
852 test_done "$testroot" "$ret"
856 (cd $testroot/wt && got rebase newbranch \
857 > $testroot/stdout 2> $testroot/stderr)
859 echo -n > $testroot/stdout.expected
860 cmp -s $testroot/stdout.expected $testroot/stdout
862 if [ $ret -ne 0 ]; then
863 diff -u $testroot/stdout.expected $testroot/stdout
864 test_done "$testroot" "$ret"
868 echo -n "got: cannot rebase branch which contains changes outside " \
869 > $testroot/stderr.expected
870 echo "of this work tree's path prefix" >> $testroot/stderr.expected
871 cmp -s $testroot/stderr.expected $testroot/stderr
873 if [ $ret -ne 0 ]; then
874 diff -u $testroot/stderr.expected $testroot/stderr
875 test_done "$testroot" "$ret"
879 # rebase should succeed when using a complete work tree
880 got checkout $testroot/repo $testroot/wt2 > /dev/null
882 if [ $ret -ne 0 ]; then
883 test_done "$testroot" "$ret"
887 (cd $testroot/wt2 && got rebase newbranch \
888 > $testroot/stdout 2> $testroot/stderr)
890 git -C $testroot/repo checkout -q newbranch
891 local new_commit1=`git_show_parent_commit $testroot/repo`
892 local new_commit2=`git_show_head $testroot/repo`
894 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
895 local short_new_commit2=`trim_obj_id 28 $new_commit2`
897 echo "G gamma/delta" > $testroot/stdout.expected
898 echo -n "$short_orig_commit2 -> $short_new_commit2" \
899 >> $testroot/stdout.expected
900 echo ": committing to delta on newbranch" \
901 >> $testroot/stdout.expected
902 echo "Switching work tree to refs/heads/newbranch" \
903 >> $testroot/stdout.expected
905 cmp -s $testroot/stdout.expected $testroot/stdout
907 if [ $ret -ne 0 ]; then
908 diff -u $testroot/stdout.expected $testroot/stdout
909 test_done "$testroot" "$ret"
913 # the first work tree should remain usable
914 (cd $testroot/wt && got update -b master \
915 > $testroot/stdout 2> $testroot/stderr)
917 if [ $ret -ne 0 ]; then
918 echo "update failed unexpectedly" >&2
919 test_done "$testroot" "1"
923 echo 'Already up-to-date' > $testroot/stdout.expected
924 cmp -s $testroot/stdout.expected $testroot/stdout
926 if [ $ret -ne 0 ]; then
927 diff -u $testroot/stdout.expected $testroot/stdout
929 test_done "$testroot" "$ret"
932 test_rebase_preserves_logmsg() {
933 local testroot=`test_init rebase_preserves_logmsg`
935 git -C $testroot/repo checkout -q -b newbranch
936 echo "modified delta on branch" > $testroot/repo/gamma/delta
937 git_commit $testroot/repo -m "modified delta on newbranch"
939 echo "modified alpha on branch" > $testroot/repo/alpha
940 git_commit $testroot/repo -m "modified alpha on newbranch"
942 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
943 > $testroot/log.expected)
945 local orig_commit1=`git_show_parent_commit $testroot/repo`
946 local orig_commit2=`git_show_head $testroot/repo`
948 git -C $testroot/repo checkout -q master
949 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
950 git_commit $testroot/repo -m "committing to zeta on master"
951 local master_commit=`git_show_head $testroot/repo`
953 got checkout $testroot/repo $testroot/wt > /dev/null
955 if [ $ret -ne 0 ]; then
956 test_done "$testroot" "$ret"
960 (cd $testroot/wt && got rebase newbranch > /dev/null \
963 git -C $testroot/repo checkout -q newbranch
964 local new_commit1=`git_show_parent_commit $testroot/repo`
965 local new_commit2=`git_show_head $testroot/repo`
967 echo -n > $testroot/stderr.expected
968 cmp -s $testroot/stderr.expected $testroot/stderr
970 if [ $ret -ne 0 ]; then
971 diff -u $testroot/stderr.expected $testroot/stderr
972 test_done "$testroot" "$ret"
976 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
978 ed -s $testroot/log.expected <<-EOF
979 ,s/$orig_commit1/$new_commit1/
980 ,s/$orig_commit2/$new_commit2/
983 cmp -s $testroot/log.expected $testroot/log
985 if [ $ret -ne 0 ]; then
986 diff -u $testroot/log.expected $testroot/log
989 test_done "$testroot" "$ret"
992 test_rebase_no_commits_to_rebase() {
993 local testroot=`test_init rebase_no_commits_to_rebase`
995 got checkout $testroot/repo $testroot/wt > /dev/null
997 if [ $ret -ne 0 ]; then
998 test_done "$testroot" "$ret"
1002 # Create an unrelated branch with 'got import'.
1003 mkdir -p $testroot/newtree
1004 echo "new file" > $testroot/newtree/newfile
1005 got import -m new -b newbranch -r $testroot/repo \
1006 $testroot/newtree > /dev/null
1008 echo "modified alpha on master" > $testroot/wt/alpha
1009 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
1011 (cd $testroot/wt && got update > /dev/null)
1013 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1014 2> $testroot/stderr)
1016 echo -n "got: specified branch shares no common ancestry " \
1017 > $testroot/stderr.expected
1018 echo "with work tree's branch" >> $testroot/stderr.expected
1019 cmp -s $testroot/stderr.expected $testroot/stderr
1021 if [ $ret -ne 0 ]; then
1022 diff -u $testroot/stderr.expected $testroot/stderr
1023 test_done "$testroot" "$ret"
1027 echo -n > $testroot/stdout.expected
1028 cmp -s $testroot/stdout.expected $testroot/stdout
1030 if [ $ret -ne 0 ]; then
1031 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1036 (cd $testroot/wt && got update > $testroot/stdout)
1037 echo "Already up-to-date" > $testroot/stdout.expected
1038 cmp -s $testroot/stdout.expected $testroot/stdout
1040 if [ $ret -ne 0 ]; then
1041 diff -u $testroot/stdout.expected $testroot/stdout
1043 test_done "$testroot" "$ret"
1046 test_rebase_forward() {
1047 local testroot=`test_init rebase_forward`
1048 local commit0=`git_show_head $testroot/repo`
1050 got checkout $testroot/repo $testroot/wt > /dev/null
1052 if [ $ret -ne 0 ]; then
1053 test_done "$testroot" "$ret"
1057 echo "change alpha 1" > $testroot/wt/alpha
1058 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1060 local commit1=`git_show_head $testroot/repo`
1062 echo "change alpha 2" > $testroot/wt/alpha
1063 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1065 local commit2=`git_show_head $testroot/repo`
1067 # Simulate a situation where fast-forward is required.
1068 # We want to fast-forward master to origin/master:
1069 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1070 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1071 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1072 (cd $testroot/repo && got ref -d master >/dev/null)
1073 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1074 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1076 (cd $testroot/wt && got up -b origin/master > /dev/null)
1078 (cd $testroot/wt && got rebase master \
1079 > $testroot/stdout 2> $testroot/stderr)
1081 echo "Forwarding refs/heads/master to commit $commit2" \
1082 > $testroot/stdout.expected
1083 echo "Switching work tree to refs/heads/master" \
1084 >> $testroot/stdout.expected
1085 cmp -s $testroot/stdout.expected $testroot/stdout
1087 if [ $ret -ne 0 ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1089 test_done "$testroot" "$ret"
1093 # Ensure that rebase operation was completed correctly
1094 (cd $testroot/wt && got rebase -a \
1095 > $testroot/stdout 2> $testroot/stderr)
1096 echo -n "" > $testroot/stdout.expected
1097 cmp -s $testroot/stdout.expected $testroot/stdout
1099 if [ $ret -ne 0 ]; then
1100 diff -u $testroot/stdout.expected $testroot/stdout
1101 test_done "$testroot" "$ret"
1104 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1105 cmp -s $testroot/stderr.expected $testroot/stderr
1107 if [ $ret -ne 0 ]; then
1108 diff -u $testroot/stderr.expected $testroot/stderr
1109 test_done "$testroot" "$ret"
1113 (cd $testroot/wt && got branch -n > $testroot/stdout)
1114 echo "master" > $testroot/stdout.expected
1115 cmp -s $testroot/stdout.expected $testroot/stdout
1117 if [ $ret -ne 0 ]; then
1118 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1123 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1124 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1125 echo "commit $commit1" >> $testroot/stdout.expected
1126 echo "commit $commit0" >> $testroot/stdout.expected
1127 cmp -s $testroot/stdout.expected $testroot/stdout
1129 if [ $ret -ne 0 ]; then
1130 diff -u $testroot/stdout.expected $testroot/stdout
1131 test_done "$testroot" "$ret"
1135 # Forward-only rebase operations should not be backed up
1136 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1137 echo -n > $testroot/stdout.expected
1138 cmp -s $testroot/stdout.expected $testroot/stdout
1140 if [ $ret -ne 0 ]; then
1141 diff -u $testroot/stdout.expected $testroot/stdout
1143 test_done "$testroot" "$ret"
1146 test_rebase_forward_path_prefix() {
1147 local testroot=`test_init rebase_forward_path_prefix`
1148 local commit0=`git_show_head $testroot/repo`
1150 got checkout $testroot/repo $testroot/wt-full > /dev/null
1152 if [ $ret -ne 0 ]; then
1153 test_done "$testroot" "$ret"
1157 echo "change alpha 1" > $testroot/wt-full/alpha
1158 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1160 local commit1=`git_show_head $testroot/repo`
1162 echo "change alpha 2" > $testroot/wt-full/alpha
1163 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1165 local commit2=`git_show_head $testroot/repo`
1167 # Simulate a situation where fast-forward is required.
1168 # We want to fast-forward master to origin/master:
1169 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1170 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1171 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1172 (cd $testroot/repo && got ref -d master >/dev/null)
1173 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1174 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1176 # Work tree which uses a path-prefix and will be used for rebasing
1177 got checkout -p epsilon -b origin/master $testroot/repo $testroot/wt \
1180 if [ $ret -ne 0 ]; then
1181 test_done "$testroot" "$ret"
1185 (cd $testroot/wt && got rebase master \
1186 > $testroot/stdout 2> $testroot/stderr)
1188 echo "Forwarding refs/heads/master to commit $commit2" \
1189 > $testroot/stdout.expected
1190 echo "Switching work tree to refs/heads/master" \
1191 >> $testroot/stdout.expected
1192 cmp -s $testroot/stdout.expected $testroot/stdout
1194 if [ $ret -ne 0 ]; then
1195 diff -u $testroot/stdout.expected $testroot/stdout
1196 test_done "$testroot" "$ret"
1200 # Ensure that rebase operation was completed correctly
1201 (cd $testroot/wt && got rebase -a \
1202 > $testroot/stdout 2> $testroot/stderr)
1203 echo -n "" > $testroot/stdout.expected
1204 cmp -s $testroot/stdout.expected $testroot/stdout
1206 if [ $ret -ne 0 ]; then
1207 diff -u $testroot/stdout.expected $testroot/stdout
1208 test_done "$testroot" "$ret"
1211 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1212 cmp -s $testroot/stderr.expected $testroot/stderr
1214 if [ $ret -ne 0 ]; then
1215 diff -u $testroot/stderr.expected $testroot/stderr
1216 test_done "$testroot" "$ret"
1220 (cd $testroot/wt && got branch -n > $testroot/stdout)
1221 echo "master" > $testroot/stdout.expected
1222 cmp -s $testroot/stdout.expected $testroot/stdout
1224 if [ $ret -ne 0 ]; then
1225 diff -u $testroot/stdout.expected $testroot/stdout
1226 test_done "$testroot" "$ret"
1230 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1231 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1232 echo "commit $commit1" >> $testroot/stdout.expected
1233 echo "commit $commit0" >> $testroot/stdout.expected
1234 cmp -s $testroot/stdout.expected $testroot/stdout
1236 if [ $ret -ne 0 ]; then
1237 diff -u $testroot/stdout.expected $testroot/stdout
1238 test_done "$testroot" "$ret"
1242 # Forward-only rebase operations should not be backed up
1243 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1244 echo -n > $testroot/stdout.expected
1245 cmp -s $testroot/stdout.expected $testroot/stdout
1247 if [ $ret -ne 0 ]; then
1248 diff -u $testroot/stdout.expected $testroot/stdout
1250 test_done "$testroot" "$ret"
1253 test_rebase_out_of_date() {
1254 local testroot=`test_init rebase_out_of_date`
1255 local initial_commit=`git_show_head $testroot/repo`
1257 git -C $testroot/repo checkout -q -b newbranch
1258 echo "modified delta on branch" > $testroot/repo/gamma/delta
1259 git_commit $testroot/repo -m "committing to delta on newbranch"
1261 echo "modified alpha on branch" > $testroot/repo/alpha
1262 git -C $testroot/repo rm -q beta
1263 echo "new file on branch" > $testroot/repo/epsilon/new
1264 git -C $testroot/repo add epsilon/new
1265 git_commit $testroot/repo -m "committing more changes on newbranch"
1267 local orig_commit1=`git_show_parent_commit $testroot/repo`
1268 local orig_commit2=`git_show_head $testroot/repo`
1270 git -C $testroot/repo checkout -q master
1271 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1272 git_commit $testroot/repo -m "committing to zeta on master"
1273 local master_commit1=`git_show_head $testroot/repo`
1275 git -C $testroot/repo checkout -q master
1276 echo "modified beta on master" > $testroot/repo/beta
1277 git_commit $testroot/repo -m "committing to beta on master"
1278 local master_commit2=`git_show_head $testroot/repo`
1280 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1283 if [ $ret -ne 0 ]; then
1284 test_done "$testroot" "$ret"
1288 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1289 2> $testroot/stderr)
1291 echo -n > $testroot/stdout.expected
1292 cmp -s $testroot/stdout.expected $testroot/stdout
1294 if [ $ret -ne 0 ]; then
1295 diff -u $testroot/stdout.expected $testroot/stdout
1296 test_done "$testroot" "$ret"
1300 echo -n "got: work tree must be updated before it can be " \
1301 > $testroot/stderr.expected
1302 echo "used to rebase a branch" >> $testroot/stderr.expected
1303 cmp -s $testroot/stderr.expected $testroot/stderr
1305 if [ $ret -ne 0 ]; then
1306 diff -u $testroot/stderr.expected $testroot/stderr
1307 test_done "$testroot" "$ret"
1311 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1312 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1313 echo "commit $master_commit1" >> $testroot/stdout.expected
1314 echo "commit $initial_commit" >> $testroot/stdout.expected
1315 cmp -s $testroot/stdout.expected $testroot/stdout
1317 if [ $ret -ne 0 ]; then
1318 diff -u $testroot/stdout.expected $testroot/stdout
1320 test_done "$testroot" "$ret"
1323 test_rebase_trims_empty_dir() {
1324 local testroot=`test_init rebase_trims_empty_dir`
1326 git -C $testroot/repo checkout -q -b newbranch
1327 echo "modified delta on branch" > $testroot/repo/gamma/delta
1328 git_commit $testroot/repo -m "committing to delta on newbranch"
1330 git -C $testroot/repo rm -q epsilon/zeta
1331 git_commit $testroot/repo -m "removing zeta on newbranch"
1333 local orig_commit1=`git_show_parent_commit $testroot/repo`
1334 local orig_commit2=`git_show_head $testroot/repo`
1336 git -C $testroot/repo checkout -q master
1337 echo "modified alpha on master" > $testroot/repo/alpha
1338 git_commit $testroot/repo -m "committing to alpha on master"
1339 local master_commit=`git_show_head $testroot/repo`
1341 got checkout $testroot/repo $testroot/wt > /dev/null
1343 if [ $ret -ne 0 ]; then
1344 test_done "$testroot" "$ret"
1348 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1350 git -C $testroot/repo checkout -q newbranch
1351 local new_commit1=`git_show_parent_commit $testroot/repo`
1352 local new_commit2=`git_show_head $testroot/repo`
1354 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1355 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1356 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1357 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1359 echo "G gamma/delta" >> $testroot/stdout.expected
1360 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1361 >> $testroot/stdout.expected
1362 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1363 echo "D epsilon/zeta" >> $testroot/stdout.expected
1364 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1365 >> $testroot/stdout.expected
1366 echo ": removing zeta on newbranch" \
1367 >> $testroot/stdout.expected
1368 echo "Switching work tree to refs/heads/newbranch" \
1369 >> $testroot/stdout.expected
1371 cmp -s $testroot/stdout.expected $testroot/stdout
1373 if [ $ret -ne 0 ]; then
1374 diff -u $testroot/stdout.expected $testroot/stdout
1375 test_done "$testroot" "$ret"
1379 echo "modified delta on branch" > $testroot/content.expected
1380 cat $testroot/wt/gamma/delta > $testroot/content
1381 cmp -s $testroot/content.expected $testroot/content
1383 if [ $ret -ne 0 ]; then
1384 diff -u $testroot/content.expected $testroot/content
1385 test_done "$testroot" "$ret"
1389 echo "modified alpha on master" > $testroot/content.expected
1390 cat $testroot/wt/alpha > $testroot/content
1391 cmp -s $testroot/content.expected $testroot/content
1393 if [ $ret -ne 0 ]; then
1394 diff -u $testroot/content.expected $testroot/content
1395 test_done "$testroot" "$ret"
1399 if [ -e $testroot/wt/epsilon ]; then
1400 echo "parent of removed zeta still exists on disk" >&2
1401 test_done "$testroot" "1"
1405 (cd $testroot/wt && got status > $testroot/stdout)
1407 echo -n > $testroot/stdout.expected
1408 cmp -s $testroot/stdout.expected $testroot/stdout
1410 if [ $ret -ne 0 ]; then
1411 diff -u $testroot/stdout.expected $testroot/stdout
1412 test_done "$testroot" "$ret"
1416 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1417 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1418 echo "commit $new_commit1" >> $testroot/stdout.expected
1419 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1420 cmp -s $testroot/stdout.expected $testroot/stdout
1422 if [ $ret -ne 0 ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1425 test_done "$testroot" "$ret"
1428 test_rebase_delete_missing_file() {
1429 local testroot=`test_init rebase_delete_missing_file`
1431 mkdir -p $testroot/repo/d/f/g
1432 echo "new file" > $testroot/repo/d/f/g/new
1433 git -C $testroot/repo add d/f/g/new
1434 git_commit $testroot/repo -m "adding a subdir"
1435 local commit0=`git_show_head $testroot/repo`
1437 got br -r $testroot/repo -c master newbranch
1439 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1441 echo "modified delta on branch" > $testroot/wt/gamma/delta
1442 (cd $testroot/wt && got commit \
1443 -m "committing to delta on newbranch" > /dev/null)
1445 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1446 (cd $testroot/wt && got commit \
1447 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1449 git -C $testroot/repo checkout -q newbranch
1450 local orig_commit1=`git_show_parent_commit $testroot/repo`
1451 local orig_commit2=`git_show_head $testroot/repo`
1453 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1454 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1456 (cd $testroot/wt && got update -b master > /dev/null)
1457 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1458 (cd $testroot/wt && got commit \
1459 -m "removing beta and d/f/g/new on master" > /dev/null)
1461 git -C $testroot/repo checkout -q master
1462 local master_commit=`git_show_head $testroot/repo`
1464 (cd $testroot/wt && got update -b master > /dev/null)
1465 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1466 2> $testroot/stderr)
1468 if [ $ret -eq 0 ]; then
1469 echo "rebase succeeded unexpectedly" >&2
1470 test_done "$testroot" "1"
1474 local new_commit1=$(cd $testroot/wt && got info | \
1475 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1477 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1478 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1480 echo "G gamma/delta" >> $testroot/stdout.expected
1481 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1482 >> $testroot/stdout.expected
1483 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1484 echo "! beta" >> $testroot/stdout.expected
1485 echo "! d/f/g/new" >> $testroot/stdout.expected
1486 echo -n "Files which had incoming changes but could not be found " \
1487 >> $testroot/stdout.expected
1488 echo "in the work tree: 2" >> $testroot/stdout.expected
1489 cmp -s $testroot/stdout.expected $testroot/stdout
1491 if [ $ret -ne 0 ]; then
1492 diff -u $testroot/stdout.expected $testroot/stdout
1493 test_done "$testroot" "$ret"
1497 echo -n "got: changes destined for some files were not yet merged " \
1498 > $testroot/stderr.expected
1499 echo -n "and should be merged manually if required before the " \
1500 >> $testroot/stderr.expected
1501 echo "rebase operation is continued" >> $testroot/stderr.expected
1502 cmp -s $testroot/stderr.expected $testroot/stderr
1504 if [ $ret -ne 0 ]; then
1505 diff -u $testroot/stderr.expected $testroot/stderr
1506 test_done "$testroot" "$ret"
1510 # ignore the missing changes and continue
1511 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1513 if [ $ret -ne 0 ]; then
1514 echo "rebase failed unexpectedly" >&2
1515 test_done "$testroot" "1"
1518 echo -n "$short_orig_commit2 -> no-op change" \
1519 > $testroot/stdout.expected
1520 echo ": removing beta and d/f/g/new on newbranch" \
1521 >> $testroot/stdout.expected
1522 echo "Switching work tree to refs/heads/newbranch" \
1523 >> $testroot/stdout.expected
1525 cmp -s $testroot/stdout.expected $testroot/stdout
1527 if [ $ret -ne 0 ]; then
1528 diff -u $testroot/stdout.expected $testroot/stdout
1529 test_done "$testroot" "$ret"
1533 echo "modified delta on branch" > $testroot/content.expected
1534 cat $testroot/wt/gamma/delta > $testroot/content
1535 cmp -s $testroot/content.expected $testroot/content
1537 if [ $ret -ne 0 ]; then
1538 diff -u $testroot/content.expected $testroot/content
1539 test_done "$testroot" "$ret"
1543 if [ -e $testroot/wt/beta ]; then
1544 echo "removed file beta still exists on disk" >&2
1545 test_done "$testroot" "1"
1549 (cd $testroot/wt && got status > $testroot/stdout)
1551 echo -n > $testroot/stdout.expected
1552 cmp -s $testroot/stdout.expected $testroot/stdout
1554 if [ $ret -ne 0 ]; then
1555 diff -u $testroot/stdout.expected $testroot/stdout
1556 test_done "$testroot" "$ret"
1560 git -C $testroot/repo checkout -q newbranch
1561 local new_commit1=`git_show_head $testroot/repo`
1562 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1564 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1565 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1566 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1567 echo "commit $commit0" >> $testroot/stdout.expected
1568 cmp -s $testroot/stdout.expected $testroot/stdout
1570 if [ $ret -ne 0 ]; then
1571 diff -u $testroot/stdout.expected $testroot/stdout
1573 test_done "$testroot" "$ret"
1576 test_rebase_rm_add_rm_file() {
1577 local testroot=`test_init rebase_rm_add_rm_file`
1579 git -C $testroot/repo checkout -q -b newbranch
1580 git -C $testroot/repo rm -q beta
1581 git_commit $testroot/repo -m "removing beta from newbranch"
1582 local orig_commit1=`git_show_head $testroot/repo`
1584 echo 'restored beta' > $testroot/repo/beta
1585 git -C $testroot/repo add beta
1586 git_commit $testroot/repo -m "restoring beta on newbranch"
1587 local orig_commit2=`git_show_head $testroot/repo`
1589 git -C $testroot/repo rm -q beta
1590 git_commit $testroot/repo -m "removing beta from newbranch again"
1591 local orig_commit3=`git_show_head $testroot/repo`
1593 git -C $testroot/repo checkout -q master
1594 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1595 git_commit $testroot/repo -m "committing to zeta on master"
1596 local master_commit=`git_show_head $testroot/repo`
1598 got checkout $testroot/repo $testroot/wt > /dev/null
1600 if [ $ret -ne 0 ]; then
1601 test_done "$testroot" "$ret"
1605 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1607 # this would error out with 'got: file index is corrupt'
1608 (cd $testroot/wt && got status > /dev/null)
1610 if [ $ret -ne 0 ]; then
1611 echo "got status command failed unexpectedly" >&2
1612 test_done "$testroot" "$ret"
1616 git -C $testroot/repo checkout -q newbranch
1617 local new_commit3=`git_show_head $testroot/repo`
1618 local new_commit2=`git_show_parent_commit $testroot/repo`
1619 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1621 git -C $testroot/repo checkout -q newbranch
1623 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1624 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1625 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1626 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1627 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1628 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1630 echo "D beta" > $testroot/stdout.expected
1631 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1632 >> $testroot/stdout.expected
1633 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1634 echo "A beta" >> $testroot/stdout.expected
1635 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1636 >> $testroot/stdout.expected
1637 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1638 echo "D beta" >> $testroot/stdout.expected
1639 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1640 >> $testroot/stdout.expected
1641 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1642 echo "Switching work tree to refs/heads/newbranch" \
1643 >> $testroot/stdout.expected
1645 cmp -s $testroot/stdout.expected $testroot/stdout
1647 if [ $ret -ne 0 ]; then
1648 diff -u $testroot/stdout.expected $testroot/stdout
1649 test_done "$testroot" "$ret"
1653 (cd $testroot/wt && got status > $testroot/stdout)
1655 if [ $ret -ne 0 ]; then
1656 echo "got status command failed unexpectedly" >&2
1657 test_done "$testroot" "$ret"
1661 echo -n > $testroot/stdout.expected
1662 cmp -s $testroot/stdout.expected $testroot/stdout
1664 if [ $ret -ne 0 ]; then
1665 diff -u $testroot/stdout.expected $testroot/stdout
1666 test_done "$testroot" "$ret"
1670 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1671 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1672 echo "commit $new_commit2" >> $testroot/stdout.expected
1673 echo "commit $new_commit1" >> $testroot/stdout.expected
1674 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1675 cmp -s $testroot/stdout.expected $testroot/stdout
1677 if [ $ret -ne 0 ]; then
1678 diff -u $testroot/stdout.expected $testroot/stdout
1680 test_done "$testroot" "$ret"
1683 test_rebase_resets_committer() {
1684 local testroot=`test_init rebase_resets_committer`
1685 local commit0=`git_show_head $testroot/repo`
1686 local commit0_author_time=`git_show_author_time $testroot/repo`
1687 local committer="Flan Luck <flan_luck@openbsd.org>"
1689 git -C $testroot/repo checkout -q -b newbranch
1690 echo "modified delta on branch" > $testroot/repo/gamma/delta
1691 git_commit $testroot/repo -m "committing to delta on newbranch"
1693 echo "modified alpha on branch" > $testroot/repo/alpha
1694 git_commit $testroot/repo -m "committing more changes on newbranch"
1696 local orig_commit1=`git_show_parent_commit $testroot/repo`
1697 local orig_commit2=`git_show_head $testroot/repo`
1698 local orig_author_time2=`git_show_author_time $testroot/repo`
1700 git -C $testroot/repo checkout -q master
1701 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1702 git_commit $testroot/repo -m "committing to zeta on master"
1703 local master_commit=`git_show_head $testroot/repo`
1705 got checkout $testroot/repo $testroot/wt > /dev/null
1707 if [ $ret -ne 0 ]; then
1708 test_done "$testroot" "$ret"
1712 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
1713 got rebase newbranch > $testroot/stdout)
1715 git -C $testroot/repo checkout -q newbranch
1716 local new_commit1=`git_show_parent_commit $testroot/repo`
1717 local new_commit2=`git_show_head $testroot/repo`
1718 local new_author_time2=`git_show_author_time $testroot/repo`
1720 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1721 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1722 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1723 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1725 echo "G gamma/delta" >> $testroot/stdout.expected
1726 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1727 >> $testroot/stdout.expected
1728 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1729 echo "G alpha" >> $testroot/stdout.expected
1730 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1731 >> $testroot/stdout.expected
1732 echo ": committing more changes on newbranch" \
1733 >> $testroot/stdout.expected
1734 echo "Switching work tree to refs/heads/newbranch" \
1735 >> $testroot/stdout.expected
1737 cmp -s $testroot/stdout.expected $testroot/stdout
1739 if [ $ret -ne 0 ]; then
1740 diff -u $testroot/stdout.expected $testroot/stdout
1741 test_done "$testroot" "$ret"
1745 # Original commit only had one author
1746 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1747 egrep '^(from|via):' > $testroot/stdout)
1748 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1749 cmp -s $testroot/stdout.expected $testroot/stdout
1751 if [ $ret -ne 0 ]; then
1752 diff -u $testroot/stdout.expected $testroot/stdout
1753 test_done "$testroot" "$ret"
1757 # Rebased commit should have new committer name added
1758 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1759 egrep '^(from|via):' > $testroot/stdout)
1760 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1761 echo "via: $committer" >> $testroot/stdout.expected
1763 cmp -s $testroot/stdout.expected $testroot/stdout
1765 if [ $ret -ne 0 ]; then
1766 diff -u $testroot/stdout.expected $testroot/stdout
1768 test_done "$testroot" "$ret"
1771 test_rebase_no_author_info() {
1772 local testroot=`test_init rebase_no_author_info`
1773 local commit0=`git_show_head $testroot/repo`
1774 local commit0_author_time=`git_show_author_time $testroot/repo`
1775 local committer="$GOT_AUTHOR"
1777 git -C $testroot/repo checkout -q -b newbranch
1778 echo "modified delta on branch" > $testroot/repo/gamma/delta
1779 git_commit $testroot/repo -m "committing to delta on newbranch"
1781 echo "modified alpha on branch" > $testroot/repo/alpha
1782 git_commit $testroot/repo -m "committing more changes on newbranch"
1784 local orig_commit1=`git_show_parent_commit $testroot/repo`
1785 local orig_commit2=`git_show_head $testroot/repo`
1786 local orig_author_time2=`git_show_author_time $testroot/repo`
1788 git -C $testroot/repo checkout -q master
1789 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1790 git_commit $testroot/repo -m "committing to zeta on master"
1791 local master_commit=`git_show_head $testroot/repo`
1793 got checkout $testroot/repo $testroot/wt > /dev/null
1795 if [ $ret -ne 0 ]; then
1796 test_done "$testroot" "$ret"
1800 # unset in a subshell to avoid affecting our environment
1801 (unset GOT_AUTHOR && cd $testroot/wt && \
1802 got rebase newbranch > $testroot/stdout)
1804 git -C $testroot/repo checkout -q newbranch
1805 local new_commit1=`git_show_parent_commit $testroot/repo`
1806 local new_commit2=`git_show_head $testroot/repo`
1807 local new_author_time2=`git_show_author_time $testroot/repo`
1809 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1810 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1811 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1812 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1814 echo "G gamma/delta" >> $testroot/stdout.expected
1815 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1816 >> $testroot/stdout.expected
1817 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1818 echo "G alpha" >> $testroot/stdout.expected
1819 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1820 >> $testroot/stdout.expected
1821 echo ": committing more changes on newbranch" \
1822 >> $testroot/stdout.expected
1823 echo "Switching work tree to refs/heads/newbranch" \
1824 >> $testroot/stdout.expected
1826 cmp -s $testroot/stdout.expected $testroot/stdout
1828 if [ $ret -ne 0 ]; then
1829 diff -u $testroot/stdout.expected $testroot/stdout
1830 test_done "$testroot" "$ret"
1834 # Original commit only had one author
1835 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1836 egrep '^(from|via):' > $testroot/stdout)
1837 echo "from: $committer" > $testroot/stdout.expected
1838 cmp -s $testroot/stdout.expected $testroot/stdout
1840 if [ $ret -ne 0 ]; then
1841 diff -u $testroot/stdout.expected $testroot/stdout
1842 test_done "$testroot" "$ret"
1846 # Author info of rebased commit should match the original
1847 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1848 egrep '^(from|via):' > $testroot/stdout)
1849 echo "from: $committer" > $testroot/stdout.expected
1851 cmp -s $testroot/stdout.expected $testroot/stdout
1853 if [ $ret -ne 0 ]; then
1854 diff -u $testroot/stdout.expected $testroot/stdout
1856 test_done "$testroot" "$ret"
1859 test_rebase_nonbranch() {
1860 local testroot=`test_init rebase_nonbranch`
1862 got ref -r $testroot/repo -c refs/heads/master \
1863 refs/remotes/origin/master >/dev/null
1865 got checkout -b master $testroot/repo $testroot/wt >/dev/null
1867 (cd $testroot/wt && got rebase origin/master > $testroot/stdout \
1868 2> $testroot/stderr)
1870 if [ $ret -eq 0 ]; then
1871 echo "rebase succeeded unexpectedly" >&2
1872 test_done "$testroot" "1"
1875 echo -n "got: will not rebase a branch which lives outside the " \
1876 > $testroot/stderr.expected
1877 echo '"refs/heads/" reference namespace' >> $testroot/stderr.expected
1878 cmp -s $testroot/stderr.expected $testroot/stderr
1880 if [ $ret -ne 0 ]; then
1881 diff -u $testroot/stderr.expected $testroot/stderr
1883 test_done "$testroot" "$ret"
1886 test_rebase_umask() {
1887 local testroot=`test_init rebase_umask`
1888 local commit0=`git_show_head "$testroot/repo"`
1890 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1891 (cd "$testroot/wt" && got branch newbranch) >/dev/null
1893 echo "modified alpha on branch" >$testroot/wt/alpha
1894 (cd "$testroot/wt" && got commit -m 'modified alpha on newbranch') \
1897 (cd "$testroot/wt" && got update -b master) >/dev/null
1899 if [ $ret -ne 0 ]; then
1900 echo "got update failed!" >&2
1901 test_done "$testroot" $ret
1905 echo "modified beta on master" >$testroot/wt/beta
1906 (cd "$testroot/wt" && got commit -m 'modified beta on master') \
1908 (cd "$testroot/wt" && got update) >/dev/null
1910 # using a subshell to avoid clobbering global umask
1911 (umask 077 && cd "$testroot/wt" && got rebase newbranch) >/dev/null
1913 if [ $ret -ne 0 ]; then
1914 echo "got rebase failed" >&2
1915 test_done "$testroot" $ret
1919 ls -l "$testroot/wt/alpha" | grep -q ^-rw-------
1920 if [ $? -ne 0 ]; then
1921 echo "alpha is not 0600 after rebase" >&2
1922 ls -l "$testroot/wt/alpha" >&2
1923 test_done "$testroot" 1
1927 test_done "$testroot" 0
1930 test_rebase_out_of_date2() {
1931 local testroot=`test_init rebase_out_of_date2`
1932 local commit0=`git_show_head $testroot/repo`
1933 local commit0_author_time=`git_show_author_time $testroot/repo`
1935 git -C $testroot/repo checkout -q -b newbranch
1936 echo "modified delta on branch" > $testroot/repo/gamma/delta
1937 git_commit $testroot/repo -m "committing to delta on newbranch"
1939 local orig_commit1=`git_show_parent_commit $testroot/repo`
1940 local orig_commit2=`git_show_head $testroot/repo`
1941 local orig_author_time2=`git_show_author_time $testroot/repo`
1943 git -C $testroot/repo checkout -q master
1944 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1945 git_commit $testroot/repo -m "committing to zeta on master"
1946 local master_commit=`git_show_head $testroot/repo`
1948 got checkout $testroot/repo $testroot/wt > /dev/null
1950 if [ $ret -ne 0 ]; then
1951 test_done "$testroot" "$ret"
1955 # Backdate the file alpha to an earlier version.
1956 # This sets the work tree's base commit ID back to $commit0,
1957 # which is out-of-date with respect to the master branch.
1958 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
1960 # Rebase into an out-of-date work tree should be refused.
1961 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1962 2> $testroot/stderr)
1964 if [ $ret -eq 0 ]; then
1965 echo "rebase succeeded unexpectedly" >&2
1966 test_done "$testroot" "1"
1969 echo -n > $testroot/stdout.expected
1970 echo -n "got: work tree must be updated before it can be used to " \
1971 > $testroot/stderr.expected
1972 echo "rebase a branch" >> $testroot/stderr.expected
1973 cmp -s $testroot/stderr.expected $testroot/stderr
1975 if [ $ret -ne 0 ]; then
1976 diff -u $testroot/stderr.expected $testroot/stderr
1978 test_done "$testroot" "$ret"
1981 test_rebase_one_commit() {
1982 local testroot=`test_init rebase_one_commit`
1984 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1985 test_done "$testroot" 1
1989 (cd $testroot/wt && got branch newbranch) >/dev/null
1991 echo "modified alpha on newbranch" >$testroot/wt/alpha
1992 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
1993 (cd $testroot/wt && got update) >/dev/null
1994 local commit=`git_show_branch_head $testroot/repo newbranch`
1996 echo -n '' > $testroot/stderr.expected
1998 (cd $testroot/wt && got rebase master >$testroot/stdout \
1999 2> $testroot/stderr)
2001 if [ $ret -ne 0 ]; then
2002 echo "rebase comand failed unexpectedly" >&2
2003 diff -u $testroot/stderr.expected $testroot/stderr
2004 test_done "$testroot" "1"
2008 echo "Forwarding refs/heads/master to commit $commit" \
2009 >$testroot/stdout.expected
2010 echo "Switching work tree to refs/heads/master" \
2011 >> $testroot/stdout.expected
2013 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2014 diff -u $testroot/stdout.expected $testroot/stdout
2015 test_done "$testroot" 1
2019 test_done "$testroot" 0
2022 test_rebase_merge_commit() {
2023 local testroot=`test_init rebase_merge_commit`
2024 local commit0=`git_show_branch_head $testroot/repo master`
2026 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
2027 test_done "$testroot" 1
2031 echo "modified delta on master" >$testroot/wt/gamma/delta
2032 (cd $testroot/wt && got commit -m 'edit delta') >/dev/null
2033 local commit1=`git_show_branch_head $testroot/repo master`
2035 (cd $testroot/wt && got branch -c $commit0 newbranch1) >/dev/null
2036 echo "modified alpha on newbranch1" >$testroot/wt/alpha
2037 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
2038 (cd $testroot/wt && got update) >/dev/null
2039 local commit2=`git_show_branch_head $testroot/repo master`
2041 echo "modified alpha on newbranch1 again" >$testroot/wt/alpha
2042 (cd $testroot/wt && got commit -m 'edit alpha again') >/dev/null
2043 (cd $testroot/wt && got update) >/dev/null
2044 local commit3=`git_show_branch_head $testroot/repo newbranch1`
2046 (cd $testroot/wt && got branch -c $commit0 newbranch2) >/dev/null
2047 echo "modified beta on newbranch2" >$testroot/wt/beta
2048 (cd $testroot/wt && got commit -m 'edit beta') >/dev/null
2049 (cd $testroot/wt && got update) >/dev/null
2050 local commit4=`git_show_branch_head $testroot/repo newbranch2`
2052 echo "modified beta on newbranch2 again" >$testroot/wt/beta
2053 (cd $testroot/wt && got commit -m 'edit beta again') >/dev/null
2054 (cd $testroot/wt && got update) >/dev/null
2055 local commit5=`git_show_branch_head $testroot/repo newbranch2`
2057 echo -n '' > $testroot/stderr.expected
2059 (cd $testroot/wt && got merge newbranch1 >$testroot/stdout \
2060 2> $testroot/stderr)
2062 if [ $ret -ne 0 ]; then
2063 echo "merge comand failed unexpectedly" >&2
2064 diff -u $testroot/stderr.expected $testroot/stderr
2065 test_done "$testroot" "1"
2069 local merge_commit=`git_show_branch_head $testroot/repo newbranch2`
2071 echo "G alpha" >> $testroot/stdout.expected
2072 echo -n "Merged refs/heads/newbranch1 into refs/heads/newbranch2: " \
2073 >> $testroot/stdout.expected
2074 echo $merge_commit >> $testroot/stdout.expected
2076 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2077 diff -u $testroot/stdout.expected $testroot/stdout
2078 test_done "$testroot" 1
2082 (cd $testroot/wt && got update -b master) >/dev/null
2083 (cd $testroot/wt && got rebase newbranch2) > $testroot/stdout
2085 local new_commit5=`git_show_parent_commit $testroot/repo newbranch2`
2086 local short_orig_commit5=`trim_obj_id 28 $commit5`
2087 local short_new_commit5=`trim_obj_id 28 $new_commit5`
2089 local new_commit4=`git_show_parent_commit $testroot/repo $new_commit5`
2090 local short_orig_commit4=`trim_obj_id 28 $commit4`
2091 local short_new_commit4=`trim_obj_id 28 $new_commit4`
2093 local new_merge_commit=`git_show_branch_head $testroot/repo newbranch2`
2094 local short_orig_merge_commit=`trim_obj_id 28 $merge_commit`
2095 local short_new_merge_commit=`trim_obj_id 28 $new_merge_commit`
2097 echo "G beta"> $testroot/stdout.expected
2098 echo "$short_orig_commit4 -> $short_new_commit4: edit beta" \
2099 >> $testroot/stdout.expected
2100 echo "G beta" >> $testroot/stdout.expected
2101 echo "$short_orig_commit5 -> $short_new_commit5: edit beta again" \
2102 >> $testroot/stdout.expected
2103 echo "G alpha" >> $testroot/stdout.expected
2104 echo -n "$short_orig_merge_commit -> $short_new_merge_commit: " \
2105 >> $testroot/stdout.expected
2106 echo "merge refs/heads/newbranch1 into refs/head" \
2107 >> $testroot/stdout.expected
2108 echo "Switching work tree to refs/heads/newbranch2" \
2109 >> $testroot/stdout.expected
2111 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2112 diff -u $testroot/stdout.expected $testroot/stdout
2113 test_done "$testroot" 1
2117 test_done "$testroot" 0
2120 test_rebase_across_merge_commit() {
2121 local testroot=`test_init rebase_across_merge_commit`
2122 local commit0=`git_show_branch_head $testroot/repo master`
2124 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
2125 test_done "$testroot" 1
2129 echo "modified delta on master" >$testroot/wt/gamma/delta
2130 (cd $testroot/wt && got commit -m 'edit delta') >/dev/null
2131 local commit1=`git_show_branch_head $testroot/repo master`
2133 (cd $testroot/wt && got branch -c $commit0 newbranch1) >/dev/null
2134 echo "modified alpha on newbranch1" >$testroot/wt/alpha
2135 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
2136 (cd $testroot/wt && got update) >/dev/null
2137 local commit2=`git_show_branch_head $testroot/repo master`
2139 echo "modified alpha on newbranch1 again" >$testroot/wt/alpha
2140 (cd $testroot/wt && got commit -m 'edit alpha again') >/dev/null
2141 (cd $testroot/wt && got update) >/dev/null
2142 local commit3=`git_show_branch_head $testroot/repo newbranch1`
2144 (cd $testroot/wt && got branch -c $commit0 newbranch2) >/dev/null
2145 echo "modified beta on newbranch2" >$testroot/wt/beta
2146 (cd $testroot/wt && got commit -m 'edit beta') >/dev/null
2147 (cd $testroot/wt && got update) >/dev/null
2148 local commit4=`git_show_branch_head $testroot/repo newbranch2`
2150 echo "modified beta on newbranch2 again" >$testroot/wt/beta
2151 (cd $testroot/wt && got commit -m 'edit beta again') >/dev/null
2152 (cd $testroot/wt && got update) >/dev/null
2153 local commit5=`git_show_branch_head $testroot/repo newbranch2`
2155 echo -n '' > $testroot/stderr.expected
2157 (cd $testroot/wt && got merge newbranch1 >$testroot/stdout \
2158 2> $testroot/stderr)
2160 if [ $ret -ne 0 ]; then
2161 echo "merge comand failed unexpectedly" >&2
2162 diff -u $testroot/stderr.expected $testroot/stderr
2163 test_done "$testroot" "1"
2167 local merge_commit=`git_show_branch_head $testroot/repo newbranch2`
2169 echo "G alpha" >> $testroot/stdout.expected
2170 echo -n "Merged refs/heads/newbranch1 into refs/heads/newbranch2: " \
2171 >> $testroot/stdout.expected
2172 echo $merge_commit >> $testroot/stdout.expected
2174 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2175 diff -u $testroot/stdout.expected $testroot/stdout
2176 test_done "$testroot" 1
2180 (cd $testroot/wt && got rebase master) > $testroot/stdout
2182 local new_commit1=`git_show_head $testroot/repo`
2183 local short_orig_commit1=`trim_obj_id 28 $commit1`
2184 local short_new_commit1=`trim_obj_id 28 $new_commit1`
2186 echo "G gamma/delta"> $testroot/stdout.expected
2187 echo "$short_orig_commit1 -> $short_new_commit1: edit delta" \
2188 >> $testroot/stdout.expected
2189 echo "Switching work tree to refs/heads/master" \
2190 >> $testroot/stdout.expected
2192 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2193 diff -u $testroot/stdout.expected $testroot/stdout
2194 test_done "$testroot" 1
2198 test_done "$testroot" 0
2201 test_rebase_merged_history_traversal() {
2202 local testroot=`test_init rebase_merged_history_traversal`
2203 local commit0=`git_show_branch_head $testroot/repo master`
2205 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
2206 test_done "$testroot" 1
2210 (cd $testroot/wt && got branch -c $commit0 newbranch1) >/dev/null
2211 echo "modified alpha on newbranch1" >$testroot/wt/alpha
2212 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
2213 (cd $testroot/wt && got update) >/dev/null
2214 local commit2=`git_show_branch_head $testroot/repo master`
2216 echo "modified alpha on newbranch1 again" >$testroot/wt/alpha
2217 (cd $testroot/wt && got commit -m 'edit alpha again') >/dev/null
2218 (cd $testroot/wt && got update) >/dev/null
2219 local commit3=`git_show_branch_head $testroot/repo newbranch1`
2221 echo -n '' > $testroot/stderr.expected
2223 (cd $testroot/wt && got update -b master) >/dev/null
2224 (cd $testroot/wt && got merge -M newbranch1 >$testroot/stdout \
2225 2> $testroot/stderr)
2227 if [ $ret -ne 0 ]; then
2228 echo "merge command failed unexpectedly" >&2
2229 diff -u $testroot/stderr.expected $testroot/stderr
2230 test_done "$testroot" "1"
2234 local merge_commit=`git_show_head $testroot/repo`
2236 echo "G alpha" > $testroot/stdout.expected
2237 echo -n "Merged refs/heads/newbranch1 into refs/heads/master: " \
2238 >> $testroot/stdout.expected
2239 echo $merge_commit >> $testroot/stdout.expected
2240 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2241 diff -u $testroot/stdout.expected $testroot/stdout
2242 test_done "$testroot" 1
2246 echo "modified delta on master" >$testroot/wt/gamma/delta
2247 (cd $testroot/wt && got commit -m 'edit delta') >/dev/null
2248 local commit1=`git_show_branch_head $testroot/repo master`
2250 (cd $testroot/wt && got branch newbranch2) >/dev/null
2251 (cd $testroot/wt && got rebase newbranch1) > $testroot/stdout
2253 echo "Forwarding refs/heads/newbranch1 to commit $commit1" > \
2254 $testroot/stdout.expected
2255 echo "Switching work tree to refs/heads/newbranch1" \
2256 >> $testroot/stdout.expected
2258 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2259 diff -u $testroot/stdout.expected $testroot/stdout
2260 test_done "$testroot" "1"
2264 test_done "$testroot" "$ret"
2268 run_test test_rebase_basic
2269 run_test test_rebase_ancestry_check
2270 run_test test_rebase_continue
2271 run_test test_rebase_abort
2272 run_test test_rebase_no_op_change
2273 run_test test_rebase_in_progress
2274 run_test test_rebase_path_prefix
2275 run_test test_rebase_preserves_logmsg
2276 run_test test_rebase_no_commits_to_rebase
2277 run_test test_rebase_forward
2278 run_test test_rebase_forward_path_prefix
2279 run_test test_rebase_out_of_date
2280 run_test test_rebase_trims_empty_dir
2281 run_test test_rebase_delete_missing_file
2282 run_test test_rebase_rm_add_rm_file
2283 run_test test_rebase_resets_committer
2284 run_test test_rebase_no_author_info
2285 run_test test_rebase_nonbranch
2286 run_test test_rebase_umask
2287 run_test test_rebase_out_of_date2
2288 run_test test_rebase_one_commit
2289 run_test test_rebase_merge_commit
2290 run_test test_rebase_across_merge_commit
2291 run_test test_rebase_merged_history_traversal