Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_rebase_basic {
20 local testroot=`test_init rebase_basic`
22 (cd $testroot/repo && git checkout -q -b newbranch)
23 echo "modified delta on branch" > $testroot/repo/gamma/delta
24 git_commit $testroot/repo -m "committing to delta on newbranch"
26 echo "modified alpha on branch" > $testroot/repo/alpha
27 (cd $testroot/repo && git rm -q beta)
28 echo "new file on branch" > $testroot/repo/epsilon/new
29 (cd $testroot/repo && git add epsilon/new)
30 git_commit $testroot/repo -m "committing more changes on newbranch"
32 local orig_commit1=`git_show_parent_commit $testroot/repo`
33 local orig_commit2=`git_show_head $testroot/repo`
35 (cd $testroot/repo && git checkout -q master)
36 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
37 git_commit $testroot/repo -m "committing to zeta on master"
38 local master_commit=`git_show_head $testroot/repo`
40 got checkout $testroot/repo $testroot/wt > /dev/null
41 ret="$?"
42 if [ "$ret" != "0" ]; then
43 test_done "$testroot" "$ret"
44 return 1
45 fi
47 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
49 (cd $testroot/repo && git checkout -q newbranch)
50 local new_commit1=`git_show_parent_commit $testroot/repo`
51 local new_commit2=`git_show_head $testroot/repo`
53 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
54 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
55 local short_new_commit1=`trim_obj_id 28 $new_commit1`
56 local short_new_commit2=`trim_obj_id 28 $new_commit2`
58 echo "G gamma/delta" >> $testroot/stdout.expected
59 echo -n "$short_orig_commit1 -> $short_new_commit1" \
60 >> $testroot/stdout.expected
61 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
62 echo "G alpha" >> $testroot/stdout.expected
63 echo "D beta" >> $testroot/stdout.expected
64 echo "A epsilon/new" >> $testroot/stdout.expected
65 echo -n "$short_orig_commit2 -> $short_new_commit2" \
66 >> $testroot/stdout.expected
67 echo ": committing more changes on newbranch" \
68 >> $testroot/stdout.expected
69 echo "Switching work tree to refs/heads/newbranch" \
70 >> $testroot/stdout.expected
72 cmp -s $testroot/stdout.expected $testroot/stdout
73 ret="$?"
74 if [ "$ret" != "0" ]; then
75 diff -u $testroot/stdout.expected $testroot/stdout
76 test_done "$testroot" "$ret"
77 return 1
78 fi
80 echo "modified delta on branch" > $testroot/content.expected
81 cat $testroot/wt/gamma/delta > $testroot/content
82 cmp -s $testroot/content.expected $testroot/content
83 ret="$?"
84 if [ "$ret" != "0" ]; then
85 diff -u $testroot/content.expected $testroot/content
86 test_done "$testroot" "$ret"
87 return 1
88 fi
90 echo "modified alpha on branch" > $testroot/content.expected
91 cat $testroot/wt/alpha > $testroot/content
92 cmp -s $testroot/content.expected $testroot/content
93 ret="$?"
94 if [ "$ret" != "0" ]; then
95 diff -u $testroot/content.expected $testroot/content
96 test_done "$testroot" "$ret"
97 return 1
98 fi
100 if [ -e $testroot/wt/beta ]; then
101 echo "removed file beta still exists on disk" >&2
102 test_done "$testroot" "1"
103 return 1
104 fi
106 echo "new file on branch" > $testroot/content.expected
107 cat $testroot/wt/epsilon/new > $testroot/content
108 cmp -s $testroot/content.expected $testroot/content
109 ret="$?"
110 if [ "$ret" != "0" ]; then
111 diff -u $testroot/content.expected $testroot/content
112 test_done "$testroot" "$ret"
113 return 1
114 fi
116 (cd $testroot/wt && got status > $testroot/stdout)
118 echo -n > $testroot/stdout.expected
119 cmp -s $testroot/stdout.expected $testroot/stdout
120 ret="$?"
121 if [ "$ret" != "0" ]; then
122 diff -u $testroot/stdout.expected $testroot/stdout
123 test_done "$testroot" "$ret"
124 return 1
125 fi
127 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
128 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
129 echo "commit $new_commit1" >> $testroot/stdout.expected
130 echo "commit $master_commit (master)" >> $testroot/stdout.expected
131 cmp -s $testroot/stdout.expected $testroot/stdout
132 ret="$?"
133 if [ "$ret" != "0" ]; then
134 diff -u $testroot/stdout.expected $testroot/stdout
135 fi
136 test_done "$testroot" "$ret"
139 function test_rebase_ancestry_check {
140 local testroot=`test_init rebase_ancestry_check`
142 got checkout $testroot/repo $testroot/wt > /dev/null
143 ret="$?"
144 if [ "$ret" != "0" ]; then
145 test_done "$testroot" "$ret"
146 return 1
147 fi
149 (cd $testroot/repo && git checkout -q -b newbranch)
150 echo "modified delta on branch" > $testroot/repo/gamma/delta
151 git_commit $testroot/repo -m "committing to delta on newbranch"
153 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
154 2> $testroot/stderr)
156 echo -n > $testroot/stdout.expected
157 cmp -s $testroot/stdout.expected $testroot/stdout
158 ret="$?"
159 if [ "$ret" != "0" ]; then
160 diff -u $testroot/stdout.expected $testroot/stdout
161 test_done "$testroot" "$ret"
162 return 1
163 fi
165 echo -n "got: specified branch resolves to a commit " \
166 > $testroot/stderr.expected
167 echo "which is already contained in work tree's branch" \
168 >> $testroot/stderr.expected
169 cmp -s $testroot/stderr.expected $testroot/stderr
170 ret="$?"
171 if [ "$ret" != "0" ]; then
172 diff -u $testroot/stderr.expected $testroot/stderr
173 fi
174 test_done "$testroot" "$ret"
177 function test_rebase_continue {
178 local testroot=`test_init rebase_continue`
179 local init_commit=`git_show_head $testroot/repo`
181 (cd $testroot/repo && git checkout -q -b newbranch)
182 echo "modified alpha on branch" > $testroot/repo/alpha
183 git_commit $testroot/repo -m "committing to alpha on newbranch"
184 local orig_commit1=`git_show_head $testroot/repo`
185 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
187 (cd $testroot/repo && git checkout -q master)
188 echo "modified alpha on master" > $testroot/repo/alpha
189 git_commit $testroot/repo -m "committing to alpha on master"
190 local master_commit=`git_show_head $testroot/repo`
192 got checkout $testroot/repo $testroot/wt > /dev/null
193 ret="$?"
194 if [ "$ret" != "0" ]; then
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
200 2> $testroot/stderr)
202 echo "C alpha" > $testroot/stdout.expected
203 echo -n "$short_orig_commit1 -> merge conflict" \
204 >> $testroot/stdout.expected
205 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
206 cmp -s $testroot/stdout.expected $testroot/stdout
207 ret="$?"
208 if [ "$ret" != "0" ]; then
209 diff -u $testroot/stdout.expected $testroot/stdout
210 test_done "$testroot" "$ret"
211 return 1
212 fi
214 echo "got: conflicts must be resolved before rebasing can continue" \
215 > $testroot/stderr.expected
216 cmp -s $testroot/stderr.expected $testroot/stderr
217 ret="$?"
218 if [ "$ret" != "0" ]; then
219 diff -u $testroot/stderr.expected $testroot/stderr
220 test_done "$testroot" "$ret"
221 return 1
222 fi
224 echo "<<<<<<< merged change: commit $orig_commit1" \
225 > $testroot/content.expected
226 echo "modified alpha on branch" >> $testroot/content.expected
227 echo "||||||| 3-way merge base: commit $init_commit" \
228 >> $testroot/content.expected
229 echo "alpha" >> $testroot/content.expected
230 echo "=======" >> $testroot/content.expected
231 echo "modified alpha on master" >> $testroot/content.expected
232 echo '>>>>>>>' >> $testroot/content.expected
233 cat $testroot/wt/alpha > $testroot/content
234 cmp -s $testroot/content.expected $testroot/content
235 ret="$?"
236 if [ "$ret" != "0" ]; then
237 diff -u $testroot/content.expected $testroot/content
238 test_done "$testroot" "$ret"
239 return 1
240 fi
242 (cd $testroot/wt && got status > $testroot/stdout)
244 echo "C alpha" > $testroot/stdout.expected
245 cmp -s $testroot/stdout.expected $testroot/stdout
246 ret="$?"
247 if [ "$ret" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 test_done "$testroot" "$ret"
250 return 1
251 fi
253 # resolve the conflict
254 echo "modified alpha on branch and master" > $testroot/wt/alpha
256 # test interaction of 'got stage' and rebase -c
257 (cd $testroot/wt && got stage alpha > /dev/null)
258 (cd $testroot/wt && got rebase -c > $testroot/stdout \
259 2> $testroot/stderr)
260 ret="$?"
261 if [ "$ret" == "0" ]; then
262 echo "rebase succeeded unexpectedly" >&2
263 test_done "$testroot" "1"
264 return 1
265 fi
266 echo -n "got: work tree contains files with staged changes; " \
267 > $testroot/stderr.expected
268 echo "these changes must be committed or unstaged first" \
269 >> $testroot/stderr.expected
270 cmp -s $testroot/stderr.expected $testroot/stderr
271 ret="$?"
272 if [ "$ret" != "0" ]; then
273 diff -u $testroot/stderr.expected $testroot/stderr
274 test_done "$testroot" "$ret"
275 return 1
276 fi
278 (cd $testroot/wt && got unstage alpha > /dev/null)
279 (cd $testroot/wt && got rebase -c > $testroot/stdout)
281 (cd $testroot/repo && git checkout -q newbranch)
282 local new_commit1=`git_show_head $testroot/repo`
283 local short_new_commit1=`trim_obj_id 28 $new_commit1`
285 echo -n "$short_orig_commit1 -> $short_new_commit1" \
286 > $testroot/stdout.expected
287 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
288 echo "Switching work tree to refs/heads/newbranch" \
289 >> $testroot/stdout.expected
291 cmp -s $testroot/stdout.expected $testroot/stdout
292 ret="$?"
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/stdout.expected $testroot/stdout
295 test_done "$testroot" "$ret"
296 return 1
297 fi
300 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
301 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
302 echo "commit $master_commit (master)" >> $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 fi
308 test_done "$testroot" "$ret"
311 function test_rebase_abort {
312 local testroot=`test_init rebase_abort`
314 local init_commit=`git_show_head $testroot/repo`
316 (cd $testroot/repo && git checkout -q -b newbranch)
317 echo "modified alpha on branch" > $testroot/repo/alpha
318 git_commit $testroot/repo -m "committing to alpha on newbranch"
319 local orig_commit1=`git_show_head $testroot/repo`
320 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
322 (cd $testroot/repo && git checkout -q master)
323 echo "modified alpha on master" > $testroot/repo/alpha
324 git_commit $testroot/repo -m "committing to alpha on master"
325 local master_commit=`git_show_head $testroot/repo`
327 got checkout $testroot/repo $testroot/wt > /dev/null
328 ret="$?"
329 if [ "$ret" != "0" ]; then
330 test_done "$testroot" "$ret"
331 return 1
332 fi
334 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
335 2> $testroot/stderr)
337 echo "C alpha" > $testroot/stdout.expected
338 echo -n "$short_orig_commit1 -> merge conflict" \
339 >> $testroot/stdout.expected
340 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
341 cmp -s $testroot/stdout.expected $testroot/stdout
342 ret="$?"
343 if [ "$ret" != "0" ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
346 return 1
347 fi
349 echo "got: conflicts must be resolved before rebasing can continue" \
350 > $testroot/stderr.expected
351 cmp -s $testroot/stderr.expected $testroot/stderr
352 ret="$?"
353 if [ "$ret" != "0" ]; then
354 diff -u $testroot/stderr.expected $testroot/stderr
355 test_done "$testroot" "$ret"
356 return 1
357 fi
359 echo "<<<<<<< merged change: commit $orig_commit1" \
360 > $testroot/content.expected
361 echo "modified alpha on branch" >> $testroot/content.expected
362 echo "||||||| 3-way merge base: commit $init_commit" \
363 >> $testroot/content.expected
364 echo "alpha" >> $testroot/content.expected
365 echo "=======" >> $testroot/content.expected
366 echo "modified alpha on master" >> $testroot/content.expected
367 echo '>>>>>>>' >> $testroot/content.expected
368 cat $testroot/wt/alpha > $testroot/content
369 cmp -s $testroot/content.expected $testroot/content
370 ret="$?"
371 if [ "$ret" != "0" ]; then
372 diff -u $testroot/content.expected $testroot/content
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 (cd $testroot/wt && got status > $testroot/stdout)
379 echo "C alpha" > $testroot/stdout.expected
380 cmp -s $testroot/stdout.expected $testroot/stdout
381 ret="$?"
382 if [ "$ret" != "0" ]; then
383 diff -u $testroot/stdout.expected $testroot/stdout
384 test_done "$testroot" "$ret"
385 return 1
386 fi
388 (cd $testroot/wt && got rebase -a > $testroot/stdout)
390 (cd $testroot/repo && git checkout -q newbranch)
392 echo "Switching work tree to refs/heads/master" \
393 > $testroot/stdout.expected
394 echo 'R alpha' >> $testroot/stdout.expected
395 echo "Rebase of refs/heads/newbranch aborted" \
396 >> $testroot/stdout.expected
398 cmp -s $testroot/stdout.expected $testroot/stdout
399 ret="$?"
400 if [ "$ret" != "0" ]; then
401 diff -u $testroot/stdout.expected $testroot/stdout
402 test_done "$testroot" "$ret"
403 return 1
404 fi
406 echo "modified alpha on master" > $testroot/content.expected
407 cat $testroot/wt/alpha > $testroot/content
408 cmp -s $testroot/content.expected $testroot/content
409 ret="$?"
410 if [ "$ret" != "0" ]; then
411 diff -u $testroot/content.expected $testroot/content
412 test_done "$testroot" "$ret"
413 return 1
414 fi
416 (cd $testroot/wt && got log -l3 -c newbranch \
417 | grep ^commit > $testroot/stdout)
418 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
419 echo "commit $init_commit" >> $testroot/stdout.expected
420 cmp -s $testroot/stdout.expected $testroot/stdout
421 ret="$?"
422 if [ "$ret" != "0" ]; then
423 diff -u $testroot/stdout.expected $testroot/stdout
424 fi
425 test_done "$testroot" "$ret"
428 function test_rebase_no_op_change {
429 local testroot=`test_init rebase_no_op_change`
430 local init_commit=`git_show_head $testroot/repo`
432 (cd $testroot/repo && git checkout -q -b newbranch)
433 echo "modified alpha on branch" > $testroot/repo/alpha
434 git_commit $testroot/repo -m "committing to alpha on newbranch"
435 local orig_commit1=`git_show_head $testroot/repo`
436 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
438 (cd $testroot/repo && git checkout -q master)
439 echo "modified alpha on master" > $testroot/repo/alpha
440 git_commit $testroot/repo -m "committing to alpha on master"
441 local master_commit=`git_show_head $testroot/repo`
443 got checkout $testroot/repo $testroot/wt > /dev/null
444 ret="$?"
445 if [ "$ret" != "0" ]; then
446 test_done "$testroot" "$ret"
447 return 1
448 fi
450 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
451 2> $testroot/stderr)
453 echo "C alpha" > $testroot/stdout.expected
454 echo -n "$short_orig_commit1 -> merge conflict" \
455 >> $testroot/stdout.expected
456 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
457 cmp -s $testroot/stdout.expected $testroot/stdout
458 ret="$?"
459 if [ "$ret" != "0" ]; then
460 diff -u $testroot/stdout.expected $testroot/stdout
461 test_done "$testroot" "$ret"
462 return 1
463 fi
465 echo "got: conflicts must be resolved before rebasing can continue" \
466 > $testroot/stderr.expected
467 cmp -s $testroot/stderr.expected $testroot/stderr
468 ret="$?"
469 if [ "$ret" != "0" ]; then
470 diff -u $testroot/stderr.expected $testroot/stderr
471 test_done "$testroot" "$ret"
472 return 1
473 fi
475 echo "<<<<<<< merged change: commit $orig_commit1" \
476 > $testroot/content.expected
477 echo "modified alpha on branch" >> $testroot/content.expected
478 echo "||||||| 3-way merge base: commit $init_commit" \
479 >> $testroot/content.expected
480 echo "alpha" >> $testroot/content.expected
481 echo "=======" >> $testroot/content.expected
482 echo "modified alpha on master" >> $testroot/content.expected
483 echo '>>>>>>>' >> $testroot/content.expected
484 cat $testroot/wt/alpha > $testroot/content
485 cmp -s $testroot/content.expected $testroot/content
486 ret="$?"
487 if [ "$ret" != "0" ]; then
488 diff -u $testroot/content.expected $testroot/content
489 test_done "$testroot" "$ret"
490 return 1
491 fi
493 (cd $testroot/wt && got status > $testroot/stdout)
495 echo "C alpha" > $testroot/stdout.expected
496 cmp -s $testroot/stdout.expected $testroot/stdout
497 ret="$?"
498 if [ "$ret" != "0" ]; then
499 diff -u $testroot/stdout.expected $testroot/stdout
500 test_done "$testroot" "$ret"
501 return 1
502 fi
504 # resolve the conflict
505 echo "modified alpha on master" > $testroot/wt/alpha
507 (cd $testroot/wt && got rebase -c > $testroot/stdout)
509 (cd $testroot/repo && git checkout -q newbranch)
510 local new_commit1=`git_show_head $testroot/repo`
512 echo -n "$short_orig_commit1 -> no-op change" \
513 > $testroot/stdout.expected
514 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
515 echo "Switching work tree to refs/heads/newbranch" \
516 >> $testroot/stdout.expected
518 cmp -s $testroot/stdout.expected $testroot/stdout
519 ret="$?"
520 if [ "$ret" != "0" ]; then
521 diff -u $testroot/stdout.expected $testroot/stdout
522 test_done "$testroot" "$ret"
523 return 1
524 fi
527 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
528 echo "commit $master_commit (master, newbranch)" \
529 > $testroot/stdout.expected
530 echo "commit $init_commit" >> $testroot/stdout.expected
531 cmp -s $testroot/stdout.expected $testroot/stdout
532 ret="$?"
533 if [ "$ret" != "0" ]; then
534 diff -u $testroot/stdout.expected $testroot/stdout
535 fi
536 test_done "$testroot" "$ret"
539 function test_rebase_in_progress {
540 local testroot=`test_init rebase_in_progress`
541 local init_commit=`git_show_head $testroot/repo`
543 (cd $testroot/repo && git checkout -q -b newbranch)
544 echo "modified alpha on branch" > $testroot/repo/alpha
545 git_commit $testroot/repo -m "committing to alpha on newbranch"
546 local orig_commit1=`git_show_head $testroot/repo`
547 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
549 (cd $testroot/repo && git checkout -q master)
550 echo "modified alpha on master" > $testroot/repo/alpha
551 git_commit $testroot/repo -m "committing to alpha on master"
552 local master_commit=`git_show_head $testroot/repo`
554 got checkout $testroot/repo $testroot/wt > /dev/null
555 ret="$?"
556 if [ "$ret" != "0" ]; then
557 test_done "$testroot" "$ret"
558 return 1
559 fi
561 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
562 2> $testroot/stderr)
564 echo "C alpha" > $testroot/stdout.expected
565 echo -n "$short_orig_commit1 -> merge conflict" \
566 >> $testroot/stdout.expected
567 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
568 cmp -s $testroot/stdout.expected $testroot/stdout
569 ret="$?"
570 if [ "$ret" != "0" ]; then
571 diff -u $testroot/stdout.expected $testroot/stdout
572 test_done "$testroot" "$ret"
573 return 1
574 fi
576 echo "got: conflicts must be resolved before rebasing can continue" \
577 > $testroot/stderr.expected
578 cmp -s $testroot/stderr.expected $testroot/stderr
579 ret="$?"
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/stderr.expected $testroot/stderr
582 test_done "$testroot" "$ret"
583 return 1
584 fi
586 echo "<<<<<<< merged change: commit $orig_commit1" \
587 > $testroot/content.expected
588 echo "modified alpha on branch" >> $testroot/content.expected
589 echo "||||||| 3-way merge base: commit $init_commit" \
590 >> $testroot/content.expected
591 echo "alpha" >> $testroot/content.expected
592 echo "=======" >> $testroot/content.expected
593 echo "modified alpha on master" >> $testroot/content.expected
594 echo '>>>>>>>' >> $testroot/content.expected
595 cat $testroot/wt/alpha > $testroot/content
596 cmp -s $testroot/content.expected $testroot/content
597 ret="$?"
598 if [ "$ret" != "0" ]; then
599 diff -u $testroot/content.expected $testroot/content
600 test_done "$testroot" "$ret"
601 return 1
602 fi
604 (cd $testroot/wt && got status > $testroot/stdout)
606 echo "C alpha" > $testroot/stdout.expected
607 cmp -s $testroot/stdout.expected $testroot/stdout
608 ret="$?"
609 if [ "$ret" != "0" ]; then
610 diff -u $testroot/stdout.expected $testroot/stdout
611 test_done "$testroot" "$ret"
612 return 1
613 fi
615 for cmd in update commit; do
616 (cd $testroot/wt && got $cmd > $testroot/stdout \
617 2> $testroot/stderr)
619 echo -n > $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
621 ret="$?"
622 if [ "$ret" != "0" ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
625 return 1
626 fi
628 echo -n "got: a rebase operation is in progress in this " \
629 > $testroot/stderr.expected
630 echo "work tree and must be continued or aborted first" \
631 >> $testroot/stderr.expected
632 cmp -s $testroot/stderr.expected $testroot/stderr
633 ret="$?"
634 if [ "$ret" != "0" ]; then
635 diff -u $testroot/stderr.expected $testroot/stderr
636 test_done "$testroot" "$ret"
637 return 1
638 fi
639 done
641 test_done "$testroot" "$ret"
644 function test_rebase_path_prefix {
645 local testroot=`test_init rebase_path_prefix`
647 (cd $testroot/repo && git checkout -q -b newbranch)
648 echo "modified delta on branch" > $testroot/repo/gamma/delta
649 git_commit $testroot/repo -m "committing to delta on newbranch"
651 local orig_commit1=`git_show_parent_commit $testroot/repo`
652 local orig_commit2=`git_show_head $testroot/repo`
654 (cd $testroot/repo && git checkout -q master)
655 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
656 git_commit $testroot/repo -m "committing to zeta on master"
657 local master_commit=`git_show_head $testroot/repo`
659 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
660 ret="$?"
661 if [ "$ret" != "0" ]; then
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 (cd $testroot/wt && got rebase newbranch \
667 > $testroot/stdout 2> $testroot/stderr)
669 echo -n > $testroot/stdout.expected
670 cmp -s $testroot/stdout.expected $testroot/stdout
671 ret="$?"
672 if [ "$ret" != "0" ]; then
673 diff -u $testroot/stdout.expected $testroot/stdout
674 test_done "$testroot" "$ret"
675 return 1
676 fi
678 echo -n "got: cannot rebase branch which contains changes outside " \
679 > $testroot/stderr.expected
680 echo "of this work tree's path prefix" >> $testroot/stderr.expected
681 cmp -s $testroot/stderr.expected $testroot/stderr
682 ret="$?"
683 if [ "$ret" != "0" ]; then
684 diff -u $testroot/stderr.expected $testroot/stderr
685 fi
686 test_done "$testroot" "$ret"
689 function test_rebase_preserves_logmsg {
690 local testroot=`test_init rebase_preserves_logmsg`
692 (cd $testroot/repo && git checkout -q -b newbranch)
693 echo "modified delta on branch" > $testroot/repo/gamma/delta
694 git_commit $testroot/repo -m "modified delta on newbranch"
696 echo "modified alpha on branch" > $testroot/repo/alpha
697 git_commit $testroot/repo -m "modified alpha on newbranch"
699 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
700 > $testroot/log.expected)
702 local orig_commit1=`git_show_parent_commit $testroot/repo`
703 local orig_commit2=`git_show_head $testroot/repo`
705 (cd $testroot/repo && git checkout -q master)
706 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
707 git_commit $testroot/repo -m "committing to zeta on master"
708 local master_commit=`git_show_head $testroot/repo`
710 got checkout $testroot/repo $testroot/wt > /dev/null
711 ret="$?"
712 if [ "$ret" != "0" ]; then
713 test_done "$testroot" "$ret"
714 return 1
715 fi
717 (cd $testroot/wt && got rebase newbranch > /dev/null \
718 2> $testroot/stderr)
720 (cd $testroot/repo && git checkout -q newbranch)
721 local new_commit1=`git_show_parent_commit $testroot/repo`
722 local new_commit2=`git_show_head $testroot/repo`
724 echo -n > $testroot/stderr.expected
725 cmp -s $testroot/stderr.expected $testroot/stderr
726 ret="$?"
727 if [ "$ret" != "0" ]; then
728 diff -u $testroot/stderr.expected $testroot/stderr
729 test_done "$testroot" "$ret"
730 return 1
731 fi
733 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
734 > $testroot/log)
735 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
736 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
737 cmp -s $testroot/log.expected $testroot/log
738 ret="$?"
739 if [ "$ret" != "0" ]; then
740 diff -u $testroot/log.expected $testroot/log
741 fi
743 test_done "$testroot" "$ret"
746 function test_rebase_no_commits_to_rebase {
747 local testroot=`test_init rebase_no_commits_to_rebase`
749 got checkout $testroot/repo $testroot/wt > /dev/null
750 ret="$?"
751 if [ "$ret" != "0" ]; then
752 test_done "$testroot" "$ret"
753 return 1
754 fi
756 (cd $testroot/wt && got branch -n newbranch)
758 echo "modified alpha on master" > $testroot/wt/alpha
759 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
760 > /dev/null)
761 (cd $testroot/wt && got update > /dev/null)
763 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
764 2> $testroot/stderr)
766 echo "got: no commits to rebase" > $testroot/stderr.expected
767 cmp -s $testroot/stderr.expected $testroot/stderr
768 ret="$?"
769 if [ "$ret" != "0" ]; then
770 diff -u $testroot/stderr.expected $testroot/stderr
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 echo "Rebase of refs/heads/newbranch aborted" \
776 > $testroot/stdout.expected
777 cmp -s $testroot/stdout.expected $testroot/stdout
778 ret="$?"
779 if [ "$ret" != "0" ]; then
780 diff -u $testroot/stdout.expected $testroot/stdout
781 test_done "$testroot" "$ret"
782 return 1
783 fi
785 (cd $testroot/wt && got update > $testroot/stdout)
786 echo "Already up-to-date" > $testroot/stdout.expected
787 cmp -s $testroot/stdout.expected $testroot/stdout
788 ret="$?"
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stdout.expected $testroot/stdout
791 fi
792 test_done "$testroot" "$ret"
795 function test_rebase_forward {
796 local testroot=`test_init rebase_forward`
797 local commit0=`git_show_head $testroot/repo`
799 got checkout $testroot/repo $testroot/wt > /dev/null
800 ret="$?"
801 if [ "$ret" != "0" ]; then
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 echo "change alpha 1" > $testroot/wt/alpha
807 (cd $testroot/wt && got commit -m 'test rebase_forward' \
808 > /dev/null)
809 local commit1=`git_show_head $testroot/repo`
811 echo "change alpha 2" > $testroot/wt/alpha
812 (cd $testroot/wt && got commit -m 'test rebase_forward' \
813 > /dev/null)
814 local commit2=`git_show_head $testroot/repo`
816 # Simulate a situation where fast-forward is required.
817 # We want to fast-forward master to origin/master:
818 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
819 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
820 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
821 (cd $testroot/repo && got ref -d master)
822 (cd $testroot/repo && got ref refs/heads/master $commit1)
823 (cd $testroot/repo && got ref refs/remotes/origin/master $commit2)
826 (cd $testroot/wt && got up -b origin/master > /dev/null)
828 (cd $testroot/wt && got rebase master \
829 > $testroot/stdout 2> $testroot/stderr)
831 echo "Forwarding refs/heads/master to commit $commit2" \
832 > $testroot/stdout.expected
833 echo "Switching work tree to refs/heads/master" \
834 >> $testroot/stdout.expected
835 cmp -s $testroot/stdout.expected $testroot/stdout
836 ret="$?"
837 if [ "$ret" != "0" ]; then
838 diff -u $testroot/stdout.expected $testroot/stdout
839 test_done "$testroot" "$ret"
840 return 1
841 fi
843 # Ensure that rebase operation was completed correctly
844 (cd $testroot/wt && got rebase -a \
845 > $testroot/stdout 2> $testroot/stderr)
846 echo -n "" > $testroot/stdout.expected
847 cmp -s $testroot/stdout.expected $testroot/stdout
848 ret="$?"
849 if [ "$ret" != "0" ]; then
850 diff -u $testroot/stdout.expected $testroot/stdout
851 test_done "$testroot" "$ret"
852 return 1
853 fi
854 echo "got: rebase operation not in progress" > $testroot/stderr.expected
855 cmp -s $testroot/stderr.expected $testroot/stderr
856 ret="$?"
857 if [ "$ret" != "0" ]; then
858 diff -u $testroot/stderr.expected $testroot/stderr
859 test_done "$testroot" "$ret"
860 return 1
861 fi
863 (cd $testroot/wt && got branch -n > $testroot/stdout)
864 echo "master" > $testroot/stdout.expected
865 cmp -s $testroot/stdout.expected $testroot/stdout
866 ret="$?"
867 if [ "$ret" != "0" ]; then
868 diff -u $testroot/stdout.expected $testroot/stdout
869 test_done "$testroot" "$ret"
870 return 1
871 fi
873 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
874 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
875 echo "commit $commit1" >> $testroot/stdout.expected
876 echo "commit $commit0" >> $testroot/stdout.expected
877 cmp -s $testroot/stdout.expected $testroot/stdout
878 ret="$?"
879 if [ "$ret" != "0" ]; then
880 diff -u $testroot/stdout.expected $testroot/stdout
881 fi
882 test_done "$testroot" "$ret"
885 function test_rebase_out_of_date {
886 local testroot=`test_init rebase_out_of_date`
887 local initial_commit=`git_show_head $testroot/repo`
889 (cd $testroot/repo && git checkout -q -b newbranch)
890 echo "modified delta on branch" > $testroot/repo/gamma/delta
891 git_commit $testroot/repo -m "committing to delta on newbranch"
893 echo "modified alpha on branch" > $testroot/repo/alpha
894 (cd $testroot/repo && git rm -q beta)
895 echo "new file on branch" > $testroot/repo/epsilon/new
896 (cd $testroot/repo && git add epsilon/new)
897 git_commit $testroot/repo -m "committing more changes on newbranch"
899 local orig_commit1=`git_show_parent_commit $testroot/repo`
900 local orig_commit2=`git_show_head $testroot/repo`
902 (cd $testroot/repo && git checkout -q master)
903 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
904 git_commit $testroot/repo -m "committing to zeta on master"
905 local master_commit1=`git_show_head $testroot/repo`
907 (cd $testroot/repo && git checkout -q master)
908 echo "modified beta on master" > $testroot/repo/beta
909 git_commit $testroot/repo -m "committing to beta on master"
910 local master_commit2=`git_show_head $testroot/repo`
912 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
913 > /dev/null
914 ret="$?"
915 if [ "$ret" != "0" ]; then
916 test_done "$testroot" "$ret"
917 return 1
918 fi
920 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
921 2> $testroot/stderr)
923 echo -n > $testroot/stdout.expected
924 cmp -s $testroot/stdout.expected $testroot/stdout
925 ret="$?"
926 if [ "$ret" != "0" ]; then
927 diff -u $testroot/stdout.expected $testroot/stdout
928 test_done "$testroot" "$ret"
929 return 1
930 fi
932 echo -n "got: work tree must be updated before it can be " \
933 > $testroot/stderr.expected
934 echo "used to rebase a branch" >> $testroot/stderr.expected
935 cmp -s $testroot/stderr.expected $testroot/stderr
936 ret="$?"
937 if [ "$ret" != "0" ]; then
938 diff -u $testroot/stderr.expected $testroot/stderr
939 test_done "$testroot" "$ret"
940 return 1
941 fi
943 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
944 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
945 echo "commit $master_commit1" >> $testroot/stdout.expected
946 echo "commit $initial_commit" >> $testroot/stdout.expected
947 cmp -s $testroot/stdout.expected $testroot/stdout
948 ret="$?"
949 if [ "$ret" != "0" ]; then
950 diff -u $testroot/stdout.expected $testroot/stdout
951 fi
952 test_done "$testroot" "$ret"
955 function test_rebase_trims_empty_dir {
956 local testroot=`test_init rebase_trims_empty_dir`
958 (cd $testroot/repo && git checkout -q -b newbranch)
959 echo "modified delta on branch" > $testroot/repo/gamma/delta
960 git_commit $testroot/repo -m "committing to delta on newbranch"
962 (cd $testroot/repo && git rm -q epsilon/zeta)
963 git_commit $testroot/repo -m "removing zeta on newbranch"
965 local orig_commit1=`git_show_parent_commit $testroot/repo`
966 local orig_commit2=`git_show_head $testroot/repo`
968 (cd $testroot/repo && git checkout -q master)
969 echo "modified alpha on master" > $testroot/repo/alpha
970 git_commit $testroot/repo -m "committing to alpha on master"
971 local master_commit=`git_show_head $testroot/repo`
973 got checkout $testroot/repo $testroot/wt > /dev/null
974 ret="$?"
975 if [ "$ret" != "0" ]; then
976 test_done "$testroot" "$ret"
977 return 1
978 fi
980 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
982 (cd $testroot/repo && git checkout -q newbranch)
983 local new_commit1=`git_show_parent_commit $testroot/repo`
984 local new_commit2=`git_show_head $testroot/repo`
986 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
987 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
988 local short_new_commit1=`trim_obj_id 28 $new_commit1`
989 local short_new_commit2=`trim_obj_id 28 $new_commit2`
991 echo "G gamma/delta" >> $testroot/stdout.expected
992 echo -n "$short_orig_commit1 -> $short_new_commit1" \
993 >> $testroot/stdout.expected
994 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
995 echo "D epsilon/zeta" >> $testroot/stdout.expected
996 echo -n "$short_orig_commit2 -> $short_new_commit2" \
997 >> $testroot/stdout.expected
998 echo ": removing zeta on newbranch" \
999 >> $testroot/stdout.expected
1000 echo "Switching work tree to refs/heads/newbranch" \
1001 >> $testroot/stdout.expected
1003 cmp -s $testroot/stdout.expected $testroot/stdout
1004 ret="$?"
1005 if [ "$ret" != "0" ]; then
1006 diff -u $testroot/stdout.expected $testroot/stdout
1007 test_done "$testroot" "$ret"
1008 return 1
1011 echo "modified delta on branch" > $testroot/content.expected
1012 cat $testroot/wt/gamma/delta > $testroot/content
1013 cmp -s $testroot/content.expected $testroot/content
1014 ret="$?"
1015 if [ "$ret" != "0" ]; then
1016 diff -u $testroot/content.expected $testroot/content
1017 test_done "$testroot" "$ret"
1018 return 1
1021 echo "modified alpha on master" > $testroot/content.expected
1022 cat $testroot/wt/alpha > $testroot/content
1023 cmp -s $testroot/content.expected $testroot/content
1024 ret="$?"
1025 if [ "$ret" != "0" ]; then
1026 diff -u $testroot/content.expected $testroot/content
1027 test_done "$testroot" "$ret"
1028 return 1
1031 if [ -e $testroot/wt/epsilon ]; then
1032 echo "parent of removed zeta still exists on disk" >&2
1033 test_done "$testroot" "1"
1034 return 1
1037 (cd $testroot/wt && got status > $testroot/stdout)
1039 echo -n > $testroot/stdout.expected
1040 cmp -s $testroot/stdout.expected $testroot/stdout
1041 ret="$?"
1042 if [ "$ret" != "0" ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1045 return 1
1048 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1049 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1050 echo "commit $new_commit1" >> $testroot/stdout.expected
1051 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1052 cmp -s $testroot/stdout.expected $testroot/stdout
1053 ret="$?"
1054 if [ "$ret" != "0" ]; then
1055 diff -u $testroot/stdout.expected $testroot/stdout
1057 test_done "$testroot" "$ret"
1060 run_test test_rebase_basic
1061 run_test test_rebase_ancestry_check
1062 run_test test_rebase_continue
1063 run_test test_rebase_abort
1064 run_test test_rebase_no_op_change
1065 run_test test_rebase_in_progress
1066 run_test test_rebase_path_prefix
1067 run_test test_rebase_preserves_logmsg
1068 run_test test_rebase_no_commits_to_rebase
1069 run_test test_rebase_forward
1070 run_test test_rebase_out_of_date
1071 run_test test_rebase_trims_empty_dir