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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -eq 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 0 ]; then
790 diff -u $testroot/stderr.expected $testroot/stderr
791 test_done "$testroot" "$ret"
792 return 1
793 fi
795 # rebase should succeed when using a complete work tree
796 got checkout $testroot/repo $testroot/wt2 > /dev/null
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 test_done "$testroot" "$ret"
800 return 1
801 fi
803 (cd $testroot/wt2 && got rebase newbranch \
804 > $testroot/stdout 2> $testroot/stderr)
806 (cd $testroot/repo && git checkout -q newbranch)
807 local new_commit1=`git_show_parent_commit $testroot/repo`
808 local new_commit2=`git_show_head $testroot/repo`
810 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
811 local short_new_commit2=`trim_obj_id 28 $new_commit2`
813 echo "G gamma/delta" > $testroot/stdout.expected
814 echo -n "$short_orig_commit2 -> $short_new_commit2" \
815 >> $testroot/stdout.expected
816 echo ": committing to delta on newbranch" \
817 >> $testroot/stdout.expected
818 echo "Switching work tree to refs/heads/newbranch" \
819 >> $testroot/stdout.expected
821 cmp -s $testroot/stdout.expected $testroot/stdout
822 ret=$?
823 if [ $ret -ne 0 ]; then
824 diff -u $testroot/stdout.expected $testroot/stdout
825 test_done "$testroot" "$ret"
826 return 1
827 fi
829 # the first work tree should remain usable
830 (cd $testroot/wt && got update -b master \
831 > $testroot/stdout 2> $testroot/stderr)
832 ret=$?
833 if [ $ret -ne 0 ]; then
834 echo "update failed unexpectedly" >&2
835 test_done "$testroot" "1"
836 return 1
837 fi
839 echo 'Already up-to-date' > $testroot/stdout.expected
840 cmp -s $testroot/stdout.expected $testroot/stdout
841 ret=$?
842 if [ $ret -ne 0 ]; then
843 diff -u $testroot/stdout.expected $testroot/stdout
844 fi
845 test_done "$testroot" "$ret"
848 test_rebase_preserves_logmsg() {
849 local testroot=`test_init rebase_preserves_logmsg`
851 (cd $testroot/repo && git checkout -q -b newbranch)
852 echo "modified delta on branch" > $testroot/repo/gamma/delta
853 git_commit $testroot/repo -m "modified delta on newbranch"
855 echo "modified alpha on branch" > $testroot/repo/alpha
856 git_commit $testroot/repo -m "modified alpha on newbranch"
858 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
859 > $testroot/log.expected)
861 local orig_commit1=`git_show_parent_commit $testroot/repo`
862 local orig_commit2=`git_show_head $testroot/repo`
864 (cd $testroot/repo && git checkout -q master)
865 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
866 git_commit $testroot/repo -m "committing to zeta on master"
867 local master_commit=`git_show_head $testroot/repo`
869 got checkout $testroot/repo $testroot/wt > /dev/null
870 ret=$?
871 if [ $ret -ne 0 ]; then
872 test_done "$testroot" "$ret"
873 return 1
874 fi
876 (cd $testroot/wt && got rebase newbranch > /dev/null \
877 2> $testroot/stderr)
879 (cd $testroot/repo && git checkout -q newbranch)
880 local new_commit1=`git_show_parent_commit $testroot/repo`
881 local new_commit2=`git_show_head $testroot/repo`
883 echo -n > $testroot/stderr.expected
884 cmp -s $testroot/stderr.expected $testroot/stderr
885 ret=$?
886 if [ $ret -ne 0 ]; then
887 diff -u $testroot/stderr.expected $testroot/stderr
888 test_done "$testroot" "$ret"
889 return 1
890 fi
892 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
893 > $testroot/log)
894 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
895 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
896 cmp -s $testroot/log.expected $testroot/log
897 ret=$?
898 if [ $ret -ne 0 ]; then
899 diff -u $testroot/log.expected $testroot/log
900 fi
902 test_done "$testroot" "$ret"
905 test_rebase_no_commits_to_rebase() {
906 local testroot=`test_init rebase_no_commits_to_rebase`
908 got checkout $testroot/repo $testroot/wt > /dev/null
909 ret=$?
910 if [ $ret -ne 0 ]; then
911 test_done "$testroot" "$ret"
912 return 1
913 fi
915 (cd $testroot/wt && got branch -n newbranch)
917 echo "modified alpha on master" > $testroot/wt/alpha
918 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
919 > /dev/null)
920 (cd $testroot/wt && got update > /dev/null)
922 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
923 2> $testroot/stderr)
925 echo "got: no commits to rebase" > $testroot/stderr.expected
926 cmp -s $testroot/stderr.expected $testroot/stderr
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 diff -u $testroot/stderr.expected $testroot/stderr
930 test_done "$testroot" "$ret"
931 return 1
932 fi
934 echo -n > $testroot/stdout.expected
935 cmp -s $testroot/stdout.expected $testroot/stdout
936 ret=$?
937 if [ $ret -ne 0 ]; then
938 diff -u $testroot/stdout.expected $testroot/stdout
939 test_done "$testroot" "$ret"
940 return 1
941 fi
943 (cd $testroot/wt && got update > $testroot/stdout)
944 echo "Already up-to-date" > $testroot/stdout.expected
945 cmp -s $testroot/stdout.expected $testroot/stdout
946 ret=$?
947 if [ $ret -ne 0 ]; then
948 diff -u $testroot/stdout.expected $testroot/stdout
949 fi
950 test_done "$testroot" "$ret"
953 test_rebase_forward() {
954 local testroot=`test_init rebase_forward`
955 local commit0=`git_show_head $testroot/repo`
957 got checkout $testroot/repo $testroot/wt > /dev/null
958 ret=$?
959 if [ $ret -ne 0 ]; then
960 test_done "$testroot" "$ret"
961 return 1
962 fi
964 echo "change alpha 1" > $testroot/wt/alpha
965 (cd $testroot/wt && got commit -m 'test rebase_forward' \
966 > /dev/null)
967 local commit1=`git_show_head $testroot/repo`
969 echo "change alpha 2" > $testroot/wt/alpha
970 (cd $testroot/wt && got commit -m 'test rebase_forward' \
971 > /dev/null)
972 local commit2=`git_show_head $testroot/repo`
974 # Simulate a situation where fast-forward is required.
975 # We want to fast-forward master to origin/master:
976 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
977 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
978 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
979 (cd $testroot/repo && got ref -d master >/dev/null)
980 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
981 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
983 (cd $testroot/wt && got up -b origin/master > /dev/null)
985 (cd $testroot/wt && got rebase master \
986 > $testroot/stdout 2> $testroot/stderr)
988 echo "Forwarding refs/heads/master to commit $commit2" \
989 > $testroot/stdout.expected
990 echo "Switching work tree to refs/heads/master" \
991 >> $testroot/stdout.expected
992 cmp -s $testroot/stdout.expected $testroot/stdout
993 ret=$?
994 if [ $ret -ne 0 ]; then
995 diff -u $testroot/stdout.expected $testroot/stdout
996 test_done "$testroot" "$ret"
997 return 1
998 fi
1000 # Ensure that rebase operation was completed correctly
1001 (cd $testroot/wt && got rebase -a \
1002 > $testroot/stdout 2> $testroot/stderr)
1003 echo -n "" > $testroot/stdout.expected
1004 cmp -s $testroot/stdout.expected $testroot/stdout
1005 ret=$?
1006 if [ $ret -ne 0 ]; then
1007 diff -u $testroot/stdout.expected $testroot/stdout
1008 test_done "$testroot" "$ret"
1009 return 1
1011 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1012 cmp -s $testroot/stderr.expected $testroot/stderr
1013 ret=$?
1014 if [ $ret -ne 0 ]; then
1015 diff -u $testroot/stderr.expected $testroot/stderr
1016 test_done "$testroot" "$ret"
1017 return 1
1020 (cd $testroot/wt && got branch -n > $testroot/stdout)
1021 echo "master" > $testroot/stdout.expected
1022 cmp -s $testroot/stdout.expected $testroot/stdout
1023 ret=$?
1024 if [ $ret -ne 0 ]; then
1025 diff -u $testroot/stdout.expected $testroot/stdout
1026 test_done "$testroot" "$ret"
1027 return 1
1030 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1031 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1032 echo "commit $commit1" >> $testroot/stdout.expected
1033 echo "commit $commit0" >> $testroot/stdout.expected
1034 cmp -s $testroot/stdout.expected $testroot/stdout
1035 ret=$?
1036 if [ $ret -ne 0 ]; then
1037 diff -u $testroot/stdout.expected $testroot/stdout
1038 test_done "$testroot" "$ret"
1039 return 1
1042 # Forward-only rebase operations should not be backed up
1043 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1044 echo -n > $testroot/stdout.expected
1045 cmp -s $testroot/stdout.expected $testroot/stdout
1046 ret=$?
1047 if [ $ret -ne 0 ]; then
1048 diff -u $testroot/stdout.expected $testroot/stdout
1050 test_done "$testroot" "$ret"
1053 test_rebase_out_of_date() {
1054 local testroot=`test_init rebase_out_of_date`
1055 local initial_commit=`git_show_head $testroot/repo`
1057 (cd $testroot/repo && git checkout -q -b newbranch)
1058 echo "modified delta on branch" > $testroot/repo/gamma/delta
1059 git_commit $testroot/repo -m "committing to delta on newbranch"
1061 echo "modified alpha on branch" > $testroot/repo/alpha
1062 (cd $testroot/repo && git rm -q beta)
1063 echo "new file on branch" > $testroot/repo/epsilon/new
1064 (cd $testroot/repo && git add epsilon/new)
1065 git_commit $testroot/repo -m "committing more changes on newbranch"
1067 local orig_commit1=`git_show_parent_commit $testroot/repo`
1068 local orig_commit2=`git_show_head $testroot/repo`
1070 (cd $testroot/repo && git checkout -q master)
1071 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1072 git_commit $testroot/repo -m "committing to zeta on master"
1073 local master_commit1=`git_show_head $testroot/repo`
1075 (cd $testroot/repo && git checkout -q master)
1076 echo "modified beta on master" > $testroot/repo/beta
1077 git_commit $testroot/repo -m "committing to beta on master"
1078 local master_commit2=`git_show_head $testroot/repo`
1080 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1081 > /dev/null
1082 ret=$?
1083 if [ $ret -ne 0 ]; then
1084 test_done "$testroot" "$ret"
1085 return 1
1088 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1089 2> $testroot/stderr)
1091 echo -n > $testroot/stdout.expected
1092 cmp -s $testroot/stdout.expected $testroot/stdout
1093 ret=$?
1094 if [ $ret -ne 0 ]; then
1095 diff -u $testroot/stdout.expected $testroot/stdout
1096 test_done "$testroot" "$ret"
1097 return 1
1100 echo -n "got: work tree must be updated before it can be " \
1101 > $testroot/stderr.expected
1102 echo "used to rebase a branch" >> $testroot/stderr.expected
1103 cmp -s $testroot/stderr.expected $testroot/stderr
1104 ret=$?
1105 if [ $ret -ne 0 ]; then
1106 diff -u $testroot/stderr.expected $testroot/stderr
1107 test_done "$testroot" "$ret"
1108 return 1
1111 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1112 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1113 echo "commit $master_commit1" >> $testroot/stdout.expected
1114 echo "commit $initial_commit" >> $testroot/stdout.expected
1115 cmp -s $testroot/stdout.expected $testroot/stdout
1116 ret=$?
1117 if [ $ret -ne 0 ]; then
1118 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1123 test_rebase_trims_empty_dir() {
1124 local testroot=`test_init rebase_trims_empty_dir`
1126 (cd $testroot/repo && git checkout -q -b newbranch)
1127 echo "modified delta on branch" > $testroot/repo/gamma/delta
1128 git_commit $testroot/repo -m "committing to delta on newbranch"
1130 (cd $testroot/repo && git rm -q epsilon/zeta)
1131 git_commit $testroot/repo -m "removing zeta on newbranch"
1133 local orig_commit1=`git_show_parent_commit $testroot/repo`
1134 local orig_commit2=`git_show_head $testroot/repo`
1136 (cd $testroot/repo && git checkout -q master)
1137 echo "modified alpha on master" > $testroot/repo/alpha
1138 git_commit $testroot/repo -m "committing to alpha on master"
1139 local master_commit=`git_show_head $testroot/repo`
1141 got checkout $testroot/repo $testroot/wt > /dev/null
1142 ret=$?
1143 if [ $ret -ne 0 ]; then
1144 test_done "$testroot" "$ret"
1145 return 1
1148 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1150 (cd $testroot/repo && git checkout -q newbranch)
1151 local new_commit1=`git_show_parent_commit $testroot/repo`
1152 local new_commit2=`git_show_head $testroot/repo`
1154 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1155 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1156 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1157 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1159 echo "G gamma/delta" >> $testroot/stdout.expected
1160 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1161 >> $testroot/stdout.expected
1162 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1163 echo "D epsilon/zeta" >> $testroot/stdout.expected
1164 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1165 >> $testroot/stdout.expected
1166 echo ": removing zeta on newbranch" \
1167 >> $testroot/stdout.expected
1168 echo "Switching work tree to refs/heads/newbranch" \
1169 >> $testroot/stdout.expected
1171 cmp -s $testroot/stdout.expected $testroot/stdout
1172 ret=$?
1173 if [ $ret -ne 0 ]; then
1174 diff -u $testroot/stdout.expected $testroot/stdout
1175 test_done "$testroot" "$ret"
1176 return 1
1179 echo "modified delta on branch" > $testroot/content.expected
1180 cat $testroot/wt/gamma/delta > $testroot/content
1181 cmp -s $testroot/content.expected $testroot/content
1182 ret=$?
1183 if [ $ret -ne 0 ]; then
1184 diff -u $testroot/content.expected $testroot/content
1185 test_done "$testroot" "$ret"
1186 return 1
1189 echo "modified alpha on master" > $testroot/content.expected
1190 cat $testroot/wt/alpha > $testroot/content
1191 cmp -s $testroot/content.expected $testroot/content
1192 ret=$?
1193 if [ $ret -ne 0 ]; then
1194 diff -u $testroot/content.expected $testroot/content
1195 test_done "$testroot" "$ret"
1196 return 1
1199 if [ -e $testroot/wt/epsilon ]; then
1200 echo "parent of removed zeta still exists on disk" >&2
1201 test_done "$testroot" "1"
1202 return 1
1205 (cd $testroot/wt && got status > $testroot/stdout)
1207 echo -n > $testroot/stdout.expected
1208 cmp -s $testroot/stdout.expected $testroot/stdout
1209 ret=$?
1210 if [ $ret -ne 0 ]; then
1211 diff -u $testroot/stdout.expected $testroot/stdout
1212 test_done "$testroot" "$ret"
1213 return 1
1216 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1217 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1218 echo "commit $new_commit1" >> $testroot/stdout.expected
1219 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1220 cmp -s $testroot/stdout.expected $testroot/stdout
1221 ret=$?
1222 if [ $ret -ne 0 ]; then
1223 diff -u $testroot/stdout.expected $testroot/stdout
1225 test_done "$testroot" "$ret"
1228 test_rebase_delete_missing_file() {
1229 local testroot=`test_init rebase_delete_missing_file`
1231 mkdir -p $testroot/repo/d/f/g
1232 echo "new file" > $testroot/repo/d/f/g/new
1233 (cd $testroot/repo && git add d/f/g/new)
1234 git_commit $testroot/repo -m "adding a subdir"
1235 local commit0=`git_show_head $testroot/repo`
1237 got br -r $testroot/repo -c master newbranch
1239 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1241 echo "modified delta on branch" > $testroot/wt/gamma/delta
1242 (cd $testroot/wt && got commit \
1243 -m "committing to delta on newbranch" > /dev/null)
1245 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1246 (cd $testroot/wt && got commit \
1247 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1249 (cd $testroot/repo && git checkout -q newbranch)
1250 local orig_commit1=`git_show_parent_commit $testroot/repo`
1251 local orig_commit2=`git_show_head $testroot/repo`
1253 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1254 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1256 (cd $testroot/wt && got update -b master > /dev/null)
1257 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1258 (cd $testroot/wt && got commit \
1259 -m "removing beta and d/f/g/new on master" > /dev/null)
1261 (cd $testroot/repo && git checkout -q master)
1262 local master_commit=`git_show_head $testroot/repo`
1264 (cd $testroot/wt && got update -b master > /dev/null)
1265 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1266 2> $testroot/stderr)
1267 ret=$?
1268 if [ $ret -eq 0 ]; then
1269 echo "rebase succeeded unexpectedly" >&2
1270 test_done "$testroot" "1"
1271 return 1
1274 local new_commit1=$(cd $testroot/wt && got info | \
1275 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1277 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1278 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1280 echo "G gamma/delta" >> $testroot/stdout.expected
1281 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1282 >> $testroot/stdout.expected
1283 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1284 echo "! beta" >> $testroot/stdout.expected
1285 echo "! d/f/g/new" >> $testroot/stdout.expected
1286 echo -n "Files which had incoming changes but could not be found " \
1287 >> $testroot/stdout.expected
1288 echo "in the work tree: 2" >> $testroot/stdout.expected
1289 cmp -s $testroot/stdout.expected $testroot/stdout
1290 ret=$?
1291 if [ $ret -ne 0 ]; then
1292 diff -u $testroot/stdout.expected $testroot/stdout
1293 test_done "$testroot" "$ret"
1294 return 1
1297 echo -n "got: changes destined for some files were not yet merged " \
1298 > $testroot/stderr.expected
1299 echo -n "and should be merged manually if required before the " \
1300 >> $testroot/stderr.expected
1301 echo "rebase operation is continued" >> $testroot/stderr.expected
1302 cmp -s $testroot/stderr.expected $testroot/stderr
1303 ret=$?
1304 if [ $ret -ne 0 ]; then
1305 diff -u $testroot/stderr.expected $testroot/stderr
1306 test_done "$testroot" "$ret"
1307 return 1
1310 # ignore the missing changes and continue
1311 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1312 ret=$?
1313 if [ $ret -ne 0 ]; then
1314 echo "rebase failed unexpectedly" >&2
1315 test_done "$testroot" "1"
1316 return 1
1318 echo -n "$short_orig_commit2 -> no-op change" \
1319 > $testroot/stdout.expected
1320 echo ": removing beta and d/f/g/new on newbranch" \
1321 >> $testroot/stdout.expected
1322 echo "Switching work tree to refs/heads/newbranch" \
1323 >> $testroot/stdout.expected
1325 cmp -s $testroot/stdout.expected $testroot/stdout
1326 ret=$?
1327 if [ $ret -ne 0 ]; then
1328 diff -u $testroot/stdout.expected $testroot/stdout
1329 test_done "$testroot" "$ret"
1330 return 1
1333 echo "modified delta on branch" > $testroot/content.expected
1334 cat $testroot/wt/gamma/delta > $testroot/content
1335 cmp -s $testroot/content.expected $testroot/content
1336 ret=$?
1337 if [ $ret -ne 0 ]; then
1338 diff -u $testroot/content.expected $testroot/content
1339 test_done "$testroot" "$ret"
1340 return 1
1343 if [ -e $testroot/wt/beta ]; then
1344 echo "removed file beta still exists on disk" >&2
1345 test_done "$testroot" "1"
1346 return 1
1349 (cd $testroot/wt && got status > $testroot/stdout)
1351 echo -n > $testroot/stdout.expected
1352 cmp -s $testroot/stdout.expected $testroot/stdout
1353 ret=$?
1354 if [ $ret -ne 0 ]; then
1355 diff -u $testroot/stdout.expected $testroot/stdout
1356 test_done "$testroot" "$ret"
1357 return 1
1360 (cd $testroot/repo && git checkout -q newbranch)
1361 local new_commit1=`git_show_head $testroot/repo`
1362 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1364 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1365 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1366 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1367 echo "commit $commit0" >> $testroot/stdout.expected
1368 cmp -s $testroot/stdout.expected $testroot/stdout
1369 ret=$?
1370 if [ $ret -ne 0 ]; then
1371 diff -u $testroot/stdout.expected $testroot/stdout
1373 test_done "$testroot" "$ret"
1376 test_rebase_rm_add_rm_file() {
1377 local testroot=`test_init rebase_rm_add_rm_file`
1379 (cd $testroot/repo && git checkout -q -b newbranch)
1380 (cd $testroot/repo && git rm -q beta)
1381 git_commit $testroot/repo -m "removing beta from newbranch"
1382 local orig_commit1=`git_show_head $testroot/repo`
1384 echo 'restored beta' > $testroot/repo/beta
1385 (cd $testroot/repo && git add beta)
1386 git_commit $testroot/repo -m "restoring beta on newbranch"
1387 local orig_commit2=`git_show_head $testroot/repo`
1389 (cd $testroot/repo && git rm -q beta)
1390 git_commit $testroot/repo -m "removing beta from newbranch again"
1391 local orig_commit3=`git_show_head $testroot/repo`
1393 (cd $testroot/repo && git checkout -q master)
1394 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1395 git_commit $testroot/repo -m "committing to zeta on master"
1396 local master_commit=`git_show_head $testroot/repo`
1398 got checkout $testroot/repo $testroot/wt > /dev/null
1399 ret=$?
1400 if [ $ret -ne 0 ]; then
1401 test_done "$testroot" "$ret"
1402 return 1
1405 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1407 # this would error out with 'got: file index is corrupt'
1408 (cd $testroot/wt && got status > /dev/null)
1409 ret=$?
1410 if [ $ret -ne 0 ]; then
1411 echo "got status command failed unexpectedly" >&2
1412 test_done "$testroot" "$ret"
1413 return 1
1416 (cd $testroot/repo && git checkout -q newbranch)
1417 local new_commit3=`git_show_head $testroot/repo`
1418 local new_commit2=`git_show_parent_commit $testroot/repo`
1419 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1421 (cd $testroot/repo && git checkout -q newbranch)
1423 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1424 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1425 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1426 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1427 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1428 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1430 echo "D beta" > $testroot/stdout.expected
1431 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1432 >> $testroot/stdout.expected
1433 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1434 echo "A beta" >> $testroot/stdout.expected
1435 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1436 >> $testroot/stdout.expected
1437 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1438 echo "D beta" >> $testroot/stdout.expected
1439 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1440 >> $testroot/stdout.expected
1441 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1442 echo "Switching work tree to refs/heads/newbranch" \
1443 >> $testroot/stdout.expected
1445 cmp -s $testroot/stdout.expected $testroot/stdout
1446 ret=$?
1447 if [ $ret -ne 0 ]; then
1448 diff -u $testroot/stdout.expected $testroot/stdout
1449 test_done "$testroot" "$ret"
1450 return 1
1453 (cd $testroot/wt && got status > $testroot/stdout)
1454 ret=$?
1455 if [ $ret -ne 0 ]; then
1456 echo "got status command failed unexpectedly" >&2
1457 test_done "$testroot" "$ret"
1458 return 1
1461 echo -n > $testroot/stdout.expected
1462 cmp -s $testroot/stdout.expected $testroot/stdout
1463 ret=$?
1464 if [ $ret -ne 0 ]; then
1465 diff -u $testroot/stdout.expected $testroot/stdout
1466 test_done "$testroot" "$ret"
1467 return 1
1470 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1471 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1472 echo "commit $new_commit2" >> $testroot/stdout.expected
1473 echo "commit $new_commit1" >> $testroot/stdout.expected
1474 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1475 cmp -s $testroot/stdout.expected $testroot/stdout
1476 ret=$?
1477 if [ $ret -ne 0 ]; then
1478 diff -u $testroot/stdout.expected $testroot/stdout
1480 test_done "$testroot" "$ret"
1483 test_parseargs "$@"
1484 run_test test_rebase_basic
1485 run_test test_rebase_ancestry_check
1486 run_test test_rebase_continue
1487 run_test test_rebase_abort
1488 run_test test_rebase_no_op_change
1489 run_test test_rebase_in_progress
1490 run_test test_rebase_path_prefix
1491 run_test test_rebase_preserves_logmsg
1492 run_test test_rebase_no_commits_to_rebase
1493 run_test test_rebase_forward
1494 run_test test_rebase_out_of_date
1495 run_test test_rebase_trims_empty_dir
1496 run_test test_rebase_delete_missing_file
1497 run_test test_rebase_rm_add_rm_file