Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_rebase_basic() {
20 local testroot=`test_init rebase_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 (cd $testroot/repo && git checkout -q -b newbranch)
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
28 echo "modified alpha on branch" > $testroot/repo/alpha
29 (cd $testroot/repo && git rm -q beta)
30 echo "new file on branch" > $testroot/repo/epsilon/new
31 (cd $testroot/repo && git add epsilon/new)
32 git_commit $testroot/repo -m "committing more changes on newbranch"
34 local orig_commit1=`git_show_parent_commit $testroot/repo`
35 local orig_commit2=`git_show_head $testroot/repo`
36 local orig_author_time2=`git_show_author_time $testroot/repo`
38 (cd $testroot/repo && git checkout -q master)
39 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
40 git_commit $testroot/repo -m "committing to zeta on master"
41 local master_commit=`git_show_head $testroot/repo`
43 got checkout $testroot/repo $testroot/wt > /dev/null
44 ret="$?"
45 if [ "$ret" != "0" ]; then
46 test_done "$testroot" "$ret"
47 return 1
48 fi
50 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
52 (cd $testroot/repo && git checkout -q newbranch)
53 local new_commit1=`git_show_parent_commit $testroot/repo`
54 local new_commit2=`git_show_head $testroot/repo`
55 local new_author_time2=`git_show_author_time $testroot/repo`
57 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
58 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
59 local short_new_commit1=`trim_obj_id 28 $new_commit1`
60 local short_new_commit2=`trim_obj_id 28 $new_commit2`
62 echo "G gamma/delta" >> $testroot/stdout.expected
63 echo -n "$short_orig_commit1 -> $short_new_commit1" \
64 >> $testroot/stdout.expected
65 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
66 echo "G alpha" >> $testroot/stdout.expected
67 echo "D beta" >> $testroot/stdout.expected
68 echo "A epsilon/new" >> $testroot/stdout.expected
69 echo -n "$short_orig_commit2 -> $short_new_commit2" \
70 >> $testroot/stdout.expected
71 echo ": committing more changes on newbranch" \
72 >> $testroot/stdout.expected
73 echo "Switching work tree to refs/heads/newbranch" \
74 >> $testroot/stdout.expected
76 cmp -s $testroot/stdout.expected $testroot/stdout
77 ret="$?"
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 echo "modified delta on branch" > $testroot/content.expected
85 cat $testroot/wt/gamma/delta > $testroot/content
86 cmp -s $testroot/content.expected $testroot/content
87 ret="$?"
88 if [ "$ret" != "0" ]; then
89 diff -u $testroot/content.expected $testroot/content
90 test_done "$testroot" "$ret"
91 return 1
92 fi
94 echo "modified alpha on branch" > $testroot/content.expected
95 cat $testroot/wt/alpha > $testroot/content
96 cmp -s $testroot/content.expected $testroot/content
97 ret="$?"
98 if [ "$ret" != "0" ]; then
99 diff -u $testroot/content.expected $testroot/content
100 test_done "$testroot" "$ret"
101 return 1
102 fi
104 if [ -e $testroot/wt/beta ]; then
105 echo "removed file beta still exists on disk" >&2
106 test_done "$testroot" "1"
107 return 1
108 fi
110 echo "new file on branch" > $testroot/content.expected
111 cat $testroot/wt/epsilon/new > $testroot/content
112 cmp -s $testroot/content.expected $testroot/content
113 ret="$?"
114 if [ "$ret" != "0" ]; then
115 diff -u $testroot/content.expected $testroot/content
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 (cd $testroot/wt && got status > $testroot/stdout)
122 echo -n > $testroot/stdout.expected
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret="$?"
125 if [ "$ret" != "0" ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
132 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
133 echo "commit $new_commit1" >> $testroot/stdout.expected
134 echo "commit $master_commit (master)" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected $testroot/stdout
136 ret="$?"
137 if [ "$ret" != "0" ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 test_done "$testroot" "$ret"
140 return 1
141 fi
143 (cd $testroot/wt && got update > $testroot/stdout)
145 echo 'Already up-to-date' > $testroot/stdout.expected
146 cmp -s $testroot/stdout.expected $testroot/stdout
147 ret="$?"
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
151 fi
153 # We should have a backup of old commits
154 (cd $testroot/repo && got rebase -l > $testroot/stdout)
155 d_orig2=`env TZ=UTC date -r $orig_author_time2 +"%a %b %e %X %Y UTC"`
156 d_new2=`env TZ=UTC date -r $new_author_time2 +"%G-%m-%d"`
157 d_0=`env TZ=UTC date -r $commit0_author_time +"%G-%m-%d"`
158 cat > $testroot/stdout.expected <<EOF
159 -----------------------------------------------
160 commit $orig_commit2 (formerly newbranch)
161 from: $GOT_AUTHOR
162 date: $d_orig2
164 committing more changes on newbranch
166 has become commit $new_commit2 (newbranch)
167 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
168 history forked at $commit0
169 $d_0 $GOT_AUTHOR_11 adding the test tree
170 EOF
171 cmp -s $testroot/stdout.expected $testroot/stdout
172 ret="$?"
173 if [ "$ret" != "0" ]; then
174 diff -u $testroot/stdout.expected $testroot/stdout
175 test_done "$testroot" "$ret"
176 fi
178 # Asking for backups of a branch which has none should yield an error
179 (cd $testroot/repo && got rebase -l master \
180 > $testroot/stdout 2> $testroot/stderr)
181 echo -n > $testroot/stdout.expected
182 echo "got: refs/got/backup/rebase/master/: no such reference found" \
183 > $testroot/stderr.expected
184 cmp -s $testroot/stdout.expected $testroot/stdout
185 ret="$?"
186 if [ "$ret" != "0" ]; then
187 diff -u $testroot/stdout.expected $testroot/stdout
188 test_done "$testroot" "$ret"
189 fi
190 cmp -s $testroot/stderr.expected $testroot/stderr
191 ret="$?"
192 if [ "$ret" != "0" ]; then
193 diff -u $testroot/stderr.expected $testroot/stderr
194 fi
195 test_done "$testroot" "$ret"
198 test_rebase_ancestry_check() {
199 local testroot=`test_init rebase_ancestry_check`
201 got checkout $testroot/repo $testroot/wt > /dev/null
202 ret="$?"
203 if [ "$ret" != "0" ]; then
204 test_done "$testroot" "$ret"
205 return 1
206 fi
208 (cd $testroot/repo && git checkout -q -b newbranch)
209 echo "modified delta on branch" > $testroot/repo/gamma/delta
210 git_commit $testroot/repo -m "committing to delta on newbranch"
212 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
213 2> $testroot/stderr)
215 echo -n > $testroot/stdout.expected
216 cmp -s $testroot/stdout.expected $testroot/stdout
217 ret="$?"
218 if [ "$ret" != "0" ]; then
219 diff -u $testroot/stdout.expected $testroot/stdout
220 test_done "$testroot" "$ret"
221 return 1
222 fi
224 echo "got: refs/heads/newbranch is already based on refs/heads/master" \
225 > $testroot/stderr.expected
226 cmp -s $testroot/stderr.expected $testroot/stderr
227 ret="$?"
228 if [ "$ret" != "0" ]; then
229 diff -u $testroot/stderr.expected $testroot/stderr
230 fi
231 test_done "$testroot" "$ret"
234 test_rebase_continue() {
235 local testroot=`test_init rebase_continue`
236 local init_commit=`git_show_head $testroot/repo`
238 (cd $testroot/repo && git checkout -q -b newbranch)
239 echo "modified alpha on branch" > $testroot/repo/alpha
240 git_commit $testroot/repo -m "committing to alpha on newbranch"
241 local orig_commit1=`git_show_head $testroot/repo`
242 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
244 (cd $testroot/repo && git checkout -q master)
245 echo "modified alpha on master" > $testroot/repo/alpha
246 git_commit $testroot/repo -m "committing to alpha on master"
247 local master_commit=`git_show_head $testroot/repo`
249 got checkout $testroot/repo $testroot/wt > /dev/null
250 ret="$?"
251 if [ "$ret" != "0" ]; then
252 test_done "$testroot" "$ret"
253 return 1
254 fi
256 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
257 2> $testroot/stderr)
259 echo "C alpha" > $testroot/stdout.expected
260 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
261 echo -n "$short_orig_commit1 -> merge conflict" \
262 >> $testroot/stdout.expected
263 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
264 cmp -s $testroot/stdout.expected $testroot/stdout
265 ret="$?"
266 if [ "$ret" != "0" ]; then
267 diff -u $testroot/stdout.expected $testroot/stdout
268 test_done "$testroot" "$ret"
269 return 1
270 fi
272 echo "got: conflicts must be resolved before rebasing can continue" \
273 > $testroot/stderr.expected
274 cmp -s $testroot/stderr.expected $testroot/stderr
275 ret="$?"
276 if [ "$ret" != "0" ]; then
277 diff -u $testroot/stderr.expected $testroot/stderr
278 test_done "$testroot" "$ret"
279 return 1
280 fi
282 echo '<<<<<<<' > $testroot/content.expected
283 echo "modified alpha on master" >> $testroot/content.expected
284 echo "||||||| 3-way merge base: commit $init_commit" \
285 >> $testroot/content.expected
286 echo "alpha" >> $testroot/content.expected
287 echo "=======" >> $testroot/content.expected
288 echo "modified alpha on branch" >> $testroot/content.expected
289 echo ">>>>>>> merged change: commit $orig_commit1" \
290 >> $testroot/content.expected
291 cat $testroot/wt/alpha > $testroot/content
292 cmp -s $testroot/content.expected $testroot/content
293 ret="$?"
294 if [ "$ret" != "0" ]; then
295 diff -u $testroot/content.expected $testroot/content
296 test_done "$testroot" "$ret"
297 return 1
298 fi
300 (cd $testroot/wt && got status > $testroot/stdout)
302 echo "C alpha" > $testroot/stdout.expected
303 cmp -s $testroot/stdout.expected $testroot/stdout
304 ret="$?"
305 if [ "$ret" != "0" ]; then
306 diff -u $testroot/stdout.expected $testroot/stdout
307 test_done "$testroot" "$ret"
308 return 1
309 fi
311 # resolve the conflict
312 echo "modified alpha on branch and master" > $testroot/wt/alpha
314 # test interaction of 'got stage' and rebase -c
315 (cd $testroot/wt && got stage alpha > /dev/null)
316 (cd $testroot/wt && got rebase -c > $testroot/stdout \
317 2> $testroot/stderr)
318 ret="$?"
319 if [ "$ret" = "0" ]; then
320 echo "rebase succeeded unexpectedly" >&2
321 test_done "$testroot" "1"
322 return 1
323 fi
324 echo -n "got: work tree contains files with staged changes; " \
325 > $testroot/stderr.expected
326 echo "these changes must be committed or unstaged first" \
327 >> $testroot/stderr.expected
328 cmp -s $testroot/stderr.expected $testroot/stderr
329 ret="$?"
330 if [ "$ret" != "0" ]; then
331 diff -u $testroot/stderr.expected $testroot/stderr
332 test_done "$testroot" "$ret"
333 return 1
334 fi
336 (cd $testroot/wt && got unstage alpha > /dev/null)
337 (cd $testroot/wt && got rebase -c > $testroot/stdout)
339 (cd $testroot/repo && git checkout -q newbranch)
340 local new_commit1=`git_show_head $testroot/repo`
341 local short_new_commit1=`trim_obj_id 28 $new_commit1`
343 echo -n "$short_orig_commit1 -> $short_new_commit1" \
344 > $testroot/stdout.expected
345 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
346 echo "Switching work tree to refs/heads/newbranch" \
347 >> $testroot/stdout.expected
349 cmp -s $testroot/stdout.expected $testroot/stdout
350 ret="$?"
351 if [ "$ret" != "0" ]; then
352 diff -u $testroot/stdout.expected $testroot/stdout
353 test_done "$testroot" "$ret"
354 return 1
355 fi
358 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
359 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
360 echo "commit $master_commit (master)" >> $testroot/stdout.expected
361 cmp -s $testroot/stdout.expected $testroot/stdout
362 ret="$?"
363 if [ "$ret" != "0" ]; then
364 diff -u $testroot/stdout.expected $testroot/stdout
365 fi
366 test_done "$testroot" "$ret"
369 test_rebase_abort() {
370 local testroot=`test_init rebase_abort`
372 local init_commit=`git_show_head $testroot/repo`
374 (cd $testroot/repo && git checkout -q -b newbranch)
375 echo "modified alpha on branch" > $testroot/repo/alpha
376 git_commit $testroot/repo -m "committing to alpha on newbranch"
377 local orig_commit1=`git_show_head $testroot/repo`
378 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
380 (cd $testroot/repo && git checkout -q master)
381 echo "modified alpha on master" > $testroot/repo/alpha
382 git_commit $testroot/repo -m "committing to alpha on master"
383 local master_commit=`git_show_head $testroot/repo`
385 got checkout $testroot/repo $testroot/wt > /dev/null
386 ret="$?"
387 if [ "$ret" != "0" ]; then
388 test_done "$testroot" "$ret"
389 return 1
390 fi
392 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
393 2> $testroot/stderr)
395 echo "C alpha" > $testroot/stdout.expected
396 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
397 echo -n "$short_orig_commit1 -> merge conflict" \
398 >> $testroot/stdout.expected
399 echo ": committing to alpha on newbranch" >> $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 "got: conflicts must be resolved before rebasing can continue" \
409 > $testroot/stderr.expected
410 cmp -s $testroot/stderr.expected $testroot/stderr
411 ret="$?"
412 if [ "$ret" != "0" ]; then
413 diff -u $testroot/stderr.expected $testroot/stderr
414 test_done "$testroot" "$ret"
415 return 1
416 fi
418 echo '<<<<<<<' > $testroot/content.expected
419 echo "modified alpha on master" >> $testroot/content.expected
420 echo "||||||| 3-way merge base: commit $init_commit" \
421 >> $testroot/content.expected
422 echo "alpha" >> $testroot/content.expected
423 echo "=======" >> $testroot/content.expected
424 echo "modified alpha on branch" >> $testroot/content.expected
425 echo ">>>>>>> merged change: commit $orig_commit1" \
426 >> $testroot/content.expected
427 cat $testroot/wt/alpha > $testroot/content
428 cmp -s $testroot/content.expected $testroot/content
429 ret="$?"
430 if [ "$ret" != "0" ]; then
431 diff -u $testroot/content.expected $testroot/content
432 test_done "$testroot" "$ret"
433 return 1
434 fi
436 (cd $testroot/wt && got status > $testroot/stdout)
438 echo "C alpha" > $testroot/stdout.expected
439 cmp -s $testroot/stdout.expected $testroot/stdout
440 ret="$?"
441 if [ "$ret" != "0" ]; then
442 diff -u $testroot/stdout.expected $testroot/stdout
443 test_done "$testroot" "$ret"
444 return 1
445 fi
447 (cd $testroot/wt && got rebase -a > $testroot/stdout)
449 (cd $testroot/repo && git checkout -q newbranch)
451 echo "Switching work tree to refs/heads/master" \
452 > $testroot/stdout.expected
453 echo 'R alpha' >> $testroot/stdout.expected
454 echo "Rebase of refs/heads/newbranch aborted" \
455 >> $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 "modified alpha on master" > $testroot/content.expected
466 cat $testroot/wt/alpha > $testroot/content
467 cmp -s $testroot/content.expected $testroot/content
468 ret="$?"
469 if [ "$ret" != "0" ]; then
470 diff -u $testroot/content.expected $testroot/content
471 test_done "$testroot" "$ret"
472 return 1
473 fi
475 (cd $testroot/wt && got log -l3 -c newbranch \
476 | grep ^commit > $testroot/stdout)
477 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
478 echo "commit $init_commit" >> $testroot/stdout.expected
479 cmp -s $testroot/stdout.expected $testroot/stdout
480 ret="$?"
481 if [ "$ret" != "0" ]; then
482 diff -u $testroot/stdout.expected $testroot/stdout
483 fi
484 test_done "$testroot" "$ret"
487 test_rebase_no_op_change() {
488 local testroot=`test_init rebase_no_op_change`
489 local init_commit=`git_show_head $testroot/repo`
491 (cd $testroot/repo && git checkout -q -b newbranch)
492 echo "modified alpha on branch" > $testroot/repo/alpha
493 git_commit $testroot/repo -m "committing to alpha on newbranch"
494 local orig_commit1=`git_show_head $testroot/repo`
495 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
497 (cd $testroot/repo && git checkout -q master)
498 echo "modified alpha on master" > $testroot/repo/alpha
499 git_commit $testroot/repo -m "committing to alpha on master"
500 local master_commit=`git_show_head $testroot/repo`
502 got checkout $testroot/repo $testroot/wt > /dev/null
503 ret="$?"
504 if [ "$ret" != "0" ]; then
505 test_done "$testroot" "$ret"
506 return 1
507 fi
509 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
510 2> $testroot/stderr)
512 echo "C alpha" > $testroot/stdout.expected
513 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
514 echo -n "$short_orig_commit1 -> merge conflict" \
515 >> $testroot/stdout.expected
516 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
517 cmp -s $testroot/stdout.expected $testroot/stdout
518 ret="$?"
519 if [ "$ret" != "0" ]; then
520 diff -u $testroot/stdout.expected $testroot/stdout
521 test_done "$testroot" "$ret"
522 return 1
523 fi
525 echo "got: conflicts must be resolved before rebasing can continue" \
526 > $testroot/stderr.expected
527 cmp -s $testroot/stderr.expected $testroot/stderr
528 ret="$?"
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stderr.expected $testroot/stderr
531 test_done "$testroot" "$ret"
532 return 1
533 fi
535 echo '<<<<<<<' > $testroot/content.expected
536 echo "modified alpha on master" >> $testroot/content.expected
537 echo "||||||| 3-way merge base: commit $init_commit" \
538 >> $testroot/content.expected
539 echo "alpha" >> $testroot/content.expected
540 echo "=======" >> $testroot/content.expected
541 echo "modified alpha on branch" >> $testroot/content.expected
542 echo ">>>>>>> merged change: commit $orig_commit1" \
543 >> $testroot/content.expected
544 cat $testroot/wt/alpha > $testroot/content
545 cmp -s $testroot/content.expected $testroot/content
546 ret="$?"
547 if [ "$ret" != "0" ]; then
548 diff -u $testroot/content.expected $testroot/content
549 test_done "$testroot" "$ret"
550 return 1
551 fi
553 (cd $testroot/wt && got status > $testroot/stdout)
555 echo "C alpha" > $testroot/stdout.expected
556 cmp -s $testroot/stdout.expected $testroot/stdout
557 ret="$?"
558 if [ "$ret" != "0" ]; then
559 diff -u $testroot/stdout.expected $testroot/stdout
560 test_done "$testroot" "$ret"
561 return 1
562 fi
564 # resolve the conflict
565 echo "modified alpha on master" > $testroot/wt/alpha
567 (cd $testroot/wt && got rebase -c > $testroot/stdout)
569 (cd $testroot/repo && git checkout -q newbranch)
570 local new_commit1=`git_show_head $testroot/repo`
572 echo -n "$short_orig_commit1 -> no-op change" \
573 > $testroot/stdout.expected
574 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
575 echo "Switching work tree to refs/heads/newbranch" \
576 >> $testroot/stdout.expected
578 cmp -s $testroot/stdout.expected $testroot/stdout
579 ret="$?"
580 if [ "$ret" != "0" ]; then
581 diff -u $testroot/stdout.expected $testroot/stdout
582 test_done "$testroot" "$ret"
583 return 1
584 fi
587 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
588 echo "commit $master_commit (master, newbranch)" \
589 > $testroot/stdout.expected
590 echo "commit $init_commit" >> $testroot/stdout.expected
591 cmp -s $testroot/stdout.expected $testroot/stdout
592 ret="$?"
593 if [ "$ret" != "0" ]; then
594 diff -u $testroot/stdout.expected $testroot/stdout
595 fi
596 test_done "$testroot" "$ret"
599 test_rebase_in_progress() {
600 local testroot=`test_init rebase_in_progress`
601 local init_commit=`git_show_head $testroot/repo`
603 (cd $testroot/repo && git checkout -q -b newbranch)
604 echo "modified alpha on branch" > $testroot/repo/alpha
605 git_commit $testroot/repo -m "committing to alpha on newbranch"
606 local orig_commit1=`git_show_head $testroot/repo`
607 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
609 (cd $testroot/repo && git checkout -q master)
610 echo "modified alpha on master" > $testroot/repo/alpha
611 git_commit $testroot/repo -m "committing to alpha on master"
612 local master_commit=`git_show_head $testroot/repo`
614 got checkout $testroot/repo $testroot/wt > /dev/null
615 ret="$?"
616 if [ "$ret" != "0" ]; then
617 test_done "$testroot" "$ret"
618 return 1
619 fi
621 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
622 2> $testroot/stderr)
624 echo "C alpha" > $testroot/stdout.expected
625 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
626 echo -n "$short_orig_commit1 -> merge conflict" \
627 >> $testroot/stdout.expected
628 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
629 cmp -s $testroot/stdout.expected $testroot/stdout
630 ret="$?"
631 if [ "$ret" != "0" ]; then
632 diff -u $testroot/stdout.expected $testroot/stdout
633 test_done "$testroot" "$ret"
634 return 1
635 fi
637 echo "got: conflicts must be resolved before rebasing can continue" \
638 > $testroot/stderr.expected
639 cmp -s $testroot/stderr.expected $testroot/stderr
640 ret="$?"
641 if [ "$ret" != "0" ]; then
642 diff -u $testroot/stderr.expected $testroot/stderr
643 test_done "$testroot" "$ret"
644 return 1
645 fi
647 echo '<<<<<<<' > $testroot/content.expected
648 echo "modified alpha on master" >> $testroot/content.expected
649 echo "||||||| 3-way merge base: commit $init_commit" \
650 >> $testroot/content.expected
651 echo "alpha" >> $testroot/content.expected
652 echo "=======" >> $testroot/content.expected
653 echo "modified alpha on branch" >> $testroot/content.expected
654 echo ">>>>>>> merged change: commit $orig_commit1" \
655 >> $testroot/content.expected
656 cat $testroot/wt/alpha > $testroot/content
657 cmp -s $testroot/content.expected $testroot/content
658 ret="$?"
659 if [ "$ret" != "0" ]; then
660 diff -u $testroot/content.expected $testroot/content
661 test_done "$testroot" "$ret"
662 return 1
663 fi
665 (cd $testroot/wt && got status > $testroot/stdout)
667 echo "C alpha" > $testroot/stdout.expected
668 cmp -s $testroot/stdout.expected $testroot/stdout
669 ret="$?"
670 if [ "$ret" != "0" ]; then
671 diff -u $testroot/stdout.expected $testroot/stdout
672 test_done "$testroot" "$ret"
673 return 1
674 fi
676 for cmd in update commit; do
677 (cd $testroot/wt && got $cmd > $testroot/stdout \
678 2> $testroot/stderr)
680 echo -n > $testroot/stdout.expected
681 cmp -s $testroot/stdout.expected $testroot/stdout
682 ret="$?"
683 if [ "$ret" != "0" ]; then
684 diff -u $testroot/stdout.expected $testroot/stdout
685 test_done "$testroot" "$ret"
686 return 1
687 fi
689 echo -n "got: a rebase operation is in progress in this " \
690 > $testroot/stderr.expected
691 echo "work tree and must be continued or aborted first" \
692 >> $testroot/stderr.expected
693 cmp -s $testroot/stderr.expected $testroot/stderr
694 ret="$?"
695 if [ "$ret" != "0" ]; then
696 diff -u $testroot/stderr.expected $testroot/stderr
697 test_done "$testroot" "$ret"
698 return 1
699 fi
700 done
702 test_done "$testroot" "$ret"
705 test_rebase_path_prefix() {
706 local testroot=`test_init rebase_path_prefix`
708 (cd $testroot/repo && git checkout -q -b newbranch)
709 echo "modified delta on branch" > $testroot/repo/gamma/delta
710 git_commit $testroot/repo -m "committing to delta on newbranch"
712 local orig_commit1=`git_show_parent_commit $testroot/repo`
713 local orig_commit2=`git_show_head $testroot/repo`
715 (cd $testroot/repo && git checkout -q master)
716 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
717 git_commit $testroot/repo -m "committing to zeta on master"
718 local master_commit=`git_show_head $testroot/repo`
720 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
721 ret="$?"
722 if [ "$ret" != "0" ]; then
723 test_done "$testroot" "$ret"
724 return 1
725 fi
727 (cd $testroot/wt && got rebase newbranch \
728 > $testroot/stdout 2> $testroot/stderr)
730 echo -n > $testroot/stdout.expected
731 cmp -s $testroot/stdout.expected $testroot/stdout
732 ret="$?"
733 if [ "$ret" != "0" ]; then
734 diff -u $testroot/stdout.expected $testroot/stdout
735 test_done "$testroot" "$ret"
736 return 1
737 fi
739 echo -n "got: cannot rebase branch which contains changes outside " \
740 > $testroot/stderr.expected
741 echo "of this work tree's path prefix" >> $testroot/stderr.expected
742 cmp -s $testroot/stderr.expected $testroot/stderr
743 ret="$?"
744 if [ "$ret" != "0" ]; then
745 diff -u $testroot/stderr.expected $testroot/stderr
746 fi
747 test_done "$testroot" "$ret"
750 test_rebase_preserves_logmsg() {
751 local testroot=`test_init rebase_preserves_logmsg`
753 (cd $testroot/repo && git checkout -q -b newbranch)
754 echo "modified delta on branch" > $testroot/repo/gamma/delta
755 git_commit $testroot/repo -m "modified delta on newbranch"
757 echo "modified alpha on branch" > $testroot/repo/alpha
758 git_commit $testroot/repo -m "modified alpha on newbranch"
760 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
761 > $testroot/log.expected)
763 local orig_commit1=`git_show_parent_commit $testroot/repo`
764 local orig_commit2=`git_show_head $testroot/repo`
766 (cd $testroot/repo && git checkout -q master)
767 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
768 git_commit $testroot/repo -m "committing to zeta on master"
769 local master_commit=`git_show_head $testroot/repo`
771 got checkout $testroot/repo $testroot/wt > /dev/null
772 ret="$?"
773 if [ "$ret" != "0" ]; then
774 test_done "$testroot" "$ret"
775 return 1
776 fi
778 (cd $testroot/wt && got rebase newbranch > /dev/null \
779 2> $testroot/stderr)
781 (cd $testroot/repo && git checkout -q newbranch)
782 local new_commit1=`git_show_parent_commit $testroot/repo`
783 local new_commit2=`git_show_head $testroot/repo`
785 echo -n > $testroot/stderr.expected
786 cmp -s $testroot/stderr.expected $testroot/stderr
787 ret="$?"
788 if [ "$ret" != "0" ]; then
789 diff -u $testroot/stderr.expected $testroot/stderr
790 test_done "$testroot" "$ret"
791 return 1
792 fi
794 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
795 > $testroot/log)
796 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
797 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
798 cmp -s $testroot/log.expected $testroot/log
799 ret="$?"
800 if [ "$ret" != "0" ]; then
801 diff -u $testroot/log.expected $testroot/log
802 fi
804 test_done "$testroot" "$ret"
807 test_rebase_no_commits_to_rebase() {
808 local testroot=`test_init rebase_no_commits_to_rebase`
810 got checkout $testroot/repo $testroot/wt > /dev/null
811 ret="$?"
812 if [ "$ret" != "0" ]; then
813 test_done "$testroot" "$ret"
814 return 1
815 fi
817 (cd $testroot/wt && got branch -n newbranch)
819 echo "modified alpha on master" > $testroot/wt/alpha
820 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
821 > /dev/null)
822 (cd $testroot/wt && got update > /dev/null)
824 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
825 2> $testroot/stderr)
827 echo "got: no commits to rebase" > $testroot/stderr.expected
828 cmp -s $testroot/stderr.expected $testroot/stderr
829 ret="$?"
830 if [ "$ret" != "0" ]; then
831 diff -u $testroot/stderr.expected $testroot/stderr
832 test_done "$testroot" "$ret"
833 return 1
834 fi
836 echo "Rebase of refs/heads/newbranch aborted" \
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 (cd $testroot/wt && got update > $testroot/stdout)
847 echo "Already up-to-date" > $testroot/stdout.expected
848 cmp -s $testroot/stdout.expected $testroot/stdout
849 ret="$?"
850 if [ "$ret" != "0" ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 fi
853 test_done "$testroot" "$ret"
856 test_rebase_forward() {
857 local testroot=`test_init rebase_forward`
858 local commit0=`git_show_head $testroot/repo`
860 got checkout $testroot/repo $testroot/wt > /dev/null
861 ret="$?"
862 if [ "$ret" != "0" ]; then
863 test_done "$testroot" "$ret"
864 return 1
865 fi
867 echo "change alpha 1" > $testroot/wt/alpha
868 (cd $testroot/wt && got commit -m 'test rebase_forward' \
869 > /dev/null)
870 local commit1=`git_show_head $testroot/repo`
872 echo "change alpha 2" > $testroot/wt/alpha
873 (cd $testroot/wt && got commit -m 'test rebase_forward' \
874 > /dev/null)
875 local commit2=`git_show_head $testroot/repo`
877 # Simulate a situation where fast-forward is required.
878 # We want to fast-forward master to origin/master:
879 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
880 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
881 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
882 (cd $testroot/repo && got ref -d master)
883 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
884 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
886 (cd $testroot/wt && got up -b origin/master > /dev/null)
888 (cd $testroot/wt && got rebase master \
889 > $testroot/stdout 2> $testroot/stderr)
891 echo "Forwarding refs/heads/master to commit $commit2" \
892 > $testroot/stdout.expected
893 echo "Switching work tree to refs/heads/master" \
894 >> $testroot/stdout.expected
895 cmp -s $testroot/stdout.expected $testroot/stdout
896 ret="$?"
897 if [ "$ret" != "0" ]; then
898 diff -u $testroot/stdout.expected $testroot/stdout
899 test_done "$testroot" "$ret"
900 return 1
901 fi
903 # Ensure that rebase operation was completed correctly
904 (cd $testroot/wt && got rebase -a \
905 > $testroot/stdout 2> $testroot/stderr)
906 echo -n "" > $testroot/stdout.expected
907 cmp -s $testroot/stdout.expected $testroot/stdout
908 ret="$?"
909 if [ "$ret" != "0" ]; then
910 diff -u $testroot/stdout.expected $testroot/stdout
911 test_done "$testroot" "$ret"
912 return 1
913 fi
914 echo "got: rebase operation not in progress" > $testroot/stderr.expected
915 cmp -s $testroot/stderr.expected $testroot/stderr
916 ret="$?"
917 if [ "$ret" != "0" ]; then
918 diff -u $testroot/stderr.expected $testroot/stderr
919 test_done "$testroot" "$ret"
920 return 1
921 fi
923 (cd $testroot/wt && got branch -n > $testroot/stdout)
924 echo "master" > $testroot/stdout.expected
925 cmp -s $testroot/stdout.expected $testroot/stdout
926 ret="$?"
927 if [ "$ret" != "0" ]; then
928 diff -u $testroot/stdout.expected $testroot/stdout
929 test_done "$testroot" "$ret"
930 return 1
931 fi
933 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
934 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
935 echo "commit $commit1" >> $testroot/stdout.expected
936 echo "commit $commit0" >> $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected $testroot/stdout
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 test_done "$testroot" "$ret"
942 fi
944 # Forward-only rebase operations should not be backed up
945 (cd $testroot/repo && got rebase -l > $testroot/stdout)
946 echo -n > $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 test_rebase_out_of_date() {
956 local testroot=`test_init rebase_out_of_date`
957 local initial_commit=`git_show_head $testroot/repo`
959 (cd $testroot/repo && git checkout -q -b newbranch)
960 echo "modified delta on branch" > $testroot/repo/gamma/delta
961 git_commit $testroot/repo -m "committing to delta on newbranch"
963 echo "modified alpha on branch" > $testroot/repo/alpha
964 (cd $testroot/repo && git rm -q beta)
965 echo "new file on branch" > $testroot/repo/epsilon/new
966 (cd $testroot/repo && git add epsilon/new)
967 git_commit $testroot/repo -m "committing more changes on newbranch"
969 local orig_commit1=`git_show_parent_commit $testroot/repo`
970 local orig_commit2=`git_show_head $testroot/repo`
972 (cd $testroot/repo && git checkout -q master)
973 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
974 git_commit $testroot/repo -m "committing to zeta on master"
975 local master_commit1=`git_show_head $testroot/repo`
977 (cd $testroot/repo && git checkout -q master)
978 echo "modified beta on master" > $testroot/repo/beta
979 git_commit $testroot/repo -m "committing to beta on master"
980 local master_commit2=`git_show_head $testroot/repo`
982 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
983 > /dev/null
984 ret="$?"
985 if [ "$ret" != "0" ]; then
986 test_done "$testroot" "$ret"
987 return 1
988 fi
990 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
991 2> $testroot/stderr)
993 echo -n > $testroot/stdout.expected
994 cmp -s $testroot/stdout.expected $testroot/stdout
995 ret="$?"
996 if [ "$ret" != "0" ]; then
997 diff -u $testroot/stdout.expected $testroot/stdout
998 test_done "$testroot" "$ret"
999 return 1
1002 echo -n "got: work tree must be updated before it can be " \
1003 > $testroot/stderr.expected
1004 echo "used to rebase a branch" >> $testroot/stderr.expected
1005 cmp -s $testroot/stderr.expected $testroot/stderr
1006 ret="$?"
1007 if [ "$ret" != "0" ]; then
1008 diff -u $testroot/stderr.expected $testroot/stderr
1009 test_done "$testroot" "$ret"
1010 return 1
1013 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1014 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1015 echo "commit $master_commit1" >> $testroot/stdout.expected
1016 echo "commit $initial_commit" >> $testroot/stdout.expected
1017 cmp -s $testroot/stdout.expected $testroot/stdout
1018 ret="$?"
1019 if [ "$ret" != "0" ]; then
1020 diff -u $testroot/stdout.expected $testroot/stdout
1022 test_done "$testroot" "$ret"
1025 test_rebase_trims_empty_dir() {
1026 local testroot=`test_init rebase_trims_empty_dir`
1028 (cd $testroot/repo && git checkout -q -b newbranch)
1029 echo "modified delta on branch" > $testroot/repo/gamma/delta
1030 git_commit $testroot/repo -m "committing to delta on newbranch"
1032 (cd $testroot/repo && git rm -q epsilon/zeta)
1033 git_commit $testroot/repo -m "removing zeta on newbranch"
1035 local orig_commit1=`git_show_parent_commit $testroot/repo`
1036 local orig_commit2=`git_show_head $testroot/repo`
1038 (cd $testroot/repo && git checkout -q master)
1039 echo "modified alpha on master" > $testroot/repo/alpha
1040 git_commit $testroot/repo -m "committing to alpha on master"
1041 local master_commit=`git_show_head $testroot/repo`
1043 got checkout $testroot/repo $testroot/wt > /dev/null
1044 ret="$?"
1045 if [ "$ret" != "0" ]; then
1046 test_done "$testroot" "$ret"
1047 return 1
1050 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1052 (cd $testroot/repo && git checkout -q newbranch)
1053 local new_commit1=`git_show_parent_commit $testroot/repo`
1054 local new_commit2=`git_show_head $testroot/repo`
1056 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1057 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1058 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1059 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1061 echo "G gamma/delta" >> $testroot/stdout.expected
1062 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1063 >> $testroot/stdout.expected
1064 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1065 echo "D epsilon/zeta" >> $testroot/stdout.expected
1066 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1067 >> $testroot/stdout.expected
1068 echo ": removing zeta on newbranch" \
1069 >> $testroot/stdout.expected
1070 echo "Switching work tree to refs/heads/newbranch" \
1071 >> $testroot/stdout.expected
1073 cmp -s $testroot/stdout.expected $testroot/stdout
1074 ret="$?"
1075 if [ "$ret" != "0" ]; then
1076 diff -u $testroot/stdout.expected $testroot/stdout
1077 test_done "$testroot" "$ret"
1078 return 1
1081 echo "modified delta on branch" > $testroot/content.expected
1082 cat $testroot/wt/gamma/delta > $testroot/content
1083 cmp -s $testroot/content.expected $testroot/content
1084 ret="$?"
1085 if [ "$ret" != "0" ]; then
1086 diff -u $testroot/content.expected $testroot/content
1087 test_done "$testroot" "$ret"
1088 return 1
1091 echo "modified alpha on master" > $testroot/content.expected
1092 cat $testroot/wt/alpha > $testroot/content
1093 cmp -s $testroot/content.expected $testroot/content
1094 ret="$?"
1095 if [ "$ret" != "0" ]; then
1096 diff -u $testroot/content.expected $testroot/content
1097 test_done "$testroot" "$ret"
1098 return 1
1101 if [ -e $testroot/wt/epsilon ]; then
1102 echo "parent of removed zeta still exists on disk" >&2
1103 test_done "$testroot" "1"
1104 return 1
1107 (cd $testroot/wt && got status > $testroot/stdout)
1109 echo -n > $testroot/stdout.expected
1110 cmp -s $testroot/stdout.expected $testroot/stdout
1111 ret="$?"
1112 if [ "$ret" != "0" ]; then
1113 diff -u $testroot/stdout.expected $testroot/stdout
1114 test_done "$testroot" "$ret"
1115 return 1
1118 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1119 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1120 echo "commit $new_commit1" >> $testroot/stdout.expected
1121 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1122 cmp -s $testroot/stdout.expected $testroot/stdout
1123 ret="$?"
1124 if [ "$ret" != "0" ]; then
1125 diff -u $testroot/stdout.expected $testroot/stdout
1127 test_done "$testroot" "$ret"
1130 test_rebase_delete_missing_file() {
1131 local testroot=`test_init rebase_delete_missing_file`
1133 mkdir -p $testroot/repo/d/f/g
1134 echo "new file" > $testroot/repo/d/f/g/new
1135 (cd $testroot/repo && git add d/f/g/new)
1136 git_commit $testroot/repo -m "adding a subdir"
1137 local commit0=`git_show_head $testroot/repo`
1139 got br -r $testroot/repo -c master newbranch
1141 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1143 echo "modified delta on branch" > $testroot/wt/gamma/delta
1144 (cd $testroot/wt && got commit \
1145 -m "committing to delta on newbranch" > /dev/null)
1147 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1148 (cd $testroot/wt && got commit \
1149 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1151 (cd $testroot/repo && git checkout -q newbranch)
1152 local orig_commit1=`git_show_parent_commit $testroot/repo`
1153 local orig_commit2=`git_show_head $testroot/repo`
1155 (cd $testroot/wt && got update -b master > /dev/null)
1156 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1157 (cd $testroot/wt && got commit \
1158 -m "removing beta and d/f/g/new on master" > /dev/null)
1160 (cd $testroot/repo && git checkout -q master)
1161 local master_commit=`git_show_head $testroot/repo`
1163 (cd $testroot/wt && got update -b master > /dev/null)
1164 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1166 (cd $testroot/repo && git checkout -q newbranch)
1167 local new_commit1=`git_show_head $testroot/repo`
1169 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1170 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1171 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1173 echo "G gamma/delta" >> $testroot/stdout.expected
1174 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1175 >> $testroot/stdout.expected
1176 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1177 echo "! beta" >> $testroot/stdout.expected
1178 echo "! d/f/g/new" >> $testroot/stdout.expected
1179 echo -n "$short_orig_commit2 -> no-op change" \
1180 >> $testroot/stdout.expected
1181 echo ": removing beta and d/f/g/new on newbranch" \
1182 >> $testroot/stdout.expected
1183 echo "Switching work tree to refs/heads/newbranch" \
1184 >> $testroot/stdout.expected
1186 cmp -s $testroot/stdout.expected $testroot/stdout
1187 ret="$?"
1188 if [ "$ret" != "0" ]; then
1189 diff -u $testroot/stdout.expected $testroot/stdout
1190 test_done "$testroot" "$ret"
1191 return 1
1194 echo "modified delta on branch" > $testroot/content.expected
1195 cat $testroot/wt/gamma/delta > $testroot/content
1196 cmp -s $testroot/content.expected $testroot/content
1197 ret="$?"
1198 if [ "$ret" != "0" ]; then
1199 diff -u $testroot/content.expected $testroot/content
1200 test_done "$testroot" "$ret"
1201 return 1
1204 if [ -e $testroot/wt/beta ]; then
1205 echo "removed file beta still exists on disk" >&2
1206 test_done "$testroot" "1"
1207 return 1
1210 (cd $testroot/wt && got status > $testroot/stdout)
1212 echo -n > $testroot/stdout.expected
1213 cmp -s $testroot/stdout.expected $testroot/stdout
1214 ret="$?"
1215 if [ "$ret" != "0" ]; then
1216 diff -u $testroot/stdout.expected $testroot/stdout
1217 test_done "$testroot" "$ret"
1218 return 1
1221 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1222 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1223 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1224 echo "commit $commit0" >> $testroot/stdout.expected
1225 cmp -s $testroot/stdout.expected $testroot/stdout
1226 ret="$?"
1227 if [ "$ret" != "0" ]; then
1228 diff -u $testroot/stdout.expected $testroot/stdout
1230 test_done "$testroot" "$ret"
1233 test_rebase_rm_add_rm_file() {
1234 local testroot=`test_init rebase_rm_add_rm_file`
1236 (cd $testroot/repo && git checkout -q -b newbranch)
1237 (cd $testroot/repo && git rm -q beta)
1238 git_commit $testroot/repo -m "removing beta from newbranch"
1239 local orig_commit1=`git_show_head $testroot/repo`
1241 echo 'restored beta' > $testroot/repo/beta
1242 (cd $testroot/repo && git add beta)
1243 git_commit $testroot/repo -m "restoring beta on newbranch"
1244 local orig_commit2=`git_show_head $testroot/repo`
1246 (cd $testroot/repo && git rm -q beta)
1247 git_commit $testroot/repo -m "removing beta from newbranch again"
1248 local orig_commit3=`git_show_head $testroot/repo`
1250 (cd $testroot/repo && git checkout -q master)
1251 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1252 git_commit $testroot/repo -m "committing to zeta on master"
1253 local master_commit=`git_show_head $testroot/repo`
1255 got checkout $testroot/repo $testroot/wt > /dev/null
1256 ret="$?"
1257 if [ "$ret" != "0" ]; then
1258 test_done "$testroot" "$ret"
1259 return 1
1262 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1264 # this would error out with 'got: file index is corrupt'
1265 (cd $testroot/wt && got status > /dev/null)
1266 ret="$?"
1267 if [ "$ret" != "0" ]; then
1268 echo "got status command failed unexpectedly" >&2
1269 test_done "$testroot" "$ret"
1270 return 1
1273 (cd $testroot/repo && git checkout -q newbranch)
1274 local new_commit3=`git_show_head $testroot/repo`
1275 local new_commit2=`git_show_parent_commit $testroot/repo`
1276 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1278 (cd $testroot/repo && git checkout -q newbranch)
1280 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1281 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1282 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1283 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1284 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1285 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1287 echo "D beta" > $testroot/stdout.expected
1288 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1289 >> $testroot/stdout.expected
1290 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1291 echo "A beta" >> $testroot/stdout.expected
1292 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1293 >> $testroot/stdout.expected
1294 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1295 echo "D beta" >> $testroot/stdout.expected
1296 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1297 >> $testroot/stdout.expected
1298 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1299 echo "Switching work tree to refs/heads/newbranch" \
1300 >> $testroot/stdout.expected
1302 cmp -s $testroot/stdout.expected $testroot/stdout
1303 ret="$?"
1304 if [ "$ret" != "0" ]; then
1305 diff -u $testroot/stdout.expected $testroot/stdout
1306 test_done "$testroot" "$ret"
1307 return 1
1310 (cd $testroot/wt && got status > $testroot/stdout)
1311 ret="$?"
1312 if [ "$ret" != "0" ]; then
1313 echo "got status command failed unexpectedly" >&2
1314 test_done "$testroot" "$ret"
1315 return 1
1318 echo -n > $testroot/stdout.expected
1319 cmp -s $testroot/stdout.expected $testroot/stdout
1320 ret="$?"
1321 if [ "$ret" != "0" ]; then
1322 diff -u $testroot/stdout.expected $testroot/stdout
1323 test_done "$testroot" "$ret"
1324 return 1
1327 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1328 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1329 echo "commit $new_commit2" >> $testroot/stdout.expected
1330 echo "commit $new_commit1" >> $testroot/stdout.expected
1331 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1332 cmp -s $testroot/stdout.expected $testroot/stdout
1333 ret="$?"
1334 if [ "$ret" != "0" ]; then
1335 diff -u $testroot/stdout.expected $testroot/stdout
1337 test_done "$testroot" "$ret"
1340 test_parseargs "$@"
1341 run_test test_rebase_basic
1342 run_test test_rebase_ancestry_check
1343 run_test test_rebase_continue
1344 run_test test_rebase_abort
1345 run_test test_rebase_no_op_change
1346 run_test test_rebase_in_progress
1347 run_test test_rebase_path_prefix
1348 run_test test_rebase_preserves_logmsg
1349 run_test test_rebase_no_commits_to_rebase
1350 run_test test_rebase_forward
1351 run_test test_rebase_out_of_date
1352 run_test test_rebase_trims_empty_dir
1353 run_test test_rebase_delete_missing_file
1354 run_test test_rebase_rm_add_rm_file