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 d_orig2=`date -u -r $orig_author_time2 +"%a %b %e %X %Y UTC"`
157 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
158 d_0=`date -u -r $commit0_author_time +"%G-%m-%d"`
159 cat > $testroot/stdout.expected <<EOF
160 -----------------------------------------------
161 commit $orig_commit2 (formerly newbranch)
162 from: $GOT_AUTHOR
163 date: $d_orig2
165 committing more changes on newbranch
167 has become commit $new_commit2 (newbranch)
168 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
169 history forked at $commit0
170 $d_0 $GOT_AUTHOR_11 adding the test tree
171 EOF
172 cmp -s $testroot/stdout.expected $testroot/stdout
173 ret="$?"
174 if [ "$ret" != "0" ]; then
175 diff -u $testroot/stdout.expected $testroot/stdout
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 # Asking for backups of a branch which has none should yield an error
181 (cd $testroot/repo && got rebase -l master \
182 > $testroot/stdout 2> $testroot/stderr)
183 echo -n > $testroot/stdout.expected
184 echo "got: refs/got/backup/rebase/master/: no such reference found" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
187 ret="$?"
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
191 return 1
192 fi
193 cmp -s $testroot/stderr.expected $testroot/stderr
194 ret="$?"
195 if [ "$ret" != "0" ]; then
196 diff -u $testroot/stderr.expected $testroot/stderr
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 # Delete all backup refs
202 (cd $testroot/repo && got rebase -X \
203 > $testroot/stdout 2> $testroot/stderr)
204 echo -n "Deleted refs/got/backup/rebase/newbranch/$new_commit2: " \
205 > $testroot/stdout.expected
206 echo "$orig_commit2" >> $testroot/stdout.expected
207 echo -n > $testroot/stderr.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret="$?"
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
214 fi
215 cmp -s $testroot/stderr.expected $testroot/stderr
216 ret="$?"
217 if [ "$ret" != "0" ]; then
218 diff -u $testroot/stderr.expected $testroot/stderr
219 test_done "$testroot" "$ret"
220 return 1
221 fi
223 (cd $testroot/repo && got rebase -l > $testroot/stdout)
224 echo -n > $testroot/stdout.expected
225 cmp -s $testroot/stdout.expected $testroot/stdout
226 ret="$?"
227 if [ "$ret" != "0" ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
229 fi
230 test_done "$testroot" "$ret"
233 test_rebase_ancestry_check() {
234 local testroot=`test_init rebase_ancestry_check`
236 got checkout $testroot/repo $testroot/wt > /dev/null
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 (cd $testroot/repo && git checkout -q -b newbranch)
244 echo "modified delta on branch" > $testroot/repo/gamma/delta
245 git_commit $testroot/repo -m "committing to delta on newbranch"
246 local newbranch_id=`git_show_head $testroot/repo`
248 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
249 2> $testroot/stderr)
251 echo "refs/heads/newbranch is already based on refs/heads/master" \
252 > $testroot/stdout.expected
253 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
254 >> $testroot/stdout.expected
255 echo "U gamma/delta" >> $testroot/stdout.expected
256 echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
257 >> $testroot/stdout.expected
258 cmp -s $testroot/stdout.expected $testroot/stdout
259 ret="$?"
260 if [ "$ret" != "0" ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
263 return 1
264 fi
266 echo -n > $testroot/stderr.expected
267 cmp -s $testroot/stderr.expected $testroot/stderr
268 ret="$?"
269 if [ "$ret" != "0" ]; then
270 diff -u $testroot/stderr.expected $testroot/stderr
271 fi
272 test_done "$testroot" "$ret"
275 test_rebase_continue() {
276 local testroot=`test_init rebase_continue`
277 local init_commit=`git_show_head $testroot/repo`
279 (cd $testroot/repo && git checkout -q -b newbranch)
280 echo "modified alpha on branch" > $testroot/repo/alpha
281 git_commit $testroot/repo -m "committing to alpha on newbranch"
282 local orig_commit1=`git_show_head $testroot/repo`
283 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
285 (cd $testroot/repo && git checkout -q master)
286 echo "modified alpha on master" > $testroot/repo/alpha
287 git_commit $testroot/repo -m "committing to alpha on master"
288 local master_commit=`git_show_head $testroot/repo`
290 got checkout $testroot/repo $testroot/wt > /dev/null
291 ret="$?"
292 if [ "$ret" != "0" ]; then
293 test_done "$testroot" "$ret"
294 return 1
295 fi
297 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
298 2> $testroot/stderr)
300 echo "C alpha" > $testroot/stdout.expected
301 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
302 echo -n "$short_orig_commit1 -> merge conflict" \
303 >> $testroot/stdout.expected
304 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
305 cmp -s $testroot/stdout.expected $testroot/stdout
306 ret="$?"
307 if [ "$ret" != "0" ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
310 return 1
311 fi
313 echo "got: conflicts must be resolved before rebasing can continue" \
314 > $testroot/stderr.expected
315 cmp -s $testroot/stderr.expected $testroot/stderr
316 ret="$?"
317 if [ "$ret" != "0" ]; then
318 diff -u $testroot/stderr.expected $testroot/stderr
319 test_done "$testroot" "$ret"
320 return 1
321 fi
323 echo '<<<<<<<' > $testroot/content.expected
324 echo "modified alpha on master" >> $testroot/content.expected
325 echo "||||||| 3-way merge base: commit $init_commit" \
326 >> $testroot/content.expected
327 echo "alpha" >> $testroot/content.expected
328 echo "=======" >> $testroot/content.expected
329 echo "modified alpha on branch" >> $testroot/content.expected
330 echo ">>>>>>> merged change: commit $orig_commit1" \
331 >> $testroot/content.expected
332 cat $testroot/wt/alpha > $testroot/content
333 cmp -s $testroot/content.expected $testroot/content
334 ret="$?"
335 if [ "$ret" != "0" ]; then
336 diff -u $testroot/content.expected $testroot/content
337 test_done "$testroot" "$ret"
338 return 1
339 fi
341 (cd $testroot/wt && got status > $testroot/stdout)
343 echo "C alpha" > $testroot/stdout.expected
344 cmp -s $testroot/stdout.expected $testroot/stdout
345 ret="$?"
346 if [ "$ret" != "0" ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 # resolve the conflict
353 echo "modified alpha on branch and master" > $testroot/wt/alpha
355 # test interaction of 'got stage' and rebase -c
356 (cd $testroot/wt && got stage alpha > /dev/null)
357 (cd $testroot/wt && got rebase -c > $testroot/stdout \
358 2> $testroot/stderr)
359 ret="$?"
360 if [ "$ret" = "0" ]; then
361 echo "rebase succeeded unexpectedly" >&2
362 test_done "$testroot" "1"
363 return 1
364 fi
365 echo -n "got: work tree contains files with staged changes; " \
366 > $testroot/stderr.expected
367 echo "these changes must be committed or unstaged first" \
368 >> $testroot/stderr.expected
369 cmp -s $testroot/stderr.expected $testroot/stderr
370 ret="$?"
371 if [ "$ret" != "0" ]; then
372 diff -u $testroot/stderr.expected $testroot/stderr
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 (cd $testroot/wt && got unstage alpha > /dev/null)
378 (cd $testroot/wt && got rebase -c > $testroot/stdout)
380 (cd $testroot/repo && git checkout -q newbranch)
381 local new_commit1=`git_show_head $testroot/repo`
382 local short_new_commit1=`trim_obj_id 28 $new_commit1`
384 echo -n "$short_orig_commit1 -> $short_new_commit1" \
385 > $testroot/stdout.expected
386 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
387 echo "Switching work tree to refs/heads/newbranch" \
388 >> $testroot/stdout.expected
390 cmp -s $testroot/stdout.expected $testroot/stdout
391 ret="$?"
392 if [ "$ret" != "0" ]; then
393 diff -u $testroot/stdout.expected $testroot/stdout
394 test_done "$testroot" "$ret"
395 return 1
396 fi
399 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
400 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
401 echo "commit $master_commit (master)" >> $testroot/stdout.expected
402 cmp -s $testroot/stdout.expected $testroot/stdout
403 ret="$?"
404 if [ "$ret" != "0" ]; then
405 diff -u $testroot/stdout.expected $testroot/stdout
406 fi
407 test_done "$testroot" "$ret"
410 test_rebase_abort() {
411 local testroot=`test_init rebase_abort`
413 local init_commit=`git_show_head $testroot/repo`
415 (cd $testroot/repo && git checkout -q -b newbranch)
416 echo "modified alpha on branch" > $testroot/repo/alpha
417 git_commit $testroot/repo -m "committing to alpha on newbranch"
418 local orig_commit1=`git_show_head $testroot/repo`
419 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
421 (cd $testroot/repo && git checkout -q master)
422 echo "modified alpha on master" > $testroot/repo/alpha
423 git_commit $testroot/repo -m "committing to alpha on master"
424 local master_commit=`git_show_head $testroot/repo`
426 got checkout $testroot/repo $testroot/wt > /dev/null
427 ret="$?"
428 if [ "$ret" != "0" ]; then
429 test_done "$testroot" "$ret"
430 return 1
431 fi
433 # unrelated unversioned file in work tree
434 touch $testroot/wt/unversioned-file
436 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
437 2> $testroot/stderr)
439 echo "C alpha" > $testroot/stdout.expected
440 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
441 echo -n "$short_orig_commit1 -> merge conflict" \
442 >> $testroot/stdout.expected
443 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
444 cmp -s $testroot/stdout.expected $testroot/stdout
445 ret="$?"
446 if [ "$ret" != "0" ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 echo "got: conflicts must be resolved before rebasing can continue" \
453 > $testroot/stderr.expected
454 cmp -s $testroot/stderr.expected $testroot/stderr
455 ret="$?"
456 if [ "$ret" != "0" ]; then
457 diff -u $testroot/stderr.expected $testroot/stderr
458 test_done "$testroot" "$ret"
459 return 1
460 fi
462 echo '<<<<<<<' > $testroot/content.expected
463 echo "modified alpha on master" >> $testroot/content.expected
464 echo "||||||| 3-way merge base: commit $init_commit" \
465 >> $testroot/content.expected
466 echo "alpha" >> $testroot/content.expected
467 echo "=======" >> $testroot/content.expected
468 echo "modified alpha on branch" >> $testroot/content.expected
469 echo ">>>>>>> merged change: commit $orig_commit1" \
470 >> $testroot/content.expected
471 cat $testroot/wt/alpha > $testroot/content
472 cmp -s $testroot/content.expected $testroot/content
473 ret="$?"
474 if [ "$ret" != "0" ]; then
475 diff -u $testroot/content.expected $testroot/content
476 test_done "$testroot" "$ret"
477 return 1
478 fi
480 (cd $testroot/wt && got status > $testroot/stdout)
482 echo "C alpha" > $testroot/stdout.expected
483 echo "? unversioned-file" >> $testroot/stdout.expected
484 cmp -s $testroot/stdout.expected $testroot/stdout
485 ret="$?"
486 if [ "$ret" != "0" ]; then
487 diff -u $testroot/stdout.expected $testroot/stdout
488 test_done "$testroot" "$ret"
489 return 1
490 fi
492 (cd $testroot/wt && got rebase -a > $testroot/stdout)
494 (cd $testroot/repo && git checkout -q newbranch)
496 echo "Switching work tree to refs/heads/master" \
497 > $testroot/stdout.expected
498 echo 'R alpha' >> $testroot/stdout.expected
499 echo "Rebase of refs/heads/newbranch aborted" \
500 >> $testroot/stdout.expected
502 cmp -s $testroot/stdout.expected $testroot/stdout
503 ret="$?"
504 if [ "$ret" != "0" ]; then
505 diff -u $testroot/stdout.expected $testroot/stdout
506 test_done "$testroot" "$ret"
507 return 1
508 fi
510 echo "modified alpha on master" > $testroot/content.expected
511 cat $testroot/wt/alpha > $testroot/content
512 cmp -s $testroot/content.expected $testroot/content
513 ret="$?"
514 if [ "$ret" != "0" ]; then
515 diff -u $testroot/content.expected $testroot/content
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 (cd $testroot/wt && got log -l3 -c newbranch \
521 | grep ^commit > $testroot/stdout)
522 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
523 echo "commit $init_commit" >> $testroot/stdout.expected
524 cmp -s $testroot/stdout.expected $testroot/stdout
525 ret="$?"
526 if [ "$ret" != "0" ]; then
527 diff -u $testroot/stdout.expected $testroot/stdout
528 fi
529 test_done "$testroot" "$ret"
532 test_rebase_no_op_change() {
533 local testroot=`test_init rebase_no_op_change`
534 local init_commit=`git_show_head $testroot/repo`
536 (cd $testroot/repo && git checkout -q -b newbranch)
537 echo "modified alpha on branch" > $testroot/repo/alpha
538 git_commit $testroot/repo -m "committing to alpha on newbranch"
539 local orig_commit1=`git_show_head $testroot/repo`
540 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
542 (cd $testroot/repo && git checkout -q master)
543 echo "modified alpha on master" > $testroot/repo/alpha
544 git_commit $testroot/repo -m "committing to alpha on master"
545 local master_commit=`git_show_head $testroot/repo`
547 got checkout $testroot/repo $testroot/wt > /dev/null
548 ret="$?"
549 if [ "$ret" != "0" ]; then
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
555 2> $testroot/stderr)
557 echo "C alpha" > $testroot/stdout.expected
558 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
559 echo -n "$short_orig_commit1 -> merge conflict" \
560 >> $testroot/stdout.expected
561 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
562 cmp -s $testroot/stdout.expected $testroot/stdout
563 ret="$?"
564 if [ "$ret" != "0" ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 echo "got: conflicts must be resolved before rebasing can continue" \
571 > $testroot/stderr.expected
572 cmp -s $testroot/stderr.expected $testroot/stderr
573 ret="$?"
574 if [ "$ret" != "0" ]; then
575 diff -u $testroot/stderr.expected $testroot/stderr
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 echo '<<<<<<<' > $testroot/content.expected
581 echo "modified alpha on master" >> $testroot/content.expected
582 echo "||||||| 3-way merge base: commit $init_commit" \
583 >> $testroot/content.expected
584 echo "alpha" >> $testroot/content.expected
585 echo "=======" >> $testroot/content.expected
586 echo "modified alpha on branch" >> $testroot/content.expected
587 echo ">>>>>>> merged change: commit $orig_commit1" \
588 >> $testroot/content.expected
589 cat $testroot/wt/alpha > $testroot/content
590 cmp -s $testroot/content.expected $testroot/content
591 ret="$?"
592 if [ "$ret" != "0" ]; then
593 diff -u $testroot/content.expected $testroot/content
594 test_done "$testroot" "$ret"
595 return 1
596 fi
598 (cd $testroot/wt && got status > $testroot/stdout)
600 echo "C alpha" > $testroot/stdout.expected
601 cmp -s $testroot/stdout.expected $testroot/stdout
602 ret="$?"
603 if [ "$ret" != "0" ]; then
604 diff -u $testroot/stdout.expected $testroot/stdout
605 test_done "$testroot" "$ret"
606 return 1
607 fi
609 # resolve the conflict
610 echo "modified alpha on master" > $testroot/wt/alpha
612 (cd $testroot/wt && got rebase -c > $testroot/stdout)
614 (cd $testroot/repo && git checkout -q newbranch)
615 local new_commit1=`git_show_head $testroot/repo`
617 echo -n "$short_orig_commit1 -> no-op change" \
618 > $testroot/stdout.expected
619 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
620 echo "Switching work tree to refs/heads/newbranch" \
621 >> $testroot/stdout.expected
623 cmp -s $testroot/stdout.expected $testroot/stdout
624 ret="$?"
625 if [ "$ret" != "0" ]; then
626 diff -u $testroot/stdout.expected $testroot/stdout
627 test_done "$testroot" "$ret"
628 return 1
629 fi
632 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
633 echo "commit $master_commit (master, newbranch)" \
634 > $testroot/stdout.expected
635 echo "commit $init_commit" >> $testroot/stdout.expected
636 cmp -s $testroot/stdout.expected $testroot/stdout
637 ret="$?"
638 if [ "$ret" != "0" ]; then
639 diff -u $testroot/stdout.expected $testroot/stdout
640 fi
641 test_done "$testroot" "$ret"
644 test_rebase_in_progress() {
645 local testroot=`test_init rebase_in_progress`
646 local init_commit=`git_show_head $testroot/repo`
648 (cd $testroot/repo && git checkout -q -b newbranch)
649 echo "modified alpha on branch" > $testroot/repo/alpha
650 git_commit $testroot/repo -m "committing to alpha on newbranch"
651 local orig_commit1=`git_show_head $testroot/repo`
652 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
654 (cd $testroot/repo && git checkout -q master)
655 echo "modified alpha on master" > $testroot/repo/alpha
656 git_commit $testroot/repo -m "committing to alpha on master"
657 local master_commit=`git_show_head $testroot/repo`
659 got checkout $testroot/repo $testroot/wt > /dev/null
660 ret="$?"
661 if [ "$ret" != "0" ]; then
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
667 2> $testroot/stderr)
669 echo "C alpha" > $testroot/stdout.expected
670 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
671 echo -n "$short_orig_commit1 -> merge conflict" \
672 >> $testroot/stdout.expected
673 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
674 cmp -s $testroot/stdout.expected $testroot/stdout
675 ret="$?"
676 if [ "$ret" != "0" ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 echo "got: conflicts must be resolved before rebasing can continue" \
683 > $testroot/stderr.expected
684 cmp -s $testroot/stderr.expected $testroot/stderr
685 ret="$?"
686 if [ "$ret" != "0" ]; then
687 diff -u $testroot/stderr.expected $testroot/stderr
688 test_done "$testroot" "$ret"
689 return 1
690 fi
692 echo '<<<<<<<' > $testroot/content.expected
693 echo "modified alpha on master" >> $testroot/content.expected
694 echo "||||||| 3-way merge base: commit $init_commit" \
695 >> $testroot/content.expected
696 echo "alpha" >> $testroot/content.expected
697 echo "=======" >> $testroot/content.expected
698 echo "modified alpha on branch" >> $testroot/content.expected
699 echo ">>>>>>> merged change: commit $orig_commit1" \
700 >> $testroot/content.expected
701 cat $testroot/wt/alpha > $testroot/content
702 cmp -s $testroot/content.expected $testroot/content
703 ret="$?"
704 if [ "$ret" != "0" ]; then
705 diff -u $testroot/content.expected $testroot/content
706 test_done "$testroot" "$ret"
707 return 1
708 fi
710 (cd $testroot/wt && got status > $testroot/stdout)
712 echo "C alpha" > $testroot/stdout.expected
713 cmp -s $testroot/stdout.expected $testroot/stdout
714 ret="$?"
715 if [ "$ret" != "0" ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 for cmd in update commit; do
722 (cd $testroot/wt && got $cmd > $testroot/stdout \
723 2> $testroot/stderr)
725 echo -n > $testroot/stdout.expected
726 cmp -s $testroot/stdout.expected $testroot/stdout
727 ret="$?"
728 if [ "$ret" != "0" ]; then
729 diff -u $testroot/stdout.expected $testroot/stdout
730 test_done "$testroot" "$ret"
731 return 1
732 fi
734 echo -n "got: a rebase operation is in progress in this " \
735 > $testroot/stderr.expected
736 echo "work tree and must be continued or aborted first" \
737 >> $testroot/stderr.expected
738 cmp -s $testroot/stderr.expected $testroot/stderr
739 ret="$?"
740 if [ "$ret" != "0" ]; then
741 diff -u $testroot/stderr.expected $testroot/stderr
742 test_done "$testroot" "$ret"
743 return 1
744 fi
745 done
747 test_done "$testroot" "$ret"
750 test_rebase_path_prefix() {
751 local testroot=`test_init rebase_path_prefix`
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 "committing to delta on newbranch"
757 local orig_commit1=`git_show_parent_commit $testroot/repo`
758 local orig_commit2=`git_show_head $testroot/repo`
760 (cd $testroot/repo && git checkout -q master)
761 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
762 git_commit $testroot/repo -m "committing to zeta on master"
763 local master_commit=`git_show_head $testroot/repo`
765 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
766 ret="$?"
767 if [ "$ret" != "0" ]; then
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 (cd $testroot/wt && got rebase newbranch \
773 > $testroot/stdout 2> $testroot/stderr)
775 echo -n > $testroot/stdout.expected
776 cmp -s $testroot/stdout.expected $testroot/stdout
777 ret="$?"
778 if [ "$ret" != "0" ]; then
779 diff -u $testroot/stdout.expected $testroot/stdout
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 echo -n "got: cannot rebase branch which contains changes outside " \
785 > $testroot/stderr.expected
786 echo "of this work tree's path prefix" >> $testroot/stderr.expected
787 cmp -s $testroot/stderr.expected $testroot/stderr
788 ret="$?"
789 if [ "$ret" != "0" ]; then
790 diff -u $testroot/stderr.expected $testroot/stderr
791 fi
792 test_done "$testroot" "$ret"
795 test_rebase_preserves_logmsg() {
796 local testroot=`test_init rebase_preserves_logmsg`
798 (cd $testroot/repo && git checkout -q -b newbranch)
799 echo "modified delta on branch" > $testroot/repo/gamma/delta
800 git_commit $testroot/repo -m "modified delta on newbranch"
802 echo "modified alpha on branch" > $testroot/repo/alpha
803 git_commit $testroot/repo -m "modified alpha on newbranch"
805 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
806 > $testroot/log.expected)
808 local orig_commit1=`git_show_parent_commit $testroot/repo`
809 local orig_commit2=`git_show_head $testroot/repo`
811 (cd $testroot/repo && git checkout -q master)
812 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
813 git_commit $testroot/repo -m "committing to zeta on master"
814 local master_commit=`git_show_head $testroot/repo`
816 got checkout $testroot/repo $testroot/wt > /dev/null
817 ret="$?"
818 if [ "$ret" != "0" ]; then
819 test_done "$testroot" "$ret"
820 return 1
821 fi
823 (cd $testroot/wt && got rebase newbranch > /dev/null \
824 2> $testroot/stderr)
826 (cd $testroot/repo && git checkout -q newbranch)
827 local new_commit1=`git_show_parent_commit $testroot/repo`
828 local new_commit2=`git_show_head $testroot/repo`
830 echo -n > $testroot/stderr.expected
831 cmp -s $testroot/stderr.expected $testroot/stderr
832 ret="$?"
833 if [ "$ret" != "0" ]; then
834 diff -u $testroot/stderr.expected $testroot/stderr
835 test_done "$testroot" "$ret"
836 return 1
837 fi
839 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
840 > $testroot/log)
841 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
842 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
843 cmp -s $testroot/log.expected $testroot/log
844 ret="$?"
845 if [ "$ret" != "0" ]; then
846 diff -u $testroot/log.expected $testroot/log
847 fi
849 test_done "$testroot" "$ret"
852 test_rebase_no_commits_to_rebase() {
853 local testroot=`test_init rebase_no_commits_to_rebase`
855 got checkout $testroot/repo $testroot/wt > /dev/null
856 ret="$?"
857 if [ "$ret" != "0" ]; then
858 test_done "$testroot" "$ret"
859 return 1
860 fi
862 (cd $testroot/wt && got branch -n newbranch)
864 echo "modified alpha on master" > $testroot/wt/alpha
865 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
866 > /dev/null)
867 (cd $testroot/wt && got update > /dev/null)
869 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
870 2> $testroot/stderr)
872 echo "got: no commits to rebase" > $testroot/stderr.expected
873 cmp -s $testroot/stderr.expected $testroot/stderr
874 ret="$?"
875 if [ "$ret" != "0" ]; then
876 diff -u $testroot/stderr.expected $testroot/stderr
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 echo "Rebase of refs/heads/newbranch aborted" \
882 > $testroot/stdout.expected
883 cmp -s $testroot/stdout.expected $testroot/stdout
884 ret="$?"
885 if [ "$ret" != "0" ]; then
886 diff -u $testroot/stdout.expected $testroot/stdout
887 test_done "$testroot" "$ret"
888 return 1
889 fi
891 (cd $testroot/wt && got update > $testroot/stdout)
892 echo "Already up-to-date" > $testroot/stdout.expected
893 cmp -s $testroot/stdout.expected $testroot/stdout
894 ret="$?"
895 if [ "$ret" != "0" ]; then
896 diff -u $testroot/stdout.expected $testroot/stdout
897 fi
898 test_done "$testroot" "$ret"
901 test_rebase_forward() {
902 local testroot=`test_init rebase_forward`
903 local commit0=`git_show_head $testroot/repo`
905 got checkout $testroot/repo $testroot/wt > /dev/null
906 ret="$?"
907 if [ "$ret" != "0" ]; then
908 test_done "$testroot" "$ret"
909 return 1
910 fi
912 echo "change alpha 1" > $testroot/wt/alpha
913 (cd $testroot/wt && got commit -m 'test rebase_forward' \
914 > /dev/null)
915 local commit1=`git_show_head $testroot/repo`
917 echo "change alpha 2" > $testroot/wt/alpha
918 (cd $testroot/wt && got commit -m 'test rebase_forward' \
919 > /dev/null)
920 local commit2=`git_show_head $testroot/repo`
922 # Simulate a situation where fast-forward is required.
923 # We want to fast-forward master to origin/master:
924 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
925 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
926 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
927 (cd $testroot/repo && got ref -d master >/dev/null)
928 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
929 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
931 (cd $testroot/wt && got up -b origin/master > /dev/null)
933 (cd $testroot/wt && got rebase master \
934 > $testroot/stdout 2> $testroot/stderr)
936 echo "Forwarding refs/heads/master to commit $commit2" \
937 > $testroot/stdout.expected
938 echo "Switching work tree to refs/heads/master" \
939 >> $testroot/stdout.expected
940 cmp -s $testroot/stdout.expected $testroot/stdout
941 ret="$?"
942 if [ "$ret" != "0" ]; then
943 diff -u $testroot/stdout.expected $testroot/stdout
944 test_done "$testroot" "$ret"
945 return 1
946 fi
948 # Ensure that rebase operation was completed correctly
949 (cd $testroot/wt && got rebase -a \
950 > $testroot/stdout 2> $testroot/stderr)
951 echo -n "" > $testroot/stdout.expected
952 cmp -s $testroot/stdout.expected $testroot/stdout
953 ret="$?"
954 if [ "$ret" != "0" ]; then
955 diff -u $testroot/stdout.expected $testroot/stdout
956 test_done "$testroot" "$ret"
957 return 1
958 fi
959 echo "got: rebase operation not in progress" > $testroot/stderr.expected
960 cmp -s $testroot/stderr.expected $testroot/stderr
961 ret="$?"
962 if [ "$ret" != "0" ]; then
963 diff -u $testroot/stderr.expected $testroot/stderr
964 test_done "$testroot" "$ret"
965 return 1
966 fi
968 (cd $testroot/wt && got branch -n > $testroot/stdout)
969 echo "master" > $testroot/stdout.expected
970 cmp -s $testroot/stdout.expected $testroot/stdout
971 ret="$?"
972 if [ "$ret" != "0" ]; then
973 diff -u $testroot/stdout.expected $testroot/stdout
974 test_done "$testroot" "$ret"
975 return 1
976 fi
978 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
979 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
980 echo "commit $commit1" >> $testroot/stdout.expected
981 echo "commit $commit0" >> $testroot/stdout.expected
982 cmp -s $testroot/stdout.expected $testroot/stdout
983 ret="$?"
984 if [ "$ret" != "0" ]; then
985 diff -u $testroot/stdout.expected $testroot/stdout
986 test_done "$testroot" "$ret"
987 return 1
988 fi
990 # Forward-only rebase operations should not be backed up
991 (cd $testroot/repo && got rebase -l > $testroot/stdout)
992 echo -n > $testroot/stdout.expected
993 cmp -s $testroot/stdout.expected $testroot/stdout
994 ret="$?"
995 if [ "$ret" != "0" ]; then
996 diff -u $testroot/stdout.expected $testroot/stdout
997 fi
998 test_done "$testroot" "$ret"
1001 test_rebase_out_of_date() {
1002 local testroot=`test_init rebase_out_of_date`
1003 local initial_commit=`git_show_head $testroot/repo`
1005 (cd $testroot/repo && git checkout -q -b newbranch)
1006 echo "modified delta on branch" > $testroot/repo/gamma/delta
1007 git_commit $testroot/repo -m "committing to delta on newbranch"
1009 echo "modified alpha on branch" > $testroot/repo/alpha
1010 (cd $testroot/repo && git rm -q beta)
1011 echo "new file on branch" > $testroot/repo/epsilon/new
1012 (cd $testroot/repo && git add epsilon/new)
1013 git_commit $testroot/repo -m "committing more changes on newbranch"
1015 local orig_commit1=`git_show_parent_commit $testroot/repo`
1016 local orig_commit2=`git_show_head $testroot/repo`
1018 (cd $testroot/repo && git checkout -q master)
1019 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1020 git_commit $testroot/repo -m "committing to zeta on master"
1021 local master_commit1=`git_show_head $testroot/repo`
1023 (cd $testroot/repo && git checkout -q master)
1024 echo "modified beta on master" > $testroot/repo/beta
1025 git_commit $testroot/repo -m "committing to beta on master"
1026 local master_commit2=`git_show_head $testroot/repo`
1028 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1029 > /dev/null
1030 ret="$?"
1031 if [ "$ret" != "0" ]; then
1032 test_done "$testroot" "$ret"
1033 return 1
1036 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1037 2> $testroot/stderr)
1039 echo -n > $testroot/stdout.expected
1040 cmp -s $testroot/stdout.expected $testroot/stdout
1041 ret="$?"
1042 if [ "$ret" != "0" ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1045 return 1
1048 echo -n "got: work tree must be updated before it can be " \
1049 > $testroot/stderr.expected
1050 echo "used to rebase a branch" >> $testroot/stderr.expected
1051 cmp -s $testroot/stderr.expected $testroot/stderr
1052 ret="$?"
1053 if [ "$ret" != "0" ]; then
1054 diff -u $testroot/stderr.expected $testroot/stderr
1055 test_done "$testroot" "$ret"
1056 return 1
1059 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1060 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1061 echo "commit $master_commit1" >> $testroot/stdout.expected
1062 echo "commit $initial_commit" >> $testroot/stdout.expected
1063 cmp -s $testroot/stdout.expected $testroot/stdout
1064 ret="$?"
1065 if [ "$ret" != "0" ]; then
1066 diff -u $testroot/stdout.expected $testroot/stdout
1068 test_done "$testroot" "$ret"
1071 test_rebase_trims_empty_dir() {
1072 local testroot=`test_init rebase_trims_empty_dir`
1074 (cd $testroot/repo && git checkout -q -b newbranch)
1075 echo "modified delta on branch" > $testroot/repo/gamma/delta
1076 git_commit $testroot/repo -m "committing to delta on newbranch"
1078 (cd $testroot/repo && git rm -q epsilon/zeta)
1079 git_commit $testroot/repo -m "removing zeta on newbranch"
1081 local orig_commit1=`git_show_parent_commit $testroot/repo`
1082 local orig_commit2=`git_show_head $testroot/repo`
1084 (cd $testroot/repo && git checkout -q master)
1085 echo "modified alpha on master" > $testroot/repo/alpha
1086 git_commit $testroot/repo -m "committing to alpha on master"
1087 local master_commit=`git_show_head $testroot/repo`
1089 got checkout $testroot/repo $testroot/wt > /dev/null
1090 ret="$?"
1091 if [ "$ret" != "0" ]; then
1092 test_done "$testroot" "$ret"
1093 return 1
1096 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1098 (cd $testroot/repo && git checkout -q newbranch)
1099 local new_commit1=`git_show_parent_commit $testroot/repo`
1100 local new_commit2=`git_show_head $testroot/repo`
1102 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1103 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1104 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1105 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1107 echo "G gamma/delta" >> $testroot/stdout.expected
1108 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1109 >> $testroot/stdout.expected
1110 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1111 echo "D epsilon/zeta" >> $testroot/stdout.expected
1112 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1113 >> $testroot/stdout.expected
1114 echo ": removing zeta on newbranch" \
1115 >> $testroot/stdout.expected
1116 echo "Switching work tree to refs/heads/newbranch" \
1117 >> $testroot/stdout.expected
1119 cmp -s $testroot/stdout.expected $testroot/stdout
1120 ret="$?"
1121 if [ "$ret" != "0" ]; then
1122 diff -u $testroot/stdout.expected $testroot/stdout
1123 test_done "$testroot" "$ret"
1124 return 1
1127 echo "modified delta on branch" > $testroot/content.expected
1128 cat $testroot/wt/gamma/delta > $testroot/content
1129 cmp -s $testroot/content.expected $testroot/content
1130 ret="$?"
1131 if [ "$ret" != "0" ]; then
1132 diff -u $testroot/content.expected $testroot/content
1133 test_done "$testroot" "$ret"
1134 return 1
1137 echo "modified alpha on master" > $testroot/content.expected
1138 cat $testroot/wt/alpha > $testroot/content
1139 cmp -s $testroot/content.expected $testroot/content
1140 ret="$?"
1141 if [ "$ret" != "0" ]; then
1142 diff -u $testroot/content.expected $testroot/content
1143 test_done "$testroot" "$ret"
1144 return 1
1147 if [ -e $testroot/wt/epsilon ]; then
1148 echo "parent of removed zeta still exists on disk" >&2
1149 test_done "$testroot" "1"
1150 return 1
1153 (cd $testroot/wt && got status > $testroot/stdout)
1155 echo -n > $testroot/stdout.expected
1156 cmp -s $testroot/stdout.expected $testroot/stdout
1157 ret="$?"
1158 if [ "$ret" != "0" ]; then
1159 diff -u $testroot/stdout.expected $testroot/stdout
1160 test_done "$testroot" "$ret"
1161 return 1
1164 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1165 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1166 echo "commit $new_commit1" >> $testroot/stdout.expected
1167 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1168 cmp -s $testroot/stdout.expected $testroot/stdout
1169 ret="$?"
1170 if [ "$ret" != "0" ]; then
1171 diff -u $testroot/stdout.expected $testroot/stdout
1173 test_done "$testroot" "$ret"
1176 test_rebase_delete_missing_file() {
1177 local testroot=`test_init rebase_delete_missing_file`
1179 mkdir -p $testroot/repo/d/f/g
1180 echo "new file" > $testroot/repo/d/f/g/new
1181 (cd $testroot/repo && git add d/f/g/new)
1182 git_commit $testroot/repo -m "adding a subdir"
1183 local commit0=`git_show_head $testroot/repo`
1185 got br -r $testroot/repo -c master newbranch
1187 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1189 echo "modified delta on branch" > $testroot/wt/gamma/delta
1190 (cd $testroot/wt && got commit \
1191 -m "committing to delta on newbranch" > /dev/null)
1193 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1194 (cd $testroot/wt && got commit \
1195 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1197 (cd $testroot/repo && git checkout -q newbranch)
1198 local orig_commit1=`git_show_parent_commit $testroot/repo`
1199 local orig_commit2=`git_show_head $testroot/repo`
1201 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1202 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1204 (cd $testroot/wt && got update -b master > /dev/null)
1205 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1206 (cd $testroot/wt && got commit \
1207 -m "removing beta and d/f/g/new on master" > /dev/null)
1209 (cd $testroot/repo && git checkout -q master)
1210 local master_commit=`git_show_head $testroot/repo`
1212 (cd $testroot/wt && got update -b master > /dev/null)
1213 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1214 2> $testroot/stderr)
1215 ret="$?"
1216 if [ "$ret" = "0" ]; then
1217 echo "rebase succeeded unexpectedly" >&2
1218 test_done "$testroot" "1"
1219 return 1
1222 local new_commit1=$(cd $testroot/wt && got info | \
1223 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1225 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1226 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1228 echo "G gamma/delta" >> $testroot/stdout.expected
1229 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1230 >> $testroot/stdout.expected
1231 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1232 echo "! beta" >> $testroot/stdout.expected
1233 echo "! d/f/g/new" >> $testroot/stdout.expected
1234 echo -n "Files which had incoming changes but could not be found " \
1235 >> $testroot/stdout.expected
1236 echo "in the work tree: 2" >> $testroot/stdout.expected
1237 cmp -s $testroot/stdout.expected $testroot/stdout
1238 ret="$?"
1239 if [ "$ret" != "0" ]; then
1240 diff -u $testroot/stdout.expected $testroot/stdout
1241 test_done "$testroot" "$ret"
1242 return 1
1245 echo -n "got: changes destined for some files were not yet merged " \
1246 > $testroot/stderr.expected
1247 echo -n "and should be merged manually if required before the " \
1248 >> $testroot/stderr.expected
1249 echo "rebase operation is continued" >> $testroot/stderr.expected
1250 cmp -s $testroot/stderr.expected $testroot/stderr
1251 ret="$?"
1252 if [ "$ret" != "0" ]; then
1253 diff -u $testroot/stderr.expected $testroot/stderr
1254 test_done "$testroot" "$ret"
1255 return 1
1258 # ignore the missing changes and continue
1259 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1260 ret="$?"
1261 if [ "$ret" != "0" ]; then
1262 echo "rebase failed unexpectedly" >&2
1263 test_done "$testroot" "1"
1264 return 1
1266 echo -n "$short_orig_commit2 -> no-op change" \
1267 > $testroot/stdout.expected
1268 echo ": removing beta and d/f/g/new on newbranch" \
1269 >> $testroot/stdout.expected
1270 echo "Switching work tree to refs/heads/newbranch" \
1271 >> $testroot/stdout.expected
1273 cmp -s $testroot/stdout.expected $testroot/stdout
1274 ret="$?"
1275 if [ "$ret" != "0" ]; then
1276 diff -u $testroot/stdout.expected $testroot/stdout
1277 test_done "$testroot" "$ret"
1278 return 1
1281 echo "modified delta on branch" > $testroot/content.expected
1282 cat $testroot/wt/gamma/delta > $testroot/content
1283 cmp -s $testroot/content.expected $testroot/content
1284 ret="$?"
1285 if [ "$ret" != "0" ]; then
1286 diff -u $testroot/content.expected $testroot/content
1287 test_done "$testroot" "$ret"
1288 return 1
1291 if [ -e $testroot/wt/beta ]; then
1292 echo "removed file beta still exists on disk" >&2
1293 test_done "$testroot" "1"
1294 return 1
1297 (cd $testroot/wt && got status > $testroot/stdout)
1299 echo -n > $testroot/stdout.expected
1300 cmp -s $testroot/stdout.expected $testroot/stdout
1301 ret="$?"
1302 if [ "$ret" != "0" ]; then
1303 diff -u $testroot/stdout.expected $testroot/stdout
1304 test_done "$testroot" "$ret"
1305 return 1
1308 (cd $testroot/repo && git checkout -q newbranch)
1309 local new_commit1=`git_show_head $testroot/repo`
1310 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1312 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1313 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1314 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1315 echo "commit $commit0" >> $testroot/stdout.expected
1316 cmp -s $testroot/stdout.expected $testroot/stdout
1317 ret="$?"
1318 if [ "$ret" != "0" ]; then
1319 diff -u $testroot/stdout.expected $testroot/stdout
1321 test_done "$testroot" "$ret"
1324 test_rebase_rm_add_rm_file() {
1325 local testroot=`test_init rebase_rm_add_rm_file`
1327 (cd $testroot/repo && git checkout -q -b newbranch)
1328 (cd $testroot/repo && git rm -q beta)
1329 git_commit $testroot/repo -m "removing beta from newbranch"
1330 local orig_commit1=`git_show_head $testroot/repo`
1332 echo 'restored beta' > $testroot/repo/beta
1333 (cd $testroot/repo && git add beta)
1334 git_commit $testroot/repo -m "restoring beta on newbranch"
1335 local orig_commit2=`git_show_head $testroot/repo`
1337 (cd $testroot/repo && git rm -q beta)
1338 git_commit $testroot/repo -m "removing beta from newbranch again"
1339 local orig_commit3=`git_show_head $testroot/repo`
1341 (cd $testroot/repo && git checkout -q master)
1342 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1343 git_commit $testroot/repo -m "committing to zeta on master"
1344 local master_commit=`git_show_head $testroot/repo`
1346 got checkout $testroot/repo $testroot/wt > /dev/null
1347 ret="$?"
1348 if [ "$ret" != "0" ]; then
1349 test_done "$testroot" "$ret"
1350 return 1
1353 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1355 # this would error out with 'got: file index is corrupt'
1356 (cd $testroot/wt && got status > /dev/null)
1357 ret="$?"
1358 if [ "$ret" != "0" ]; then
1359 echo "got status command failed unexpectedly" >&2
1360 test_done "$testroot" "$ret"
1361 return 1
1364 (cd $testroot/repo && git checkout -q newbranch)
1365 local new_commit3=`git_show_head $testroot/repo`
1366 local new_commit2=`git_show_parent_commit $testroot/repo`
1367 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1369 (cd $testroot/repo && git checkout -q newbranch)
1371 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1372 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1373 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1374 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1375 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1376 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1378 echo "D beta" > $testroot/stdout.expected
1379 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1380 >> $testroot/stdout.expected
1381 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1382 echo "A beta" >> $testroot/stdout.expected
1383 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1384 >> $testroot/stdout.expected
1385 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1386 echo "D beta" >> $testroot/stdout.expected
1387 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1388 >> $testroot/stdout.expected
1389 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1390 echo "Switching work tree to refs/heads/newbranch" \
1391 >> $testroot/stdout.expected
1393 cmp -s $testroot/stdout.expected $testroot/stdout
1394 ret="$?"
1395 if [ "$ret" != "0" ]; then
1396 diff -u $testroot/stdout.expected $testroot/stdout
1397 test_done "$testroot" "$ret"
1398 return 1
1401 (cd $testroot/wt && got status > $testroot/stdout)
1402 ret="$?"
1403 if [ "$ret" != "0" ]; then
1404 echo "got status command failed unexpectedly" >&2
1405 test_done "$testroot" "$ret"
1406 return 1
1409 echo -n > $testroot/stdout.expected
1410 cmp -s $testroot/stdout.expected $testroot/stdout
1411 ret="$?"
1412 if [ "$ret" != "0" ]; then
1413 diff -u $testroot/stdout.expected $testroot/stdout
1414 test_done "$testroot" "$ret"
1415 return 1
1418 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1419 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1420 echo "commit $new_commit2" >> $testroot/stdout.expected
1421 echo "commit $new_commit1" >> $testroot/stdout.expected
1422 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1423 cmp -s $testroot/stdout.expected $testroot/stdout
1424 ret="$?"
1425 if [ "$ret" != "0" ]; then
1426 diff -u $testroot/stdout.expected $testroot/stdout
1428 test_done "$testroot" "$ret"
1431 test_parseargs "$@"
1432 run_test test_rebase_basic
1433 run_test test_rebase_ancestry_check
1434 run_test test_rebase_continue
1435 run_test test_rebase_abort
1436 run_test test_rebase_no_op_change
1437 run_test test_rebase_in_progress
1438 run_test test_rebase_path_prefix
1439 run_test test_rebase_preserves_logmsg
1440 run_test test_rebase_no_commits_to_rebase
1441 run_test test_rebase_forward
1442 run_test test_rebase_out_of_date
1443 run_test test_rebase_trims_empty_dir
1444 run_test test_rebase_delete_missing_file
1445 run_test test_rebase_rm_add_rm_file