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 return 1
152 fi
154 # We should have a backup of old commits
155 (cd $testroot/repo && got rebase -l > $testroot/stdout)
156 local prev_LC_TIME="$LC_TIME"
157 export LC_TIME=C
158 d_orig2=`date -u -d "@$orig_author_time2" +"%a %b %e %X %Y UTC"`
159 export LC_TIME="$prev_LC_TIME"
160 d_new2=`date -u -d "@$new_author_time2" +"%G-%m-%d"`
161 d_0=`date -u -d "@$commit0_author_time" +"%G-%m-%d"`
162 cat > $testroot/stdout.expected <<EOF
163 -----------------------------------------------
164 commit $orig_commit2 (formerly newbranch)
165 from: $GOT_AUTHOR
166 date: $d_orig2
168 committing more changes on newbranch
170 has become commit $new_commit2 (newbranch)
171 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
172 history forked at $commit0
173 $d_0 $GOT_AUTHOR_11 adding the test tree
174 EOF
175 cmp -s $testroot/stdout.expected $testroot/stdout
176 ret="$?"
177 if [ "$ret" != "0" ]; then
178 diff -u $testroot/stdout.expected $testroot/stdout
179 test_done "$testroot" "$ret"
180 return 1
181 fi
183 # Asking for backups of a branch which has none should yield an error
184 (cd $testroot/repo && got rebase -l master \
185 > $testroot/stdout 2> $testroot/stderr)
186 echo -n > $testroot/stdout.expected
187 echo "got: refs/got/backup/rebase/master/: no such reference found" \
188 > $testroot/stderr.expected
189 cmp -s $testroot/stdout.expected $testroot/stdout
190 ret="$?"
191 if [ "$ret" != "0" ]; then
192 diff -u $testroot/stdout.expected $testroot/stdout
193 test_done "$testroot" "$ret"
194 return 1
195 fi
196 cmp -s $testroot/stderr.expected $testroot/stderr
197 ret="$?"
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stderr.expected $testroot/stderr
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 # Delete all backup refs
205 (cd $testroot/repo && got rebase -X \
206 > $testroot/stdout 2> $testroot/stderr)
207 echo -n "Deleted refs/got/backup/rebase/newbranch/$new_commit2: " \
208 > $testroot/stdout.expected
209 echo "$orig_commit2" >> $testroot/stdout.expected
210 echo -n > $testroot/stderr.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
216 return 1
217 fi
218 cmp -s $testroot/stderr.expected $testroot/stderr
219 ret="$?"
220 if [ "$ret" != "0" ]; then
221 diff -u $testroot/stderr.expected $testroot/stderr
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 (cd $testroot/repo && got rebase -l > $testroot/stdout)
227 echo -n > $testroot/stdout.expected
228 cmp -s $testroot/stdout.expected $testroot/stdout
229 ret="$?"
230 if [ "$ret" != "0" ]; then
231 diff -u $testroot/stdout.expected $testroot/stdout
232 fi
233 test_done "$testroot" "$ret"
236 test_rebase_ancestry_check() {
237 local testroot=`test_init rebase_ancestry_check`
239 got checkout $testroot/repo $testroot/wt > /dev/null
240 ret="$?"
241 if [ "$ret" != "0" ]; then
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 (cd $testroot/repo && git checkout -q -b newbranch)
247 echo "modified delta on branch" > $testroot/repo/gamma/delta
248 git_commit $testroot/repo -m "committing to delta on newbranch"
249 local newbranch_id=`git_show_head $testroot/repo`
251 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
252 2> $testroot/stderr)
254 echo "refs/heads/newbranch is already based on refs/heads/master" \
255 > $testroot/stdout.expected
256 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
257 >> $testroot/stdout.expected
258 echo "U gamma/delta" >> $testroot/stdout.expected
259 echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
260 >> $testroot/stdout.expected
261 cmp -s $testroot/stdout.expected $testroot/stdout
262 ret="$?"
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 echo -n > $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 fi
275 test_done "$testroot" "$ret"
278 test_rebase_continue() {
279 local testroot=`test_init rebase_continue`
280 local init_commit=`git_show_head $testroot/repo`
282 (cd $testroot/repo && git checkout -q -b newbranch)
283 echo "modified alpha on branch" > $testroot/repo/alpha
284 git_commit $testroot/repo -m "committing to alpha on newbranch"
285 local orig_commit1=`git_show_head $testroot/repo`
286 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
288 (cd $testroot/repo && git checkout -q master)
289 echo "modified alpha on master" > $testroot/repo/alpha
290 git_commit $testroot/repo -m "committing to alpha on master"
291 local master_commit=`git_show_head $testroot/repo`
293 got checkout $testroot/repo $testroot/wt > /dev/null
294 ret="$?"
295 if [ "$ret" != "0" ]; then
296 test_done "$testroot" "$ret"
297 return 1
298 fi
300 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
301 2> $testroot/stderr)
303 echo "C alpha" > $testroot/stdout.expected
304 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
305 echo -n "$short_orig_commit1 -> merge conflict" \
306 >> $testroot/stdout.expected
307 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
308 cmp -s $testroot/stdout.expected $testroot/stdout
309 ret="$?"
310 if [ "$ret" != "0" ]; then
311 diff -u $testroot/stdout.expected $testroot/stdout
312 test_done "$testroot" "$ret"
313 return 1
314 fi
316 echo "got: conflicts must be resolved before rebasing can continue" \
317 > $testroot/stderr.expected
318 cmp -s $testroot/stderr.expected $testroot/stderr
319 ret="$?"
320 if [ "$ret" != "0" ]; then
321 diff -u $testroot/stderr.expected $testroot/stderr
322 test_done "$testroot" "$ret"
323 return 1
324 fi
326 echo '<<<<<<<' > $testroot/content.expected
327 echo "modified alpha on master" >> $testroot/content.expected
328 echo "||||||| 3-way merge base: commit $init_commit" \
329 >> $testroot/content.expected
330 echo "alpha" >> $testroot/content.expected
331 echo "=======" >> $testroot/content.expected
332 echo "modified alpha on branch" >> $testroot/content.expected
333 echo ">>>>>>> merged change: commit $orig_commit1" \
334 >> $testroot/content.expected
335 cat $testroot/wt/alpha > $testroot/content
336 cmp -s $testroot/content.expected $testroot/content
337 ret="$?"
338 if [ "$ret" != "0" ]; then
339 diff -u $testroot/content.expected $testroot/content
340 test_done "$testroot" "$ret"
341 return 1
342 fi
344 (cd $testroot/wt && got status > $testroot/stdout)
346 echo "C alpha" > $testroot/stdout.expected
347 cmp -s $testroot/stdout.expected $testroot/stdout
348 ret="$?"
349 if [ "$ret" != "0" ]; then
350 diff -u $testroot/stdout.expected $testroot/stdout
351 test_done "$testroot" "$ret"
352 return 1
353 fi
355 # resolve the conflict
356 echo "modified alpha on branch and master" > $testroot/wt/alpha
358 # test interaction of 'got stage' and rebase -c
359 (cd $testroot/wt && got stage alpha > /dev/null)
360 (cd $testroot/wt && got rebase -c > $testroot/stdout \
361 2> $testroot/stderr)
362 ret="$?"
363 if [ "$ret" = "0" ]; then
364 echo "rebase succeeded unexpectedly" >&2
365 test_done "$testroot" "1"
366 return 1
367 fi
368 echo -n "got: work tree contains files with staged changes; " \
369 > $testroot/stderr.expected
370 echo "these changes must be committed or unstaged first" \
371 >> $testroot/stderr.expected
372 cmp -s $testroot/stderr.expected $testroot/stderr
373 ret="$?"
374 if [ "$ret" != "0" ]; then
375 diff -u $testroot/stderr.expected $testroot/stderr
376 test_done "$testroot" "$ret"
377 return 1
378 fi
380 (cd $testroot/wt && got unstage alpha > /dev/null)
381 (cd $testroot/wt && got rebase -c > $testroot/stdout)
383 (cd $testroot/repo && git checkout -q newbranch)
384 local new_commit1=`git_show_head $testroot/repo`
385 local short_new_commit1=`trim_obj_id 28 $new_commit1`
387 echo -n "$short_orig_commit1 -> $short_new_commit1" \
388 > $testroot/stdout.expected
389 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
390 echo "Switching work tree to refs/heads/newbranch" \
391 >> $testroot/stdout.expected
393 cmp -s $testroot/stdout.expected $testroot/stdout
394 ret="$?"
395 if [ "$ret" != "0" ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
398 return 1
399 fi
402 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
403 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
404 echo "commit $master_commit (master)" >> $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected $testroot/stdout
406 ret="$?"
407 if [ "$ret" != "0" ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 fi
410 test_done "$testroot" "$ret"
413 test_rebase_abort() {
414 local testroot=`test_init rebase_abort`
416 local init_commit=`git_show_head $testroot/repo`
418 (cd $testroot/repo && git checkout -q -b newbranch)
419 echo "modified alpha on branch" > $testroot/repo/alpha
420 git_commit $testroot/repo -m "committing to alpha on newbranch"
421 local orig_commit1=`git_show_head $testroot/repo`
422 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
424 (cd $testroot/repo && git checkout -q master)
425 echo "modified alpha on master" > $testroot/repo/alpha
426 git_commit $testroot/repo -m "committing to alpha on master"
427 local master_commit=`git_show_head $testroot/repo`
429 got checkout $testroot/repo $testroot/wt > /dev/null
430 ret="$?"
431 if [ "$ret" != "0" ]; then
432 test_done "$testroot" "$ret"
433 return 1
434 fi
436 # unrelated unversioned file in work tree
437 touch $testroot/wt/unversioned-file
439 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
440 2> $testroot/stderr)
442 echo "C alpha" > $testroot/stdout.expected
443 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
444 echo -n "$short_orig_commit1 -> merge conflict" \
445 >> $testroot/stdout.expected
446 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
447 cmp -s $testroot/stdout.expected $testroot/stdout
448 ret="$?"
449 if [ "$ret" != "0" ]; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" "$ret"
452 return 1
453 fi
455 echo "got: conflicts must be resolved before rebasing can continue" \
456 > $testroot/stderr.expected
457 cmp -s $testroot/stderr.expected $testroot/stderr
458 ret="$?"
459 if [ "$ret" != "0" ]; then
460 diff -u $testroot/stderr.expected $testroot/stderr
461 test_done "$testroot" "$ret"
462 return 1
463 fi
465 echo '<<<<<<<' > $testroot/content.expected
466 echo "modified alpha on master" >> $testroot/content.expected
467 echo "||||||| 3-way merge base: commit $init_commit" \
468 >> $testroot/content.expected
469 echo "alpha" >> $testroot/content.expected
470 echo "=======" >> $testroot/content.expected
471 echo "modified alpha on branch" >> $testroot/content.expected
472 echo ">>>>>>> merged change: commit $orig_commit1" \
473 >> $testroot/content.expected
474 cat $testroot/wt/alpha > $testroot/content
475 cmp -s $testroot/content.expected $testroot/content
476 ret="$?"
477 if [ "$ret" != "0" ]; then
478 diff -u $testroot/content.expected $testroot/content
479 test_done "$testroot" "$ret"
480 return 1
481 fi
483 (cd $testroot/wt && got status > $testroot/stdout)
485 echo "C alpha" > $testroot/stdout.expected
486 echo "? unversioned-file" >> $testroot/stdout.expected
487 cmp -s $testroot/stdout.expected $testroot/stdout
488 ret="$?"
489 if [ "$ret" != "0" ]; then
490 diff -u $testroot/stdout.expected $testroot/stdout
491 test_done "$testroot" "$ret"
492 return 1
493 fi
495 (cd $testroot/wt && got rebase -a > $testroot/stdout)
497 (cd $testroot/repo && git checkout -q newbranch)
499 echo "Switching work tree to refs/heads/master" \
500 > $testroot/stdout.expected
501 echo 'R alpha' >> $testroot/stdout.expected
502 echo "Rebase of refs/heads/newbranch aborted" \
503 >> $testroot/stdout.expected
505 cmp -s $testroot/stdout.expected $testroot/stdout
506 ret="$?"
507 if [ "$ret" != "0" ]; then
508 diff -u $testroot/stdout.expected $testroot/stdout
509 test_done "$testroot" "$ret"
510 return 1
511 fi
513 echo "modified alpha on master" > $testroot/content.expected
514 cat $testroot/wt/alpha > $testroot/content
515 cmp -s $testroot/content.expected $testroot/content
516 ret="$?"
517 if [ "$ret" != "0" ]; then
518 diff -u $testroot/content.expected $testroot/content
519 test_done "$testroot" "$ret"
520 return 1
521 fi
523 (cd $testroot/wt && got log -l3 -c newbranch \
524 | grep ^commit > $testroot/stdout)
525 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
526 echo "commit $init_commit" >> $testroot/stdout.expected
527 cmp -s $testroot/stdout.expected $testroot/stdout
528 ret="$?"
529 if [ "$ret" != "0" ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 fi
532 test_done "$testroot" "$ret"
535 test_rebase_no_op_change() {
536 local testroot=`test_init rebase_no_op_change`
537 local init_commit=`git_show_head $testroot/repo`
539 (cd $testroot/repo && git checkout -q -b newbranch)
540 echo "modified alpha on branch" > $testroot/repo/alpha
541 git_commit $testroot/repo -m "committing to alpha on newbranch"
542 local orig_commit1=`git_show_head $testroot/repo`
543 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
545 (cd $testroot/repo && git checkout -q master)
546 echo "modified alpha on master" > $testroot/repo/alpha
547 git_commit $testroot/repo -m "committing to alpha on master"
548 local master_commit=`git_show_head $testroot/repo`
550 got checkout $testroot/repo $testroot/wt > /dev/null
551 ret="$?"
552 if [ "$ret" != "0" ]; then
553 test_done "$testroot" "$ret"
554 return 1
555 fi
557 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
558 2> $testroot/stderr)
560 echo "C alpha" > $testroot/stdout.expected
561 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
562 echo -n "$short_orig_commit1 -> merge conflict" \
563 >> $testroot/stdout.expected
564 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
565 cmp -s $testroot/stdout.expected $testroot/stdout
566 ret="$?"
567 if [ "$ret" != "0" ]; then
568 diff -u $testroot/stdout.expected $testroot/stdout
569 test_done "$testroot" "$ret"
570 return 1
571 fi
573 echo "got: conflicts must be resolved before rebasing can continue" \
574 > $testroot/stderr.expected
575 cmp -s $testroot/stderr.expected $testroot/stderr
576 ret="$?"
577 if [ "$ret" != "0" ]; then
578 diff -u $testroot/stderr.expected $testroot/stderr
579 test_done "$testroot" "$ret"
580 return 1
581 fi
583 echo '<<<<<<<' > $testroot/content.expected
584 echo "modified alpha on master" >> $testroot/content.expected
585 echo "||||||| 3-way merge base: commit $init_commit" \
586 >> $testroot/content.expected
587 echo "alpha" >> $testroot/content.expected
588 echo "=======" >> $testroot/content.expected
589 echo "modified alpha on branch" >> $testroot/content.expected
590 echo ">>>>>>> merged change: commit $orig_commit1" \
591 >> $testroot/content.expected
592 cat $testroot/wt/alpha > $testroot/content
593 cmp -s $testroot/content.expected $testroot/content
594 ret="$?"
595 if [ "$ret" != "0" ]; then
596 diff -u $testroot/content.expected $testroot/content
597 test_done "$testroot" "$ret"
598 return 1
599 fi
601 (cd $testroot/wt && got status > $testroot/stdout)
603 echo "C alpha" > $testroot/stdout.expected
604 cmp -s $testroot/stdout.expected $testroot/stdout
605 ret="$?"
606 if [ "$ret" != "0" ]; then
607 diff -u $testroot/stdout.expected $testroot/stdout
608 test_done "$testroot" "$ret"
609 return 1
610 fi
612 # resolve the conflict
613 echo "modified alpha on master" > $testroot/wt/alpha
615 (cd $testroot/wt && got rebase -c > $testroot/stdout)
617 (cd $testroot/repo && git checkout -q newbranch)
618 local new_commit1=`git_show_head $testroot/repo`
620 echo -n "$short_orig_commit1 -> no-op change" \
621 > $testroot/stdout.expected
622 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
623 echo "Switching work tree to refs/heads/newbranch" \
624 >> $testroot/stdout.expected
626 cmp -s $testroot/stdout.expected $testroot/stdout
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
631 return 1
632 fi
635 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
636 echo "commit $master_commit (master, newbranch)" \
637 > $testroot/stdout.expected
638 echo "commit $init_commit" >> $testroot/stdout.expected
639 cmp -s $testroot/stdout.expected $testroot/stdout
640 ret="$?"
641 if [ "$ret" != "0" ]; then
642 diff -u $testroot/stdout.expected $testroot/stdout
643 fi
644 test_done "$testroot" "$ret"
647 test_rebase_in_progress() {
648 local testroot=`test_init rebase_in_progress`
649 local init_commit=`git_show_head $testroot/repo`
651 (cd $testroot/repo && git checkout -q -b newbranch)
652 echo "modified alpha on branch" > $testroot/repo/alpha
653 git_commit $testroot/repo -m "committing to alpha on newbranch"
654 local orig_commit1=`git_show_head $testroot/repo`
655 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
657 (cd $testroot/repo && git checkout -q master)
658 echo "modified alpha on master" > $testroot/repo/alpha
659 git_commit $testroot/repo -m "committing to alpha on master"
660 local master_commit=`git_show_head $testroot/repo`
662 got checkout $testroot/repo $testroot/wt > /dev/null
663 ret="$?"
664 if [ "$ret" != "0" ]; then
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
670 2> $testroot/stderr)
672 echo "C alpha" > $testroot/stdout.expected
673 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
674 echo -n "$short_orig_commit1 -> merge conflict" \
675 >> $testroot/stdout.expected
676 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
677 cmp -s $testroot/stdout.expected $testroot/stdout
678 ret="$?"
679 if [ "$ret" != "0" ]; then
680 diff -u $testroot/stdout.expected $testroot/stdout
681 test_done "$testroot" "$ret"
682 return 1
683 fi
685 echo "got: conflicts must be resolved before rebasing can continue" \
686 > $testroot/stderr.expected
687 cmp -s $testroot/stderr.expected $testroot/stderr
688 ret="$?"
689 if [ "$ret" != "0" ]; then
690 diff -u $testroot/stderr.expected $testroot/stderr
691 test_done "$testroot" "$ret"
692 return 1
693 fi
695 echo '<<<<<<<' > $testroot/content.expected
696 echo "modified alpha on master" >> $testroot/content.expected
697 echo "||||||| 3-way merge base: commit $init_commit" \
698 >> $testroot/content.expected
699 echo "alpha" >> $testroot/content.expected
700 echo "=======" >> $testroot/content.expected
701 echo "modified alpha on branch" >> $testroot/content.expected
702 echo ">>>>>>> merged change: commit $orig_commit1" \
703 >> $testroot/content.expected
704 cat $testroot/wt/alpha > $testroot/content
705 cmp -s $testroot/content.expected $testroot/content
706 ret="$?"
707 if [ "$ret" != "0" ]; then
708 diff -u $testroot/content.expected $testroot/content
709 test_done "$testroot" "$ret"
710 return 1
711 fi
713 (cd $testroot/wt && got status > $testroot/stdout)
715 echo "C alpha" > $testroot/stdout.expected
716 cmp -s $testroot/stdout.expected $testroot/stdout
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 diff -u $testroot/stdout.expected $testroot/stdout
720 test_done "$testroot" "$ret"
721 return 1
722 fi
724 for cmd in update commit; do
725 (cd $testroot/wt && got $cmd > $testroot/stdout \
726 2> $testroot/stderr)
728 echo -n > $testroot/stdout.expected
729 cmp -s $testroot/stdout.expected $testroot/stdout
730 ret="$?"
731 if [ "$ret" != "0" ]; then
732 diff -u $testroot/stdout.expected $testroot/stdout
733 test_done "$testroot" "$ret"
734 return 1
735 fi
737 echo -n "got: a rebase operation is in progress in this " \
738 > $testroot/stderr.expected
739 echo "work tree and must be continued or aborted first" \
740 >> $testroot/stderr.expected
741 cmp -s $testroot/stderr.expected $testroot/stderr
742 ret="$?"
743 if [ "$ret" != "0" ]; then
744 diff -u $testroot/stderr.expected $testroot/stderr
745 test_done "$testroot" "$ret"
746 return 1
747 fi
748 done
750 test_done "$testroot" "$ret"
753 test_rebase_path_prefix() {
754 local testroot=`test_init rebase_path_prefix`
756 (cd $testroot/repo && git checkout -q -b newbranch)
757 echo "modified delta on branch" > $testroot/repo/gamma/delta
758 git_commit $testroot/repo -m "committing to delta on newbranch"
760 local orig_commit1=`git_show_parent_commit $testroot/repo`
761 local orig_commit2=`git_show_head $testroot/repo`
763 (cd $testroot/repo && git checkout -q master)
764 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
765 git_commit $testroot/repo -m "committing to zeta on master"
766 local master_commit=`git_show_head $testroot/repo`
768 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
769 ret="$?"
770 if [ "$ret" != "0" ]; then
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 (cd $testroot/wt && got rebase newbranch \
776 > $testroot/stdout 2> $testroot/stderr)
778 echo -n > $testroot/stdout.expected
779 cmp -s $testroot/stdout.expected $testroot/stdout
780 ret="$?"
781 if [ "$ret" != "0" ]; then
782 diff -u $testroot/stdout.expected $testroot/stdout
783 test_done "$testroot" "$ret"
784 return 1
785 fi
787 echo -n "got: cannot rebase branch which contains changes outside " \
788 > $testroot/stderr.expected
789 echo "of this work tree's path prefix" >> $testroot/stderr.expected
790 cmp -s $testroot/stderr.expected $testroot/stderr
791 ret="$?"
792 if [ "$ret" != "0" ]; then
793 diff -u $testroot/stderr.expected $testroot/stderr
794 fi
795 test_done "$testroot" "$ret"
798 test_rebase_preserves_logmsg() {
799 local testroot=`test_init rebase_preserves_logmsg`
801 (cd $testroot/repo && git checkout -q -b newbranch)
802 echo "modified delta on branch" > $testroot/repo/gamma/delta
803 git_commit $testroot/repo -m "modified delta on newbranch"
805 echo "modified alpha on branch" > $testroot/repo/alpha
806 git_commit $testroot/repo -m "modified alpha on newbranch"
808 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
809 > $testroot/log.expected)
811 local orig_commit1=`git_show_parent_commit $testroot/repo`
812 local orig_commit2=`git_show_head $testroot/repo`
814 (cd $testroot/repo && git checkout -q master)
815 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
816 git_commit $testroot/repo -m "committing to zeta on master"
817 local master_commit=`git_show_head $testroot/repo`
819 got checkout $testroot/repo $testroot/wt > /dev/null
820 ret="$?"
821 if [ "$ret" != "0" ]; then
822 test_done "$testroot" "$ret"
823 return 1
824 fi
826 (cd $testroot/wt && got rebase newbranch > /dev/null \
827 2> $testroot/stderr)
829 (cd $testroot/repo && git checkout -q newbranch)
830 local new_commit1=`git_show_parent_commit $testroot/repo`
831 local new_commit2=`git_show_head $testroot/repo`
833 echo -n > $testroot/stderr.expected
834 cmp -s $testroot/stderr.expected $testroot/stderr
835 ret="$?"
836 if [ "$ret" != "0" ]; then
837 diff -u $testroot/stderr.expected $testroot/stderr
838 test_done "$testroot" "$ret"
839 return 1
840 fi
842 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
843 > $testroot/log)
844 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
845 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
846 cmp -s $testroot/log.expected $testroot/log
847 ret="$?"
848 if [ "$ret" != "0" ]; then
849 diff -u $testroot/log.expected $testroot/log
850 fi
852 test_done "$testroot" "$ret"
855 test_rebase_no_commits_to_rebase() {
856 local testroot=`test_init rebase_no_commits_to_rebase`
858 got checkout $testroot/repo $testroot/wt > /dev/null
859 ret="$?"
860 if [ "$ret" != "0" ]; then
861 test_done "$testroot" "$ret"
862 return 1
863 fi
865 (cd $testroot/wt && got branch -n newbranch)
867 echo "modified alpha on master" > $testroot/wt/alpha
868 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
869 > /dev/null)
870 (cd $testroot/wt && got update > /dev/null)
872 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
873 2> $testroot/stderr)
875 echo "got: no commits to rebase" > $testroot/stderr.expected
876 cmp -s $testroot/stderr.expected $testroot/stderr
877 ret="$?"
878 if [ "$ret" != "0" ]; then
879 diff -u $testroot/stderr.expected $testroot/stderr
880 test_done "$testroot" "$ret"
881 return 1
882 fi
884 echo "Rebase of refs/heads/newbranch aborted" \
885 > $testroot/stdout.expected
886 cmp -s $testroot/stdout.expected $testroot/stdout
887 ret="$?"
888 if [ "$ret" != "0" ]; then
889 diff -u $testroot/stdout.expected $testroot/stdout
890 test_done "$testroot" "$ret"
891 return 1
892 fi
894 (cd $testroot/wt && got update > $testroot/stdout)
895 echo "Already up-to-date" > $testroot/stdout.expected
896 cmp -s $testroot/stdout.expected $testroot/stdout
897 ret="$?"
898 if [ "$ret" != "0" ]; then
899 diff -u $testroot/stdout.expected $testroot/stdout
900 fi
901 test_done "$testroot" "$ret"
904 test_rebase_forward() {
905 local testroot=`test_init rebase_forward`
906 local commit0=`git_show_head $testroot/repo`
908 got checkout $testroot/repo $testroot/wt > /dev/null
909 ret="$?"
910 if [ "$ret" != "0" ]; then
911 test_done "$testroot" "$ret"
912 return 1
913 fi
915 echo "change alpha 1" > $testroot/wt/alpha
916 (cd $testroot/wt && got commit -m 'test rebase_forward' \
917 > /dev/null)
918 local commit1=`git_show_head $testroot/repo`
920 echo "change alpha 2" > $testroot/wt/alpha
921 (cd $testroot/wt && got commit -m 'test rebase_forward' \
922 > /dev/null)
923 local commit2=`git_show_head $testroot/repo`
925 # Simulate a situation where fast-forward is required.
926 # We want to fast-forward master to origin/master:
927 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
928 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
929 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
930 (cd $testroot/repo && got ref -d master >/dev/null)
931 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
932 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
934 (cd $testroot/wt && got up -b origin/master > /dev/null)
936 (cd $testroot/wt && got rebase master \
937 > $testroot/stdout 2> $testroot/stderr)
939 echo "Forwarding refs/heads/master to commit $commit2" \
940 > $testroot/stdout.expected
941 echo "Switching work tree to refs/heads/master" \
942 >> $testroot/stdout.expected
943 cmp -s $testroot/stdout.expected $testroot/stdout
944 ret="$?"
945 if [ "$ret" != "0" ]; then
946 diff -u $testroot/stdout.expected $testroot/stdout
947 test_done "$testroot" "$ret"
948 return 1
949 fi
951 # Ensure that rebase operation was completed correctly
952 (cd $testroot/wt && got rebase -a \
953 > $testroot/stdout 2> $testroot/stderr)
954 echo -n "" > $testroot/stdout.expected
955 cmp -s $testroot/stdout.expected $testroot/stdout
956 ret="$?"
957 if [ "$ret" != "0" ]; then
958 diff -u $testroot/stdout.expected $testroot/stdout
959 test_done "$testroot" "$ret"
960 return 1
961 fi
962 echo "got: rebase operation not in progress" > $testroot/stderr.expected
963 cmp -s $testroot/stderr.expected $testroot/stderr
964 ret="$?"
965 if [ "$ret" != "0" ]; then
966 diff -u $testroot/stderr.expected $testroot/stderr
967 test_done "$testroot" "$ret"
968 return 1
969 fi
971 (cd $testroot/wt && got branch -n > $testroot/stdout)
972 echo "master" > $testroot/stdout.expected
973 cmp -s $testroot/stdout.expected $testroot/stdout
974 ret="$?"
975 if [ "$ret" != "0" ]; then
976 diff -u $testroot/stdout.expected $testroot/stdout
977 test_done "$testroot" "$ret"
978 return 1
979 fi
981 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
982 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
983 echo "commit $commit1" >> $testroot/stdout.expected
984 echo "commit $commit0" >> $testroot/stdout.expected
985 cmp -s $testroot/stdout.expected $testroot/stdout
986 ret="$?"
987 if [ "$ret" != "0" ]; then
988 diff -u $testroot/stdout.expected $testroot/stdout
989 test_done "$testroot" "$ret"
990 return 1
991 fi
993 # Forward-only rebase operations should not be backed up
994 (cd $testroot/repo && got rebase -l > $testroot/stdout)
995 echo -n > $testroot/stdout.expected
996 cmp -s $testroot/stdout.expected $testroot/stdout
997 ret="$?"
998 if [ "$ret" != "0" ]; then
999 diff -u $testroot/stdout.expected $testroot/stdout
1001 test_done "$testroot" "$ret"
1004 test_rebase_out_of_date() {
1005 local testroot=`test_init rebase_out_of_date`
1006 local initial_commit=`git_show_head $testroot/repo`
1008 (cd $testroot/repo && git checkout -q -b newbranch)
1009 echo "modified delta on branch" > $testroot/repo/gamma/delta
1010 git_commit $testroot/repo -m "committing to delta on newbranch"
1012 echo "modified alpha on branch" > $testroot/repo/alpha
1013 (cd $testroot/repo && git rm -q beta)
1014 echo "new file on branch" > $testroot/repo/epsilon/new
1015 (cd $testroot/repo && git add epsilon/new)
1016 git_commit $testroot/repo -m "committing more changes on newbranch"
1018 local orig_commit1=`git_show_parent_commit $testroot/repo`
1019 local orig_commit2=`git_show_head $testroot/repo`
1021 (cd $testroot/repo && git checkout -q master)
1022 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1023 git_commit $testroot/repo -m "committing to zeta on master"
1024 local master_commit1=`git_show_head $testroot/repo`
1026 (cd $testroot/repo && git checkout -q master)
1027 echo "modified beta on master" > $testroot/repo/beta
1028 git_commit $testroot/repo -m "committing to beta on master"
1029 local master_commit2=`git_show_head $testroot/repo`
1031 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1032 > /dev/null
1033 ret="$?"
1034 if [ "$ret" != "0" ]; then
1035 test_done "$testroot" "$ret"
1036 return 1
1039 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1040 2> $testroot/stderr)
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 echo -n "got: work tree must be updated before it can be " \
1052 > $testroot/stderr.expected
1053 echo "used to rebase a branch" >> $testroot/stderr.expected
1054 cmp -s $testroot/stderr.expected $testroot/stderr
1055 ret="$?"
1056 if [ "$ret" != "0" ]; then
1057 diff -u $testroot/stderr.expected $testroot/stderr
1058 test_done "$testroot" "$ret"
1059 return 1
1062 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1063 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1064 echo "commit $master_commit1" >> $testroot/stdout.expected
1065 echo "commit $initial_commit" >> $testroot/stdout.expected
1066 cmp -s $testroot/stdout.expected $testroot/stdout
1067 ret="$?"
1068 if [ "$ret" != "0" ]; then
1069 diff -u $testroot/stdout.expected $testroot/stdout
1071 test_done "$testroot" "$ret"
1074 test_rebase_trims_empty_dir() {
1075 local testroot=`test_init rebase_trims_empty_dir`
1077 (cd $testroot/repo && git checkout -q -b newbranch)
1078 echo "modified delta on branch" > $testroot/repo/gamma/delta
1079 git_commit $testroot/repo -m "committing to delta on newbranch"
1081 (cd $testroot/repo && git rm -q epsilon/zeta)
1082 git_commit $testroot/repo -m "removing zeta on newbranch"
1084 local orig_commit1=`git_show_parent_commit $testroot/repo`
1085 local orig_commit2=`git_show_head $testroot/repo`
1087 (cd $testroot/repo && git checkout -q master)
1088 echo "modified alpha on master" > $testroot/repo/alpha
1089 git_commit $testroot/repo -m "committing to alpha on master"
1090 local master_commit=`git_show_head $testroot/repo`
1092 got checkout $testroot/repo $testroot/wt > /dev/null
1093 ret="$?"
1094 if [ "$ret" != "0" ]; then
1095 test_done "$testroot" "$ret"
1096 return 1
1099 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1101 (cd $testroot/repo && git checkout -q newbranch)
1102 local new_commit1=`git_show_parent_commit $testroot/repo`
1103 local new_commit2=`git_show_head $testroot/repo`
1105 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1106 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1107 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1108 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1110 echo "G gamma/delta" >> $testroot/stdout.expected
1111 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1112 >> $testroot/stdout.expected
1113 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1114 echo "D epsilon/zeta" >> $testroot/stdout.expected
1115 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1116 >> $testroot/stdout.expected
1117 echo ": removing zeta on newbranch" \
1118 >> $testroot/stdout.expected
1119 echo "Switching work tree to refs/heads/newbranch" \
1120 >> $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
1126 test_done "$testroot" "$ret"
1127 return 1
1130 echo "modified delta on branch" > $testroot/content.expected
1131 cat $testroot/wt/gamma/delta > $testroot/content
1132 cmp -s $testroot/content.expected $testroot/content
1133 ret="$?"
1134 if [ "$ret" != "0" ]; then
1135 diff -u $testroot/content.expected $testroot/content
1136 test_done "$testroot" "$ret"
1137 return 1
1140 echo "modified alpha on master" > $testroot/content.expected
1141 cat $testroot/wt/alpha > $testroot/content
1142 cmp -s $testroot/content.expected $testroot/content
1143 ret="$?"
1144 if [ "$ret" != "0" ]; then
1145 diff -u $testroot/content.expected $testroot/content
1146 test_done "$testroot" "$ret"
1147 return 1
1150 if [ -e $testroot/wt/epsilon ]; then
1151 echo "parent of removed zeta still exists on disk" >&2
1152 test_done "$testroot" "1"
1153 return 1
1156 (cd $testroot/wt && got status > $testroot/stdout)
1158 echo -n > $testroot/stdout.expected
1159 cmp -s $testroot/stdout.expected $testroot/stdout
1160 ret="$?"
1161 if [ "$ret" != "0" ]; then
1162 diff -u $testroot/stdout.expected $testroot/stdout
1163 test_done "$testroot" "$ret"
1164 return 1
1167 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1168 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1169 echo "commit $new_commit1" >> $testroot/stdout.expected
1170 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1171 cmp -s $testroot/stdout.expected $testroot/stdout
1172 ret="$?"
1173 if [ "$ret" != "0" ]; then
1174 diff -u $testroot/stdout.expected $testroot/stdout
1176 test_done "$testroot" "$ret"
1179 test_rebase_delete_missing_file() {
1180 local testroot=`test_init rebase_delete_missing_file`
1182 mkdir -p $testroot/repo/d/f/g
1183 echo "new file" > $testroot/repo/d/f/g/new
1184 (cd $testroot/repo && git add d/f/g/new)
1185 git_commit $testroot/repo -m "adding a subdir"
1186 local commit0=`git_show_head $testroot/repo`
1188 got br -r $testroot/repo -c master newbranch
1190 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1192 echo "modified delta on branch" > $testroot/wt/gamma/delta
1193 (cd $testroot/wt && got commit \
1194 -m "committing to delta on newbranch" > /dev/null)
1196 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1197 (cd $testroot/wt && got commit \
1198 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1200 (cd $testroot/repo && git checkout -q newbranch)
1201 local orig_commit1=`git_show_parent_commit $testroot/repo`
1202 local orig_commit2=`git_show_head $testroot/repo`
1204 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1205 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1207 (cd $testroot/wt && got update -b master > /dev/null)
1208 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1209 (cd $testroot/wt && got commit \
1210 -m "removing beta and d/f/g/new on master" > /dev/null)
1212 (cd $testroot/repo && git checkout -q master)
1213 local master_commit=`git_show_head $testroot/repo`
1215 (cd $testroot/wt && got update -b master > /dev/null)
1216 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1217 2> $testroot/stderr)
1218 ret="$?"
1219 if [ "$ret" = "0" ]; then
1220 echo "rebase succeeded unexpectedly" >&2
1221 test_done "$testroot" "1"
1222 return 1
1225 local new_commit1=$(cd $testroot/wt && got info | \
1226 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1228 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1229 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1231 echo "G gamma/delta" >> $testroot/stdout.expected
1232 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1233 >> $testroot/stdout.expected
1234 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1235 echo "! beta" >> $testroot/stdout.expected
1236 echo "! d/f/g/new" >> $testroot/stdout.expected
1237 echo -n "Files which had incoming changes but could not be found " \
1238 >> $testroot/stdout.expected
1239 echo "in the work tree: 2" >> $testroot/stdout.expected
1240 cmp -s $testroot/stdout.expected $testroot/stdout
1241 ret="$?"
1242 if [ "$ret" != "0" ]; then
1243 diff -u $testroot/stdout.expected $testroot/stdout
1244 test_done "$testroot" "$ret"
1245 return 1
1248 echo -n "got: changes destined for some files were not yet merged " \
1249 > $testroot/stderr.expected
1250 echo -n "and should be merged manually if required before the " \
1251 >> $testroot/stderr.expected
1252 echo "rebase operation is continued" >> $testroot/stderr.expected
1253 cmp -s $testroot/stderr.expected $testroot/stderr
1254 ret="$?"
1255 if [ "$ret" != "0" ]; then
1256 diff -u $testroot/stderr.expected $testroot/stderr
1257 test_done "$testroot" "$ret"
1258 return 1
1261 # ignore the missing changes and continue
1262 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1263 ret="$?"
1264 if [ "$ret" != "0" ]; then
1265 echo "rebase failed unexpectedly" >&2
1266 test_done "$testroot" "1"
1267 return 1
1269 echo -n "$short_orig_commit2 -> no-op change" \
1270 > $testroot/stdout.expected
1271 echo ": removing beta and d/f/g/new on newbranch" \
1272 >> $testroot/stdout.expected
1273 echo "Switching work tree to refs/heads/newbranch" \
1274 >> $testroot/stdout.expected
1276 cmp -s $testroot/stdout.expected $testroot/stdout
1277 ret="$?"
1278 if [ "$ret" != "0" ]; then
1279 diff -u $testroot/stdout.expected $testroot/stdout
1280 test_done "$testroot" "$ret"
1281 return 1
1284 echo "modified delta on branch" > $testroot/content.expected
1285 cat $testroot/wt/gamma/delta > $testroot/content
1286 cmp -s $testroot/content.expected $testroot/content
1287 ret="$?"
1288 if [ "$ret" != "0" ]; then
1289 diff -u $testroot/content.expected $testroot/content
1290 test_done "$testroot" "$ret"
1291 return 1
1294 if [ -e $testroot/wt/beta ]; then
1295 echo "removed file beta still exists on disk" >&2
1296 test_done "$testroot" "1"
1297 return 1
1300 (cd $testroot/wt && got status > $testroot/stdout)
1302 echo -n > $testroot/stdout.expected
1303 cmp -s $testroot/stdout.expected $testroot/stdout
1304 ret="$?"
1305 if [ "$ret" != "0" ]; then
1306 diff -u $testroot/stdout.expected $testroot/stdout
1307 test_done "$testroot" "$ret"
1308 return 1
1311 (cd $testroot/repo && git checkout -q newbranch)
1312 local new_commit1=`git_show_head $testroot/repo`
1313 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1315 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1316 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1317 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1318 echo "commit $commit0" >> $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
1324 test_done "$testroot" "$ret"
1327 test_rebase_rm_add_rm_file() {
1328 local testroot=`test_init rebase_rm_add_rm_file`
1330 (cd $testroot/repo && git checkout -q -b newbranch)
1331 (cd $testroot/repo && git rm -q beta)
1332 git_commit $testroot/repo -m "removing beta from newbranch"
1333 local orig_commit1=`git_show_head $testroot/repo`
1335 echo 'restored beta' > $testroot/repo/beta
1336 (cd $testroot/repo && git add beta)
1337 git_commit $testroot/repo -m "restoring beta on newbranch"
1338 local orig_commit2=`git_show_head $testroot/repo`
1340 (cd $testroot/repo && git rm -q beta)
1341 git_commit $testroot/repo -m "removing beta from newbranch again"
1342 local orig_commit3=`git_show_head $testroot/repo`
1344 (cd $testroot/repo && git checkout -q master)
1345 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1346 git_commit $testroot/repo -m "committing to zeta on master"
1347 local master_commit=`git_show_head $testroot/repo`
1349 got checkout $testroot/repo $testroot/wt > /dev/null
1350 ret="$?"
1351 if [ "$ret" != "0" ]; then
1352 test_done "$testroot" "$ret"
1353 return 1
1356 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1358 # this would error out with 'got: file index is corrupt'
1359 (cd $testroot/wt && got status > /dev/null)
1360 ret="$?"
1361 if [ "$ret" != "0" ]; then
1362 echo "got status command failed unexpectedly" >&2
1363 test_done "$testroot" "$ret"
1364 return 1
1367 (cd $testroot/repo && git checkout -q newbranch)
1368 local new_commit3=`git_show_head $testroot/repo`
1369 local new_commit2=`git_show_parent_commit $testroot/repo`
1370 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1372 (cd $testroot/repo && git checkout -q newbranch)
1374 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1375 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1376 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1377 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1378 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1379 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1381 echo "D beta" > $testroot/stdout.expected
1382 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1383 >> $testroot/stdout.expected
1384 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1385 echo "A beta" >> $testroot/stdout.expected
1386 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1387 >> $testroot/stdout.expected
1388 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1389 echo "D beta" >> $testroot/stdout.expected
1390 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1391 >> $testroot/stdout.expected
1392 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1393 echo "Switching work tree to refs/heads/newbranch" \
1394 >> $testroot/stdout.expected
1396 cmp -s $testroot/stdout.expected $testroot/stdout
1397 ret="$?"
1398 if [ "$ret" != "0" ]; then
1399 diff -u $testroot/stdout.expected $testroot/stdout
1400 test_done "$testroot" "$ret"
1401 return 1
1404 (cd $testroot/wt && got status > $testroot/stdout)
1405 ret="$?"
1406 if [ "$ret" != "0" ]; then
1407 echo "got status command failed unexpectedly" >&2
1408 test_done "$testroot" "$ret"
1409 return 1
1412 echo -n > $testroot/stdout.expected
1413 cmp -s $testroot/stdout.expected $testroot/stdout
1414 ret="$?"
1415 if [ "$ret" != "0" ]; then
1416 diff -u $testroot/stdout.expected $testroot/stdout
1417 test_done "$testroot" "$ret"
1418 return 1
1421 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1422 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1423 echo "commit $new_commit2" >> $testroot/stdout.expected
1424 echo "commit $new_commit1" >> $testroot/stdout.expected
1425 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1426 cmp -s $testroot/stdout.expected $testroot/stdout
1427 ret="$?"
1428 if [ "$ret" != "0" ]; then
1429 diff -u $testroot/stdout.expected $testroot/stdout
1431 test_done "$testroot" "$ret"
1434 test_parseargs "$@"
1435 run_test test_rebase_basic
1436 run_test test_rebase_ancestry_check
1437 run_test test_rebase_continue
1438 run_test test_rebase_abort
1439 run_test test_rebase_no_op_change
1440 run_test test_rebase_in_progress
1441 run_test test_rebase_path_prefix
1442 run_test test_rebase_preserves_logmsg
1443 run_test test_rebase_no_commits_to_rebase
1444 run_test test_rebase_forward
1445 run_test test_rebase_out_of_date
1446 run_test test_rebase_trims_empty_dir
1447 run_test test_rebase_delete_missing_file
1448 run_test test_rebase_rm_add_rm_file