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 -c $commit1 refs/heads/master)
823 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
825 (cd $testroot/wt && got up -b origin/master > /dev/null)
827 (cd $testroot/wt && got rebase master \
828 > $testroot/stdout 2> $testroot/stderr)
830 echo "Forwarding refs/heads/master to commit $commit2" \
831 > $testroot/stdout.expected
832 echo "Switching work tree to refs/heads/master" \
833 >> $testroot/stdout.expected
834 cmp -s $testroot/stdout.expected $testroot/stdout
835 ret="$?"
836 if [ "$ret" != "0" ]; then
837 diff -u $testroot/stdout.expected $testroot/stdout
838 test_done "$testroot" "$ret"
839 return 1
840 fi
842 # Ensure that rebase operation was completed correctly
843 (cd $testroot/wt && got rebase -a \
844 > $testroot/stdout 2> $testroot/stderr)
845 echo -n "" > $testroot/stdout.expected
846 cmp -s $testroot/stdout.expected $testroot/stdout
847 ret="$?"
848 if [ "$ret" != "0" ]; then
849 diff -u $testroot/stdout.expected $testroot/stdout
850 test_done "$testroot" "$ret"
851 return 1
852 fi
853 echo "got: rebase operation not in progress" > $testroot/stderr.expected
854 cmp -s $testroot/stderr.expected $testroot/stderr
855 ret="$?"
856 if [ "$ret" != "0" ]; then
857 diff -u $testroot/stderr.expected $testroot/stderr
858 test_done "$testroot" "$ret"
859 return 1
860 fi
862 (cd $testroot/wt && got branch -n > $testroot/stdout)
863 echo "master" > $testroot/stdout.expected
864 cmp -s $testroot/stdout.expected $testroot/stdout
865 ret="$?"
866 if [ "$ret" != "0" ]; then
867 diff -u $testroot/stdout.expected $testroot/stdout
868 test_done "$testroot" "$ret"
869 return 1
870 fi
872 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
873 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
874 echo "commit $commit1" >> $testroot/stdout.expected
875 echo "commit $commit0" >> $testroot/stdout.expected
876 cmp -s $testroot/stdout.expected $testroot/stdout
877 ret="$?"
878 if [ "$ret" != "0" ]; then
879 diff -u $testroot/stdout.expected $testroot/stdout
880 fi
881 test_done "$testroot" "$ret"
884 function test_rebase_out_of_date {
885 local testroot=`test_init rebase_out_of_date`
886 local initial_commit=`git_show_head $testroot/repo`
888 (cd $testroot/repo && git checkout -q -b newbranch)
889 echo "modified delta on branch" > $testroot/repo/gamma/delta
890 git_commit $testroot/repo -m "committing to delta on newbranch"
892 echo "modified alpha on branch" > $testroot/repo/alpha
893 (cd $testroot/repo && git rm -q beta)
894 echo "new file on branch" > $testroot/repo/epsilon/new
895 (cd $testroot/repo && git add epsilon/new)
896 git_commit $testroot/repo -m "committing more changes on newbranch"
898 local orig_commit1=`git_show_parent_commit $testroot/repo`
899 local orig_commit2=`git_show_head $testroot/repo`
901 (cd $testroot/repo && git checkout -q master)
902 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
903 git_commit $testroot/repo -m "committing to zeta on master"
904 local master_commit1=`git_show_head $testroot/repo`
906 (cd $testroot/repo && git checkout -q master)
907 echo "modified beta on master" > $testroot/repo/beta
908 git_commit $testroot/repo -m "committing to beta on master"
909 local master_commit2=`git_show_head $testroot/repo`
911 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
912 > /dev/null
913 ret="$?"
914 if [ "$ret" != "0" ]; then
915 test_done "$testroot" "$ret"
916 return 1
917 fi
919 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
920 2> $testroot/stderr)
922 echo -n > $testroot/stdout.expected
923 cmp -s $testroot/stdout.expected $testroot/stdout
924 ret="$?"
925 if [ "$ret" != "0" ]; then
926 diff -u $testroot/stdout.expected $testroot/stdout
927 test_done "$testroot" "$ret"
928 return 1
929 fi
931 echo -n "got: work tree must be updated before it can be " \
932 > $testroot/stderr.expected
933 echo "used to rebase a branch" >> $testroot/stderr.expected
934 cmp -s $testroot/stderr.expected $testroot/stderr
935 ret="$?"
936 if [ "$ret" != "0" ]; then
937 diff -u $testroot/stderr.expected $testroot/stderr
938 test_done "$testroot" "$ret"
939 return 1
940 fi
942 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
943 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
944 echo "commit $master_commit1" >> $testroot/stdout.expected
945 echo "commit $initial_commit" >> $testroot/stdout.expected
946 cmp -s $testroot/stdout.expected $testroot/stdout
947 ret="$?"
948 if [ "$ret" != "0" ]; then
949 diff -u $testroot/stdout.expected $testroot/stdout
950 fi
951 test_done "$testroot" "$ret"
954 function test_rebase_trims_empty_dir {
955 local testroot=`test_init rebase_trims_empty_dir`
957 (cd $testroot/repo && git checkout -q -b newbranch)
958 echo "modified delta on branch" > $testroot/repo/gamma/delta
959 git_commit $testroot/repo -m "committing to delta on newbranch"
961 (cd $testroot/repo && git rm -q epsilon/zeta)
962 git_commit $testroot/repo -m "removing zeta on newbranch"
964 local orig_commit1=`git_show_parent_commit $testroot/repo`
965 local orig_commit2=`git_show_head $testroot/repo`
967 (cd $testroot/repo && git checkout -q master)
968 echo "modified alpha on master" > $testroot/repo/alpha
969 git_commit $testroot/repo -m "committing to alpha on master"
970 local master_commit=`git_show_head $testroot/repo`
972 got checkout $testroot/repo $testroot/wt > /dev/null
973 ret="$?"
974 if [ "$ret" != "0" ]; then
975 test_done "$testroot" "$ret"
976 return 1
977 fi
979 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
981 (cd $testroot/repo && git checkout -q newbranch)
982 local new_commit1=`git_show_parent_commit $testroot/repo`
983 local new_commit2=`git_show_head $testroot/repo`
985 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
986 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
987 local short_new_commit1=`trim_obj_id 28 $new_commit1`
988 local short_new_commit2=`trim_obj_id 28 $new_commit2`
990 echo "G gamma/delta" >> $testroot/stdout.expected
991 echo -n "$short_orig_commit1 -> $short_new_commit1" \
992 >> $testroot/stdout.expected
993 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
994 echo "D epsilon/zeta" >> $testroot/stdout.expected
995 echo -n "$short_orig_commit2 -> $short_new_commit2" \
996 >> $testroot/stdout.expected
997 echo ": removing zeta on newbranch" \
998 >> $testroot/stdout.expected
999 echo "Switching work tree to refs/heads/newbranch" \
1000 >> $testroot/stdout.expected
1002 cmp -s $testroot/stdout.expected $testroot/stdout
1003 ret="$?"
1004 if [ "$ret" != "0" ]; then
1005 diff -u $testroot/stdout.expected $testroot/stdout
1006 test_done "$testroot" "$ret"
1007 return 1
1010 echo "modified delta on branch" > $testroot/content.expected
1011 cat $testroot/wt/gamma/delta > $testroot/content
1012 cmp -s $testroot/content.expected $testroot/content
1013 ret="$?"
1014 if [ "$ret" != "0" ]; then
1015 diff -u $testroot/content.expected $testroot/content
1016 test_done "$testroot" "$ret"
1017 return 1
1020 echo "modified alpha on master" > $testroot/content.expected
1021 cat $testroot/wt/alpha > $testroot/content
1022 cmp -s $testroot/content.expected $testroot/content
1023 ret="$?"
1024 if [ "$ret" != "0" ]; then
1025 diff -u $testroot/content.expected $testroot/content
1026 test_done "$testroot" "$ret"
1027 return 1
1030 if [ -e $testroot/wt/epsilon ]; then
1031 echo "parent of removed zeta still exists on disk" >&2
1032 test_done "$testroot" "1"
1033 return 1
1036 (cd $testroot/wt && got status > $testroot/stdout)
1038 echo -n > $testroot/stdout.expected
1039 cmp -s $testroot/stdout.expected $testroot/stdout
1040 ret="$?"
1041 if [ "$ret" != "0" ]; then
1042 diff -u $testroot/stdout.expected $testroot/stdout
1043 test_done "$testroot" "$ret"
1044 return 1
1047 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1048 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1049 echo "commit $new_commit1" >> $testroot/stdout.expected
1050 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1051 cmp -s $testroot/stdout.expected $testroot/stdout
1052 ret="$?"
1053 if [ "$ret" != "0" ]; then
1054 diff -u $testroot/stdout.expected $testroot/stdout
1056 test_done "$testroot" "$ret"
1059 function test_rebase_delete_missing_file {
1060 local testroot=`test_init rebase_delete_missing_file`
1062 mkdir -p $testroot/repo/d/f/g
1063 echo "new file" > $testroot/repo/d/f/g/new
1064 (cd $testroot/repo && git add d/f/g/new)
1065 git_commit $testroot/repo -m "adding a subdir"
1066 local commit0=`git_show_head $testroot/repo`
1068 got br -r $testroot/repo -c master newbranch
1070 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1072 echo "modified delta on branch" > $testroot/wt/gamma/delta
1073 (cd $testroot/wt && got commit \
1074 -m "committing to delta on newbranch" > /dev/null)
1076 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1077 (cd $testroot/wt && got commit \
1078 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1080 (cd $testroot/repo && git checkout -q newbranch)
1081 local orig_commit1=`git_show_parent_commit $testroot/repo`
1082 local orig_commit2=`git_show_head $testroot/repo`
1084 (cd $testroot/wt && got update -b master > /dev/null)
1085 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1086 (cd $testroot/wt && got commit \
1087 -m "removing beta and d/f/g/new on master" > /dev/null)
1089 (cd $testroot/repo && git checkout -q master)
1090 local master_commit=`git_show_head $testroot/repo`
1092 (cd $testroot/wt && got update -b master > /dev/null)
1093 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1095 (cd $testroot/repo && git checkout -q newbranch)
1096 local new_commit1=`git_show_head $testroot/repo`
1098 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1099 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1100 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1102 echo "G gamma/delta" >> $testroot/stdout.expected
1103 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1104 >> $testroot/stdout.expected
1105 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1106 echo "! beta" >> $testroot/stdout.expected
1107 echo "! d/f/g/new" >> $testroot/stdout.expected
1108 echo -n "$short_orig_commit2 -> no-op change" \
1109 >> $testroot/stdout.expected
1110 echo ": removing beta and d/f/g/new on newbranch" \
1111 >> $testroot/stdout.expected
1112 echo "Switching work tree to refs/heads/newbranch" \
1113 >> $testroot/stdout.expected
1115 cmp -s $testroot/stdout.expected $testroot/stdout
1116 ret="$?"
1117 if [ "$ret" != "0" ]; then
1118 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1120 return 1
1123 echo "modified delta on branch" > $testroot/content.expected
1124 cat $testroot/wt/gamma/delta > $testroot/content
1125 cmp -s $testroot/content.expected $testroot/content
1126 ret="$?"
1127 if [ "$ret" != "0" ]; then
1128 diff -u $testroot/content.expected $testroot/content
1129 test_done "$testroot" "$ret"
1130 return 1
1133 if [ -e $testroot/wt/beta ]; then
1134 echo "removed file beta still exists on disk" >&2
1135 test_done "$testroot" "1"
1136 return 1
1139 (cd $testroot/wt && got status > $testroot/stdout)
1141 echo -n > $testroot/stdout.expected
1142 cmp -s $testroot/stdout.expected $testroot/stdout
1143 ret="$?"
1144 if [ "$ret" != "0" ]; then
1145 diff -u $testroot/stdout.expected $testroot/stdout
1146 test_done "$testroot" "$ret"
1147 return 1
1150 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1151 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1152 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1153 echo "commit $commit0" >> $testroot/stdout.expected
1154 cmp -s $testroot/stdout.expected $testroot/stdout
1155 ret="$?"
1156 if [ "$ret" != "0" ]; then
1157 diff -u $testroot/stdout.expected $testroot/stdout
1159 test_done "$testroot" "$ret"
1162 run_test test_rebase_basic
1163 run_test test_rebase_ancestry_check
1164 run_test test_rebase_continue
1165 run_test test_rebase_abort
1166 run_test test_rebase_no_op_change
1167 run_test test_rebase_in_progress
1168 run_test test_rebase_path_prefix
1169 run_test test_rebase_preserves_logmsg
1170 run_test test_rebase_no_commits_to_rebase
1171 run_test test_rebase_forward
1172 run_test test_rebase_out_of_date
1173 run_test test_rebase_trims_empty_dir
1174 run_test test_rebase_delete_missing_file