Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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.
17 . ./common.sh
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
41 ret="$?"
42 if [ "$ret" != "0" ]; then
43 test_done "$testroot" "$ret"
44 return 1
45 fi
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
73 ret="$?"
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stdout.expected $testroot/stdout
76 test_done "$testroot" "$ret"
77 return 1
78 fi
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
83 ret="$?"
84 if [ "$ret" != "0" ]; then
85 diff -u $testroot/content.expected $testroot/content
86 test_done "$testroot" "$ret"
87 return 1
88 fi
90 echo "modified alpha on branch" > $testroot/content.expected
91 cat $testroot/wt/alpha > $testroot/content
92 cmp -s $testroot/content.expected $testroot/content
93 ret="$?"
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/content.expected $testroot/content
96 test_done "$testroot" "$ret"
97 return 1
98 fi
100 if [ -e $testroot/wt/beta ]; then
101 echo "removed file beta still exists on disk" >&2
102 test_done "$testroot" "1"
103 return 1
104 fi
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
109 ret="$?"
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/content.expected $testroot/content
112 test_done "$testroot" "$ret"
113 return 1
114 fi
116 (cd $testroot/wt && got status > $testroot/stdout)
118 echo -n > $testroot/stdout.expected
119 cmp -s $testroot/stdout.expected $testroot/stdout
120 ret="$?"
121 if [ "$ret" != "0" ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 test_done "$testroot" "$ret"
124 return 1
125 fi
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
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stdout.expected $testroot/stdout
135 fi
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
143 ret="$?"
144 if [ "$ret" != "0" ]; then
145 test_done "$testroot" "$ret"
146 return 1
147 fi
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 \
154 2> $testroot/stderr)
156 echo -n > $testroot/stdout.expected
157 cmp -s $testroot/stdout.expected $testroot/stdout
158 ret="$?"
159 if [ "$ret" != "0" ]; then
160 diff -u $testroot/stdout.expected $testroot/stdout
161 test_done "$testroot" "$ret"
162 return 1
163 fi
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
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
173 fi
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`
186 (cd $testroot/repo && git checkout -q master)
187 echo "modified alpha on master" > $testroot/repo/alpha
188 git_commit $testroot/repo -m "committing to alpha on master"
189 local master_commit=`git_show_head $testroot/repo`
191 got checkout $testroot/repo $testroot/wt > /dev/null
192 ret="$?"
193 if [ "$ret" != "0" ]; then
194 test_done "$testroot" "$ret"
195 return 1
196 fi
198 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
199 2> $testroot/stderr)
201 echo "C alpha" > $testroot/stdout.expected
202 cmp -s $testroot/stdout.expected $testroot/stdout
203 ret="$?"
204 if [ "$ret" != "0" ]; then
205 diff -u $testroot/stdout.expected $testroot/stdout
206 test_done "$testroot" "$ret"
207 return 1
208 fi
210 echo "got: conflicts must be resolved before rebasing can continue" \
211 > $testroot/stderr.expected
212 cmp -s $testroot/stderr.expected $testroot/stderr
213 ret="$?"
214 if [ "$ret" != "0" ]; then
215 diff -u $testroot/stderr.expected $testroot/stderr
216 test_done "$testroot" "$ret"
217 return 1
218 fi
220 echo "<<<<<<< merged change: commit $orig_commit1" \
221 > $testroot/content.expected
222 echo "modified alpha on branch" >> $testroot/content.expected
223 echo "||||||| 3-way merge base: commit $init_commit" \
224 >> $testroot/content.expected
225 echo "alpha" >> $testroot/content.expected
226 echo "=======" >> $testroot/content.expected
227 echo "modified alpha on master" >> $testroot/content.expected
228 echo '>>>>>>>' >> $testroot/content.expected
229 cat $testroot/wt/alpha > $testroot/content
230 cmp -s $testroot/content.expected $testroot/content
231 ret="$?"
232 if [ "$ret" != "0" ]; then
233 diff -u $testroot/content.expected $testroot/content
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 (cd $testroot/wt && got status > $testroot/stdout)
240 echo "C alpha" > $testroot/stdout.expected
241 cmp -s $testroot/stdout.expected $testroot/stdout
242 ret="$?"
243 if [ "$ret" != "0" ]; then
244 diff -u $testroot/stdout.expected $testroot/stdout
245 test_done "$testroot" "$ret"
246 return 1
247 fi
249 # resolve the conflict
250 echo "modified alpha on branch and master" > $testroot/wt/alpha
252 # test interaction of 'got stage' and rebase -c
253 (cd $testroot/wt && got stage alpha > /dev/null)
254 (cd $testroot/wt && got rebase -c > $testroot/stdout \
255 2> $testroot/stderr)
256 ret="$?"
257 if [ "$ret" == "0" ]; then
258 echo "rebase succeeded unexpectedly" >&2
259 test_done "$testroot" "1"
260 return 1
261 fi
262 echo -n "got: work tree contains files with staged changes; " \
263 > $testroot/stderr.expected
264 echo "these changes must be committed or unstaged first" \
265 >> $testroot/stderr.expected
266 cmp -s $testroot/stderr.expected $testroot/stderr
267 ret="$?"
268 if [ "$ret" != "0" ]; then
269 diff -u $testroot/stderr.expected $testroot/stderr
270 test_done "$testroot" "$ret"
271 return 1
272 fi
274 (cd $testroot/wt && got unstage alpha > /dev/null)
275 (cd $testroot/wt && got rebase -c > $testroot/stdout)
277 (cd $testroot/repo && git checkout -q newbranch)
278 local new_commit1=`git_show_head $testroot/repo`
280 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
281 local short_new_commit1=`trim_obj_id 28 $new_commit1`
283 echo -n "$short_orig_commit1 -> $short_new_commit1" \
284 > $testroot/stdout.expected
285 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
286 echo "Switching work tree to refs/heads/newbranch" \
287 >> $testroot/stdout.expected
289 cmp -s $testroot/stdout.expected $testroot/stdout
290 ret="$?"
291 if [ "$ret" != "0" ]; then
292 diff -u $testroot/stdout.expected $testroot/stdout
293 test_done "$testroot" "$ret"
294 return 1
295 fi
298 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
299 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
300 echo "commit $master_commit (master)" >> $testroot/stdout.expected
301 cmp -s $testroot/stdout.expected $testroot/stdout
302 ret="$?"
303 if [ "$ret" != "0" ]; then
304 diff -u $testroot/stdout.expected $testroot/stdout
305 fi
306 test_done "$testroot" "$ret"
309 function test_rebase_abort {
310 local testroot=`test_init rebase_abort`
312 local init_commit=`git_show_head $testroot/repo`
314 (cd $testroot/repo && git checkout -q -b newbranch)
315 echo "modified alpha on branch" > $testroot/repo/alpha
316 git_commit $testroot/repo -m "committing to alpha on newbranch"
317 local orig_commit1=`git_show_head $testroot/repo`
319 (cd $testroot/repo && git checkout -q master)
320 echo "modified alpha on master" > $testroot/repo/alpha
321 git_commit $testroot/repo -m "committing to alpha on master"
322 local master_commit=`git_show_head $testroot/repo`
324 got checkout $testroot/repo $testroot/wt > /dev/null
325 ret="$?"
326 if [ "$ret" != "0" ]; then
327 test_done "$testroot" "$ret"
328 return 1
329 fi
331 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
332 2> $testroot/stderr)
334 echo "C alpha" > $testroot/stdout.expected
335 cmp -s $testroot/stdout.expected $testroot/stdout
336 ret="$?"
337 if [ "$ret" != "0" ]; then
338 diff -u $testroot/stdout.expected $testroot/stdout
339 test_done "$testroot" "$ret"
340 return 1
341 fi
343 echo "got: conflicts must be resolved before rebasing can continue" \
344 > $testroot/stderr.expected
345 cmp -s $testroot/stderr.expected $testroot/stderr
346 ret="$?"
347 if [ "$ret" != "0" ]; then
348 diff -u $testroot/stderr.expected $testroot/stderr
349 test_done "$testroot" "$ret"
350 return 1
351 fi
353 echo "<<<<<<< merged change: commit $orig_commit1" \
354 > $testroot/content.expected
355 echo "modified alpha on branch" >> $testroot/content.expected
356 echo "||||||| 3-way merge base: commit $init_commit" \
357 >> $testroot/content.expected
358 echo "alpha" >> $testroot/content.expected
359 echo "=======" >> $testroot/content.expected
360 echo "modified alpha on master" >> $testroot/content.expected
361 echo '>>>>>>>' >> $testroot/content.expected
362 cat $testroot/wt/alpha > $testroot/content
363 cmp -s $testroot/content.expected $testroot/content
364 ret="$?"
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/content.expected $testroot/content
367 test_done "$testroot" "$ret"
368 return 1
369 fi
371 (cd $testroot/wt && got status > $testroot/stdout)
373 echo "C alpha" > $testroot/stdout.expected
374 cmp -s $testroot/stdout.expected $testroot/stdout
375 ret="$?"
376 if [ "$ret" != "0" ]; then
377 diff -u $testroot/stdout.expected $testroot/stdout
378 test_done "$testroot" "$ret"
379 return 1
380 fi
382 (cd $testroot/wt && got rebase -a > $testroot/stdout)
384 (cd $testroot/repo && git checkout -q newbranch)
386 echo "Switching work tree to refs/heads/master" \
387 > $testroot/stdout.expected
388 echo 'R alpha' >> $testroot/stdout.expected
389 echo "Rebase of refs/heads/newbranch aborted" \
390 >> $testroot/stdout.expected
392 cmp -s $testroot/stdout.expected $testroot/stdout
393 ret="$?"
394 if [ "$ret" != "0" ]; then
395 diff -u $testroot/stdout.expected $testroot/stdout
396 test_done "$testroot" "$ret"
397 return 1
398 fi
400 echo "modified alpha on master" > $testroot/content.expected
401 cat $testroot/wt/alpha > $testroot/content
402 cmp -s $testroot/content.expected $testroot/content
403 ret="$?"
404 if [ "$ret" != "0" ]; then
405 diff -u $testroot/content.expected $testroot/content
406 test_done "$testroot" "$ret"
407 return 1
408 fi
410 (cd $testroot/wt && got log -l3 -c newbranch \
411 | grep ^commit > $testroot/stdout)
412 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
413 echo "commit $init_commit" >> $testroot/stdout.expected
414 cmp -s $testroot/stdout.expected $testroot/stdout
415 ret="$?"
416 if [ "$ret" != "0" ]; then
417 diff -u $testroot/stdout.expected $testroot/stdout
418 fi
419 test_done "$testroot" "$ret"
422 function test_rebase_no_op_change {
423 local testroot=`test_init rebase_no_op_change`
424 local init_commit=`git_show_head $testroot/repo`
426 (cd $testroot/repo && git checkout -q -b newbranch)
427 echo "modified alpha on branch" > $testroot/repo/alpha
428 git_commit $testroot/repo -m "committing to alpha on newbranch"
429 local orig_commit1=`git_show_head $testroot/repo`
431 (cd $testroot/repo && git checkout -q master)
432 echo "modified alpha on master" > $testroot/repo/alpha
433 git_commit $testroot/repo -m "committing to alpha on master"
434 local master_commit=`git_show_head $testroot/repo`
436 got checkout $testroot/repo $testroot/wt > /dev/null
437 ret="$?"
438 if [ "$ret" != "0" ]; then
439 test_done "$testroot" "$ret"
440 return 1
441 fi
443 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
444 2> $testroot/stderr)
446 echo "C alpha" > $testroot/stdout.expected
447 cmp -s $testroot/stdout.expected $testroot/stdout
448 ret="$?"
449 if [ "$ret" != "0" ]; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" "$ret"
452 return 1
453 fi
455 echo "got: conflicts must be resolved before rebasing can continue" \
456 > $testroot/stderr.expected
457 cmp -s $testroot/stderr.expected $testroot/stderr
458 ret="$?"
459 if [ "$ret" != "0" ]; then
460 diff -u $testroot/stderr.expected $testroot/stderr
461 test_done "$testroot" "$ret"
462 return 1
463 fi
465 echo "<<<<<<< merged change: commit $orig_commit1" \
466 > $testroot/content.expected
467 echo "modified alpha on branch" >> $testroot/content.expected
468 echo "||||||| 3-way merge base: commit $init_commit" \
469 >> $testroot/content.expected
470 echo "alpha" >> $testroot/content.expected
471 echo "=======" >> $testroot/content.expected
472 echo "modified alpha on master" >> $testroot/content.expected
473 echo '>>>>>>>' >> $testroot/content.expected
474 cat $testroot/wt/alpha > $testroot/content
475 cmp -s $testroot/content.expected $testroot/content
476 ret="$?"
477 if [ "$ret" != "0" ]; then
478 diff -u $testroot/content.expected $testroot/content
479 test_done "$testroot" "$ret"
480 return 1
481 fi
483 (cd $testroot/wt && got status > $testroot/stdout)
485 echo "C alpha" > $testroot/stdout.expected
486 cmp -s $testroot/stdout.expected $testroot/stdout
487 ret="$?"
488 if [ "$ret" != "0" ]; then
489 diff -u $testroot/stdout.expected $testroot/stdout
490 test_done "$testroot" "$ret"
491 return 1
492 fi
494 # resolve the conflict
495 echo "modified alpha on master" > $testroot/wt/alpha
497 (cd $testroot/wt && got rebase -c > $testroot/stdout)
499 (cd $testroot/repo && git checkout -q newbranch)
500 local new_commit1=`git_show_head $testroot/repo`
502 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
504 echo -n "$short_orig_commit1 -> no-op change" \
505 > $testroot/stdout.expected
506 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
507 echo "Switching work tree to refs/heads/newbranch" \
508 >> $testroot/stdout.expected
510 cmp -s $testroot/stdout.expected $testroot/stdout
511 ret="$?"
512 if [ "$ret" != "0" ]; then
513 diff -u $testroot/stdout.expected $testroot/stdout
514 test_done "$testroot" "$ret"
515 return 1
516 fi
519 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
520 echo "commit $master_commit (master, newbranch)" \
521 > $testroot/stdout.expected
522 echo "commit $init_commit" >> $testroot/stdout.expected
523 cmp -s $testroot/stdout.expected $testroot/stdout
524 ret="$?"
525 if [ "$ret" != "0" ]; then
526 diff -u $testroot/stdout.expected $testroot/stdout
527 fi
528 test_done "$testroot" "$ret"
531 function test_rebase_in_progress {
532 local testroot=`test_init rebase_in_progress`
533 local init_commit=`git_show_head $testroot/repo`
535 (cd $testroot/repo && git checkout -q -b newbranch)
536 echo "modified alpha on branch" > $testroot/repo/alpha
537 git_commit $testroot/repo -m "committing to alpha on newbranch"
538 local orig_commit1=`git_show_head $testroot/repo`
540 (cd $testroot/repo && git checkout -q master)
541 echo "modified alpha on master" > $testroot/repo/alpha
542 git_commit $testroot/repo -m "committing to alpha on master"
543 local master_commit=`git_show_head $testroot/repo`
545 got checkout $testroot/repo $testroot/wt > /dev/null
546 ret="$?"
547 if [ "$ret" != "0" ]; then
548 test_done "$testroot" "$ret"
549 return 1
550 fi
552 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
553 2> $testroot/stderr)
555 echo "C alpha" > $testroot/stdout.expected
556 cmp -s $testroot/stdout.expected $testroot/stdout
557 ret="$?"
558 if [ "$ret" != "0" ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
561 return 1
562 fi
564 echo "got: conflicts must be resolved before rebasing can continue" \
565 > $testroot/stderr.expected
566 cmp -s $testroot/stderr.expected $testroot/stderr
567 ret="$?"
568 if [ "$ret" != "0" ]; then
569 diff -u $testroot/stderr.expected $testroot/stderr
570 test_done "$testroot" "$ret"
571 return 1
572 fi
574 echo "<<<<<<< merged change: commit $orig_commit1" \
575 > $testroot/content.expected
576 echo "modified alpha on branch" >> $testroot/content.expected
577 echo "||||||| 3-way merge base: commit $init_commit" \
578 >> $testroot/content.expected
579 echo "alpha" >> $testroot/content.expected
580 echo "=======" >> $testroot/content.expected
581 echo "modified alpha on master" >> $testroot/content.expected
582 echo '>>>>>>>' >> $testroot/content.expected
583 cat $testroot/wt/alpha > $testroot/content
584 cmp -s $testroot/content.expected $testroot/content
585 ret="$?"
586 if [ "$ret" != "0" ]; then
587 diff -u $testroot/content.expected $testroot/content
588 test_done "$testroot" "$ret"
589 return 1
590 fi
592 (cd $testroot/wt && got status > $testroot/stdout)
594 echo "C alpha" > $testroot/stdout.expected
595 cmp -s $testroot/stdout.expected $testroot/stdout
596 ret="$?"
597 if [ "$ret" != "0" ]; then
598 diff -u $testroot/stdout.expected $testroot/stdout
599 test_done "$testroot" "$ret"
600 return 1
601 fi
603 for cmd in update commit; do
604 (cd $testroot/wt && got $cmd > $testroot/stdout \
605 2> $testroot/stderr)
607 echo -n > $testroot/stdout.expected
608 cmp -s $testroot/stdout.expected $testroot/stdout
609 ret="$?"
610 if [ "$ret" != "0" ]; then
611 diff -u $testroot/stdout.expected $testroot/stdout
612 test_done "$testroot" "$ret"
613 return 1
614 fi
616 echo -n "got: a rebase operation is in progress in this " \
617 > $testroot/stderr.expected
618 echo "work tree and must be continued or aborted first" \
619 >> $testroot/stderr.expected
620 cmp -s $testroot/stderr.expected $testroot/stderr
621 ret="$?"
622 if [ "$ret" != "0" ]; then
623 diff -u $testroot/stderr.expected $testroot/stderr
624 test_done "$testroot" "$ret"
625 return 1
626 fi
627 done
629 test_done "$testroot" "$ret"
632 function test_rebase_path_prefix {
633 local testroot=`test_init rebase_path_prefix`
635 (cd $testroot/repo && git checkout -q -b newbranch)
636 echo "modified delta on branch" > $testroot/repo/gamma/delta
637 git_commit $testroot/repo -m "committing to delta on newbranch"
639 local orig_commit1=`git_show_parent_commit $testroot/repo`
640 local orig_commit2=`git_show_head $testroot/repo`
642 (cd $testroot/repo && git checkout -q master)
643 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
644 git_commit $testroot/repo -m "committing to zeta on master"
645 local master_commit=`git_show_head $testroot/repo`
647 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
648 ret="$?"
649 if [ "$ret" != "0" ]; then
650 test_done "$testroot" "$ret"
651 return 1
652 fi
654 (cd $testroot/wt && got rebase newbranch \
655 > $testroot/stdout 2> $testroot/stderr)
657 echo -n > $testroot/stdout.expected
658 cmp -s $testroot/stdout.expected $testroot/stdout
659 ret="$?"
660 if [ "$ret" != "0" ]; then
661 diff -u $testroot/stdout.expected $testroot/stdout
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 echo -n "got: cannot rebase branch which contains changes outside " \
667 > $testroot/stderr.expected
668 echo "of this work tree's path prefix" >> $testroot/stderr.expected
669 cmp -s $testroot/stderr.expected $testroot/stderr
670 ret="$?"
671 if [ "$ret" != "0" ]; then
672 diff -u $testroot/stderr.expected $testroot/stderr
673 fi
674 test_done "$testroot" "$ret"
677 function test_rebase_preserves_logmsg {
678 local testroot=`test_init rebase_preserves_logmsg`
680 (cd $testroot/repo && git checkout -q -b newbranch)
681 echo "modified delta on branch" > $testroot/repo/gamma/delta
682 git_commit $testroot/repo -m "modified delta on newbranch"
684 echo "modified alpha on branch" > $testroot/repo/alpha
685 git_commit $testroot/repo -m "modified alpha on newbranch"
687 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
688 > $testroot/log.expected)
690 local orig_commit1=`git_show_parent_commit $testroot/repo`
691 local orig_commit2=`git_show_head $testroot/repo`
693 (cd $testroot/repo && git checkout -q master)
694 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
695 git_commit $testroot/repo -m "committing to zeta on master"
696 local master_commit=`git_show_head $testroot/repo`
698 got checkout $testroot/repo $testroot/wt > /dev/null
699 ret="$?"
700 if [ "$ret" != "0" ]; then
701 test_done "$testroot" "$ret"
702 return 1
703 fi
705 (cd $testroot/wt && got rebase newbranch > /dev/null \
706 2> $testroot/stderr)
708 (cd $testroot/repo && git checkout -q newbranch)
709 local new_commit1=`git_show_parent_commit $testroot/repo`
710 local new_commit2=`git_show_head $testroot/repo`
712 echo -n > $testroot/stderr.expected
713 cmp -s $testroot/stderr.expected $testroot/stderr
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 diff -u $testroot/stderr.expected $testroot/stderr
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
722 > $testroot/log)
723 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
724 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
725 cmp -s $testroot/log.expected $testroot/log
726 ret="$?"
727 if [ "$ret" != "0" ]; then
728 diff -u $testroot/log.expected $testroot/log
729 fi
731 test_done "$testroot" "$ret"
734 function test_rebase_no_commits_to_rebase {
735 local testroot=`test_init rebase_no_commits_to_rebase`
737 got checkout $testroot/repo $testroot/wt > /dev/null
738 ret="$?"
739 if [ "$ret" != "0" ]; then
740 test_done "$testroot" "$ret"
741 return 1
742 fi
744 (cd $testroot/wt && got branch newbranch)
746 echo "modified alpha on master" > $testroot/wt/alpha
747 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
748 > /dev/null)
749 (cd $testroot/wt && got update > /dev/null)
751 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
752 2> $testroot/stderr)
754 echo "got: no commits to rebase" > $testroot/stderr.expected
755 cmp -s $testroot/stderr.expected $testroot/stderr
756 ret="$?"
757 if [ "$ret" != "0" ]; then
758 diff -u $testroot/stderr.expected $testroot/stderr
759 test_done "$testroot" "$ret"
760 return 1
761 fi
763 echo "Rebase of refs/heads/newbranch aborted" \
764 > $testroot/stdout.expected
765 cmp -s $testroot/stdout.expected $testroot/stdout
766 ret="$?"
767 if [ "$ret" != "0" ]; then
768 diff -u $testroot/stdout.expected $testroot/stdout
769 test_done "$testroot" "$ret"
770 return 1
771 fi
773 (cd $testroot/wt && got update > $testroot/stdout)
774 echo "Already up-to-date" > $testroot/stdout.expected
775 cmp -s $testroot/stdout.expected $testroot/stdout
776 ret="$?"
777 if [ "$ret" != "0" ]; then
778 diff -u $testroot/stdout.expected $testroot/stdout
779 fi
780 test_done "$testroot" "$ret"
783 function test_rebase_forward {
784 local testroot=`test_init rebase_forward`
785 local commit0=`git_show_head $testroot/repo`
787 got checkout $testroot/repo $testroot/wt > /dev/null
788 ret="$?"
789 if [ "$ret" != "0" ]; then
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 echo "change alpha 1" > $testroot/wt/alpha
795 (cd $testroot/wt && got commit -m 'test rebase_forward' \
796 > /dev/null)
797 local commit1=`git_show_head $testroot/repo`
799 echo "change alpha 2" > $testroot/wt/alpha
800 (cd $testroot/wt && got commit -m 'test rebase_forward' \
801 > /dev/null)
802 local commit2=`git_show_head $testroot/repo`
804 # Simulate a situation where fast-forward is required.
805 # We want to fast-forward master to origin/master:
806 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
807 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
808 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
809 (cd $testroot/repo && got ref -d master)
810 (cd $testroot/repo && got ref refs/heads/master $commit1)
811 (cd $testroot/repo && got ref refs/remotes/origin/master $commit2)
814 (cd $testroot/wt && got up -b origin/master > /dev/null)
816 (cd $testroot/wt && got rebase master \
817 > $testroot/stdout 2> $testroot/stderr)
819 echo "Forwarding refs/heads/master to commit $commit2" \
820 > $testroot/stdout.expected
821 echo "Switching work tree to refs/heads/master" \
822 >> $testroot/stdout.expected
823 cmp -s $testroot/stdout.expected $testroot/stdout
824 ret="$?"
825 if [ "$ret" != "0" ]; then
826 diff -u $testroot/stdout.expected $testroot/stdout
827 test_done "$testroot" "$ret"
828 return 1
829 fi
831 # Ensure that rebase operation was completed correctly
832 (cd $testroot/wt && got rebase -a \
833 > $testroot/stdout 2> $testroot/stderr)
834 echo -n "" > $testroot/stdout.expected
835 cmp -s $testroot/stdout.expected $testroot/stdout
836 ret="$?"
837 if [ "$ret" != "0" ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
840 return 1
841 fi
842 echo "got: rebase operation not in progress" > $testroot/stderr.expected
843 cmp -s $testroot/stderr.expected $testroot/stderr
844 ret="$?"
845 if [ "$ret" != "0" ]; then
846 diff -u $testroot/stderr.expected $testroot/stderr
847 test_done "$testroot" "$ret"
848 return 1
849 fi
851 (cd $testroot/wt && got branch > $testroot/stdout)
852 echo "master" > $testroot/stdout.expected
853 cmp -s $testroot/stdout.expected $testroot/stdout
854 ret="$?"
855 if [ "$ret" != "0" ]; then
856 diff -u $testroot/stdout.expected $testroot/stdout
857 test_done "$testroot" "$ret"
858 return 1
859 fi
861 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
862 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
863 echo "commit $commit1" >> $testroot/stdout.expected
864 echo "commit $commit0" >> $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
866 ret="$?"
867 if [ "$ret" != "0" ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 fi
870 test_done "$testroot" "$ret"
873 function test_rebase_out_of_date {
874 local testroot=`test_init rebase_out_of_date`
875 local initial_commit=`git_show_head $testroot/repo`
877 (cd $testroot/repo && git checkout -q -b newbranch)
878 echo "modified delta on branch" > $testroot/repo/gamma/delta
879 git_commit $testroot/repo -m "committing to delta on newbranch"
881 echo "modified alpha on branch" > $testroot/repo/alpha
882 (cd $testroot/repo && git rm -q beta)
883 echo "new file on branch" > $testroot/repo/epsilon/new
884 (cd $testroot/repo && git add epsilon/new)
885 git_commit $testroot/repo -m "committing more changes on newbranch"
887 local orig_commit1=`git_show_parent_commit $testroot/repo`
888 local orig_commit2=`git_show_head $testroot/repo`
890 (cd $testroot/repo && git checkout -q master)
891 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
892 git_commit $testroot/repo -m "committing to zeta on master"
893 local master_commit1=`git_show_head $testroot/repo`
895 (cd $testroot/repo && git checkout -q master)
896 echo "modified beta on master" > $testroot/repo/beta
897 git_commit $testroot/repo -m "committing to beta on master"
898 local master_commit2=`git_show_head $testroot/repo`
900 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
901 > /dev/null
902 ret="$?"
903 if [ "$ret" != "0" ]; then
904 test_done "$testroot" "$ret"
905 return 1
906 fi
908 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
909 2> $testroot/stderr)
911 echo -n > $testroot/stdout.expected
912 cmp -s $testroot/stdout.expected $testroot/stdout
913 ret="$?"
914 if [ "$ret" != "0" ]; then
915 diff -u $testroot/stdout.expected $testroot/stdout
916 test_done "$testroot" "$ret"
917 return 1
918 fi
920 echo -n "got: work tree must be updated before it can be " \
921 > $testroot/stderr.expected
922 echo "used to rebase a branch" >> $testroot/stderr.expected
923 cmp -s $testroot/stderr.expected $testroot/stderr
924 ret="$?"
925 if [ "$ret" != "0" ]; then
926 diff -u $testroot/stderr.expected $testroot/stderr
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
932 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
933 echo "commit $master_commit1" >> $testroot/stdout.expected
934 echo "commit $initial_commit" >> $testroot/stdout.expected
935 cmp -s $testroot/stdout.expected $testroot/stdout
936 ret="$?"
937 if [ "$ret" != "0" ]; then
938 diff -u $testroot/stdout.expected $testroot/stdout
939 fi
940 test_done "$testroot" "$ret"
943 run_test test_rebase_basic
944 run_test test_rebase_ancestry_check
945 run_test test_rebase_continue
946 run_test test_rebase_abort
947 run_test test_rebase_no_op_change
948 run_test test_rebase_in_progress
949 run_test test_rebase_path_prefix
950 run_test test_rebase_preserves_logmsg
951 run_test test_rebase_no_commits_to_rebase
952 run_test test_rebase_forward
953 run_test test_rebase_out_of_date