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 "Files with new merge conflicts: 1" >> $testroot/stdout.expected
204 echo -n "$short_orig_commit1 -> merge conflict" \
205 >> $testroot/stdout.expected
206 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
207 cmp -s $testroot/stdout.expected $testroot/stdout
208 ret="$?"
209 if [ "$ret" != "0" ]; then
210 diff -u $testroot/stdout.expected $testroot/stdout
211 test_done "$testroot" "$ret"
212 return 1
213 fi
215 echo "got: conflicts must be resolved before rebasing can continue" \
216 > $testroot/stderr.expected
217 cmp -s $testroot/stderr.expected $testroot/stderr
218 ret="$?"
219 if [ "$ret" != "0" ]; then
220 diff -u $testroot/stderr.expected $testroot/stderr
221 test_done "$testroot" "$ret"
222 return 1
223 fi
225 echo "<<<<<<< merged change: commit $orig_commit1" \
226 > $testroot/content.expected
227 echo "modified alpha on branch" >> $testroot/content.expected
228 echo "||||||| 3-way merge base: commit $init_commit" \
229 >> $testroot/content.expected
230 echo "alpha" >> $testroot/content.expected
231 echo "=======" >> $testroot/content.expected
232 echo "modified alpha on master" >> $testroot/content.expected
233 echo '>>>>>>>' >> $testroot/content.expected
234 cat $testroot/wt/alpha > $testroot/content
235 cmp -s $testroot/content.expected $testroot/content
236 ret="$?"
237 if [ "$ret" != "0" ]; then
238 diff -u $testroot/content.expected $testroot/content
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 (cd $testroot/wt && got status > $testroot/stdout)
245 echo "C alpha" > $testroot/stdout.expected
246 cmp -s $testroot/stdout.expected $testroot/stdout
247 ret="$?"
248 if [ "$ret" != "0" ]; then
249 diff -u $testroot/stdout.expected $testroot/stdout
250 test_done "$testroot" "$ret"
251 return 1
252 fi
254 # resolve the conflict
255 echo "modified alpha on branch and master" > $testroot/wt/alpha
257 # test interaction of 'got stage' and rebase -c
258 (cd $testroot/wt && got stage alpha > /dev/null)
259 (cd $testroot/wt && got rebase -c > $testroot/stdout \
260 2> $testroot/stderr)
261 ret="$?"
262 if [ "$ret" == "0" ]; then
263 echo "rebase succeeded unexpectedly" >&2
264 test_done "$testroot" "1"
265 return 1
266 fi
267 echo -n "got: work tree contains files with staged changes; " \
268 > $testroot/stderr.expected
269 echo "these changes must be committed or unstaged first" \
270 >> $testroot/stderr.expected
271 cmp -s $testroot/stderr.expected $testroot/stderr
272 ret="$?"
273 if [ "$ret" != "0" ]; then
274 diff -u $testroot/stderr.expected $testroot/stderr
275 test_done "$testroot" "$ret"
276 return 1
277 fi
279 (cd $testroot/wt && got unstage alpha > /dev/null)
280 (cd $testroot/wt && got rebase -c > $testroot/stdout)
282 (cd $testroot/repo && git checkout -q newbranch)
283 local new_commit1=`git_show_head $testroot/repo`
284 local short_new_commit1=`trim_obj_id 28 $new_commit1`
286 echo -n "$short_orig_commit1 -> $short_new_commit1" \
287 > $testroot/stdout.expected
288 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
289 echo "Switching work tree to refs/heads/newbranch" \
290 >> $testroot/stdout.expected
292 cmp -s $testroot/stdout.expected $testroot/stdout
293 ret="$?"
294 if [ "$ret" != "0" ]; then
295 diff -u $testroot/stdout.expected $testroot/stdout
296 test_done "$testroot" "$ret"
297 return 1
298 fi
301 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
302 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
303 echo "commit $master_commit (master)" >> $testroot/stdout.expected
304 cmp -s $testroot/stdout.expected $testroot/stdout
305 ret="$?"
306 if [ "$ret" != "0" ]; then
307 diff -u $testroot/stdout.expected $testroot/stdout
308 fi
309 test_done "$testroot" "$ret"
312 function test_rebase_abort {
313 local testroot=`test_init rebase_abort`
315 local init_commit=`git_show_head $testroot/repo`
317 (cd $testroot/repo && git checkout -q -b newbranch)
318 echo "modified alpha on branch" > $testroot/repo/alpha
319 git_commit $testroot/repo -m "committing to alpha on newbranch"
320 local orig_commit1=`git_show_head $testroot/repo`
321 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
323 (cd $testroot/repo && git checkout -q master)
324 echo "modified alpha on master" > $testroot/repo/alpha
325 git_commit $testroot/repo -m "committing to alpha on master"
326 local master_commit=`git_show_head $testroot/repo`
328 got checkout $testroot/repo $testroot/wt > /dev/null
329 ret="$?"
330 if [ "$ret" != "0" ]; then
331 test_done "$testroot" "$ret"
332 return 1
333 fi
335 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
336 2> $testroot/stderr)
338 echo "C alpha" > $testroot/stdout.expected
339 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
340 echo -n "$short_orig_commit1 -> merge conflict" \
341 >> $testroot/stdout.expected
342 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
343 cmp -s $testroot/stdout.expected $testroot/stdout
344 ret="$?"
345 if [ "$ret" != "0" ]; then
346 diff -u $testroot/stdout.expected $testroot/stdout
347 test_done "$testroot" "$ret"
348 return 1
349 fi
351 echo "got: conflicts must be resolved before rebasing can continue" \
352 > $testroot/stderr.expected
353 cmp -s $testroot/stderr.expected $testroot/stderr
354 ret="$?"
355 if [ "$ret" != "0" ]; then
356 diff -u $testroot/stderr.expected $testroot/stderr
357 test_done "$testroot" "$ret"
358 return 1
359 fi
361 echo "<<<<<<< merged change: commit $orig_commit1" \
362 > $testroot/content.expected
363 echo "modified alpha on branch" >> $testroot/content.expected
364 echo "||||||| 3-way merge base: commit $init_commit" \
365 >> $testroot/content.expected
366 echo "alpha" >> $testroot/content.expected
367 echo "=======" >> $testroot/content.expected
368 echo "modified alpha on master" >> $testroot/content.expected
369 echo '>>>>>>>' >> $testroot/content.expected
370 cat $testroot/wt/alpha > $testroot/content
371 cmp -s $testroot/content.expected $testroot/content
372 ret="$?"
373 if [ "$ret" != "0" ]; then
374 diff -u $testroot/content.expected $testroot/content
375 test_done "$testroot" "$ret"
376 return 1
377 fi
379 (cd $testroot/wt && got status > $testroot/stdout)
381 echo "C alpha" > $testroot/stdout.expected
382 cmp -s $testroot/stdout.expected $testroot/stdout
383 ret="$?"
384 if [ "$ret" != "0" ]; then
385 diff -u $testroot/stdout.expected $testroot/stdout
386 test_done "$testroot" "$ret"
387 return 1
388 fi
390 (cd $testroot/wt && got rebase -a > $testroot/stdout)
392 (cd $testroot/repo && git checkout -q newbranch)
394 echo "Switching work tree to refs/heads/master" \
395 > $testroot/stdout.expected
396 echo 'R alpha' >> $testroot/stdout.expected
397 echo "Rebase of refs/heads/newbranch aborted" \
398 >> $testroot/stdout.expected
400 cmp -s $testroot/stdout.expected $testroot/stdout
401 ret="$?"
402 if [ "$ret" != "0" ]; then
403 diff -u $testroot/stdout.expected $testroot/stdout
404 test_done "$testroot" "$ret"
405 return 1
406 fi
408 echo "modified alpha on master" > $testroot/content.expected
409 cat $testroot/wt/alpha > $testroot/content
410 cmp -s $testroot/content.expected $testroot/content
411 ret="$?"
412 if [ "$ret" != "0" ]; then
413 diff -u $testroot/content.expected $testroot/content
414 test_done "$testroot" "$ret"
415 return 1
416 fi
418 (cd $testroot/wt && got log -l3 -c newbranch \
419 | grep ^commit > $testroot/stdout)
420 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
421 echo "commit $init_commit" >> $testroot/stdout.expected
422 cmp -s $testroot/stdout.expected $testroot/stdout
423 ret="$?"
424 if [ "$ret" != "0" ]; then
425 diff -u $testroot/stdout.expected $testroot/stdout
426 fi
427 test_done "$testroot" "$ret"
430 function test_rebase_no_op_change {
431 local testroot=`test_init rebase_no_op_change`
432 local init_commit=`git_show_head $testroot/repo`
434 (cd $testroot/repo && git checkout -q -b newbranch)
435 echo "modified alpha on branch" > $testroot/repo/alpha
436 git_commit $testroot/repo -m "committing to alpha on newbranch"
437 local orig_commit1=`git_show_head $testroot/repo`
438 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
440 (cd $testroot/repo && git checkout -q master)
441 echo "modified alpha on master" > $testroot/repo/alpha
442 git_commit $testroot/repo -m "committing to alpha on master"
443 local master_commit=`git_show_head $testroot/repo`
445 got checkout $testroot/repo $testroot/wt > /dev/null
446 ret="$?"
447 if [ "$ret" != "0" ]; then
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
453 2> $testroot/stderr)
455 echo "C alpha" > $testroot/stdout.expected
456 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
457 echo -n "$short_orig_commit1 -> merge conflict" \
458 >> $testroot/stdout.expected
459 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
460 cmp -s $testroot/stdout.expected $testroot/stdout
461 ret="$?"
462 if [ "$ret" != "0" ]; then
463 diff -u $testroot/stdout.expected $testroot/stdout
464 test_done "$testroot" "$ret"
465 return 1
466 fi
468 echo "got: conflicts must be resolved before rebasing can continue" \
469 > $testroot/stderr.expected
470 cmp -s $testroot/stderr.expected $testroot/stderr
471 ret="$?"
472 if [ "$ret" != "0" ]; then
473 diff -u $testroot/stderr.expected $testroot/stderr
474 test_done "$testroot" "$ret"
475 return 1
476 fi
478 echo "<<<<<<< merged change: commit $orig_commit1" \
479 > $testroot/content.expected
480 echo "modified alpha on branch" >> $testroot/content.expected
481 echo "||||||| 3-way merge base: commit $init_commit" \
482 >> $testroot/content.expected
483 echo "alpha" >> $testroot/content.expected
484 echo "=======" >> $testroot/content.expected
485 echo "modified alpha on master" >> $testroot/content.expected
486 echo '>>>>>>>' >> $testroot/content.expected
487 cat $testroot/wt/alpha > $testroot/content
488 cmp -s $testroot/content.expected $testroot/content
489 ret="$?"
490 if [ "$ret" != "0" ]; then
491 diff -u $testroot/content.expected $testroot/content
492 test_done "$testroot" "$ret"
493 return 1
494 fi
496 (cd $testroot/wt && got status > $testroot/stdout)
498 echo "C alpha" > $testroot/stdout.expected
499 cmp -s $testroot/stdout.expected $testroot/stdout
500 ret="$?"
501 if [ "$ret" != "0" ]; then
502 diff -u $testroot/stdout.expected $testroot/stdout
503 test_done "$testroot" "$ret"
504 return 1
505 fi
507 # resolve the conflict
508 echo "modified alpha on master" > $testroot/wt/alpha
510 (cd $testroot/wt && got rebase -c > $testroot/stdout)
512 (cd $testroot/repo && git checkout -q newbranch)
513 local new_commit1=`git_show_head $testroot/repo`
515 echo -n "$short_orig_commit1 -> no-op change" \
516 > $testroot/stdout.expected
517 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
518 echo "Switching work tree to refs/heads/newbranch" \
519 >> $testroot/stdout.expected
521 cmp -s $testroot/stdout.expected $testroot/stdout
522 ret="$?"
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 test_done "$testroot" "$ret"
526 return 1
527 fi
530 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
531 echo "commit $master_commit (master, newbranch)" \
532 > $testroot/stdout.expected
533 echo "commit $init_commit" >> $testroot/stdout.expected
534 cmp -s $testroot/stdout.expected $testroot/stdout
535 ret="$?"
536 if [ "$ret" != "0" ]; then
537 diff -u $testroot/stdout.expected $testroot/stdout
538 fi
539 test_done "$testroot" "$ret"
542 function test_rebase_in_progress {
543 local testroot=`test_init rebase_in_progress`
544 local init_commit=`git_show_head $testroot/repo`
546 (cd $testroot/repo && git checkout -q -b newbranch)
547 echo "modified alpha on branch" > $testroot/repo/alpha
548 git_commit $testroot/repo -m "committing to alpha on newbranch"
549 local orig_commit1=`git_show_head $testroot/repo`
550 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
552 (cd $testroot/repo && git checkout -q master)
553 echo "modified alpha on master" > $testroot/repo/alpha
554 git_commit $testroot/repo -m "committing to alpha on master"
555 local master_commit=`git_show_head $testroot/repo`
557 got checkout $testroot/repo $testroot/wt > /dev/null
558 ret="$?"
559 if [ "$ret" != "0" ]; then
560 test_done "$testroot" "$ret"
561 return 1
562 fi
564 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
565 2> $testroot/stderr)
567 echo "C alpha" > $testroot/stdout.expected
568 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
569 echo -n "$short_orig_commit1 -> merge conflict" \
570 >> $testroot/stdout.expected
571 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
572 cmp -s $testroot/stdout.expected $testroot/stdout
573 ret="$?"
574 if [ "$ret" != "0" ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 echo "got: conflicts must be resolved before rebasing can continue" \
581 > $testroot/stderr.expected
582 cmp -s $testroot/stderr.expected $testroot/stderr
583 ret="$?"
584 if [ "$ret" != "0" ]; then
585 diff -u $testroot/stderr.expected $testroot/stderr
586 test_done "$testroot" "$ret"
587 return 1
588 fi
590 echo "<<<<<<< merged change: commit $orig_commit1" \
591 > $testroot/content.expected
592 echo "modified alpha on branch" >> $testroot/content.expected
593 echo "||||||| 3-way merge base: commit $init_commit" \
594 >> $testroot/content.expected
595 echo "alpha" >> $testroot/content.expected
596 echo "=======" >> $testroot/content.expected
597 echo "modified alpha on master" >> $testroot/content.expected
598 echo '>>>>>>>' >> $testroot/content.expected
599 cat $testroot/wt/alpha > $testroot/content
600 cmp -s $testroot/content.expected $testroot/content
601 ret="$?"
602 if [ "$ret" != "0" ]; then
603 diff -u $testroot/content.expected $testroot/content
604 test_done "$testroot" "$ret"
605 return 1
606 fi
608 (cd $testroot/wt && got status > $testroot/stdout)
610 echo "C alpha" > $testroot/stdout.expected
611 cmp -s $testroot/stdout.expected $testroot/stdout
612 ret="$?"
613 if [ "$ret" != "0" ]; then
614 diff -u $testroot/stdout.expected $testroot/stdout
615 test_done "$testroot" "$ret"
616 return 1
617 fi
619 for cmd in update commit; do
620 (cd $testroot/wt && got $cmd > $testroot/stdout \
621 2> $testroot/stderr)
623 echo -n > $testroot/stdout.expected
624 cmp -s $testroot/stdout.expected $testroot/stdout
625 ret="$?"
626 if [ "$ret" != "0" ]; then
627 diff -u $testroot/stdout.expected $testroot/stdout
628 test_done "$testroot" "$ret"
629 return 1
630 fi
632 echo -n "got: a rebase operation is in progress in this " \
633 > $testroot/stderr.expected
634 echo "work tree and must be continued or aborted first" \
635 >> $testroot/stderr.expected
636 cmp -s $testroot/stderr.expected $testroot/stderr
637 ret="$?"
638 if [ "$ret" != "0" ]; then
639 diff -u $testroot/stderr.expected $testroot/stderr
640 test_done "$testroot" "$ret"
641 return 1
642 fi
643 done
645 test_done "$testroot" "$ret"
648 function test_rebase_path_prefix {
649 local testroot=`test_init rebase_path_prefix`
651 (cd $testroot/repo && git checkout -q -b newbranch)
652 echo "modified delta on branch" > $testroot/repo/gamma/delta
653 git_commit $testroot/repo -m "committing to delta on newbranch"
655 local orig_commit1=`git_show_parent_commit $testroot/repo`
656 local orig_commit2=`git_show_head $testroot/repo`
658 (cd $testroot/repo && git checkout -q master)
659 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
660 git_commit $testroot/repo -m "committing to zeta on master"
661 local master_commit=`git_show_head $testroot/repo`
663 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
664 ret="$?"
665 if [ "$ret" != "0" ]; then
666 test_done "$testroot" "$ret"
667 return 1
668 fi
670 (cd $testroot/wt && got rebase newbranch \
671 > $testroot/stdout 2> $testroot/stderr)
673 echo -n > $testroot/stdout.expected
674 cmp -s $testroot/stdout.expected $testroot/stdout
675 ret="$?"
676 if [ "$ret" != "0" ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 echo -n "got: cannot rebase branch which contains changes outside " \
683 > $testroot/stderr.expected
684 echo "of this work tree's path prefix" >> $testroot/stderr.expected
685 cmp -s $testroot/stderr.expected $testroot/stderr
686 ret="$?"
687 if [ "$ret" != "0" ]; then
688 diff -u $testroot/stderr.expected $testroot/stderr
689 fi
690 test_done "$testroot" "$ret"
693 function test_rebase_preserves_logmsg {
694 local testroot=`test_init rebase_preserves_logmsg`
696 (cd $testroot/repo && git checkout -q -b newbranch)
697 echo "modified delta on branch" > $testroot/repo/gamma/delta
698 git_commit $testroot/repo -m "modified delta on newbranch"
700 echo "modified alpha on branch" > $testroot/repo/alpha
701 git_commit $testroot/repo -m "modified alpha on newbranch"
703 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
704 > $testroot/log.expected)
706 local orig_commit1=`git_show_parent_commit $testroot/repo`
707 local orig_commit2=`git_show_head $testroot/repo`
709 (cd $testroot/repo && git checkout -q master)
710 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
711 git_commit $testroot/repo -m "committing to zeta on master"
712 local master_commit=`git_show_head $testroot/repo`
714 got checkout $testroot/repo $testroot/wt > /dev/null
715 ret="$?"
716 if [ "$ret" != "0" ]; then
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 (cd $testroot/wt && got rebase newbranch > /dev/null \
722 2> $testroot/stderr)
724 (cd $testroot/repo && git checkout -q newbranch)
725 local new_commit1=`git_show_parent_commit $testroot/repo`
726 local new_commit2=`git_show_head $testroot/repo`
728 echo -n > $testroot/stderr.expected
729 cmp -s $testroot/stderr.expected $testroot/stderr
730 ret="$?"
731 if [ "$ret" != "0" ]; then
732 diff -u $testroot/stderr.expected $testroot/stderr
733 test_done "$testroot" "$ret"
734 return 1
735 fi
737 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
738 > $testroot/log)
739 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
740 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
741 cmp -s $testroot/log.expected $testroot/log
742 ret="$?"
743 if [ "$ret" != "0" ]; then
744 diff -u $testroot/log.expected $testroot/log
745 fi
747 test_done "$testroot" "$ret"
750 function test_rebase_no_commits_to_rebase {
751 local testroot=`test_init rebase_no_commits_to_rebase`
753 got checkout $testroot/repo $testroot/wt > /dev/null
754 ret="$?"
755 if [ "$ret" != "0" ]; then
756 test_done "$testroot" "$ret"
757 return 1
758 fi
760 (cd $testroot/wt && got branch -n newbranch)
762 echo "modified alpha on master" > $testroot/wt/alpha
763 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
764 > /dev/null)
765 (cd $testroot/wt && got update > /dev/null)
767 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
768 2> $testroot/stderr)
770 echo "got: no commits to rebase" > $testroot/stderr.expected
771 cmp -s $testroot/stderr.expected $testroot/stderr
772 ret="$?"
773 if [ "$ret" != "0" ]; then
774 diff -u $testroot/stderr.expected $testroot/stderr
775 test_done "$testroot" "$ret"
776 return 1
777 fi
779 echo "Rebase of refs/heads/newbranch aborted" \
780 > $testroot/stdout.expected
781 cmp -s $testroot/stdout.expected $testroot/stdout
782 ret="$?"
783 if [ "$ret" != "0" ]; then
784 diff -u $testroot/stdout.expected $testroot/stdout
785 test_done "$testroot" "$ret"
786 return 1
787 fi
789 (cd $testroot/wt && got update > $testroot/stdout)
790 echo "Already up-to-date" > $testroot/stdout.expected
791 cmp -s $testroot/stdout.expected $testroot/stdout
792 ret="$?"
793 if [ "$ret" != "0" ]; then
794 diff -u $testroot/stdout.expected $testroot/stdout
795 fi
796 test_done "$testroot" "$ret"
799 function test_rebase_forward {
800 local testroot=`test_init rebase_forward`
801 local commit0=`git_show_head $testroot/repo`
803 got checkout $testroot/repo $testroot/wt > /dev/null
804 ret="$?"
805 if [ "$ret" != "0" ]; then
806 test_done "$testroot" "$ret"
807 return 1
808 fi
810 echo "change alpha 1" > $testroot/wt/alpha
811 (cd $testroot/wt && got commit -m 'test rebase_forward' \
812 > /dev/null)
813 local commit1=`git_show_head $testroot/repo`
815 echo "change alpha 2" > $testroot/wt/alpha
816 (cd $testroot/wt && got commit -m 'test rebase_forward' \
817 > /dev/null)
818 local commit2=`git_show_head $testroot/repo`
820 # Simulate a situation where fast-forward is required.
821 # We want to fast-forward master to origin/master:
822 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
823 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
824 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
825 (cd $testroot/repo && got ref -d master)
826 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
827 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
829 (cd $testroot/wt && got up -b origin/master > /dev/null)
831 (cd $testroot/wt && got rebase master \
832 > $testroot/stdout 2> $testroot/stderr)
834 echo "Forwarding refs/heads/master to commit $commit2" \
835 > $testroot/stdout.expected
836 echo "Switching work tree to refs/heads/master" \
837 >> $testroot/stdout.expected
838 cmp -s $testroot/stdout.expected $testroot/stdout
839 ret="$?"
840 if [ "$ret" != "0" ]; then
841 diff -u $testroot/stdout.expected $testroot/stdout
842 test_done "$testroot" "$ret"
843 return 1
844 fi
846 # Ensure that rebase operation was completed correctly
847 (cd $testroot/wt && got rebase -a \
848 > $testroot/stdout 2> $testroot/stderr)
849 echo -n "" > $testroot/stdout.expected
850 cmp -s $testroot/stdout.expected $testroot/stdout
851 ret="$?"
852 if [ "$ret" != "0" ]; then
853 diff -u $testroot/stdout.expected $testroot/stdout
854 test_done "$testroot" "$ret"
855 return 1
856 fi
857 echo "got: rebase operation not in progress" > $testroot/stderr.expected
858 cmp -s $testroot/stderr.expected $testroot/stderr
859 ret="$?"
860 if [ "$ret" != "0" ]; then
861 diff -u $testroot/stderr.expected $testroot/stderr
862 test_done "$testroot" "$ret"
863 return 1
864 fi
866 (cd $testroot/wt && got branch -n > $testroot/stdout)
867 echo "master" > $testroot/stdout.expected
868 cmp -s $testroot/stdout.expected $testroot/stdout
869 ret="$?"
870 if [ "$ret" != "0" ]; then
871 diff -u $testroot/stdout.expected $testroot/stdout
872 test_done "$testroot" "$ret"
873 return 1
874 fi
876 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
877 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
878 echo "commit $commit1" >> $testroot/stdout.expected
879 echo "commit $commit0" >> $testroot/stdout.expected
880 cmp -s $testroot/stdout.expected $testroot/stdout
881 ret="$?"
882 if [ "$ret" != "0" ]; then
883 diff -u $testroot/stdout.expected $testroot/stdout
884 fi
885 test_done "$testroot" "$ret"
888 function test_rebase_out_of_date {
889 local testroot=`test_init rebase_out_of_date`
890 local initial_commit=`git_show_head $testroot/repo`
892 (cd $testroot/repo && git checkout -q -b newbranch)
893 echo "modified delta on branch" > $testroot/repo/gamma/delta
894 git_commit $testroot/repo -m "committing to delta on newbranch"
896 echo "modified alpha on branch" > $testroot/repo/alpha
897 (cd $testroot/repo && git rm -q beta)
898 echo "new file on branch" > $testroot/repo/epsilon/new
899 (cd $testroot/repo && git add epsilon/new)
900 git_commit $testroot/repo -m "committing more changes on newbranch"
902 local orig_commit1=`git_show_parent_commit $testroot/repo`
903 local orig_commit2=`git_show_head $testroot/repo`
905 (cd $testroot/repo && git checkout -q master)
906 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
907 git_commit $testroot/repo -m "committing to zeta on master"
908 local master_commit1=`git_show_head $testroot/repo`
910 (cd $testroot/repo && git checkout -q master)
911 echo "modified beta on master" > $testroot/repo/beta
912 git_commit $testroot/repo -m "committing to beta on master"
913 local master_commit2=`git_show_head $testroot/repo`
915 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
916 > /dev/null
917 ret="$?"
918 if [ "$ret" != "0" ]; then
919 test_done "$testroot" "$ret"
920 return 1
921 fi
923 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
924 2> $testroot/stderr)
926 echo -n > $testroot/stdout.expected
927 cmp -s $testroot/stdout.expected $testroot/stdout
928 ret="$?"
929 if [ "$ret" != "0" ]; then
930 diff -u $testroot/stdout.expected $testroot/stdout
931 test_done "$testroot" "$ret"
932 return 1
933 fi
935 echo -n "got: work tree must be updated before it can be " \
936 > $testroot/stderr.expected
937 echo "used to rebase a branch" >> $testroot/stderr.expected
938 cmp -s $testroot/stderr.expected $testroot/stderr
939 ret="$?"
940 if [ "$ret" != "0" ]; then
941 diff -u $testroot/stderr.expected $testroot/stderr
942 test_done "$testroot" "$ret"
943 return 1
944 fi
946 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
947 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
948 echo "commit $master_commit1" >> $testroot/stdout.expected
949 echo "commit $initial_commit" >> $testroot/stdout.expected
950 cmp -s $testroot/stdout.expected $testroot/stdout
951 ret="$?"
952 if [ "$ret" != "0" ]; then
953 diff -u $testroot/stdout.expected $testroot/stdout
954 fi
955 test_done "$testroot" "$ret"
958 function test_rebase_trims_empty_dir {
959 local testroot=`test_init rebase_trims_empty_dir`
961 (cd $testroot/repo && git checkout -q -b newbranch)
962 echo "modified delta on branch" > $testroot/repo/gamma/delta
963 git_commit $testroot/repo -m "committing to delta on newbranch"
965 (cd $testroot/repo && git rm -q epsilon/zeta)
966 git_commit $testroot/repo -m "removing zeta on newbranch"
968 local orig_commit1=`git_show_parent_commit $testroot/repo`
969 local orig_commit2=`git_show_head $testroot/repo`
971 (cd $testroot/repo && git checkout -q master)
972 echo "modified alpha on master" > $testroot/repo/alpha
973 git_commit $testroot/repo -m "committing to alpha on master"
974 local master_commit=`git_show_head $testroot/repo`
976 got checkout $testroot/repo $testroot/wt > /dev/null
977 ret="$?"
978 if [ "$ret" != "0" ]; then
979 test_done "$testroot" "$ret"
980 return 1
981 fi
983 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
985 (cd $testroot/repo && git checkout -q newbranch)
986 local new_commit1=`git_show_parent_commit $testroot/repo`
987 local new_commit2=`git_show_head $testroot/repo`
989 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
990 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
991 local short_new_commit1=`trim_obj_id 28 $new_commit1`
992 local short_new_commit2=`trim_obj_id 28 $new_commit2`
994 echo "G gamma/delta" >> $testroot/stdout.expected
995 echo -n "$short_orig_commit1 -> $short_new_commit1" \
996 >> $testroot/stdout.expected
997 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
998 echo "D epsilon/zeta" >> $testroot/stdout.expected
999 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1000 >> $testroot/stdout.expected
1001 echo ": removing zeta on newbranch" \
1002 >> $testroot/stdout.expected
1003 echo "Switching work tree to refs/heads/newbranch" \
1004 >> $testroot/stdout.expected
1006 cmp -s $testroot/stdout.expected $testroot/stdout
1007 ret="$?"
1008 if [ "$ret" != "0" ]; then
1009 diff -u $testroot/stdout.expected $testroot/stdout
1010 test_done "$testroot" "$ret"
1011 return 1
1014 echo "modified delta on branch" > $testroot/content.expected
1015 cat $testroot/wt/gamma/delta > $testroot/content
1016 cmp -s $testroot/content.expected $testroot/content
1017 ret="$?"
1018 if [ "$ret" != "0" ]; then
1019 diff -u $testroot/content.expected $testroot/content
1020 test_done "$testroot" "$ret"
1021 return 1
1024 echo "modified alpha on master" > $testroot/content.expected
1025 cat $testroot/wt/alpha > $testroot/content
1026 cmp -s $testroot/content.expected $testroot/content
1027 ret="$?"
1028 if [ "$ret" != "0" ]; then
1029 diff -u $testroot/content.expected $testroot/content
1030 test_done "$testroot" "$ret"
1031 return 1
1034 if [ -e $testroot/wt/epsilon ]; then
1035 echo "parent of removed zeta still exists on disk" >&2
1036 test_done "$testroot" "1"
1037 return 1
1040 (cd $testroot/wt && got status > $testroot/stdout)
1042 echo -n > $testroot/stdout.expected
1043 cmp -s $testroot/stdout.expected $testroot/stdout
1044 ret="$?"
1045 if [ "$ret" != "0" ]; then
1046 diff -u $testroot/stdout.expected $testroot/stdout
1047 test_done "$testroot" "$ret"
1048 return 1
1051 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1052 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1053 echo "commit $new_commit1" >> $testroot/stdout.expected
1054 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1055 cmp -s $testroot/stdout.expected $testroot/stdout
1056 ret="$?"
1057 if [ "$ret" != "0" ]; then
1058 diff -u $testroot/stdout.expected $testroot/stdout
1060 test_done "$testroot" "$ret"
1063 function test_rebase_delete_missing_file {
1064 local testroot=`test_init rebase_delete_missing_file`
1066 mkdir -p $testroot/repo/d/f/g
1067 echo "new file" > $testroot/repo/d/f/g/new
1068 (cd $testroot/repo && git add d/f/g/new)
1069 git_commit $testroot/repo -m "adding a subdir"
1070 local commit0=`git_show_head $testroot/repo`
1072 got br -r $testroot/repo -c master newbranch
1074 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1076 echo "modified delta on branch" > $testroot/wt/gamma/delta
1077 (cd $testroot/wt && got commit \
1078 -m "committing to delta on newbranch" > /dev/null)
1080 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1081 (cd $testroot/wt && got commit \
1082 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1084 (cd $testroot/repo && git checkout -q newbranch)
1085 local orig_commit1=`git_show_parent_commit $testroot/repo`
1086 local orig_commit2=`git_show_head $testroot/repo`
1088 (cd $testroot/wt && got update -b master > /dev/null)
1089 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1090 (cd $testroot/wt && got commit \
1091 -m "removing beta and d/f/g/new on master" > /dev/null)
1093 (cd $testroot/repo && git checkout -q master)
1094 local master_commit=`git_show_head $testroot/repo`
1096 (cd $testroot/wt && got update -b master > /dev/null)
1097 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1099 (cd $testroot/repo && git checkout -q newbranch)
1100 local new_commit1=`git_show_head $testroot/repo`
1102 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1103 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1104 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1106 echo "G gamma/delta" >> $testroot/stdout.expected
1107 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1108 >> $testroot/stdout.expected
1109 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1110 echo "! beta" >> $testroot/stdout.expected
1111 echo "! d/f/g/new" >> $testroot/stdout.expected
1112 echo -n "$short_orig_commit2 -> no-op change" \
1113 >> $testroot/stdout.expected
1114 echo ": removing beta and d/f/g/new on newbranch" \
1115 >> $testroot/stdout.expected
1116 echo "Switching work tree to refs/heads/newbranch" \
1117 >> $testroot/stdout.expected
1119 cmp -s $testroot/stdout.expected $testroot/stdout
1120 ret="$?"
1121 if [ "$ret" != "0" ]; then
1122 diff -u $testroot/stdout.expected $testroot/stdout
1123 test_done "$testroot" "$ret"
1124 return 1
1127 echo "modified delta on branch" > $testroot/content.expected
1128 cat $testroot/wt/gamma/delta > $testroot/content
1129 cmp -s $testroot/content.expected $testroot/content
1130 ret="$?"
1131 if [ "$ret" != "0" ]; then
1132 diff -u $testroot/content.expected $testroot/content
1133 test_done "$testroot" "$ret"
1134 return 1
1137 if [ -e $testroot/wt/beta ]; then
1138 echo "removed file beta still exists on disk" >&2
1139 test_done "$testroot" "1"
1140 return 1
1143 (cd $testroot/wt && got status > $testroot/stdout)
1145 echo -n > $testroot/stdout.expected
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1147 ret="$?"
1148 if [ "$ret" != "0" ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1151 return 1
1154 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1155 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1156 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1157 echo "commit $commit0" >> $testroot/stdout.expected
1158 cmp -s $testroot/stdout.expected $testroot/stdout
1159 ret="$?"
1160 if [ "$ret" != "0" ]; then
1161 diff -u $testroot/stdout.expected $testroot/stdout
1163 test_done "$testroot" "$ret"
1166 run_test test_rebase_basic
1167 run_test test_rebase_ancestry_check
1168 run_test test_rebase_continue
1169 run_test test_rebase_abort
1170 run_test test_rebase_no_op_change
1171 run_test test_rebase_in_progress
1172 run_test test_rebase_path_prefix
1173 run_test test_rebase_preserves_logmsg
1174 run_test test_rebase_no_commits_to_rebase
1175 run_test test_rebase_forward
1176 run_test test_rebase_out_of_date
1177 run_test test_rebase_trims_empty_dir
1178 run_test test_rebase_delete_missing_file