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 "alpha" >> $testroot/content.expected
223 echo "=======" >> $testroot/content.expected
224 echo "modified alpha on master" >> $testroot/content.expected
225 echo '>>>>>>> alpha' >> $testroot/content.expected
226 cat $testroot/wt/alpha > $testroot/content
227 cmp -s $testroot/content.expected $testroot/content
228 ret="$?"
229 if [ "$ret" != "0" ]; then
230 diff -u $testroot/content.expected $testroot/content
231 test_done "$testroot" "$ret"
232 return 1
233 fi
235 (cd $testroot/wt && got status > $testroot/stdout)
237 echo "C alpha" > $testroot/stdout.expected
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret="$?"
240 if [ "$ret" != "0" ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 # resolve the conflict
247 echo "modified alpha on branch and master" > $testroot/wt/alpha
249 # test interaction of 'got stage' and rebase -c
250 (cd $testroot/wt && got stage alpha > /dev/null)
251 (cd $testroot/wt && got rebase -c > $testroot/stdout \
252 2> $testroot/stderr)
253 ret="$?"
254 if [ "$ret" == "0" ]; then
255 echo "rebase succeeded unexpectedly" >&2
256 test_done "$testroot" "1"
257 return 1
258 fi
259 echo -n "got: work tree contains files with staged changes; " \
260 > $testroot/stderr.expected
261 echo "these changes must be committed or unstaged first" \
262 >> $testroot/stderr.expected
263 cmp -s $testroot/stderr.expected $testroot/stderr
264 ret="$?"
265 if [ "$ret" != "0" ]; then
266 diff -u $testroot/stderr.expected $testroot/stderr
267 test_done "$testroot" "$ret"
268 return 1
269 fi
271 (cd $testroot/wt && got unstage alpha > /dev/null)
272 (cd $testroot/wt && got rebase -c > $testroot/stdout)
274 (cd $testroot/repo && git checkout -q newbranch)
275 local new_commit1=`git_show_head $testroot/repo`
277 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
278 local short_new_commit1=`trim_obj_id 28 $new_commit1`
280 echo -n "$short_orig_commit1 -> $short_new_commit1" \
281 > $testroot/stdout.expected
282 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
283 echo "Switching work tree to refs/heads/newbranch" \
284 >> $testroot/stdout.expected
286 cmp -s $testroot/stdout.expected $testroot/stdout
287 ret="$?"
288 if [ "$ret" != "0" ]; then
289 diff -u $testroot/stdout.expected $testroot/stdout
290 test_done "$testroot" "$ret"
291 return 1
292 fi
295 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
296 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
297 echo "commit $master_commit (master)" >> $testroot/stdout.expected
298 cmp -s $testroot/stdout.expected $testroot/stdout
299 ret="$?"
300 if [ "$ret" != "0" ]; then
301 diff -u $testroot/stdout.expected $testroot/stdout
302 fi
303 test_done "$testroot" "$ret"
306 function test_rebase_abort {
307 local testroot=`test_init rebase_abort`
309 local init_commit=`git_show_head $testroot/repo`
311 (cd $testroot/repo && git checkout -q -b newbranch)
312 echo "modified alpha on branch" > $testroot/repo/alpha
313 git_commit $testroot/repo -m "committing to alpha on newbranch"
314 local orig_commit1=`git_show_head $testroot/repo`
316 (cd $testroot/repo && git checkout -q master)
317 echo "modified alpha on master" > $testroot/repo/alpha
318 git_commit $testroot/repo -m "committing to alpha on master"
319 local master_commit=`git_show_head $testroot/repo`
321 got checkout $testroot/repo $testroot/wt > /dev/null
322 ret="$?"
323 if [ "$ret" != "0" ]; then
324 test_done "$testroot" "$ret"
325 return 1
326 fi
328 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
329 2> $testroot/stderr)
331 echo "C alpha" > $testroot/stdout.expected
332 cmp -s $testroot/stdout.expected $testroot/stdout
333 ret="$?"
334 if [ "$ret" != "0" ]; then
335 diff -u $testroot/stdout.expected $testroot/stdout
336 test_done "$testroot" "$ret"
337 return 1
338 fi
340 echo "got: conflicts must be resolved before rebasing can continue" \
341 > $testroot/stderr.expected
342 cmp -s $testroot/stderr.expected $testroot/stderr
343 ret="$?"
344 if [ "$ret" != "0" ]; then
345 diff -u $testroot/stderr.expected $testroot/stderr
346 test_done "$testroot" "$ret"
347 return 1
348 fi
350 echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
351 echo "modified alpha on branch" >> $testroot/content.expected
352 echo "|||||||" >> $testroot/content.expected
353 echo "alpha" >> $testroot/content.expected
354 echo "=======" >> $testroot/content.expected
355 echo "modified alpha on master" >> $testroot/content.expected
356 echo '>>>>>>> alpha' >> $testroot/content.expected
357 cat $testroot/wt/alpha > $testroot/content
358 cmp -s $testroot/content.expected $testroot/content
359 ret="$?"
360 if [ "$ret" != "0" ]; then
361 diff -u $testroot/content.expected $testroot/content
362 test_done "$testroot" "$ret"
363 return 1
364 fi
366 (cd $testroot/wt && got status > $testroot/stdout)
368 echo "C alpha" > $testroot/stdout.expected
369 cmp -s $testroot/stdout.expected $testroot/stdout
370 ret="$?"
371 if [ "$ret" != "0" ]; then
372 diff -u $testroot/stdout.expected $testroot/stdout
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 (cd $testroot/wt && got rebase -a > $testroot/stdout)
379 (cd $testroot/repo && git checkout -q newbranch)
381 echo "Switching work tree to refs/heads/master" \
382 > $testroot/stdout.expected
383 echo 'R alpha' >> $testroot/stdout.expected
384 echo "Rebase of refs/heads/newbranch aborted" \
385 >> $testroot/stdout.expected
387 cmp -s $testroot/stdout.expected $testroot/stdout
388 ret="$?"
389 if [ "$ret" != "0" ]; then
390 diff -u $testroot/stdout.expected $testroot/stdout
391 test_done "$testroot" "$ret"
392 return 1
393 fi
395 echo "modified alpha on master" > $testroot/content.expected
396 cat $testroot/wt/alpha > $testroot/content
397 cmp -s $testroot/content.expected $testroot/content
398 ret="$?"
399 if [ "$ret" != "0" ]; then
400 diff -u $testroot/content.expected $testroot/content
401 test_done "$testroot" "$ret"
402 return 1
403 fi
405 (cd $testroot/wt && got log -l3 -c newbranch \
406 | grep ^commit > $testroot/stdout)
407 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
408 echo "commit $init_commit" >> $testroot/stdout.expected
409 cmp -s $testroot/stdout.expected $testroot/stdout
410 ret="$?"
411 if [ "$ret" != "0" ]; then
412 diff -u $testroot/stdout.expected $testroot/stdout
413 fi
414 test_done "$testroot" "$ret"
417 function test_rebase_no_op_change {
418 local testroot=`test_init rebase_no_op_change`
419 local init_commit=`git_show_head $testroot/repo`
421 (cd $testroot/repo && git checkout -q -b newbranch)
422 echo "modified alpha on branch" > $testroot/repo/alpha
423 git_commit $testroot/repo -m "committing to alpha on newbranch"
424 local orig_commit1=`git_show_head $testroot/repo`
426 (cd $testroot/repo && git checkout -q master)
427 echo "modified alpha on master" > $testroot/repo/alpha
428 git_commit $testroot/repo -m "committing to alpha on master"
429 local master_commit=`git_show_head $testroot/repo`
431 got checkout $testroot/repo $testroot/wt > /dev/null
432 ret="$?"
433 if [ "$ret" != "0" ]; then
434 test_done "$testroot" "$ret"
435 return 1
436 fi
438 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
439 2> $testroot/stderr)
441 echo "C alpha" > $testroot/stdout.expected
442 cmp -s $testroot/stdout.expected $testroot/stdout
443 ret="$?"
444 if [ "$ret" != "0" ]; then
445 diff -u $testroot/stdout.expected $testroot/stdout
446 test_done "$testroot" "$ret"
447 return 1
448 fi
450 echo "got: conflicts must be resolved before rebasing can continue" \
451 > $testroot/stderr.expected
452 cmp -s $testroot/stderr.expected $testroot/stderr
453 ret="$?"
454 if [ "$ret" != "0" ]; then
455 diff -u $testroot/stderr.expected $testroot/stderr
456 test_done "$testroot" "$ret"
457 return 1
458 fi
460 echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
461 echo "modified alpha on branch" >> $testroot/content.expected
462 echo "|||||||" >> $testroot/content.expected
463 echo "alpha" >> $testroot/content.expected
464 echo "=======" >> $testroot/content.expected
465 echo "modified alpha on master" >> $testroot/content.expected
466 echo '>>>>>>> alpha' >> $testroot/content.expected
467 cat $testroot/wt/alpha > $testroot/content
468 cmp -s $testroot/content.expected $testroot/content
469 ret="$?"
470 if [ "$ret" != "0" ]; then
471 diff -u $testroot/content.expected $testroot/content
472 test_done "$testroot" "$ret"
473 return 1
474 fi
476 (cd $testroot/wt && got status > $testroot/stdout)
478 echo "C alpha" > $testroot/stdout.expected
479 cmp -s $testroot/stdout.expected $testroot/stdout
480 ret="$?"
481 if [ "$ret" != "0" ]; then
482 diff -u $testroot/stdout.expected $testroot/stdout
483 test_done "$testroot" "$ret"
484 return 1
485 fi
487 # resolve the conflict
488 echo "modified alpha on master" > $testroot/wt/alpha
490 (cd $testroot/wt && got rebase -c > $testroot/stdout)
492 (cd $testroot/repo && git checkout -q newbranch)
493 local new_commit1=`git_show_head $testroot/repo`
495 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
497 echo -n "$short_orig_commit1 -> no-op change" \
498 > $testroot/stdout.expected
499 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
500 echo "Switching work tree to refs/heads/newbranch" \
501 >> $testroot/stdout.expected
503 cmp -s $testroot/stdout.expected $testroot/stdout
504 ret="$?"
505 if [ "$ret" != "0" ]; then
506 diff -u $testroot/stdout.expected $testroot/stdout
507 test_done "$testroot" "$ret"
508 return 1
509 fi
512 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
513 echo "commit $master_commit (master, newbranch)" \
514 > $testroot/stdout.expected
515 echo "commit $init_commit" >> $testroot/stdout.expected
516 cmp -s $testroot/stdout.expected $testroot/stdout
517 ret="$?"
518 if [ "$ret" != "0" ]; then
519 diff -u $testroot/stdout.expected $testroot/stdout
520 fi
521 test_done "$testroot" "$ret"
524 function test_rebase_in_progress {
525 local testroot=`test_init rebase_in_progress`
526 local init_commit=`git_show_head $testroot/repo`
528 (cd $testroot/repo && git checkout -q -b newbranch)
529 echo "modified alpha on branch" > $testroot/repo/alpha
530 git_commit $testroot/repo -m "committing to alpha on newbranch"
531 local orig_commit1=`git_show_head $testroot/repo`
533 (cd $testroot/repo && git checkout -q master)
534 echo "modified alpha on master" > $testroot/repo/alpha
535 git_commit $testroot/repo -m "committing to alpha on master"
536 local master_commit=`git_show_head $testroot/repo`
538 got checkout $testroot/repo $testroot/wt > /dev/null
539 ret="$?"
540 if [ "$ret" != "0" ]; then
541 test_done "$testroot" "$ret"
542 return 1
543 fi
545 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
546 2> $testroot/stderr)
548 echo "C alpha" > $testroot/stdout.expected
549 cmp -s $testroot/stdout.expected $testroot/stdout
550 ret="$?"
551 if [ "$ret" != "0" ]; then
552 diff -u $testroot/stdout.expected $testroot/stdout
553 test_done "$testroot" "$ret"
554 return 1
555 fi
557 echo "got: conflicts must be resolved before rebasing can continue" \
558 > $testroot/stderr.expected
559 cmp -s $testroot/stderr.expected $testroot/stderr
560 ret="$?"
561 if [ "$ret" != "0" ]; then
562 diff -u $testroot/stderr.expected $testroot/stderr
563 test_done "$testroot" "$ret"
564 return 1
565 fi
567 echo "<<<<<<< commit $orig_commit1" > $testroot/content.expected
568 echo "modified alpha on branch" >> $testroot/content.expected
569 echo "|||||||" >> $testroot/content.expected
570 echo "alpha" >> $testroot/content.expected
571 echo "=======" >> $testroot/content.expected
572 echo "modified alpha on master" >> $testroot/content.expected
573 echo '>>>>>>> alpha' >> $testroot/content.expected
574 cat $testroot/wt/alpha > $testroot/content
575 cmp -s $testroot/content.expected $testroot/content
576 ret="$?"
577 if [ "$ret" != "0" ]; then
578 diff -u $testroot/content.expected $testroot/content
579 test_done "$testroot" "$ret"
580 return 1
581 fi
583 (cd $testroot/wt && got status > $testroot/stdout)
585 echo "C alpha" > $testroot/stdout.expected
586 cmp -s $testroot/stdout.expected $testroot/stdout
587 ret="$?"
588 if [ "$ret" != "0" ]; then
589 diff -u $testroot/stdout.expected $testroot/stdout
590 test_done "$testroot" "$ret"
591 return 1
592 fi
594 for cmd in update commit; do
595 (cd $testroot/wt && got $cmd > $testroot/stdout \
596 2> $testroot/stderr)
598 echo -n > $testroot/stdout.expected
599 cmp -s $testroot/stdout.expected $testroot/stdout
600 ret="$?"
601 if [ "$ret" != "0" ]; then
602 diff -u $testroot/stdout.expected $testroot/stdout
603 test_done "$testroot" "$ret"
604 return 1
605 fi
607 echo -n "got: a rebase operation is in progress in this " \
608 > $testroot/stderr.expected
609 echo "work tree and must be continued or aborted first" \
610 >> $testroot/stderr.expected
611 cmp -s $testroot/stderr.expected $testroot/stderr
612 ret="$?"
613 if [ "$ret" != "0" ]; then
614 diff -u $testroot/stderr.expected $testroot/stderr
615 test_done "$testroot" "$ret"
616 return 1
617 fi
618 done
620 test_done "$testroot" "$ret"
623 function test_rebase_path_prefix {
624 local testroot=`test_init rebase_path_prefix`
626 (cd $testroot/repo && git checkout -q -b newbranch)
627 echo "modified delta on branch" > $testroot/repo/gamma/delta
628 git_commit $testroot/repo -m "committing to delta on newbranch"
630 local orig_commit1=`git_show_parent_commit $testroot/repo`
631 local orig_commit2=`git_show_head $testroot/repo`
633 (cd $testroot/repo && git checkout -q master)
634 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
635 git_commit $testroot/repo -m "committing to zeta on master"
636 local master_commit=`git_show_head $testroot/repo`
638 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
639 ret="$?"
640 if [ "$ret" != "0" ]; then
641 test_done "$testroot" "$ret"
642 return 1
643 fi
645 (cd $testroot/wt && got rebase newbranch \
646 > $testroot/stdout 2> $testroot/stderr)
648 echo -n > $testroot/stdout.expected
649 cmp -s $testroot/stdout.expected $testroot/stdout
650 ret="$?"
651 if [ "$ret" != "0" ]; then
652 diff -u $testroot/stdout.expected $testroot/stdout
653 test_done "$testroot" "$ret"
654 return 1
655 fi
657 echo -n "got: cannot rebase branch which contains changes outside " \
658 > $testroot/stderr.expected
659 echo "of this work tree's path prefix" >> $testroot/stderr.expected
660 cmp -s $testroot/stderr.expected $testroot/stderr
661 ret="$?"
662 if [ "$ret" != "0" ]; then
663 diff -u $testroot/stderr.expected $testroot/stderr
664 fi
665 test_done "$testroot" "$ret"
668 function test_rebase_preserves_logmsg {
669 local testroot=`test_init rebase_preserves_logmsg`
671 (cd $testroot/repo && git checkout -q -b newbranch)
672 echo "modified delta on branch" > $testroot/repo/gamma/delta
673 git_commit $testroot/repo -m "modified delta on newbranch"
675 echo "modified alpha on branch" > $testroot/repo/alpha
676 git_commit $testroot/repo -m "modified alpha on newbranch"
678 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
679 > $testroot/log.expected)
681 local orig_commit1=`git_show_parent_commit $testroot/repo`
682 local orig_commit2=`git_show_head $testroot/repo`
684 (cd $testroot/repo && git checkout -q master)
685 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
686 git_commit $testroot/repo -m "committing to zeta on master"
687 local master_commit=`git_show_head $testroot/repo`
689 got checkout $testroot/repo $testroot/wt > /dev/null
690 ret="$?"
691 if [ "$ret" != "0" ]; then
692 test_done "$testroot" "$ret"
693 return 1
694 fi
696 (cd $testroot/wt && got rebase newbranch > /dev/null \
697 2> $testroot/stderr)
699 (cd $testroot/repo && git checkout -q newbranch)
700 local new_commit1=`git_show_parent_commit $testroot/repo`
701 local new_commit2=`git_show_head $testroot/repo`
703 echo -n > $testroot/stderr.expected
704 cmp -s $testroot/stderr.expected $testroot/stderr
705 ret="$?"
706 if [ "$ret" != "0" ]; then
707 diff -u $testroot/stderr.expected $testroot/stderr
708 test_done "$testroot" "$ret"
709 return 1
710 fi
712 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
713 > $testroot/log)
714 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
715 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
716 cmp -s $testroot/log.expected $testroot/log
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 diff -u $testroot/log.expected $testroot/log
720 fi
722 test_done "$testroot" "$ret"
725 function test_rebase_no_commits_to_rebase {
726 local testroot=`test_init rebase_no_commits_to_rebase`
728 got checkout $testroot/repo $testroot/wt > /dev/null
729 ret="$?"
730 if [ "$ret" != "0" ]; then
731 test_done "$testroot" "$ret"
732 return 1
733 fi
735 (cd $testroot/wt && got branch newbranch)
737 echo "modified alpha on master" > $testroot/wt/alpha
738 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
739 > /dev/null)
740 (cd $testroot/wt && got update > /dev/null)
742 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
743 2> $testroot/stderr)
745 echo "got: no commits to rebase" > $testroot/stderr.expected
746 cmp -s $testroot/stderr.expected $testroot/stderr
747 ret="$?"
748 if [ "$ret" != "0" ]; then
749 diff -u $testroot/stderr.expected $testroot/stderr
750 test_done "$testroot" "$ret"
751 return 1
752 fi
754 echo "Rebase of refs/heads/newbranch aborted" \
755 > $testroot/stdout.expected
756 cmp -s $testroot/stdout.expected $testroot/stdout
757 ret="$?"
758 if [ "$ret" != "0" ]; then
759 diff -u $testroot/stdout.expected $testroot/stdout
760 test_done "$testroot" "$ret"
761 return 1
762 fi
764 (cd $testroot/wt && got update > $testroot/stdout)
765 echo "Already up-to-date" > $testroot/stdout.expected
766 cmp -s $testroot/stdout.expected $testroot/stdout
767 ret="$?"
768 if [ "$ret" != "0" ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 fi
771 test_done "$testroot" "$ret"
774 run_test test_rebase_basic
775 run_test test_rebase_ancestry_check
776 run_test test_rebase_continue
777 run_test test_rebase_abort
778 run_test test_rebase_no_op_change
779 run_test test_rebase_in_progress
780 run_test test_rebase_path_prefix
781 run_test test_rebase_preserves_logmsg
782 run_test test_rebase_no_commits_to_rebase