Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_rebase_basic() {
20 local testroot=`test_init rebase_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 (cd $testroot/repo && git checkout -q -b newbranch)
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
28 echo "modified alpha on branch" > $testroot/repo/alpha
29 (cd $testroot/repo && git rm -q beta)
30 echo "new file on branch" > $testroot/repo/epsilon/new
31 (cd $testroot/repo && git add epsilon/new)
32 git_commit $testroot/repo -m "committing more changes on newbranch"
34 local orig_commit1=`git_show_parent_commit $testroot/repo`
35 local orig_commit2=`git_show_head $testroot/repo`
36 local orig_author_time2=`git_show_author_time $testroot/repo`
38 (cd $testroot/repo && git checkout -q master)
39 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
40 git_commit $testroot/repo -m "committing to zeta on master"
41 local master_commit=`git_show_head $testroot/repo`
43 got checkout $testroot/repo $testroot/wt > /dev/null
44 ret="$?"
45 if [ "$ret" != "0" ]; then
46 test_done "$testroot" "$ret"
47 return 1
48 fi
50 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
52 (cd $testroot/repo && git checkout -q newbranch)
53 local new_commit1=`git_show_parent_commit $testroot/repo`
54 local new_commit2=`git_show_head $testroot/repo`
55 local new_author_time2=`git_show_author_time $testroot/repo`
57 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
58 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
59 local short_new_commit1=`trim_obj_id 28 $new_commit1`
60 local short_new_commit2=`trim_obj_id 28 $new_commit2`
62 echo "G gamma/delta" >> $testroot/stdout.expected
63 echo -n "$short_orig_commit1 -> $short_new_commit1" \
64 >> $testroot/stdout.expected
65 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
66 echo "G alpha" >> $testroot/stdout.expected
67 echo "D beta" >> $testroot/stdout.expected
68 echo "A epsilon/new" >> $testroot/stdout.expected
69 echo -n "$short_orig_commit2 -> $short_new_commit2" \
70 >> $testroot/stdout.expected
71 echo ": committing more changes on newbranch" \
72 >> $testroot/stdout.expected
73 echo "Switching work tree to refs/heads/newbranch" \
74 >> $testroot/stdout.expected
76 cmp -s $testroot/stdout.expected $testroot/stdout
77 ret="$?"
78 if [ "$ret" != "0" ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 echo "modified delta on branch" > $testroot/content.expected
85 cat $testroot/wt/gamma/delta > $testroot/content
86 cmp -s $testroot/content.expected $testroot/content
87 ret="$?"
88 if [ "$ret" != "0" ]; then
89 diff -u $testroot/content.expected $testroot/content
90 test_done "$testroot" "$ret"
91 return 1
92 fi
94 echo "modified alpha on branch" > $testroot/content.expected
95 cat $testroot/wt/alpha > $testroot/content
96 cmp -s $testroot/content.expected $testroot/content
97 ret="$?"
98 if [ "$ret" != "0" ]; then
99 diff -u $testroot/content.expected $testroot/content
100 test_done "$testroot" "$ret"
101 return 1
102 fi
104 if [ -e $testroot/wt/beta ]; then
105 echo "removed file beta still exists on disk" >&2
106 test_done "$testroot" "1"
107 return 1
108 fi
110 echo "new file on branch" > $testroot/content.expected
111 cat $testroot/wt/epsilon/new > $testroot/content
112 cmp -s $testroot/content.expected $testroot/content
113 ret="$?"
114 if [ "$ret" != "0" ]; then
115 diff -u $testroot/content.expected $testroot/content
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 (cd $testroot/wt && got status > $testroot/stdout)
122 echo -n > $testroot/stdout.expected
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret="$?"
125 if [ "$ret" != "0" ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
132 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
133 echo "commit $new_commit1" >> $testroot/stdout.expected
134 echo "commit $master_commit (master)" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected $testroot/stdout
136 ret="$?"
137 if [ "$ret" != "0" ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 test_done "$testroot" "$ret"
140 return 1
141 fi
143 (cd $testroot/wt && got update > $testroot/stdout)
145 echo 'Already up-to-date' > $testroot/stdout.expected
146 cmp -s $testroot/stdout.expected $testroot/stdout
147 ret="$?"
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
151 return 1
152 fi
154 # We should have a backup of old commits
155 (cd $testroot/repo && got rebase -l > $testroot/stdout)
156 local prev_LC_TIME="$LC_TIME"
157 export LC_TIME=C
158 d_orig2=`date -u -d "@$orig_author_time2" +"%a %b %e %X %Y UTC"`
159 export LC_TIME="$prev_LC_TIME"
160 d_new2=`date -u -d "@$new_author_time2" +"%G-%m-%d"`
161 d_0=`date -u -d "@$commit0_author_time" +"%G-%m-%d"`
162 cat > $testroot/stdout.expected <<EOF
163 -----------------------------------------------
164 commit $orig_commit2 (formerly newbranch)
165 from: $GOT_AUTHOR
166 date: $d_orig2
168 committing more changes on newbranch
170 has become commit $new_commit2 (newbranch)
171 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
172 history forked at $commit0
173 $d_0 $GOT_AUTHOR_11 adding the test tree
174 EOF
175 cmp -s $testroot/stdout.expected $testroot/stdout
176 ret="$?"
177 if [ "$ret" != "0" ]; then
178 diff -u $testroot/stdout.expected $testroot/stdout
179 test_done "$testroot" "$ret"
180 return 1
181 fi
183 # Asking for backups of a branch which has none should yield an error
184 (cd $testroot/repo && got rebase -l master \
185 > $testroot/stdout 2> $testroot/stderr)
186 echo -n > $testroot/stdout.expected
187 echo "got: refs/got/backup/rebase/master/: no such reference found" \
188 > $testroot/stderr.expected
189 cmp -s $testroot/stdout.expected $testroot/stdout
190 ret="$?"
191 if [ "$ret" != "0" ]; then
192 diff -u $testroot/stdout.expected $testroot/stdout
193 test_done "$testroot" "$ret"
194 return 1
195 fi
196 cmp -s $testroot/stderr.expected $testroot/stderr
197 ret="$?"
198 if [ "$ret" != "0" ]; then
199 diff -u $testroot/stderr.expected $testroot/stderr
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 # Delete all backup refs
205 (cd $testroot/repo && got rebase -X \
206 > $testroot/stdout 2> $testroot/stderr)
207 echo -n "Deleted refs/got/backup/rebase/newbranch/$new_commit2: " \
208 > $testroot/stdout.expected
209 echo "$orig_commit2" >> $testroot/stdout.expected
210 echo -n > $testroot/stderr.expected
211 cmp -s $testroot/stdout.expected $testroot/stdout
212 ret="$?"
213 if [ "$ret" != "0" ]; then
214 diff -u $testroot/stdout.expected $testroot/stdout
215 test_done "$testroot" "$ret"
216 return 1
217 fi
218 cmp -s $testroot/stderr.expected $testroot/stderr
219 ret="$?"
220 if [ "$ret" != "0" ]; then
221 diff -u $testroot/stderr.expected $testroot/stderr
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 (cd $testroot/repo && got rebase -l > $testroot/stdout)
227 echo -n > $testroot/stdout.expected
228 cmp -s $testroot/stdout.expected $testroot/stdout
229 ret="$?"
230 if [ "$ret" != "0" ]; then
231 diff -u $testroot/stdout.expected $testroot/stdout
232 fi
233 test_done "$testroot" "$ret"
236 test_rebase_ancestry_check() {
237 local testroot=`test_init rebase_ancestry_check`
239 got checkout $testroot/repo $testroot/wt > /dev/null
240 ret="$?"
241 if [ "$ret" != "0" ]; then
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 (cd $testroot/repo && git checkout -q -b newbranch)
247 echo "modified delta on branch" > $testroot/repo/gamma/delta
248 git_commit $testroot/repo -m "committing to delta on newbranch"
250 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
251 2> $testroot/stderr)
253 echo -n > $testroot/stdout.expected
254 cmp -s $testroot/stdout.expected $testroot/stdout
255 ret="$?"
256 if [ "$ret" != "0" ]; then
257 diff -u $testroot/stdout.expected $testroot/stdout
258 test_done "$testroot" "$ret"
259 return 1
260 fi
262 echo "got: refs/heads/newbranch is already based on refs/heads/master" \
263 > $testroot/stderr.expected
264 cmp -s $testroot/stderr.expected $testroot/stderr
265 ret="$?"
266 if [ "$ret" != "0" ]; then
267 diff -u $testroot/stderr.expected $testroot/stderr
268 fi
269 test_done "$testroot" "$ret"
272 test_rebase_continue() {
273 local testroot=`test_init rebase_continue`
274 local init_commit=`git_show_head $testroot/repo`
276 (cd $testroot/repo && git checkout -q -b newbranch)
277 echo "modified alpha on branch" > $testroot/repo/alpha
278 git_commit $testroot/repo -m "committing to alpha on newbranch"
279 local orig_commit1=`git_show_head $testroot/repo`
280 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
282 (cd $testroot/repo && git checkout -q master)
283 echo "modified alpha on master" > $testroot/repo/alpha
284 git_commit $testroot/repo -m "committing to alpha on master"
285 local master_commit=`git_show_head $testroot/repo`
287 got checkout $testroot/repo $testroot/wt > /dev/null
288 ret="$?"
289 if [ "$ret" != "0" ]; then
290 test_done "$testroot" "$ret"
291 return 1
292 fi
294 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
295 2> $testroot/stderr)
297 echo "C alpha" > $testroot/stdout.expected
298 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
299 echo -n "$short_orig_commit1 -> merge conflict" \
300 >> $testroot/stdout.expected
301 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
302 cmp -s $testroot/stdout.expected $testroot/stdout
303 ret="$?"
304 if [ "$ret" != "0" ]; then
305 diff -u $testroot/stdout.expected $testroot/stdout
306 test_done "$testroot" "$ret"
307 return 1
308 fi
310 echo "got: conflicts must be resolved before rebasing can continue" \
311 > $testroot/stderr.expected
312 cmp -s $testroot/stderr.expected $testroot/stderr
313 ret="$?"
314 if [ "$ret" != "0" ]; then
315 diff -u $testroot/stderr.expected $testroot/stderr
316 test_done "$testroot" "$ret"
317 return 1
318 fi
320 echo '<<<<<<<' > $testroot/content.expected
321 echo "modified alpha on master" >> $testroot/content.expected
322 echo "||||||| 3-way merge base: commit $init_commit" \
323 >> $testroot/content.expected
324 echo "alpha" >> $testroot/content.expected
325 echo "=======" >> $testroot/content.expected
326 echo "modified alpha on branch" >> $testroot/content.expected
327 echo ">>>>>>> merged change: commit $orig_commit1" \
328 >> $testroot/content.expected
329 cat $testroot/wt/alpha > $testroot/content
330 cmp -s $testroot/content.expected $testroot/content
331 ret="$?"
332 if [ "$ret" != "0" ]; then
333 diff -u $testroot/content.expected $testroot/content
334 test_done "$testroot" "$ret"
335 return 1
336 fi
338 (cd $testroot/wt && got status > $testroot/stdout)
340 echo "C alpha" > $testroot/stdout.expected
341 cmp -s $testroot/stdout.expected $testroot/stdout
342 ret="$?"
343 if [ "$ret" != "0" ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
346 return 1
347 fi
349 # resolve the conflict
350 echo "modified alpha on branch and master" > $testroot/wt/alpha
352 # test interaction of 'got stage' and rebase -c
353 (cd $testroot/wt && got stage alpha > /dev/null)
354 (cd $testroot/wt && got rebase -c > $testroot/stdout \
355 2> $testroot/stderr)
356 ret="$?"
357 if [ "$ret" = "0" ]; then
358 echo "rebase succeeded unexpectedly" >&2
359 test_done "$testroot" "1"
360 return 1
361 fi
362 echo -n "got: work tree contains files with staged changes; " \
363 > $testroot/stderr.expected
364 echo "these changes must be committed or unstaged first" \
365 >> $testroot/stderr.expected
366 cmp -s $testroot/stderr.expected $testroot/stderr
367 ret="$?"
368 if [ "$ret" != "0" ]; then
369 diff -u $testroot/stderr.expected $testroot/stderr
370 test_done "$testroot" "$ret"
371 return 1
372 fi
374 (cd $testroot/wt && got unstage alpha > /dev/null)
375 (cd $testroot/wt && got rebase -c > $testroot/stdout)
377 (cd $testroot/repo && git checkout -q newbranch)
378 local new_commit1=`git_show_head $testroot/repo`
379 local short_new_commit1=`trim_obj_id 28 $new_commit1`
381 echo -n "$short_orig_commit1 -> $short_new_commit1" \
382 > $testroot/stdout.expected
383 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
384 echo "Switching work tree to refs/heads/newbranch" \
385 >> $testroot/stdout.expected
387 cmp -s $testroot/stdout.expected $testroot/stdout
388 ret="$?"
389 if [ "$ret" != "0" ]; then
390 diff -u $testroot/stdout.expected $testroot/stdout
391 test_done "$testroot" "$ret"
392 return 1
393 fi
396 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
397 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
398 echo "commit $master_commit (master)" >> $testroot/stdout.expected
399 cmp -s $testroot/stdout.expected $testroot/stdout
400 ret="$?"
401 if [ "$ret" != "0" ]; then
402 diff -u $testroot/stdout.expected $testroot/stdout
403 fi
404 test_done "$testroot" "$ret"
407 test_rebase_abort() {
408 local testroot=`test_init rebase_abort`
410 local init_commit=`git_show_head $testroot/repo`
412 (cd $testroot/repo && git checkout -q -b newbranch)
413 echo "modified alpha on branch" > $testroot/repo/alpha
414 git_commit $testroot/repo -m "committing to alpha on newbranch"
415 local orig_commit1=`git_show_head $testroot/repo`
416 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
418 (cd $testroot/repo && git checkout -q master)
419 echo "modified alpha on master" > $testroot/repo/alpha
420 git_commit $testroot/repo -m "committing to alpha on master"
421 local master_commit=`git_show_head $testroot/repo`
423 got checkout $testroot/repo $testroot/wt > /dev/null
424 ret="$?"
425 if [ "$ret" != "0" ]; then
426 test_done "$testroot" "$ret"
427 return 1
428 fi
430 # unrelated unversioned file in work tree
431 touch $testroot/wt/unversioned-file
433 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
434 2> $testroot/stderr)
436 echo "C alpha" > $testroot/stdout.expected
437 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
438 echo -n "$short_orig_commit1 -> merge conflict" \
439 >> $testroot/stdout.expected
440 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
441 cmp -s $testroot/stdout.expected $testroot/stdout
442 ret="$?"
443 if [ "$ret" != "0" ]; then
444 diff -u $testroot/stdout.expected $testroot/stdout
445 test_done "$testroot" "$ret"
446 return 1
447 fi
449 echo "got: conflicts must be resolved before rebasing can continue" \
450 > $testroot/stderr.expected
451 cmp -s $testroot/stderr.expected $testroot/stderr
452 ret="$?"
453 if [ "$ret" != "0" ]; then
454 diff -u $testroot/stderr.expected $testroot/stderr
455 test_done "$testroot" "$ret"
456 return 1
457 fi
459 echo '<<<<<<<' > $testroot/content.expected
460 echo "modified alpha on master" >> $testroot/content.expected
461 echo "||||||| 3-way merge base: commit $init_commit" \
462 >> $testroot/content.expected
463 echo "alpha" >> $testroot/content.expected
464 echo "=======" >> $testroot/content.expected
465 echo "modified alpha on branch" >> $testroot/content.expected
466 echo ">>>>>>> merged change: commit $orig_commit1" \
467 >> $testroot/content.expected
468 cat $testroot/wt/alpha > $testroot/content
469 cmp -s $testroot/content.expected $testroot/content
470 ret="$?"
471 if [ "$ret" != "0" ]; then
472 diff -u $testroot/content.expected $testroot/content
473 test_done "$testroot" "$ret"
474 return 1
475 fi
477 (cd $testroot/wt && got status > $testroot/stdout)
479 echo "C alpha" > $testroot/stdout.expected
480 echo "? unversioned-file" >> $testroot/stdout.expected
481 cmp -s $testroot/stdout.expected $testroot/stdout
482 ret="$?"
483 if [ "$ret" != "0" ]; then
484 diff -u $testroot/stdout.expected $testroot/stdout
485 test_done "$testroot" "$ret"
486 return 1
487 fi
489 (cd $testroot/wt && got rebase -a > $testroot/stdout)
491 (cd $testroot/repo && git checkout -q newbranch)
493 echo "Switching work tree to refs/heads/master" \
494 > $testroot/stdout.expected
495 echo 'R alpha' >> $testroot/stdout.expected
496 echo "Rebase of refs/heads/newbranch aborted" \
497 >> $testroot/stdout.expected
499 cmp -s $testroot/stdout.expected $testroot/stdout
500 ret="$?"
501 if [ "$ret" != "0" ]; then
502 diff -u $testroot/stdout.expected $testroot/stdout
503 test_done "$testroot" "$ret"
504 return 1
505 fi
507 echo "modified alpha on master" > $testroot/content.expected
508 cat $testroot/wt/alpha > $testroot/content
509 cmp -s $testroot/content.expected $testroot/content
510 ret="$?"
511 if [ "$ret" != "0" ]; then
512 diff -u $testroot/content.expected $testroot/content
513 test_done "$testroot" "$ret"
514 return 1
515 fi
517 (cd $testroot/wt && got log -l3 -c newbranch \
518 | grep ^commit > $testroot/stdout)
519 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
520 echo "commit $init_commit" >> $testroot/stdout.expected
521 cmp -s $testroot/stdout.expected $testroot/stdout
522 ret="$?"
523 if [ "$ret" != "0" ]; then
524 diff -u $testroot/stdout.expected $testroot/stdout
525 fi
526 test_done "$testroot" "$ret"
529 test_rebase_no_op_change() {
530 local testroot=`test_init rebase_no_op_change`
531 local init_commit=`git_show_head $testroot/repo`
533 (cd $testroot/repo && git checkout -q -b newbranch)
534 echo "modified alpha on branch" > $testroot/repo/alpha
535 git_commit $testroot/repo -m "committing to alpha on newbranch"
536 local orig_commit1=`git_show_head $testroot/repo`
537 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
539 (cd $testroot/repo && git checkout -q master)
540 echo "modified alpha on master" > $testroot/repo/alpha
541 git_commit $testroot/repo -m "committing to alpha on master"
542 local master_commit=`git_show_head $testroot/repo`
544 got checkout $testroot/repo $testroot/wt > /dev/null
545 ret="$?"
546 if [ "$ret" != "0" ]; then
547 test_done "$testroot" "$ret"
548 return 1
549 fi
551 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
552 2> $testroot/stderr)
554 echo "C alpha" > $testroot/stdout.expected
555 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
556 echo -n "$short_orig_commit1 -> merge conflict" \
557 >> $testroot/stdout.expected
558 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
559 cmp -s $testroot/stdout.expected $testroot/stdout
560 ret="$?"
561 if [ "$ret" != "0" ]; then
562 diff -u $testroot/stdout.expected $testroot/stdout
563 test_done "$testroot" "$ret"
564 return 1
565 fi
567 echo "got: conflicts must be resolved before rebasing can continue" \
568 > $testroot/stderr.expected
569 cmp -s $testroot/stderr.expected $testroot/stderr
570 ret="$?"
571 if [ "$ret" != "0" ]; then
572 diff -u $testroot/stderr.expected $testroot/stderr
573 test_done "$testroot" "$ret"
574 return 1
575 fi
577 echo '<<<<<<<' > $testroot/content.expected
578 echo "modified alpha on master" >> $testroot/content.expected
579 echo "||||||| 3-way merge base: commit $init_commit" \
580 >> $testroot/content.expected
581 echo "alpha" >> $testroot/content.expected
582 echo "=======" >> $testroot/content.expected
583 echo "modified alpha on branch" >> $testroot/content.expected
584 echo ">>>>>>> merged change: commit $orig_commit1" \
585 >> $testroot/content.expected
586 cat $testroot/wt/alpha > $testroot/content
587 cmp -s $testroot/content.expected $testroot/content
588 ret="$?"
589 if [ "$ret" != "0" ]; then
590 diff -u $testroot/content.expected $testroot/content
591 test_done "$testroot" "$ret"
592 return 1
593 fi
595 (cd $testroot/wt && got status > $testroot/stdout)
597 echo "C alpha" > $testroot/stdout.expected
598 cmp -s $testroot/stdout.expected $testroot/stdout
599 ret="$?"
600 if [ "$ret" != "0" ]; then
601 diff -u $testroot/stdout.expected $testroot/stdout
602 test_done "$testroot" "$ret"
603 return 1
604 fi
606 # resolve the conflict
607 echo "modified alpha on master" > $testroot/wt/alpha
609 (cd $testroot/wt && got rebase -c > $testroot/stdout)
611 (cd $testroot/repo && git checkout -q newbranch)
612 local new_commit1=`git_show_head $testroot/repo`
614 echo -n "$short_orig_commit1 -> no-op change" \
615 > $testroot/stdout.expected
616 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
617 echo "Switching work tree to refs/heads/newbranch" \
618 >> $testroot/stdout.expected
620 cmp -s $testroot/stdout.expected $testroot/stdout
621 ret="$?"
622 if [ "$ret" != "0" ]; then
623 diff -u $testroot/stdout.expected $testroot/stdout
624 test_done "$testroot" "$ret"
625 return 1
626 fi
629 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
630 echo "commit $master_commit (master, newbranch)" \
631 > $testroot/stdout.expected
632 echo "commit $init_commit" >> $testroot/stdout.expected
633 cmp -s $testroot/stdout.expected $testroot/stdout
634 ret="$?"
635 if [ "$ret" != "0" ]; then
636 diff -u $testroot/stdout.expected $testroot/stdout
637 fi
638 test_done "$testroot" "$ret"
641 test_rebase_in_progress() {
642 local testroot=`test_init rebase_in_progress`
643 local init_commit=`git_show_head $testroot/repo`
645 (cd $testroot/repo && git checkout -q -b newbranch)
646 echo "modified alpha on branch" > $testroot/repo/alpha
647 git_commit $testroot/repo -m "committing to alpha on newbranch"
648 local orig_commit1=`git_show_head $testroot/repo`
649 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
651 (cd $testroot/repo && git checkout -q master)
652 echo "modified alpha on master" > $testroot/repo/alpha
653 git_commit $testroot/repo -m "committing to alpha on master"
654 local master_commit=`git_show_head $testroot/repo`
656 got checkout $testroot/repo $testroot/wt > /dev/null
657 ret="$?"
658 if [ "$ret" != "0" ]; then
659 test_done "$testroot" "$ret"
660 return 1
661 fi
663 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
664 2> $testroot/stderr)
666 echo "C alpha" > $testroot/stdout.expected
667 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
668 echo -n "$short_orig_commit1 -> merge conflict" \
669 >> $testroot/stdout.expected
670 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
671 cmp -s $testroot/stdout.expected $testroot/stdout
672 ret="$?"
673 if [ "$ret" != "0" ]; then
674 diff -u $testroot/stdout.expected $testroot/stdout
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 echo "got: conflicts must be resolved before rebasing can continue" \
680 > $testroot/stderr.expected
681 cmp -s $testroot/stderr.expected $testroot/stderr
682 ret="$?"
683 if [ "$ret" != "0" ]; then
684 diff -u $testroot/stderr.expected $testroot/stderr
685 test_done "$testroot" "$ret"
686 return 1
687 fi
689 echo '<<<<<<<' > $testroot/content.expected
690 echo "modified alpha on master" >> $testroot/content.expected
691 echo "||||||| 3-way merge base: commit $init_commit" \
692 >> $testroot/content.expected
693 echo "alpha" >> $testroot/content.expected
694 echo "=======" >> $testroot/content.expected
695 echo "modified alpha on branch" >> $testroot/content.expected
696 echo ">>>>>>> merged change: commit $orig_commit1" \
697 >> $testroot/content.expected
698 cat $testroot/wt/alpha > $testroot/content
699 cmp -s $testroot/content.expected $testroot/content
700 ret="$?"
701 if [ "$ret" != "0" ]; then
702 diff -u $testroot/content.expected $testroot/content
703 test_done "$testroot" "$ret"
704 return 1
705 fi
707 (cd $testroot/wt && got status > $testroot/stdout)
709 echo "C alpha" > $testroot/stdout.expected
710 cmp -s $testroot/stdout.expected $testroot/stdout
711 ret="$?"
712 if [ "$ret" != "0" ]; then
713 diff -u $testroot/stdout.expected $testroot/stdout
714 test_done "$testroot" "$ret"
715 return 1
716 fi
718 for cmd in update commit; do
719 (cd $testroot/wt && got $cmd > $testroot/stdout \
720 2> $testroot/stderr)
722 echo -n > $testroot/stdout.expected
723 cmp -s $testroot/stdout.expected $testroot/stdout
724 ret="$?"
725 if [ "$ret" != "0" ]; then
726 diff -u $testroot/stdout.expected $testroot/stdout
727 test_done "$testroot" "$ret"
728 return 1
729 fi
731 echo -n "got: a rebase operation is in progress in this " \
732 > $testroot/stderr.expected
733 echo "work tree and must be continued or aborted first" \
734 >> $testroot/stderr.expected
735 cmp -s $testroot/stderr.expected $testroot/stderr
736 ret="$?"
737 if [ "$ret" != "0" ]; then
738 diff -u $testroot/stderr.expected $testroot/stderr
739 test_done "$testroot" "$ret"
740 return 1
741 fi
742 done
744 test_done "$testroot" "$ret"
747 test_rebase_path_prefix() {
748 local testroot=`test_init rebase_path_prefix`
750 (cd $testroot/repo && git checkout -q -b newbranch)
751 echo "modified delta on branch" > $testroot/repo/gamma/delta
752 git_commit $testroot/repo -m "committing to delta on newbranch"
754 local orig_commit1=`git_show_parent_commit $testroot/repo`
755 local orig_commit2=`git_show_head $testroot/repo`
757 (cd $testroot/repo && git checkout -q master)
758 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
759 git_commit $testroot/repo -m "committing to zeta on master"
760 local master_commit=`git_show_head $testroot/repo`
762 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
763 ret="$?"
764 if [ "$ret" != "0" ]; then
765 test_done "$testroot" "$ret"
766 return 1
767 fi
769 (cd $testroot/wt && got rebase newbranch \
770 > $testroot/stdout 2> $testroot/stderr)
772 echo -n > $testroot/stdout.expected
773 cmp -s $testroot/stdout.expected $testroot/stdout
774 ret="$?"
775 if [ "$ret" != "0" ]; then
776 diff -u $testroot/stdout.expected $testroot/stdout
777 test_done "$testroot" "$ret"
778 return 1
779 fi
781 echo -n "got: cannot rebase branch which contains changes outside " \
782 > $testroot/stderr.expected
783 echo "of this work tree's path prefix" >> $testroot/stderr.expected
784 cmp -s $testroot/stderr.expected $testroot/stderr
785 ret="$?"
786 if [ "$ret" != "0" ]; then
787 diff -u $testroot/stderr.expected $testroot/stderr
788 fi
789 test_done "$testroot" "$ret"
792 test_rebase_preserves_logmsg() {
793 local testroot=`test_init rebase_preserves_logmsg`
795 (cd $testroot/repo && git checkout -q -b newbranch)
796 echo "modified delta on branch" > $testroot/repo/gamma/delta
797 git_commit $testroot/repo -m "modified delta on newbranch"
799 echo "modified alpha on branch" > $testroot/repo/alpha
800 git_commit $testroot/repo -m "modified alpha on newbranch"
802 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
803 > $testroot/log.expected)
805 local orig_commit1=`git_show_parent_commit $testroot/repo`
806 local orig_commit2=`git_show_head $testroot/repo`
808 (cd $testroot/repo && git checkout -q master)
809 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
810 git_commit $testroot/repo -m "committing to zeta on master"
811 local master_commit=`git_show_head $testroot/repo`
813 got checkout $testroot/repo $testroot/wt > /dev/null
814 ret="$?"
815 if [ "$ret" != "0" ]; then
816 test_done "$testroot" "$ret"
817 return 1
818 fi
820 (cd $testroot/wt && got rebase newbranch > /dev/null \
821 2> $testroot/stderr)
823 (cd $testroot/repo && git checkout -q newbranch)
824 local new_commit1=`git_show_parent_commit $testroot/repo`
825 local new_commit2=`git_show_head $testroot/repo`
827 echo -n > $testroot/stderr.expected
828 cmp -s $testroot/stderr.expected $testroot/stderr
829 ret="$?"
830 if [ "$ret" != "0" ]; then
831 diff -u $testroot/stderr.expected $testroot/stderr
832 test_done "$testroot" "$ret"
833 return 1
834 fi
836 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
837 > $testroot/log)
838 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
839 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
840 cmp -s $testroot/log.expected $testroot/log
841 ret="$?"
842 if [ "$ret" != "0" ]; then
843 diff -u $testroot/log.expected $testroot/log
844 fi
846 test_done "$testroot" "$ret"
849 test_rebase_no_commits_to_rebase() {
850 local testroot=`test_init rebase_no_commits_to_rebase`
852 got checkout $testroot/repo $testroot/wt > /dev/null
853 ret="$?"
854 if [ "$ret" != "0" ]; then
855 test_done "$testroot" "$ret"
856 return 1
857 fi
859 (cd $testroot/wt && got branch -n newbranch)
861 echo "modified alpha on master" > $testroot/wt/alpha
862 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
863 > /dev/null)
864 (cd $testroot/wt && got update > /dev/null)
866 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
867 2> $testroot/stderr)
869 echo "got: no commits to rebase" > $testroot/stderr.expected
870 cmp -s $testroot/stderr.expected $testroot/stderr
871 ret="$?"
872 if [ "$ret" != "0" ]; then
873 diff -u $testroot/stderr.expected $testroot/stderr
874 test_done "$testroot" "$ret"
875 return 1
876 fi
878 echo "Rebase of refs/heads/newbranch aborted" \
879 > $testroot/stdout.expected
880 cmp -s $testroot/stdout.expected $testroot/stdout
881 ret="$?"
882 if [ "$ret" != "0" ]; then
883 diff -u $testroot/stdout.expected $testroot/stdout
884 test_done "$testroot" "$ret"
885 return 1
886 fi
888 (cd $testroot/wt && got update > $testroot/stdout)
889 echo "Already up-to-date" > $testroot/stdout.expected
890 cmp -s $testroot/stdout.expected $testroot/stdout
891 ret="$?"
892 if [ "$ret" != "0" ]; then
893 diff -u $testroot/stdout.expected $testroot/stdout
894 fi
895 test_done "$testroot" "$ret"
898 test_rebase_forward() {
899 local testroot=`test_init rebase_forward`
900 local commit0=`git_show_head $testroot/repo`
902 got checkout $testroot/repo $testroot/wt > /dev/null
903 ret="$?"
904 if [ "$ret" != "0" ]; then
905 test_done "$testroot" "$ret"
906 return 1
907 fi
909 echo "change alpha 1" > $testroot/wt/alpha
910 (cd $testroot/wt && got commit -m 'test rebase_forward' \
911 > /dev/null)
912 local commit1=`git_show_head $testroot/repo`
914 echo "change alpha 2" > $testroot/wt/alpha
915 (cd $testroot/wt && got commit -m 'test rebase_forward' \
916 > /dev/null)
917 local commit2=`git_show_head $testroot/repo`
919 # Simulate a situation where fast-forward is required.
920 # We want to fast-forward master to origin/master:
921 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
922 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
923 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
924 (cd $testroot/repo && got ref -d master >/dev/null)
925 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
926 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
928 (cd $testroot/wt && got up -b origin/master > /dev/null)
930 (cd $testroot/wt && got rebase master \
931 > $testroot/stdout 2> $testroot/stderr)
933 echo "Forwarding refs/heads/master to commit $commit2" \
934 > $testroot/stdout.expected
935 echo "Switching work tree to refs/heads/master" \
936 >> $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected $testroot/stdout
938 ret="$?"
939 if [ "$ret" != "0" ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
941 test_done "$testroot" "$ret"
942 return 1
943 fi
945 # Ensure that rebase operation was completed correctly
946 (cd $testroot/wt && got rebase -a \
947 > $testroot/stdout 2> $testroot/stderr)
948 echo -n "" > $testroot/stdout.expected
949 cmp -s $testroot/stdout.expected $testroot/stdout
950 ret="$?"
951 if [ "$ret" != "0" ]; then
952 diff -u $testroot/stdout.expected $testroot/stdout
953 test_done "$testroot" "$ret"
954 return 1
955 fi
956 echo "got: rebase operation not in progress" > $testroot/stderr.expected
957 cmp -s $testroot/stderr.expected $testroot/stderr
958 ret="$?"
959 if [ "$ret" != "0" ]; then
960 diff -u $testroot/stderr.expected $testroot/stderr
961 test_done "$testroot" "$ret"
962 return 1
963 fi
965 (cd $testroot/wt && got branch -n > $testroot/stdout)
966 echo "master" > $testroot/stdout.expected
967 cmp -s $testroot/stdout.expected $testroot/stdout
968 ret="$?"
969 if [ "$ret" != "0" ]; then
970 diff -u $testroot/stdout.expected $testroot/stdout
971 test_done "$testroot" "$ret"
972 return 1
973 fi
975 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
976 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
977 echo "commit $commit1" >> $testroot/stdout.expected
978 echo "commit $commit0" >> $testroot/stdout.expected
979 cmp -s $testroot/stdout.expected $testroot/stdout
980 ret="$?"
981 if [ "$ret" != "0" ]; then
982 diff -u $testroot/stdout.expected $testroot/stdout
983 test_done "$testroot" "$ret"
984 return 1
985 fi
987 # Forward-only rebase operations should not be backed up
988 (cd $testroot/repo && got rebase -l > $testroot/stdout)
989 echo -n > $testroot/stdout.expected
990 cmp -s $testroot/stdout.expected $testroot/stdout
991 ret="$?"
992 if [ "$ret" != "0" ]; then
993 diff -u $testroot/stdout.expected $testroot/stdout
994 fi
995 test_done "$testroot" "$ret"
998 test_rebase_out_of_date() {
999 local testroot=`test_init rebase_out_of_date`
1000 local initial_commit=`git_show_head $testroot/repo`
1002 (cd $testroot/repo && git checkout -q -b newbranch)
1003 echo "modified delta on branch" > $testroot/repo/gamma/delta
1004 git_commit $testroot/repo -m "committing to delta on newbranch"
1006 echo "modified alpha on branch" > $testroot/repo/alpha
1007 (cd $testroot/repo && git rm -q beta)
1008 echo "new file on branch" > $testroot/repo/epsilon/new
1009 (cd $testroot/repo && git add epsilon/new)
1010 git_commit $testroot/repo -m "committing more changes on newbranch"
1012 local orig_commit1=`git_show_parent_commit $testroot/repo`
1013 local orig_commit2=`git_show_head $testroot/repo`
1015 (cd $testroot/repo && git checkout -q master)
1016 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1017 git_commit $testroot/repo -m "committing to zeta on master"
1018 local master_commit1=`git_show_head $testroot/repo`
1020 (cd $testroot/repo && git checkout -q master)
1021 echo "modified beta on master" > $testroot/repo/beta
1022 git_commit $testroot/repo -m "committing to beta on master"
1023 local master_commit2=`git_show_head $testroot/repo`
1025 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1026 > /dev/null
1027 ret="$?"
1028 if [ "$ret" != "0" ]; then
1029 test_done "$testroot" "$ret"
1030 return 1
1033 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1034 2> $testroot/stderr)
1036 echo -n > $testroot/stdout.expected
1037 cmp -s $testroot/stdout.expected $testroot/stdout
1038 ret="$?"
1039 if [ "$ret" != "0" ]; then
1040 diff -u $testroot/stdout.expected $testroot/stdout
1041 test_done "$testroot" "$ret"
1042 return 1
1045 echo -n "got: work tree must be updated before it can be " \
1046 > $testroot/stderr.expected
1047 echo "used to rebase a branch" >> $testroot/stderr.expected
1048 cmp -s $testroot/stderr.expected $testroot/stderr
1049 ret="$?"
1050 if [ "$ret" != "0" ]; then
1051 diff -u $testroot/stderr.expected $testroot/stderr
1052 test_done "$testroot" "$ret"
1053 return 1
1056 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1057 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1058 echo "commit $master_commit1" >> $testroot/stdout.expected
1059 echo "commit $initial_commit" >> $testroot/stdout.expected
1060 cmp -s $testroot/stdout.expected $testroot/stdout
1061 ret="$?"
1062 if [ "$ret" != "0" ]; then
1063 diff -u $testroot/stdout.expected $testroot/stdout
1065 test_done "$testroot" "$ret"
1068 test_rebase_trims_empty_dir() {
1069 local testroot=`test_init rebase_trims_empty_dir`
1071 (cd $testroot/repo && git checkout -q -b newbranch)
1072 echo "modified delta on branch" > $testroot/repo/gamma/delta
1073 git_commit $testroot/repo -m "committing to delta on newbranch"
1075 (cd $testroot/repo && git rm -q epsilon/zeta)
1076 git_commit $testroot/repo -m "removing zeta on newbranch"
1078 local orig_commit1=`git_show_parent_commit $testroot/repo`
1079 local orig_commit2=`git_show_head $testroot/repo`
1081 (cd $testroot/repo && git checkout -q master)
1082 echo "modified alpha on master" > $testroot/repo/alpha
1083 git_commit $testroot/repo -m "committing to alpha on master"
1084 local master_commit=`git_show_head $testroot/repo`
1086 got checkout $testroot/repo $testroot/wt > /dev/null
1087 ret="$?"
1088 if [ "$ret" != "0" ]; then
1089 test_done "$testroot" "$ret"
1090 return 1
1093 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1095 (cd $testroot/repo && git checkout -q newbranch)
1096 local new_commit1=`git_show_parent_commit $testroot/repo`
1097 local new_commit2=`git_show_head $testroot/repo`
1099 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1100 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1101 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1102 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1104 echo "G gamma/delta" >> $testroot/stdout.expected
1105 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1106 >> $testroot/stdout.expected
1107 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1108 echo "D epsilon/zeta" >> $testroot/stdout.expected
1109 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1110 >> $testroot/stdout.expected
1111 echo ": removing zeta on newbranch" \
1112 >> $testroot/stdout.expected
1113 echo "Switching work tree to refs/heads/newbranch" \
1114 >> $testroot/stdout.expected
1116 cmp -s $testroot/stdout.expected $testroot/stdout
1117 ret="$?"
1118 if [ "$ret" != "0" ]; then
1119 diff -u $testroot/stdout.expected $testroot/stdout
1120 test_done "$testroot" "$ret"
1121 return 1
1124 echo "modified delta on branch" > $testroot/content.expected
1125 cat $testroot/wt/gamma/delta > $testroot/content
1126 cmp -s $testroot/content.expected $testroot/content
1127 ret="$?"
1128 if [ "$ret" != "0" ]; then
1129 diff -u $testroot/content.expected $testroot/content
1130 test_done "$testroot" "$ret"
1131 return 1
1134 echo "modified alpha on master" > $testroot/content.expected
1135 cat $testroot/wt/alpha > $testroot/content
1136 cmp -s $testroot/content.expected $testroot/content
1137 ret="$?"
1138 if [ "$ret" != "0" ]; then
1139 diff -u $testroot/content.expected $testroot/content
1140 test_done "$testroot" "$ret"
1141 return 1
1144 if [ -e $testroot/wt/epsilon ]; then
1145 echo "parent of removed zeta still exists on disk" >&2
1146 test_done "$testroot" "1"
1147 return 1
1150 (cd $testroot/wt && got status > $testroot/stdout)
1152 echo -n > $testroot/stdout.expected
1153 cmp -s $testroot/stdout.expected $testroot/stdout
1154 ret="$?"
1155 if [ "$ret" != "0" ]; then
1156 diff -u $testroot/stdout.expected $testroot/stdout
1157 test_done "$testroot" "$ret"
1158 return 1
1161 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1162 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1163 echo "commit $new_commit1" >> $testroot/stdout.expected
1164 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1165 cmp -s $testroot/stdout.expected $testroot/stdout
1166 ret="$?"
1167 if [ "$ret" != "0" ]; then
1168 diff -u $testroot/stdout.expected $testroot/stdout
1170 test_done "$testroot" "$ret"
1173 test_rebase_delete_missing_file() {
1174 local testroot=`test_init rebase_delete_missing_file`
1176 mkdir -p $testroot/repo/d/f/g
1177 echo "new file" > $testroot/repo/d/f/g/new
1178 (cd $testroot/repo && git add d/f/g/new)
1179 git_commit $testroot/repo -m "adding a subdir"
1180 local commit0=`git_show_head $testroot/repo`
1182 got br -r $testroot/repo -c master newbranch
1184 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1186 echo "modified delta on branch" > $testroot/wt/gamma/delta
1187 (cd $testroot/wt && got commit \
1188 -m "committing to delta on newbranch" > /dev/null)
1190 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1191 (cd $testroot/wt && got commit \
1192 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1194 (cd $testroot/repo && git checkout -q newbranch)
1195 local orig_commit1=`git_show_parent_commit $testroot/repo`
1196 local orig_commit2=`git_show_head $testroot/repo`
1198 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1199 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1201 (cd $testroot/wt && got update -b master > /dev/null)
1202 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1203 (cd $testroot/wt && got commit \
1204 -m "removing beta and d/f/g/new on master" > /dev/null)
1206 (cd $testroot/repo && git checkout -q master)
1207 local master_commit=`git_show_head $testroot/repo`
1209 (cd $testroot/wt && got update -b master > /dev/null)
1210 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1211 2> $testroot/stderr)
1212 ret="$?"
1213 if [ "$ret" = "0" ]; then
1214 echo "rebase succeeded unexpectedly" >&2
1215 test_done "$testroot" "1"
1216 return 1
1219 local new_commit1=$(cd $testroot/wt && got info | \
1220 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1222 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1223 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1225 echo "G gamma/delta" >> $testroot/stdout.expected
1226 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1227 >> $testroot/stdout.expected
1228 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1229 echo "! beta" >> $testroot/stdout.expected
1230 echo "! d/f/g/new" >> $testroot/stdout.expected
1231 echo -n "Files which had incoming changes but could not be found " \
1232 >> $testroot/stdout.expected
1233 echo "in the work tree: 2" >> $testroot/stdout.expected
1234 cmp -s $testroot/stdout.expected $testroot/stdout
1235 ret="$?"
1236 if [ "$ret" != "0" ]; then
1237 diff -u $testroot/stdout.expected $testroot/stdout
1238 test_done "$testroot" "$ret"
1239 return 1
1242 echo -n "got: changes destined for some files were not yet merged " \
1243 > $testroot/stderr.expected
1244 echo -n "and should be merged manually if required before the " \
1245 >> $testroot/stderr.expected
1246 echo "rebase operation is continued" >> $testroot/stderr.expected
1247 cmp -s $testroot/stderr.expected $testroot/stderr
1248 ret="$?"
1249 if [ "$ret" != "0" ]; then
1250 diff -u $testroot/stderr.expected $testroot/stderr
1251 test_done "$testroot" "$ret"
1252 return 1
1255 # ignore the missing changes and continue
1256 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1257 ret="$?"
1258 if [ "$ret" != "0" ]; then
1259 echo "rebase failed unexpectedly" >&2
1260 test_done "$testroot" "1"
1261 return 1
1263 echo -n "$short_orig_commit2 -> no-op change" \
1264 > $testroot/stdout.expected
1265 echo ": removing beta and d/f/g/new on newbranch" \
1266 >> $testroot/stdout.expected
1267 echo "Switching work tree to refs/heads/newbranch" \
1268 >> $testroot/stdout.expected
1270 cmp -s $testroot/stdout.expected $testroot/stdout
1271 ret="$?"
1272 if [ "$ret" != "0" ]; then
1273 diff -u $testroot/stdout.expected $testroot/stdout
1274 test_done "$testroot" "$ret"
1275 return 1
1278 echo "modified delta on branch" > $testroot/content.expected
1279 cat $testroot/wt/gamma/delta > $testroot/content
1280 cmp -s $testroot/content.expected $testroot/content
1281 ret="$?"
1282 if [ "$ret" != "0" ]; then
1283 diff -u $testroot/content.expected $testroot/content
1284 test_done "$testroot" "$ret"
1285 return 1
1288 if [ -e $testroot/wt/beta ]; then
1289 echo "removed file beta still exists on disk" >&2
1290 test_done "$testroot" "1"
1291 return 1
1294 (cd $testroot/wt && got status > $testroot/stdout)
1296 echo -n > $testroot/stdout.expected
1297 cmp -s $testroot/stdout.expected $testroot/stdout
1298 ret="$?"
1299 if [ "$ret" != "0" ]; then
1300 diff -u $testroot/stdout.expected $testroot/stdout
1301 test_done "$testroot" "$ret"
1302 return 1
1305 (cd $testroot/repo && git checkout -q newbranch)
1306 local new_commit1=`git_show_head $testroot/repo`
1307 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1309 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1310 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1311 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1312 echo "commit $commit0" >> $testroot/stdout.expected
1313 cmp -s $testroot/stdout.expected $testroot/stdout
1314 ret="$?"
1315 if [ "$ret" != "0" ]; then
1316 diff -u $testroot/stdout.expected $testroot/stdout
1318 test_done "$testroot" "$ret"
1321 test_rebase_rm_add_rm_file() {
1322 local testroot=`test_init rebase_rm_add_rm_file`
1324 (cd $testroot/repo && git checkout -q -b newbranch)
1325 (cd $testroot/repo && git rm -q beta)
1326 git_commit $testroot/repo -m "removing beta from newbranch"
1327 local orig_commit1=`git_show_head $testroot/repo`
1329 echo 'restored beta' > $testroot/repo/beta
1330 (cd $testroot/repo && git add beta)
1331 git_commit $testroot/repo -m "restoring beta on newbranch"
1332 local orig_commit2=`git_show_head $testroot/repo`
1334 (cd $testroot/repo && git rm -q beta)
1335 git_commit $testroot/repo -m "removing beta from newbranch again"
1336 local orig_commit3=`git_show_head $testroot/repo`
1338 (cd $testroot/repo && git checkout -q master)
1339 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1340 git_commit $testroot/repo -m "committing to zeta on master"
1341 local master_commit=`git_show_head $testroot/repo`
1343 got checkout $testroot/repo $testroot/wt > /dev/null
1344 ret="$?"
1345 if [ "$ret" != "0" ]; then
1346 test_done "$testroot" "$ret"
1347 return 1
1350 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1352 # this would error out with 'got: file index is corrupt'
1353 (cd $testroot/wt && got status > /dev/null)
1354 ret="$?"
1355 if [ "$ret" != "0" ]; then
1356 echo "got status command failed unexpectedly" >&2
1357 test_done "$testroot" "$ret"
1358 return 1
1361 (cd $testroot/repo && git checkout -q newbranch)
1362 local new_commit3=`git_show_head $testroot/repo`
1363 local new_commit2=`git_show_parent_commit $testroot/repo`
1364 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1366 (cd $testroot/repo && git checkout -q newbranch)
1368 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1369 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1370 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1371 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1372 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1373 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1375 echo "D beta" > $testroot/stdout.expected
1376 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1377 >> $testroot/stdout.expected
1378 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1379 echo "A beta" >> $testroot/stdout.expected
1380 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1381 >> $testroot/stdout.expected
1382 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1383 echo "D beta" >> $testroot/stdout.expected
1384 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1385 >> $testroot/stdout.expected
1386 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1387 echo "Switching work tree to refs/heads/newbranch" \
1388 >> $testroot/stdout.expected
1390 cmp -s $testroot/stdout.expected $testroot/stdout
1391 ret="$?"
1392 if [ "$ret" != "0" ]; then
1393 diff -u $testroot/stdout.expected $testroot/stdout
1394 test_done "$testroot" "$ret"
1395 return 1
1398 (cd $testroot/wt && got status > $testroot/stdout)
1399 ret="$?"
1400 if [ "$ret" != "0" ]; then
1401 echo "got status command failed unexpectedly" >&2
1402 test_done "$testroot" "$ret"
1403 return 1
1406 echo -n > $testroot/stdout.expected
1407 cmp -s $testroot/stdout.expected $testroot/stdout
1408 ret="$?"
1409 if [ "$ret" != "0" ]; then
1410 diff -u $testroot/stdout.expected $testroot/stdout
1411 test_done "$testroot" "$ret"
1412 return 1
1415 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1416 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1417 echo "commit $new_commit2" >> $testroot/stdout.expected
1418 echo "commit $new_commit1" >> $testroot/stdout.expected
1419 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1420 cmp -s $testroot/stdout.expected $testroot/stdout
1421 ret="$?"
1422 if [ "$ret" != "0" ]; then
1423 diff -u $testroot/stdout.expected $testroot/stdout
1425 test_done "$testroot" "$ret"
1428 test_parseargs "$@"
1429 run_test test_rebase_basic
1430 run_test test_rebase_ancestry_check
1431 run_test test_rebase_continue
1432 run_test test_rebase_abort
1433 run_test test_rebase_no_op_change
1434 run_test test_rebase_in_progress
1435 run_test test_rebase_path_prefix
1436 run_test test_rebase_preserves_logmsg
1437 run_test test_rebase_no_commits_to_rebase
1438 run_test test_rebase_forward
1439 run_test test_rebase_out_of_date
1440 run_test test_rebase_trims_empty_dir
1441 run_test test_rebase_delete_missing_file
1442 run_test test_rebase_rm_add_rm_file