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 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 test_done "$testroot" "$ret"
136 return 1
137 fi
139 (cd $testroot/wt && got update > $testroot/stdout)
141 echo 'Already up-to-date' > $testroot/stdout.expected
142 cmp -s $testroot/stdout.expected $testroot/stdout
143 ret="$?"
144 if [ "$ret" != "0" ]; then
145 diff -u $testroot/stdout.expected $testroot/stdout
146 fi
147 test_done "$testroot" "$ret"
150 test_rebase_ancestry_check() {
151 local testroot=`test_init rebase_ancestry_check`
153 got checkout $testroot/repo $testroot/wt > /dev/null
154 ret="$?"
155 if [ "$ret" != "0" ]; then
156 test_done "$testroot" "$ret"
157 return 1
158 fi
160 (cd $testroot/repo && git checkout -q -b newbranch)
161 echo "modified delta on branch" > $testroot/repo/gamma/delta
162 git_commit $testroot/repo -m "committing to delta on newbranch"
164 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
165 2> $testroot/stderr)
167 echo -n > $testroot/stdout.expected
168 cmp -s $testroot/stdout.expected $testroot/stdout
169 ret="$?"
170 if [ "$ret" != "0" ]; then
171 diff -u $testroot/stdout.expected $testroot/stdout
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 echo -n "got: specified branch resolves to a commit " \
177 > $testroot/stderr.expected
178 echo "which is already contained in work tree's branch" \
179 >> $testroot/stderr.expected
180 cmp -s $testroot/stderr.expected $testroot/stderr
181 ret="$?"
182 if [ "$ret" != "0" ]; then
183 diff -u $testroot/stderr.expected $testroot/stderr
184 fi
185 test_done "$testroot" "$ret"
188 test_rebase_continue() {
189 local testroot=`test_init rebase_continue`
190 local init_commit=`git_show_head $testroot/repo`
192 (cd $testroot/repo && git checkout -q -b newbranch)
193 echo "modified alpha on branch" > $testroot/repo/alpha
194 git_commit $testroot/repo -m "committing to alpha on newbranch"
195 local orig_commit1=`git_show_head $testroot/repo`
196 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
198 (cd $testroot/repo && git checkout -q master)
199 echo "modified alpha on master" > $testroot/repo/alpha
200 git_commit $testroot/repo -m "committing to alpha on master"
201 local master_commit=`git_show_head $testroot/repo`
203 got checkout $testroot/repo $testroot/wt > /dev/null
204 ret="$?"
205 if [ "$ret" != "0" ]; then
206 test_done "$testroot" "$ret"
207 return 1
208 fi
210 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
211 2> $testroot/stderr)
213 echo "C alpha" > $testroot/stdout.expected
214 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
215 echo -n "$short_orig_commit1 -> merge conflict" \
216 >> $testroot/stdout.expected
217 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
218 cmp -s $testroot/stdout.expected $testroot/stdout
219 ret="$?"
220 if [ "$ret" != "0" ]; then
221 diff -u $testroot/stdout.expected $testroot/stdout
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 echo "got: conflicts must be resolved before rebasing can continue" \
227 > $testroot/stderr.expected
228 cmp -s $testroot/stderr.expected $testroot/stderr
229 ret="$?"
230 if [ "$ret" != "0" ]; then
231 diff -u $testroot/stderr.expected $testroot/stderr
232 test_done "$testroot" "$ret"
233 return 1
234 fi
236 echo "<<<<<<< merged change: commit $orig_commit1" \
237 > $testroot/content.expected
238 echo "modified alpha on branch" >> $testroot/content.expected
239 echo "||||||| 3-way merge base: commit $init_commit" \
240 >> $testroot/content.expected
241 echo "alpha" >> $testroot/content.expected
242 echo "=======" >> $testroot/content.expected
243 echo "modified alpha on master" >> $testroot/content.expected
244 echo '>>>>>>>' >> $testroot/content.expected
245 cat $testroot/wt/alpha > $testroot/content
246 cmp -s $testroot/content.expected $testroot/content
247 ret="$?"
248 if [ "$ret" != "0" ]; then
249 diff -u $testroot/content.expected $testroot/content
250 test_done "$testroot" "$ret"
251 return 1
252 fi
254 (cd $testroot/wt && got status > $testroot/stdout)
256 echo "C alpha" > $testroot/stdout.expected
257 cmp -s $testroot/stdout.expected $testroot/stdout
258 ret="$?"
259 if [ "$ret" != "0" ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
262 return 1
263 fi
265 # resolve the conflict
266 echo "modified alpha on branch and master" > $testroot/wt/alpha
268 # test interaction of 'got stage' and rebase -c
269 (cd $testroot/wt && got stage alpha > /dev/null)
270 (cd $testroot/wt && got rebase -c > $testroot/stdout \
271 2> $testroot/stderr)
272 ret="$?"
273 if [ "$ret" = "0" ]; then
274 echo "rebase succeeded unexpectedly" >&2
275 test_done "$testroot" "1"
276 return 1
277 fi
278 echo -n "got: work tree contains files with staged changes; " \
279 > $testroot/stderr.expected
280 echo "these changes must be committed or unstaged first" \
281 >> $testroot/stderr.expected
282 cmp -s $testroot/stderr.expected $testroot/stderr
283 ret="$?"
284 if [ "$ret" != "0" ]; then
285 diff -u $testroot/stderr.expected $testroot/stderr
286 test_done "$testroot" "$ret"
287 return 1
288 fi
290 (cd $testroot/wt && got unstage alpha > /dev/null)
291 (cd $testroot/wt && got rebase -c > $testroot/stdout)
293 (cd $testroot/repo && git checkout -q newbranch)
294 local new_commit1=`git_show_head $testroot/repo`
295 local short_new_commit1=`trim_obj_id 28 $new_commit1`
297 echo -n "$short_orig_commit1 -> $short_new_commit1" \
298 > $testroot/stdout.expected
299 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
300 echo "Switching work tree to refs/heads/newbranch" \
301 >> $testroot/stdout.expected
303 cmp -s $testroot/stdout.expected $testroot/stdout
304 ret="$?"
305 if [ "$ret" != "0" ]; then
306 diff -u $testroot/stdout.expected $testroot/stdout
307 test_done "$testroot" "$ret"
308 return 1
309 fi
312 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
313 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
314 echo "commit $master_commit (master)" >> $testroot/stdout.expected
315 cmp -s $testroot/stdout.expected $testroot/stdout
316 ret="$?"
317 if [ "$ret" != "0" ]; then
318 diff -u $testroot/stdout.expected $testroot/stdout
319 fi
320 test_done "$testroot" "$ret"
323 test_rebase_abort() {
324 local testroot=`test_init rebase_abort`
326 local init_commit=`git_show_head $testroot/repo`
328 (cd $testroot/repo && git checkout -q -b newbranch)
329 echo "modified alpha on branch" > $testroot/repo/alpha
330 git_commit $testroot/repo -m "committing to alpha on newbranch"
331 local orig_commit1=`git_show_head $testroot/repo`
332 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
334 (cd $testroot/repo && git checkout -q master)
335 echo "modified alpha on master" > $testroot/repo/alpha
336 git_commit $testroot/repo -m "committing to alpha on master"
337 local master_commit=`git_show_head $testroot/repo`
339 got checkout $testroot/repo $testroot/wt > /dev/null
340 ret="$?"
341 if [ "$ret" != "0" ]; then
342 test_done "$testroot" "$ret"
343 return 1
344 fi
346 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
347 2> $testroot/stderr)
349 echo "C alpha" > $testroot/stdout.expected
350 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
351 echo -n "$short_orig_commit1 -> merge conflict" \
352 >> $testroot/stdout.expected
353 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
354 cmp -s $testroot/stdout.expected $testroot/stdout
355 ret="$?"
356 if [ "$ret" != "0" ]; then
357 diff -u $testroot/stdout.expected $testroot/stdout
358 test_done "$testroot" "$ret"
359 return 1
360 fi
362 echo "got: conflicts must be resolved before rebasing can continue" \
363 > $testroot/stderr.expected
364 cmp -s $testroot/stderr.expected $testroot/stderr
365 ret="$?"
366 if [ "$ret" != "0" ]; then
367 diff -u $testroot/stderr.expected $testroot/stderr
368 test_done "$testroot" "$ret"
369 return 1
370 fi
372 echo "<<<<<<< merged change: commit $orig_commit1" \
373 > $testroot/content.expected
374 echo "modified alpha on branch" >> $testroot/content.expected
375 echo "||||||| 3-way merge base: commit $init_commit" \
376 >> $testroot/content.expected
377 echo "alpha" >> $testroot/content.expected
378 echo "=======" >> $testroot/content.expected
379 echo "modified alpha on master" >> $testroot/content.expected
380 echo '>>>>>>>' >> $testroot/content.expected
381 cat $testroot/wt/alpha > $testroot/content
382 cmp -s $testroot/content.expected $testroot/content
383 ret="$?"
384 if [ "$ret" != "0" ]; then
385 diff -u $testroot/content.expected $testroot/content
386 test_done "$testroot" "$ret"
387 return 1
388 fi
390 (cd $testroot/wt && got status > $testroot/stdout)
392 echo "C alpha" > $testroot/stdout.expected
393 cmp -s $testroot/stdout.expected $testroot/stdout
394 ret="$?"
395 if [ "$ret" != "0" ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
398 return 1
399 fi
401 (cd $testroot/wt && got rebase -a > $testroot/stdout)
403 (cd $testroot/repo && git checkout -q newbranch)
405 echo "Switching work tree to refs/heads/master" \
406 > $testroot/stdout.expected
407 echo 'R alpha' >> $testroot/stdout.expected
408 echo "Rebase of refs/heads/newbranch aborted" \
409 >> $testroot/stdout.expected
411 cmp -s $testroot/stdout.expected $testroot/stdout
412 ret="$?"
413 if [ "$ret" != "0" ]; then
414 diff -u $testroot/stdout.expected $testroot/stdout
415 test_done "$testroot" "$ret"
416 return 1
417 fi
419 echo "modified alpha on master" > $testroot/content.expected
420 cat $testroot/wt/alpha > $testroot/content
421 cmp -s $testroot/content.expected $testroot/content
422 ret="$?"
423 if [ "$ret" != "0" ]; then
424 diff -u $testroot/content.expected $testroot/content
425 test_done "$testroot" "$ret"
426 return 1
427 fi
429 (cd $testroot/wt && got log -l3 -c newbranch \
430 | grep ^commit > $testroot/stdout)
431 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
432 echo "commit $init_commit" >> $testroot/stdout.expected
433 cmp -s $testroot/stdout.expected $testroot/stdout
434 ret="$?"
435 if [ "$ret" != "0" ]; then
436 diff -u $testroot/stdout.expected $testroot/stdout
437 fi
438 test_done "$testroot" "$ret"
441 test_rebase_no_op_change() {
442 local testroot=`test_init rebase_no_op_change`
443 local init_commit=`git_show_head $testroot/repo`
445 (cd $testroot/repo && git checkout -q -b newbranch)
446 echo "modified alpha on branch" > $testroot/repo/alpha
447 git_commit $testroot/repo -m "committing to alpha on newbranch"
448 local orig_commit1=`git_show_head $testroot/repo`
449 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
451 (cd $testroot/repo && git checkout -q master)
452 echo "modified alpha on master" > $testroot/repo/alpha
453 git_commit $testroot/repo -m "committing to alpha on master"
454 local master_commit=`git_show_head $testroot/repo`
456 got checkout $testroot/repo $testroot/wt > /dev/null
457 ret="$?"
458 if [ "$ret" != "0" ]; then
459 test_done "$testroot" "$ret"
460 return 1
461 fi
463 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
464 2> $testroot/stderr)
466 echo "C alpha" > $testroot/stdout.expected
467 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
468 echo -n "$short_orig_commit1 -> merge conflict" \
469 >> $testroot/stdout.expected
470 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
471 cmp -s $testroot/stdout.expected $testroot/stdout
472 ret="$?"
473 if [ "$ret" != "0" ]; then
474 diff -u $testroot/stdout.expected $testroot/stdout
475 test_done "$testroot" "$ret"
476 return 1
477 fi
479 echo "got: conflicts must be resolved before rebasing can continue" \
480 > $testroot/stderr.expected
481 cmp -s $testroot/stderr.expected $testroot/stderr
482 ret="$?"
483 if [ "$ret" != "0" ]; then
484 diff -u $testroot/stderr.expected $testroot/stderr
485 test_done "$testroot" "$ret"
486 return 1
487 fi
489 echo "<<<<<<< merged change: commit $orig_commit1" \
490 > $testroot/content.expected
491 echo "modified alpha on branch" >> $testroot/content.expected
492 echo "||||||| 3-way merge base: commit $init_commit" \
493 >> $testroot/content.expected
494 echo "alpha" >> $testroot/content.expected
495 echo "=======" >> $testroot/content.expected
496 echo "modified alpha on master" >> $testroot/content.expected
497 echo '>>>>>>>' >> $testroot/content.expected
498 cat $testroot/wt/alpha > $testroot/content
499 cmp -s $testroot/content.expected $testroot/content
500 ret="$?"
501 if [ "$ret" != "0" ]; then
502 diff -u $testroot/content.expected $testroot/content
503 test_done "$testroot" "$ret"
504 return 1
505 fi
507 (cd $testroot/wt && got status > $testroot/stdout)
509 echo "C alpha" > $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
518 # resolve the conflict
519 echo "modified alpha on master" > $testroot/wt/alpha
521 (cd $testroot/wt && got rebase -c > $testroot/stdout)
523 (cd $testroot/repo && git checkout -q newbranch)
524 local new_commit1=`git_show_head $testroot/repo`
526 echo -n "$short_orig_commit1 -> no-op change" \
527 > $testroot/stdout.expected
528 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
529 echo "Switching work tree to refs/heads/newbranch" \
530 >> $testroot/stdout.expected
532 cmp -s $testroot/stdout.expected $testroot/stdout
533 ret="$?"
534 if [ "$ret" != "0" ]; then
535 diff -u $testroot/stdout.expected $testroot/stdout
536 test_done "$testroot" "$ret"
537 return 1
538 fi
541 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
542 echo "commit $master_commit (master, newbranch)" \
543 > $testroot/stdout.expected
544 echo "commit $init_commit" >> $testroot/stdout.expected
545 cmp -s $testroot/stdout.expected $testroot/stdout
546 ret="$?"
547 if [ "$ret" != "0" ]; then
548 diff -u $testroot/stdout.expected $testroot/stdout
549 fi
550 test_done "$testroot" "$ret"
553 test_rebase_in_progress() {
554 local testroot=`test_init rebase_in_progress`
555 local init_commit=`git_show_head $testroot/repo`
557 (cd $testroot/repo && git checkout -q -b newbranch)
558 echo "modified alpha on branch" > $testroot/repo/alpha
559 git_commit $testroot/repo -m "committing to alpha on newbranch"
560 local orig_commit1=`git_show_head $testroot/repo`
561 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
563 (cd $testroot/repo && git checkout -q master)
564 echo "modified alpha on master" > $testroot/repo/alpha
565 git_commit $testroot/repo -m "committing to alpha on master"
566 local master_commit=`git_show_head $testroot/repo`
568 got checkout $testroot/repo $testroot/wt > /dev/null
569 ret="$?"
570 if [ "$ret" != "0" ]; then
571 test_done "$testroot" "$ret"
572 return 1
573 fi
575 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
576 2> $testroot/stderr)
578 echo "C alpha" > $testroot/stdout.expected
579 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
580 echo -n "$short_orig_commit1 -> merge conflict" \
581 >> $testroot/stdout.expected
582 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
583 cmp -s $testroot/stdout.expected $testroot/stdout
584 ret="$?"
585 if [ "$ret" != "0" ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
588 return 1
589 fi
591 echo "got: conflicts must be resolved before rebasing can continue" \
592 > $testroot/stderr.expected
593 cmp -s $testroot/stderr.expected $testroot/stderr
594 ret="$?"
595 if [ "$ret" != "0" ]; then
596 diff -u $testroot/stderr.expected $testroot/stderr
597 test_done "$testroot" "$ret"
598 return 1
599 fi
601 echo "<<<<<<< merged change: commit $orig_commit1" \
602 > $testroot/content.expected
603 echo "modified alpha on branch" >> $testroot/content.expected
604 echo "||||||| 3-way merge base: commit $init_commit" \
605 >> $testroot/content.expected
606 echo "alpha" >> $testroot/content.expected
607 echo "=======" >> $testroot/content.expected
608 echo "modified alpha on master" >> $testroot/content.expected
609 echo '>>>>>>>' >> $testroot/content.expected
610 cat $testroot/wt/alpha > $testroot/content
611 cmp -s $testroot/content.expected $testroot/content
612 ret="$?"
613 if [ "$ret" != "0" ]; then
614 diff -u $testroot/content.expected $testroot/content
615 test_done "$testroot" "$ret"
616 return 1
617 fi
619 (cd $testroot/wt && got status > $testroot/stdout)
621 echo "C alpha" > $testroot/stdout.expected
622 cmp -s $testroot/stdout.expected $testroot/stdout
623 ret="$?"
624 if [ "$ret" != "0" ]; then
625 diff -u $testroot/stdout.expected $testroot/stdout
626 test_done "$testroot" "$ret"
627 return 1
628 fi
630 for cmd in update commit; do
631 (cd $testroot/wt && got $cmd > $testroot/stdout \
632 2> $testroot/stderr)
634 echo -n > $testroot/stdout.expected
635 cmp -s $testroot/stdout.expected $testroot/stdout
636 ret="$?"
637 if [ "$ret" != "0" ]; then
638 diff -u $testroot/stdout.expected $testroot/stdout
639 test_done "$testroot" "$ret"
640 return 1
641 fi
643 echo -n "got: a rebase operation is in progress in this " \
644 > $testroot/stderr.expected
645 echo "work tree and must be continued or aborted first" \
646 >> $testroot/stderr.expected
647 cmp -s $testroot/stderr.expected $testroot/stderr
648 ret="$?"
649 if [ "$ret" != "0" ]; then
650 diff -u $testroot/stderr.expected $testroot/stderr
651 test_done "$testroot" "$ret"
652 return 1
653 fi
654 done
656 test_done "$testroot" "$ret"
659 test_rebase_path_prefix() {
660 local testroot=`test_init rebase_path_prefix`
662 (cd $testroot/repo && git checkout -q -b newbranch)
663 echo "modified delta on branch" > $testroot/repo/gamma/delta
664 git_commit $testroot/repo -m "committing to delta on newbranch"
666 local orig_commit1=`git_show_parent_commit $testroot/repo`
667 local orig_commit2=`git_show_head $testroot/repo`
669 (cd $testroot/repo && git checkout -q master)
670 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
671 git_commit $testroot/repo -m "committing to zeta on master"
672 local master_commit=`git_show_head $testroot/repo`
674 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
675 ret="$?"
676 if [ "$ret" != "0" ]; then
677 test_done "$testroot" "$ret"
678 return 1
679 fi
681 (cd $testroot/wt && got rebase newbranch \
682 > $testroot/stdout 2> $testroot/stderr)
684 echo -n > $testroot/stdout.expected
685 cmp -s $testroot/stdout.expected $testroot/stdout
686 ret="$?"
687 if [ "$ret" != "0" ]; then
688 diff -u $testroot/stdout.expected $testroot/stdout
689 test_done "$testroot" "$ret"
690 return 1
691 fi
693 echo -n "got: cannot rebase branch which contains changes outside " \
694 > $testroot/stderr.expected
695 echo "of this work tree's path prefix" >> $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 fi
701 test_done "$testroot" "$ret"
704 test_rebase_preserves_logmsg() {
705 local testroot=`test_init rebase_preserves_logmsg`
707 (cd $testroot/repo && git checkout -q -b newbranch)
708 echo "modified delta on branch" > $testroot/repo/gamma/delta
709 git_commit $testroot/repo -m "modified delta on newbranch"
711 echo "modified alpha on branch" > $testroot/repo/alpha
712 git_commit $testroot/repo -m "modified alpha on newbranch"
714 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
715 > $testroot/log.expected)
717 local orig_commit1=`git_show_parent_commit $testroot/repo`
718 local orig_commit2=`git_show_head $testroot/repo`
720 (cd $testroot/repo && git checkout -q master)
721 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
722 git_commit $testroot/repo -m "committing to zeta on master"
723 local master_commit=`git_show_head $testroot/repo`
725 got checkout $testroot/repo $testroot/wt > /dev/null
726 ret="$?"
727 if [ "$ret" != "0" ]; then
728 test_done "$testroot" "$ret"
729 return 1
730 fi
732 (cd $testroot/wt && got rebase newbranch > /dev/null \
733 2> $testroot/stderr)
735 (cd $testroot/repo && git checkout -q newbranch)
736 local new_commit1=`git_show_parent_commit $testroot/repo`
737 local new_commit2=`git_show_head $testroot/repo`
739 echo -n > $testroot/stderr.expected
740 cmp -s $testroot/stderr.expected $testroot/stderr
741 ret="$?"
742 if [ "$ret" != "0" ]; then
743 diff -u $testroot/stderr.expected $testroot/stderr
744 test_done "$testroot" "$ret"
745 return 1
746 fi
748 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
749 > $testroot/log)
750 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
751 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
752 cmp -s $testroot/log.expected $testroot/log
753 ret="$?"
754 if [ "$ret" != "0" ]; then
755 diff -u $testroot/log.expected $testroot/log
756 fi
758 test_done "$testroot" "$ret"
761 test_rebase_no_commits_to_rebase() {
762 local testroot=`test_init rebase_no_commits_to_rebase`
764 got checkout $testroot/repo $testroot/wt > /dev/null
765 ret="$?"
766 if [ "$ret" != "0" ]; then
767 test_done "$testroot" "$ret"
768 return 1
769 fi
771 (cd $testroot/wt && got branch -n newbranch)
773 echo "modified alpha on master" > $testroot/wt/alpha
774 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
775 > /dev/null)
776 (cd $testroot/wt && got update > /dev/null)
778 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
779 2> $testroot/stderr)
781 echo "got: no commits to rebase" > $testroot/stderr.expected
782 cmp -s $testroot/stderr.expected $testroot/stderr
783 ret="$?"
784 if [ "$ret" != "0" ]; then
785 diff -u $testroot/stderr.expected $testroot/stderr
786 test_done "$testroot" "$ret"
787 return 1
788 fi
790 echo "Rebase of refs/heads/newbranch aborted" \
791 > $testroot/stdout.expected
792 cmp -s $testroot/stdout.expected $testroot/stdout
793 ret="$?"
794 if [ "$ret" != "0" ]; then
795 diff -u $testroot/stdout.expected $testroot/stdout
796 test_done "$testroot" "$ret"
797 return 1
798 fi
800 (cd $testroot/wt && got update > $testroot/stdout)
801 echo "Already up-to-date" > $testroot/stdout.expected
802 cmp -s $testroot/stdout.expected $testroot/stdout
803 ret="$?"
804 if [ "$ret" != "0" ]; then
805 diff -u $testroot/stdout.expected $testroot/stdout
806 fi
807 test_done "$testroot" "$ret"
810 test_rebase_forward() {
811 local testroot=`test_init rebase_forward`
812 local commit0=`git_show_head $testroot/repo`
814 got checkout $testroot/repo $testroot/wt > /dev/null
815 ret="$?"
816 if [ "$ret" != "0" ]; then
817 test_done "$testroot" "$ret"
818 return 1
819 fi
821 echo "change alpha 1" > $testroot/wt/alpha
822 (cd $testroot/wt && got commit -m 'test rebase_forward' \
823 > /dev/null)
824 local commit1=`git_show_head $testroot/repo`
826 echo "change alpha 2" > $testroot/wt/alpha
827 (cd $testroot/wt && got commit -m 'test rebase_forward' \
828 > /dev/null)
829 local commit2=`git_show_head $testroot/repo`
831 # Simulate a situation where fast-forward is required.
832 # We want to fast-forward master to origin/master:
833 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
834 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
835 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
836 (cd $testroot/repo && got ref -d master)
837 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
838 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
840 (cd $testroot/wt && got up -b origin/master > /dev/null)
842 (cd $testroot/wt && got rebase master \
843 > $testroot/stdout 2> $testroot/stderr)
845 echo "Forwarding refs/heads/master to commit $commit2" \
846 > $testroot/stdout.expected
847 echo "Switching work tree to refs/heads/master" \
848 >> $testroot/stdout.expected
849 cmp -s $testroot/stdout.expected $testroot/stdout
850 ret="$?"
851 if [ "$ret" != "0" ]; then
852 diff -u $testroot/stdout.expected $testroot/stdout
853 test_done "$testroot" "$ret"
854 return 1
855 fi
857 # Ensure that rebase operation was completed correctly
858 (cd $testroot/wt && got rebase -a \
859 > $testroot/stdout 2> $testroot/stderr)
860 echo -n "" > $testroot/stdout.expected
861 cmp -s $testroot/stdout.expected $testroot/stdout
862 ret="$?"
863 if [ "$ret" != "0" ]; then
864 diff -u $testroot/stdout.expected $testroot/stdout
865 test_done "$testroot" "$ret"
866 return 1
867 fi
868 echo "got: rebase operation not in progress" > $testroot/stderr.expected
869 cmp -s $testroot/stderr.expected $testroot/stderr
870 ret="$?"
871 if [ "$ret" != "0" ]; then
872 diff -u $testroot/stderr.expected $testroot/stderr
873 test_done "$testroot" "$ret"
874 return 1
875 fi
877 (cd $testroot/wt && got branch -n > $testroot/stdout)
878 echo "master" > $testroot/stdout.expected
879 cmp -s $testroot/stdout.expected $testroot/stdout
880 ret="$?"
881 if [ "$ret" != "0" ]; then
882 diff -u $testroot/stdout.expected $testroot/stdout
883 test_done "$testroot" "$ret"
884 return 1
885 fi
887 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
888 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
889 echo "commit $commit1" >> $testroot/stdout.expected
890 echo "commit $commit0" >> $testroot/stdout.expected
891 cmp -s $testroot/stdout.expected $testroot/stdout
892 ret="$?"
893 if [ "$ret" != "0" ]; then
894 diff -u $testroot/stdout.expected $testroot/stdout
895 fi
896 test_done "$testroot" "$ret"
899 test_rebase_out_of_date() {
900 local testroot=`test_init rebase_out_of_date`
901 local initial_commit=`git_show_head $testroot/repo`
903 (cd $testroot/repo && git checkout -q -b newbranch)
904 echo "modified delta on branch" > $testroot/repo/gamma/delta
905 git_commit $testroot/repo -m "committing to delta on newbranch"
907 echo "modified alpha on branch" > $testroot/repo/alpha
908 (cd $testroot/repo && git rm -q beta)
909 echo "new file on branch" > $testroot/repo/epsilon/new
910 (cd $testroot/repo && git add epsilon/new)
911 git_commit $testroot/repo -m "committing more changes on newbranch"
913 local orig_commit1=`git_show_parent_commit $testroot/repo`
914 local orig_commit2=`git_show_head $testroot/repo`
916 (cd $testroot/repo && git checkout -q master)
917 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
918 git_commit $testroot/repo -m "committing to zeta on master"
919 local master_commit1=`git_show_head $testroot/repo`
921 (cd $testroot/repo && git checkout -q master)
922 echo "modified beta on master" > $testroot/repo/beta
923 git_commit $testroot/repo -m "committing to beta on master"
924 local master_commit2=`git_show_head $testroot/repo`
926 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
927 > /dev/null
928 ret="$?"
929 if [ "$ret" != "0" ]; then
930 test_done "$testroot" "$ret"
931 return 1
932 fi
934 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
935 2> $testroot/stderr)
937 echo -n > $testroot/stdout.expected
938 cmp -s $testroot/stdout.expected $testroot/stdout
939 ret="$?"
940 if [ "$ret" != "0" ]; then
941 diff -u $testroot/stdout.expected $testroot/stdout
942 test_done "$testroot" "$ret"
943 return 1
944 fi
946 echo -n "got: work tree must be updated before it can be " \
947 > $testroot/stderr.expected
948 echo "used to rebase a branch" >> $testroot/stderr.expected
949 cmp -s $testroot/stderr.expected $testroot/stderr
950 ret="$?"
951 if [ "$ret" != "0" ]; then
952 diff -u $testroot/stderr.expected $testroot/stderr
953 test_done "$testroot" "$ret"
954 return 1
955 fi
957 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
958 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
959 echo "commit $master_commit1" >> $testroot/stdout.expected
960 echo "commit $initial_commit" >> $testroot/stdout.expected
961 cmp -s $testroot/stdout.expected $testroot/stdout
962 ret="$?"
963 if [ "$ret" != "0" ]; then
964 diff -u $testroot/stdout.expected $testroot/stdout
965 fi
966 test_done "$testroot" "$ret"
969 test_rebase_trims_empty_dir() {
970 local testroot=`test_init rebase_trims_empty_dir`
972 (cd $testroot/repo && git checkout -q -b newbranch)
973 echo "modified delta on branch" > $testroot/repo/gamma/delta
974 git_commit $testroot/repo -m "committing to delta on newbranch"
976 (cd $testroot/repo && git rm -q epsilon/zeta)
977 git_commit $testroot/repo -m "removing zeta on newbranch"
979 local orig_commit1=`git_show_parent_commit $testroot/repo`
980 local orig_commit2=`git_show_head $testroot/repo`
982 (cd $testroot/repo && git checkout -q master)
983 echo "modified alpha on master" > $testroot/repo/alpha
984 git_commit $testroot/repo -m "committing to alpha on master"
985 local master_commit=`git_show_head $testroot/repo`
987 got checkout $testroot/repo $testroot/wt > /dev/null
988 ret="$?"
989 if [ "$ret" != "0" ]; then
990 test_done "$testroot" "$ret"
991 return 1
992 fi
994 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
996 (cd $testroot/repo && git checkout -q newbranch)
997 local new_commit1=`git_show_parent_commit $testroot/repo`
998 local new_commit2=`git_show_head $testroot/repo`
1000 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1001 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1002 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1003 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1005 echo "G gamma/delta" >> $testroot/stdout.expected
1006 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1007 >> $testroot/stdout.expected
1008 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1009 echo "D epsilon/zeta" >> $testroot/stdout.expected
1010 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1011 >> $testroot/stdout.expected
1012 echo ": removing zeta on newbranch" \
1013 >> $testroot/stdout.expected
1014 echo "Switching work tree to refs/heads/newbranch" \
1015 >> $testroot/stdout.expected
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1018 ret="$?"
1019 if [ "$ret" != "0" ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1021 test_done "$testroot" "$ret"
1022 return 1
1025 echo "modified delta on branch" > $testroot/content.expected
1026 cat $testroot/wt/gamma/delta > $testroot/content
1027 cmp -s $testroot/content.expected $testroot/content
1028 ret="$?"
1029 if [ "$ret" != "0" ]; then
1030 diff -u $testroot/content.expected $testroot/content
1031 test_done "$testroot" "$ret"
1032 return 1
1035 echo "modified alpha on master" > $testroot/content.expected
1036 cat $testroot/wt/alpha > $testroot/content
1037 cmp -s $testroot/content.expected $testroot/content
1038 ret="$?"
1039 if [ "$ret" != "0" ]; then
1040 diff -u $testroot/content.expected $testroot/content
1041 test_done "$testroot" "$ret"
1042 return 1
1045 if [ -e $testroot/wt/epsilon ]; then
1046 echo "parent of removed zeta still exists on disk" >&2
1047 test_done "$testroot" "1"
1048 return 1
1051 (cd $testroot/wt && got status > $testroot/stdout)
1053 echo -n > $testroot/stdout.expected
1054 cmp -s $testroot/stdout.expected $testroot/stdout
1055 ret="$?"
1056 if [ "$ret" != "0" ]; then
1057 diff -u $testroot/stdout.expected $testroot/stdout
1058 test_done "$testroot" "$ret"
1059 return 1
1062 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1063 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1064 echo "commit $new_commit1" >> $testroot/stdout.expected
1065 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1066 cmp -s $testroot/stdout.expected $testroot/stdout
1067 ret="$?"
1068 if [ "$ret" != "0" ]; then
1069 diff -u $testroot/stdout.expected $testroot/stdout
1071 test_done "$testroot" "$ret"
1074 test_rebase_delete_missing_file() {
1075 local testroot=`test_init rebase_delete_missing_file`
1077 mkdir -p $testroot/repo/d/f/g
1078 echo "new file" > $testroot/repo/d/f/g/new
1079 (cd $testroot/repo && git add d/f/g/new)
1080 git_commit $testroot/repo -m "adding a subdir"
1081 local commit0=`git_show_head $testroot/repo`
1083 got br -r $testroot/repo -c master newbranch
1085 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1087 echo "modified delta on branch" > $testroot/wt/gamma/delta
1088 (cd $testroot/wt && got commit \
1089 -m "committing to delta on newbranch" > /dev/null)
1091 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1092 (cd $testroot/wt && got commit \
1093 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1095 (cd $testroot/repo && git checkout -q newbranch)
1096 local orig_commit1=`git_show_parent_commit $testroot/repo`
1097 local orig_commit2=`git_show_head $testroot/repo`
1099 (cd $testroot/wt && got update -b master > /dev/null)
1100 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1101 (cd $testroot/wt && got commit \
1102 -m "removing beta and d/f/g/new on master" > /dev/null)
1104 (cd $testroot/repo && git checkout -q master)
1105 local master_commit=`git_show_head $testroot/repo`
1107 (cd $testroot/wt && got update -b master > /dev/null)
1108 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1110 (cd $testroot/repo && git checkout -q newbranch)
1111 local new_commit1=`git_show_head $testroot/repo`
1113 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1114 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1115 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1117 echo "G gamma/delta" >> $testroot/stdout.expected
1118 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1119 >> $testroot/stdout.expected
1120 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1121 echo "! beta" >> $testroot/stdout.expected
1122 echo "! d/f/g/new" >> $testroot/stdout.expected
1123 echo -n "$short_orig_commit2 -> no-op change" \
1124 >> $testroot/stdout.expected
1125 echo ": removing beta and d/f/g/new on newbranch" \
1126 >> $testroot/stdout.expected
1127 echo "Switching work tree to refs/heads/newbranch" \
1128 >> $testroot/stdout.expected
1130 cmp -s $testroot/stdout.expected $testroot/stdout
1131 ret="$?"
1132 if [ "$ret" != "0" ]; then
1133 diff -u $testroot/stdout.expected $testroot/stdout
1134 test_done "$testroot" "$ret"
1135 return 1
1138 echo "modified delta on branch" > $testroot/content.expected
1139 cat $testroot/wt/gamma/delta > $testroot/content
1140 cmp -s $testroot/content.expected $testroot/content
1141 ret="$?"
1142 if [ "$ret" != "0" ]; then
1143 diff -u $testroot/content.expected $testroot/content
1144 test_done "$testroot" "$ret"
1145 return 1
1148 if [ -e $testroot/wt/beta ]; then
1149 echo "removed file beta still exists on disk" >&2
1150 test_done "$testroot" "1"
1151 return 1
1154 (cd $testroot/wt && got status > $testroot/stdout)
1156 echo -n > $testroot/stdout.expected
1157 cmp -s $testroot/stdout.expected $testroot/stdout
1158 ret="$?"
1159 if [ "$ret" != "0" ]; then
1160 diff -u $testroot/stdout.expected $testroot/stdout
1161 test_done "$testroot" "$ret"
1162 return 1
1165 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1166 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1167 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1168 echo "commit $commit0" >> $testroot/stdout.expected
1169 cmp -s $testroot/stdout.expected $testroot/stdout
1170 ret="$?"
1171 if [ "$ret" != "0" ]; then
1172 diff -u $testroot/stdout.expected $testroot/stdout
1174 test_done "$testroot" "$ret"
1177 test_rebase_rm_add_rm_file() {
1178 local testroot=`test_init rebase_rm_add_rm_file`
1180 (cd $testroot/repo && git checkout -q -b newbranch)
1181 (cd $testroot/repo && git rm -q beta)
1182 git_commit $testroot/repo -m "removing beta from newbranch"
1183 local orig_commit1=`git_show_head $testroot/repo`
1185 echo 'restored beta' > $testroot/repo/beta
1186 (cd $testroot/repo && git add beta)
1187 git_commit $testroot/repo -m "restoring beta on newbranch"
1188 local orig_commit2=`git_show_head $testroot/repo`
1190 (cd $testroot/repo && git rm -q beta)
1191 git_commit $testroot/repo -m "removing beta from newbranch again"
1192 local orig_commit3=`git_show_head $testroot/repo`
1194 (cd $testroot/repo && git checkout -q master)
1195 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1196 git_commit $testroot/repo -m "committing to zeta on master"
1197 local master_commit=`git_show_head $testroot/repo`
1199 got checkout $testroot/repo $testroot/wt > /dev/null
1200 ret="$?"
1201 if [ "$ret" != "0" ]; then
1202 test_done "$testroot" "$ret"
1203 return 1
1206 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1208 # this would error out with 'got: file index is corrupt'
1209 (cd $testroot/wt && got status > /dev/null)
1210 ret="$?"
1211 if [ "$ret" != "0" ]; then
1212 echo "got status command failed unexpectedly" >&2
1213 test_done "$testroot" "$ret"
1214 return 1
1217 (cd $testroot/repo && git checkout -q newbranch)
1218 local new_commit3=`git_show_head $testroot/repo`
1219 local new_commit2=`git_show_parent_commit $testroot/repo`
1220 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1222 (cd $testroot/repo && git checkout -q newbranch)
1224 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1225 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1226 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1227 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1228 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1229 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1231 echo "D beta" > $testroot/stdout.expected
1232 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1233 >> $testroot/stdout.expected
1234 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1235 echo "A beta" >> $testroot/stdout.expected
1236 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1237 >> $testroot/stdout.expected
1238 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1239 echo "D beta" >> $testroot/stdout.expected
1240 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1241 >> $testroot/stdout.expected
1242 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1243 echo "Switching work tree to refs/heads/newbranch" \
1244 >> $testroot/stdout.expected
1246 cmp -s $testroot/stdout.expected $testroot/stdout
1247 ret="$?"
1248 if [ "$ret" != "0" ]; then
1249 diff -u $testroot/stdout.expected $testroot/stdout
1250 test_done "$testroot" "$ret"
1251 return 1
1254 (cd $testroot/wt && got status > $testroot/stdout)
1255 ret="$?"
1256 if [ "$ret" != "0" ]; then
1257 echo "got status command failed unexpectedly" >&2
1258 test_done "$testroot" "$ret"
1259 return 1
1262 echo -n > $testroot/stdout.expected
1263 cmp -s $testroot/stdout.expected $testroot/stdout
1264 ret="$?"
1265 if [ "$ret" != "0" ]; then
1266 diff -u $testroot/stdout.expected $testroot/stdout
1267 test_done "$testroot" "$ret"
1268 return 1
1271 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1272 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1273 echo "commit $new_commit2" >> $testroot/stdout.expected
1274 echo "commit $new_commit1" >> $testroot/stdout.expected
1275 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1276 cmp -s $testroot/stdout.expected $testroot/stdout
1277 ret="$?"
1278 if [ "$ret" != "0" ]; then
1279 diff -u $testroot/stdout.expected $testroot/stdout
1281 test_done "$testroot" "$ret"
1284 test_parseargs "$@"
1285 run_test test_rebase_basic
1286 run_test test_rebase_ancestry_check
1287 run_test test_rebase_continue
1288 run_test test_rebase_abort
1289 run_test test_rebase_no_op_change
1290 run_test test_rebase_in_progress
1291 run_test test_rebase_path_prefix
1292 run_test test_rebase_preserves_logmsg
1293 run_test test_rebase_no_commits_to_rebase
1294 run_test test_rebase_forward
1295 run_test test_rebase_out_of_date
1296 run_test test_rebase_trims_empty_dir
1297 run_test test_rebase_delete_missing_file
1298 run_test test_rebase_rm_add_rm_file