Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 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`
180 (cd $testroot/repo && git checkout -q -b newbranch)
181 echo "modified alpha on branch" > $testroot/repo/alpha
182 git_commit $testroot/repo -m "committing to alpha on newbranch"
183 local orig_commit1=`git_show_head $testroot/repo`
185 (cd $testroot/repo && git checkout -q master)
186 echo "modified alpha on master" > $testroot/repo/alpha
187 git_commit $testroot/repo -m "committing to alpha on master"
188 local master_commit=`git_show_head $testroot/repo`
190 got checkout $testroot/repo $testroot/wt > /dev/null
191 ret="$?"
192 if [ "$ret" != "0" ]; then
193 test_done "$testroot" "$ret"
194 return 1
195 fi
197 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
198 2> $testroot/stderr)
200 echo "C alpha" > $testroot/stdout.expected
201 cmp -s $testroot/stdout.expected $testroot/stdout
202 ret="$?"
203 if [ "$ret" != "0" ]; then
204 diff -u $testroot/stdout.expected $testroot/stdout
205 test_done "$testroot" "$ret"
206 return 1
207 fi
209 echo "got: conflicts must be resolved before rebasing can continue" \
210 > $testroot/stderr.expected
211 cmp -s $testroot/stderr.expected $testroot/stderr
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 diff -u $testroot/stderr.expected $testroot/stderr
215 test_done "$testroot" "$ret"
216 return 1
217 fi
219 echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
220 echo "modified alpha on branch" >> $testroot/content.expected
221 echo "=======" >> $testroot/content.expected
222 echo "modified alpha on master" >> $testroot/content.expected
223 echo '>>>>>>> alpha' >> $testroot/content.expected
224 cat $testroot/wt/alpha > $testroot/content
225 cmp -s $testroot/content.expected $testroot/content
226 ret="$?"
227 if [ "$ret" != "0" ]; then
228 diff -u $testroot/content.expected $testroot/content
229 test_done "$testroot" "$ret"
230 return 1
231 fi
233 (cd $testroot/wt && got status > $testroot/stdout)
235 echo "C alpha" > $testroot/stdout.expected
236 cmp -s $testroot/stdout.expected $testroot/stdout
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 diff -u $testroot/stdout.expected $testroot/stdout
240 test_done "$testroot" "$ret"
241 return 1
242 fi
244 # resolve the conflict
245 echo "modified alpha on branch and master" > $testroot/wt/alpha
247 # test interaction of 'got stage' and rebase -c
248 (cd $testroot/wt && got stage alpha > /dev/null)
249 (cd $testroot/wt && got rebase -c > $testroot/stdout \
250 2> $testroot/stderr)
251 ret="$?"
252 if [ "$ret" == "0" ]; then
253 echo "rebase succeeded unexpectedly" >&2
254 test_done "$testroot" "1"
255 return 1
256 fi
257 echo -n "got: work tree contains files with staged changes; " \
258 > $testroot/stderr.expected
259 echo "these changes must be committed or unstaged first" \
260 >> $testroot/stderr.expected
261 cmp -s $testroot/stderr.expected $testroot/stderr
262 ret="$?"
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stderr.expected $testroot/stderr
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 (cd $testroot/wt && got unstage alpha > /dev/null)
270 (cd $testroot/wt && got rebase -c > $testroot/stdout)
272 (cd $testroot/repo && git checkout -q newbranch)
273 local new_commit1=`git_show_head $testroot/repo`
275 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
276 local short_new_commit1=`trim_obj_id 28 $new_commit1`
278 echo -n "$short_orig_commit1 -> $short_new_commit1" \
279 > $testroot/stdout.expected
280 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
281 echo "Switching work tree to refs/heads/newbranch" \
282 >> $testroot/stdout.expected
284 cmp -s $testroot/stdout.expected $testroot/stdout
285 ret="$?"
286 if [ "$ret" != "0" ]; then
287 diff -u $testroot/stdout.expected $testroot/stdout
288 test_done "$testroot" "$ret"
289 return 1
290 fi
293 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
294 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
295 echo "commit $master_commit (master)" >> $testroot/stdout.expected
296 cmp -s $testroot/stdout.expected $testroot/stdout
297 ret="$?"
298 if [ "$ret" != "0" ]; then
299 diff -u $testroot/stdout.expected $testroot/stdout
300 fi
301 test_done "$testroot" "$ret"
304 function test_rebase_abort {
305 local testroot=`test_init rebase_abort`
307 local init_commit=`git_show_head $testroot/repo`
309 (cd $testroot/repo && git checkout -q -b newbranch)
310 echo "modified alpha on branch" > $testroot/repo/alpha
311 git_commit $testroot/repo -m "committing to alpha on newbranch"
312 local orig_commit1=`git_show_head $testroot/repo`
314 (cd $testroot/repo && git checkout -q master)
315 echo "modified alpha on master" > $testroot/repo/alpha
316 git_commit $testroot/repo -m "committing to alpha on master"
317 local master_commit=`git_show_head $testroot/repo`
319 got checkout $testroot/repo $testroot/wt > /dev/null
320 ret="$?"
321 if [ "$ret" != "0" ]; then
322 test_done "$testroot" "$ret"
323 return 1
324 fi
326 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
327 2> $testroot/stderr)
329 echo "C alpha" > $testroot/stdout.expected
330 cmp -s $testroot/stdout.expected $testroot/stdout
331 ret="$?"
332 if [ "$ret" != "0" ]; then
333 diff -u $testroot/stdout.expected $testroot/stdout
334 test_done "$testroot" "$ret"
335 return 1
336 fi
338 echo "got: conflicts must be resolved before rebasing can continue" \
339 > $testroot/stderr.expected
340 cmp -s $testroot/stderr.expected $testroot/stderr
341 ret="$?"
342 if [ "$ret" != "0" ]; then
343 diff -u $testroot/stderr.expected $testroot/stderr
344 test_done "$testroot" "$ret"
345 return 1
346 fi
348 echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
349 echo "modified alpha on branch" >> $testroot/content.expected
350 echo "=======" >> $testroot/content.expected
351 echo "modified alpha on master" >> $testroot/content.expected
352 echo '>>>>>>> alpha' >> $testroot/content.expected
353 cat $testroot/wt/alpha > $testroot/content
354 cmp -s $testroot/content.expected $testroot/content
355 ret="$?"
356 if [ "$ret" != "0" ]; then
357 diff -u $testroot/content.expected $testroot/content
358 test_done "$testroot" "$ret"
359 return 1
360 fi
362 (cd $testroot/wt && got status > $testroot/stdout)
364 echo "C alpha" > $testroot/stdout.expected
365 cmp -s $testroot/stdout.expected $testroot/stdout
366 ret="$?"
367 if [ "$ret" != "0" ]; then
368 diff -u $testroot/stdout.expected $testroot/stdout
369 test_done "$testroot" "$ret"
370 return 1
371 fi
373 (cd $testroot/wt && got rebase -a > $testroot/stdout)
375 (cd $testroot/repo && git checkout -q newbranch)
377 echo "Switching work tree to refs/heads/master" \
378 > $testroot/stdout.expected
379 echo 'R alpha' >> $testroot/stdout.expected
380 echo "Rebase of refs/heads/newbranch aborted" \
381 >> $testroot/stdout.expected
383 cmp -s $testroot/stdout.expected $testroot/stdout
384 ret="$?"
385 if [ "$ret" != "0" ]; then
386 diff -u $testroot/stdout.expected $testroot/stdout
387 test_done "$testroot" "$ret"
388 return 1
389 fi
391 echo "modified alpha on master" > $testroot/content.expected
392 cat $testroot/wt/alpha > $testroot/content
393 cmp -s $testroot/content.expected $testroot/content
394 ret="$?"
395 if [ "$ret" != "0" ]; then
396 diff -u $testroot/content.expected $testroot/content
397 test_done "$testroot" "$ret"
398 return 1
399 fi
401 (cd $testroot/wt && got log -l3 -c newbranch \
402 | grep ^commit > $testroot/stdout)
403 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
404 echo "commit $init_commit" >> $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected $testroot/stdout
406 ret="$?"
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 fi
410 test_done "$testroot" "$ret"
413 function test_rebase_no_op_change {
414 local testroot=`test_init rebase_no_op_change`
415 local init_commit=`git_show_head $testroot/repo`
417 (cd $testroot/repo && git checkout -q -b newbranch)
418 echo "modified alpha on branch" > $testroot/repo/alpha
419 git_commit $testroot/repo -m "committing to alpha on newbranch"
420 local orig_commit1=`git_show_head $testroot/repo`
422 (cd $testroot/repo && git checkout -q master)
423 echo "modified alpha on master" > $testroot/repo/alpha
424 git_commit $testroot/repo -m "committing to alpha on master"
425 local master_commit=`git_show_head $testroot/repo`
427 got checkout $testroot/repo $testroot/wt > /dev/null
428 ret="$?"
429 if [ "$ret" != "0" ]; then
430 test_done "$testroot" "$ret"
431 return 1
432 fi
434 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
435 2> $testroot/stderr)
437 echo "C alpha" > $testroot/stdout.expected
438 cmp -s $testroot/stdout.expected $testroot/stdout
439 ret="$?"
440 if [ "$ret" != "0" ]; then
441 diff -u $testroot/stdout.expected $testroot/stdout
442 test_done "$testroot" "$ret"
443 return 1
444 fi
446 echo "got: conflicts must be resolved before rebasing can continue" \
447 > $testroot/stderr.expected
448 cmp -s $testroot/stderr.expected $testroot/stderr
449 ret="$?"
450 if [ "$ret" != "0" ]; then
451 diff -u $testroot/stderr.expected $testroot/stderr
452 test_done "$testroot" "$ret"
453 return 1
454 fi
456 echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
457 echo "modified alpha on branch" >> $testroot/content.expected
458 echo "=======" >> $testroot/content.expected
459 echo "modified alpha on master" >> $testroot/content.expected
460 echo '>>>>>>> alpha' >> $testroot/content.expected
461 cat $testroot/wt/alpha > $testroot/content
462 cmp -s $testroot/content.expected $testroot/content
463 ret="$?"
464 if [ "$ret" != "0" ]; then
465 diff -u $testroot/content.expected $testroot/content
466 test_done "$testroot" "$ret"
467 return 1
468 fi
470 (cd $testroot/wt && got status > $testroot/stdout)
472 echo "C alpha" > $testroot/stdout.expected
473 cmp -s $testroot/stdout.expected $testroot/stdout
474 ret="$?"
475 if [ "$ret" != "0" ]; then
476 diff -u $testroot/stdout.expected $testroot/stdout
477 test_done "$testroot" "$ret"
478 return 1
479 fi
481 # resolve the conflict
482 echo "modified alpha on master" > $testroot/wt/alpha
484 (cd $testroot/wt && got rebase -c > $testroot/stdout)
486 (cd $testroot/repo && git checkout -q newbranch)
487 local new_commit1=`git_show_head $testroot/repo`
489 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
491 echo -n "$short_orig_commit1 -> no-op change" \
492 > $testroot/stdout.expected
493 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
494 echo "Switching work tree to refs/heads/newbranch" \
495 >> $testroot/stdout.expected
497 cmp -s $testroot/stdout.expected $testroot/stdout
498 ret="$?"
499 if [ "$ret" != "0" ]; then
500 diff -u $testroot/stdout.expected $testroot/stdout
501 test_done "$testroot" "$ret"
502 return 1
503 fi
506 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
507 echo "commit $master_commit (master, newbranch)" \
508 > $testroot/stdout.expected
509 echo "commit $init_commit" >> $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 fi
515 test_done "$testroot" "$ret"
518 function test_rebase_in_progress {
519 local testroot=`test_init rebase_in_progress`
520 local init_commit=`git_show_head $testroot/repo`
522 (cd $testroot/repo && git checkout -q -b newbranch)
523 echo "modified alpha on branch" > $testroot/repo/alpha
524 git_commit $testroot/repo -m "committing to alpha on newbranch"
525 local orig_commit1=`git_show_head $testroot/repo`
527 (cd $testroot/repo && git checkout -q master)
528 echo "modified alpha on master" > $testroot/repo/alpha
529 git_commit $testroot/repo -m "committing to alpha on master"
530 local master_commit=`git_show_head $testroot/repo`
532 got checkout $testroot/repo $testroot/wt > /dev/null
533 ret="$?"
534 if [ "$ret" != "0" ]; then
535 test_done "$testroot" "$ret"
536 return 1
537 fi
539 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
540 2> $testroot/stderr)
542 echo "C alpha" > $testroot/stdout.expected
543 cmp -s $testroot/stdout.expected $testroot/stdout
544 ret="$?"
545 if [ "$ret" != "0" ]; then
546 diff -u $testroot/stdout.expected $testroot/stdout
547 test_done "$testroot" "$ret"
548 return 1
549 fi
551 echo "got: conflicts must be resolved before rebasing can continue" \
552 > $testroot/stderr.expected
553 cmp -s $testroot/stderr.expected $testroot/stderr
554 ret="$?"
555 if [ "$ret" != "0" ]; then
556 diff -u $testroot/stderr.expected $testroot/stderr
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
562 echo "modified alpha on branch" >> $testroot/content.expected
563 echo "=======" >> $testroot/content.expected
564 echo "modified alpha on master" >> $testroot/content.expected
565 echo '>>>>>>> alpha' >> $testroot/content.expected
566 cat $testroot/wt/alpha > $testroot/content
567 cmp -s $testroot/content.expected $testroot/content
568 ret="$?"
569 if [ "$ret" != "0" ]; then
570 diff -u $testroot/content.expected $testroot/content
571 test_done "$testroot" "$ret"
572 return 1
573 fi
575 (cd $testroot/wt && got status > $testroot/stdout)
577 echo "C alpha" > $testroot/stdout.expected
578 cmp -s $testroot/stdout.expected $testroot/stdout
579 ret="$?"
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/stdout.expected $testroot/stdout
582 test_done "$testroot" "$ret"
583 return 1
584 fi
586 for cmd in update commit; do
587 (cd $testroot/wt && got $cmd > $testroot/stdout \
588 2> $testroot/stderr)
590 echo -n > $testroot/stdout.expected
591 cmp -s $testroot/stdout.expected $testroot/stdout
592 ret="$?"
593 if [ "$ret" != "0" ]; then
594 diff -u $testroot/stdout.expected $testroot/stdout
595 test_done "$testroot" "$ret"
596 return 1
597 fi
599 echo -n "got: a rebase operation is in progress in this " \
600 > $testroot/stderr.expected
601 echo "work tree and must be continued or aborted first" \
602 >> $testroot/stderr.expected
603 cmp -s $testroot/stderr.expected $testroot/stderr
604 ret="$?"
605 if [ "$ret" != "0" ]; then
606 diff -u $testroot/stderr.expected $testroot/stderr
607 test_done "$testroot" "$ret"
608 return 1
609 fi
610 done
612 test_done "$testroot" "$ret"
615 function test_rebase_path_prefix {
616 local testroot=`test_init rebase_path_prefix`
618 (cd $testroot/repo && git checkout -q -b newbranch)
619 echo "modified delta on branch" > $testroot/repo/gamma/delta
620 git_commit $testroot/repo -m "committing to delta on newbranch"
622 local orig_commit1=`git_show_parent_commit $testroot/repo`
623 local orig_commit2=`git_show_head $testroot/repo`
625 (cd $testroot/repo && git checkout -q master)
626 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
627 git_commit $testroot/repo -m "committing to zeta on master"
628 local master_commit=`git_show_head $testroot/repo`
630 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
631 ret="$?"
632 if [ "$ret" != "0" ]; then
633 test_done "$testroot" "$ret"
634 return 1
635 fi
637 (cd $testroot/wt && got rebase newbranch \
638 > $testroot/stdout 2> $testroot/stderr)
640 echo -n > $testroot/stdout.expected
641 cmp -s $testroot/stdout.expected $testroot/stdout
642 ret="$?"
643 if [ "$ret" != "0" ]; then
644 diff -u $testroot/stdout.expected $testroot/stdout
645 test_done "$testroot" "$ret"
646 return 1
647 fi
649 echo -n "got: cannot rebase branch which contains changes outside " \
650 > $testroot/stderr.expected
651 echo "of this work tree's path prefix" >> $testroot/stderr.expected
652 cmp -s $testroot/stderr.expected $testroot/stderr
653 ret="$?"
654 if [ "$ret" != "0" ]; then
655 diff -u $testroot/stderr.expected $testroot/stderr
656 fi
657 test_done "$testroot" "$ret"
660 function test_rebase_preserves_logmsg {
661 local testroot=`test_init rebase_preserves_logmsg`
663 (cd $testroot/repo && git checkout -q -b newbranch)
664 echo "modified delta on branch" > $testroot/repo/gamma/delta
665 git_commit $testroot/repo -m "modified delta on newbranch"
667 echo "modified alpha on branch" > $testroot/repo/alpha
668 git_commit $testroot/repo -m "modified alpha on newbranch"
670 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
671 > $testroot/log.expected)
673 local orig_commit1=`git_show_parent_commit $testroot/repo`
674 local orig_commit2=`git_show_head $testroot/repo`
676 (cd $testroot/repo && git checkout -q master)
677 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
678 git_commit $testroot/repo -m "committing to zeta on master"
679 local master_commit=`git_show_head $testroot/repo`
681 got checkout $testroot/repo $testroot/wt > /dev/null
682 ret="$?"
683 if [ "$ret" != "0" ]; then
684 test_done "$testroot" "$ret"
685 return 1
686 fi
688 (cd $testroot/wt && got rebase newbranch > /dev/null \
689 2> $testroot/stderr)
691 (cd $testroot/repo && git checkout -q newbranch)
692 local new_commit1=`git_show_parent_commit $testroot/repo`
693 local new_commit2=`git_show_head $testroot/repo`
695 echo -n > $testroot/stderr.expected
696 cmp -s $testroot/stderr.expected $testroot/stderr
697 ret="$?"
698 if [ "$ret" != "0" ]; then
699 diff -u $testroot/stderr.expected $testroot/stderr
700 test_done "$testroot" "$ret"
701 return 1
702 fi
704 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
705 > $testroot/log)
706 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
707 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
708 cmp -s $testroot/log.expected $testroot/log
709 ret="$?"
710 if [ "$ret" != "0" ]; then
711 diff -u $testroot/log.expected $testroot/log
712 fi
714 test_done "$testroot" "$ret"
717 run_test test_rebase_basic
718 run_test test_rebase_ancestry_check
719 run_test test_rebase_continue
720 run_test test_rebase_abort
721 run_test test_rebase_no_op_change
722 run_test test_rebase_in_progress
723 run_test test_rebase_path_prefix
724 run_test test_rebase_preserves_logmsg