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 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 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 -ne 0 ]; then
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 (cd $testroot/repo && git checkout -q -b newbranch)
247 echo "modified delta on branch" > $testroot/repo/gamma/delta
248 git_commit $testroot/repo -m "committing to delta on newbranch"
249 local newbranch_id=`git_show_head $testroot/repo`
251 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
252 2> $testroot/stderr)
254 echo "refs/heads/newbranch is already based on refs/heads/master" \
255 > $testroot/stdout.expected
256 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
257 >> $testroot/stdout.expected
258 echo "U gamma/delta" >> $testroot/stdout.expected
259 echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
260 >> $testroot/stdout.expected
261 cmp -s $testroot/stdout.expected $testroot/stdout
262 ret=$?
263 if [ $ret -ne 0 ]; then
264 diff -u $testroot/stdout.expected $testroot/stdout
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 echo -n > $testroot/stderr.expected
270 cmp -s $testroot/stderr.expected $testroot/stderr
271 ret=$?
272 if [ $ret -ne 0 ]; then
273 diff -u $testroot/stderr.expected $testroot/stderr
274 fi
275 test_done "$testroot" "$ret"
278 test_rebase_continue() {
279 local testroot=`test_init rebase_continue`
280 local init_commit=`git_show_head $testroot/repo`
282 (cd $testroot/repo && git checkout -q -b newbranch)
283 echo "modified alpha on branch" > $testroot/repo/alpha
284 git_commit $testroot/repo -m "committing to alpha on newbranch"
285 local orig_commit1=`git_show_head $testroot/repo`
286 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
288 (cd $testroot/repo && git checkout -q master)
289 echo "modified alpha on master" > $testroot/repo/alpha
290 git_commit $testroot/repo -m "committing to alpha on master"
291 local master_commit=`git_show_head $testroot/repo`
293 got checkout $testroot/repo $testroot/wt > /dev/null
294 ret=$?
295 if [ $ret -ne 0 ]; then
296 test_done "$testroot" "$ret"
297 return 1
298 fi
300 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
301 2> $testroot/stderr)
303 echo "C alpha" > $testroot/stdout.expected
304 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
305 echo -n "$short_orig_commit1 -> merge conflict" \
306 >> $testroot/stdout.expected
307 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
308 cmp -s $testroot/stdout.expected $testroot/stdout
309 ret=$?
310 if [ $ret -ne 0 ]; then
311 diff -u $testroot/stdout.expected $testroot/stdout
312 test_done "$testroot" "$ret"
313 return 1
314 fi
316 echo "got: conflicts must be resolved before rebasing can continue" \
317 > $testroot/stderr.expected
318 cmp -s $testroot/stderr.expected $testroot/stderr
319 ret=$?
320 if [ $ret -ne 0 ]; then
321 diff -u $testroot/stderr.expected $testroot/stderr
322 test_done "$testroot" "$ret"
323 return 1
324 fi
326 echo '<<<<<<<' > $testroot/content.expected
327 echo "modified alpha on master" >> $testroot/content.expected
328 echo "||||||| 3-way merge base: commit $init_commit" \
329 >> $testroot/content.expected
330 echo "alpha" >> $testroot/content.expected
331 echo "=======" >> $testroot/content.expected
332 echo "modified alpha on branch" >> $testroot/content.expected
333 echo ">>>>>>> merged change: commit $orig_commit1" \
334 >> $testroot/content.expected
335 cat $testroot/wt/alpha > $testroot/content
336 cmp -s $testroot/content.expected $testroot/content
337 ret=$?
338 if [ $ret -ne 0 ]; then
339 diff -u $testroot/content.expected $testroot/content
340 test_done "$testroot" "$ret"
341 return 1
342 fi
344 (cd $testroot/wt && got status > $testroot/stdout)
346 echo "C alpha" > $testroot/stdout.expected
347 cmp -s $testroot/stdout.expected $testroot/stdout
348 ret=$?
349 if [ $ret -ne 0 ]; then
350 diff -u $testroot/stdout.expected $testroot/stdout
351 test_done "$testroot" "$ret"
352 return 1
353 fi
355 # resolve the conflict
356 echo "modified alpha on branch and master" > $testroot/wt/alpha
358 # test interaction of 'got stage' and rebase -c
359 (cd $testroot/wt && got stage alpha > /dev/null)
360 (cd $testroot/wt && got rebase -c > $testroot/stdout \
361 2> $testroot/stderr)
362 ret=$?
363 if [ $ret -eq 0 ]; then
364 echo "rebase succeeded unexpectedly" >&2
365 test_done "$testroot" "1"
366 return 1
367 fi
368 echo -n "got: work tree contains files with staged changes; " \
369 > $testroot/stderr.expected
370 echo "these changes must be committed or unstaged first" \
371 >> $testroot/stderr.expected
372 cmp -s $testroot/stderr.expected $testroot/stderr
373 ret=$?
374 if [ $ret -ne 0 ]; then
375 diff -u $testroot/stderr.expected $testroot/stderr
376 test_done "$testroot" "$ret"
377 return 1
378 fi
380 (cd $testroot/wt && got unstage alpha > /dev/null)
381 (cd $testroot/wt && got rebase -c > $testroot/stdout)
383 (cd $testroot/repo && git checkout -q newbranch)
384 local new_commit1=`git_show_head $testroot/repo`
385 local short_new_commit1=`trim_obj_id 28 $new_commit1`
387 echo -n "$short_orig_commit1 -> $short_new_commit1" \
388 > $testroot/stdout.expected
389 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
390 echo "Switching work tree to refs/heads/newbranch" \
391 >> $testroot/stdout.expected
393 cmp -s $testroot/stdout.expected $testroot/stdout
394 ret=$?
395 if [ $ret -ne 0 ]; then
396 diff -u $testroot/stdout.expected $testroot/stdout
397 test_done "$testroot" "$ret"
398 return 1
399 fi
402 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
403 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
404 echo "commit $master_commit (master)" >> $testroot/stdout.expected
405 cmp -s $testroot/stdout.expected $testroot/stdout
406 ret=$?
407 if [ $ret -ne 0 ]; then
408 diff -u $testroot/stdout.expected $testroot/stdout
409 fi
410 test_done "$testroot" "$ret"
413 test_rebase_abort() {
414 local testroot=`test_init rebase_abort`
416 local init_commit=`git_show_head $testroot/repo`
418 (cd $testroot/repo && git checkout -q -b newbranch)
419 echo "modified alpha on branch" > $testroot/repo/alpha
420 git_commit $testroot/repo -m "committing to alpha on newbranch"
421 local orig_commit1=`git_show_head $testroot/repo`
422 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
424 (cd $testroot/repo && git checkout -q master)
425 echo "modified alpha on master" > $testroot/repo/alpha
426 git_commit $testroot/repo -m "committing to alpha on master"
427 local master_commit=`git_show_head $testroot/repo`
429 got checkout $testroot/repo $testroot/wt > /dev/null
430 ret=$?
431 if [ $ret -ne 0 ]; then
432 test_done "$testroot" "$ret"
433 return 1
434 fi
436 # unrelated unversioned file in work tree
437 touch $testroot/wt/unversioned-file
439 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
440 2> $testroot/stderr)
442 echo "C alpha" > $testroot/stdout.expected
443 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
444 echo -n "$short_orig_commit1 -> merge conflict" \
445 >> $testroot/stdout.expected
446 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
447 cmp -s $testroot/stdout.expected $testroot/stdout
448 ret=$?
449 if [ $ret -ne 0 ]; then
450 diff -u $testroot/stdout.expected $testroot/stdout
451 test_done "$testroot" "$ret"
452 return 1
453 fi
455 echo "got: conflicts must be resolved before rebasing can continue" \
456 > $testroot/stderr.expected
457 cmp -s $testroot/stderr.expected $testroot/stderr
458 ret=$?
459 if [ $ret -ne 0 ]; then
460 diff -u $testroot/stderr.expected $testroot/stderr
461 test_done "$testroot" "$ret"
462 return 1
463 fi
465 echo '<<<<<<<' > $testroot/content.expected
466 echo "modified alpha on master" >> $testroot/content.expected
467 echo "||||||| 3-way merge base: commit $init_commit" \
468 >> $testroot/content.expected
469 echo "alpha" >> $testroot/content.expected
470 echo "=======" >> $testroot/content.expected
471 echo "modified alpha on branch" >> $testroot/content.expected
472 echo ">>>>>>> merged change: commit $orig_commit1" \
473 >> $testroot/content.expected
474 cat $testroot/wt/alpha > $testroot/content
475 cmp -s $testroot/content.expected $testroot/content
476 ret=$?
477 if [ $ret -ne 0 ]; then
478 diff -u $testroot/content.expected $testroot/content
479 test_done "$testroot" "$ret"
480 return 1
481 fi
483 (cd $testroot/wt && got status > $testroot/stdout)
485 echo "C alpha" > $testroot/stdout.expected
486 echo "? unversioned-file" >> $testroot/stdout.expected
487 cmp -s $testroot/stdout.expected $testroot/stdout
488 ret=$?
489 if [ $ret -ne 0 ]; then
490 diff -u $testroot/stdout.expected $testroot/stdout
491 test_done "$testroot" "$ret"
492 return 1
493 fi
495 (cd $testroot/wt && got rebase -a > $testroot/stdout)
497 (cd $testroot/repo && git checkout -q newbranch)
499 echo "Switching work tree to refs/heads/master" \
500 > $testroot/stdout.expected
501 echo 'R alpha' >> $testroot/stdout.expected
502 echo "Rebase of refs/heads/newbranch aborted" \
503 >> $testroot/stdout.expected
505 cmp -s $testroot/stdout.expected $testroot/stdout
506 ret=$?
507 if [ $ret -ne 0 ]; then
508 diff -u $testroot/stdout.expected $testroot/stdout
509 test_done "$testroot" "$ret"
510 return 1
511 fi
513 echo "modified alpha on master" > $testroot/content.expected
514 cat $testroot/wt/alpha > $testroot/content
515 cmp -s $testroot/content.expected $testroot/content
516 ret=$?
517 if [ $ret -ne 0 ]; then
518 diff -u $testroot/content.expected $testroot/content
519 test_done "$testroot" "$ret"
520 return 1
521 fi
523 (cd $testroot/wt && got log -l3 -c newbranch \
524 | grep ^commit > $testroot/stdout)
525 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
526 echo "commit $init_commit" >> $testroot/stdout.expected
527 cmp -s $testroot/stdout.expected $testroot/stdout
528 ret=$?
529 if [ $ret -ne 0 ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 fi
532 test_done "$testroot" "$ret"
535 test_rebase_no_op_change() {
536 local testroot=`test_init rebase_no_op_change`
537 local init_commit=`git_show_head $testroot/repo`
539 (cd $testroot/repo && git checkout -q -b newbranch)
540 echo "modified alpha on branch" > $testroot/repo/alpha
541 git_commit $testroot/repo -m "committing to alpha on newbranch"
542 local orig_commit1=`git_show_head $testroot/repo`
543 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
545 (cd $testroot/repo && git checkout -q master)
546 echo "modified alpha on master" > $testroot/repo/alpha
547 git_commit $testroot/repo -m "committing to alpha on master"
548 local master_commit=`git_show_head $testroot/repo`
550 got checkout $testroot/repo $testroot/wt > /dev/null
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 test_done "$testroot" "$ret"
554 return 1
555 fi
557 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
558 2> $testroot/stderr)
560 echo "C alpha" > $testroot/stdout.expected
561 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
562 echo -n "$short_orig_commit1 -> merge conflict" \
563 >> $testroot/stdout.expected
564 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
565 cmp -s $testroot/stdout.expected $testroot/stdout
566 ret=$?
567 if [ $ret -ne 0 ]; then
568 diff -u $testroot/stdout.expected $testroot/stdout
569 test_done "$testroot" "$ret"
570 return 1
571 fi
573 echo "got: conflicts must be resolved before rebasing can continue" \
574 > $testroot/stderr.expected
575 cmp -s $testroot/stderr.expected $testroot/stderr
576 ret=$?
577 if [ $ret -ne 0 ]; then
578 diff -u $testroot/stderr.expected $testroot/stderr
579 test_done "$testroot" "$ret"
580 return 1
581 fi
583 echo '<<<<<<<' > $testroot/content.expected
584 echo "modified alpha on master" >> $testroot/content.expected
585 echo "||||||| 3-way merge base: commit $init_commit" \
586 >> $testroot/content.expected
587 echo "alpha" >> $testroot/content.expected
588 echo "=======" >> $testroot/content.expected
589 echo "modified alpha on branch" >> $testroot/content.expected
590 echo ">>>>>>> merged change: commit $orig_commit1" \
591 >> $testroot/content.expected
592 cat $testroot/wt/alpha > $testroot/content
593 cmp -s $testroot/content.expected $testroot/content
594 ret=$?
595 if [ $ret -ne 0 ]; then
596 diff -u $testroot/content.expected $testroot/content
597 test_done "$testroot" "$ret"
598 return 1
599 fi
601 (cd $testroot/wt && got status > $testroot/stdout)
603 echo "C alpha" > $testroot/stdout.expected
604 cmp -s $testroot/stdout.expected $testroot/stdout
605 ret=$?
606 if [ $ret -ne 0 ]; then
607 diff -u $testroot/stdout.expected $testroot/stdout
608 test_done "$testroot" "$ret"
609 return 1
610 fi
612 # resolve the conflict
613 echo "modified alpha on master" > $testroot/wt/alpha
615 (cd $testroot/wt && got rebase -c > $testroot/stdout)
617 (cd $testroot/repo && git checkout -q newbranch)
618 local new_commit1=`git_show_head $testroot/repo`
620 echo -n "$short_orig_commit1 -> no-op change" \
621 > $testroot/stdout.expected
622 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
623 echo "Switching work tree to refs/heads/newbranch" \
624 >> $testroot/stdout.expected
626 cmp -s $testroot/stdout.expected $testroot/stdout
627 ret=$?
628 if [ $ret -ne 0 ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 test_done "$testroot" "$ret"
631 return 1
632 fi
635 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
636 echo "commit $master_commit (master, newbranch)" \
637 > $testroot/stdout.expected
638 echo "commit $init_commit" >> $testroot/stdout.expected
639 cmp -s $testroot/stdout.expected $testroot/stdout
640 ret=$?
641 if [ $ret -ne 0 ]; then
642 diff -u $testroot/stdout.expected $testroot/stdout
643 fi
644 test_done "$testroot" "$ret"
647 test_rebase_in_progress() {
648 local testroot=`test_init rebase_in_progress`
649 local init_commit=`git_show_head $testroot/repo`
651 (cd $testroot/repo && git checkout -q -b newbranch)
652 echo "modified alpha on branch" > $testroot/repo/alpha
653 git_commit $testroot/repo -m "committing to alpha on newbranch"
654 local orig_commit1=`git_show_head $testroot/repo`
655 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
657 (cd $testroot/repo && git checkout -q master)
658 echo "modified alpha on master" > $testroot/repo/alpha
659 git_commit $testroot/repo -m "committing to alpha on master"
660 local master_commit=`git_show_head $testroot/repo`
662 got checkout $testroot/repo $testroot/wt > /dev/null
663 ret=$?
664 if [ $ret -ne 0 ]; then
665 test_done "$testroot" "$ret"
666 return 1
667 fi
669 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
670 2> $testroot/stderr)
672 echo "C alpha" > $testroot/stdout.expected
673 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
674 echo -n "$short_orig_commit1 -> merge conflict" \
675 >> $testroot/stdout.expected
676 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
677 cmp -s $testroot/stdout.expected $testroot/stdout
678 ret=$?
679 if [ $ret -ne 0 ]; then
680 diff -u $testroot/stdout.expected $testroot/stdout
681 test_done "$testroot" "$ret"
682 return 1
683 fi
685 echo "got: conflicts must be resolved before rebasing can continue" \
686 > $testroot/stderr.expected
687 cmp -s $testroot/stderr.expected $testroot/stderr
688 ret=$?
689 if [ $ret -ne 0 ]; then
690 diff -u $testroot/stderr.expected $testroot/stderr
691 test_done "$testroot" "$ret"
692 return 1
693 fi
695 echo '<<<<<<<' > $testroot/content.expected
696 echo "modified alpha on master" >> $testroot/content.expected
697 echo "||||||| 3-way merge base: commit $init_commit" \
698 >> $testroot/content.expected
699 echo "alpha" >> $testroot/content.expected
700 echo "=======" >> $testroot/content.expected
701 echo "modified alpha on branch" >> $testroot/content.expected
702 echo ">>>>>>> merged change: commit $orig_commit1" \
703 >> $testroot/content.expected
704 cat $testroot/wt/alpha > $testroot/content
705 cmp -s $testroot/content.expected $testroot/content
706 ret=$?
707 if [ $ret -ne 0 ]; then
708 diff -u $testroot/content.expected $testroot/content
709 test_done "$testroot" "$ret"
710 return 1
711 fi
713 (cd $testroot/wt && got status > $testroot/stdout)
715 echo "C alpha" > $testroot/stdout.expected
716 cmp -s $testroot/stdout.expected $testroot/stdout
717 ret=$?
718 if [ $ret -ne 0 ]; then
719 diff -u $testroot/stdout.expected $testroot/stdout
720 test_done "$testroot" "$ret"
721 return 1
722 fi
724 for cmd in update commit; do
725 (cd $testroot/wt && got $cmd > $testroot/stdout \
726 2> $testroot/stderr)
728 echo -n > $testroot/stdout.expected
729 cmp -s $testroot/stdout.expected $testroot/stdout
730 ret=$?
731 if [ $ret -ne 0 ]; then
732 diff -u $testroot/stdout.expected $testroot/stdout
733 test_done "$testroot" "$ret"
734 return 1
735 fi
737 echo -n "got: a rebase operation is in progress in this " \
738 > $testroot/stderr.expected
739 echo "work tree and must be continued or aborted first" \
740 >> $testroot/stderr.expected
741 cmp -s $testroot/stderr.expected $testroot/stderr
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/stderr.expected $testroot/stderr
745 test_done "$testroot" "$ret"
746 return 1
747 fi
748 done
750 test_done "$testroot" "$ret"
753 test_rebase_path_prefix() {
754 local testroot=`test_init rebase_path_prefix`
756 (cd $testroot/repo && git checkout -q -b newbranch)
757 echo "modified delta on branch" > $testroot/repo/gamma/delta
758 git_commit $testroot/repo -m "committing to delta on newbranch"
760 local orig_commit1=`git_show_parent_commit $testroot/repo`
761 local orig_commit2=`git_show_head $testroot/repo`
763 (cd $testroot/repo && git checkout -q master)
764 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
765 git_commit $testroot/repo -m "committing to zeta on master"
766 local master_commit=`git_show_head $testroot/repo`
768 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
769 ret=$?
770 if [ $ret -ne 0 ]; then
771 test_done "$testroot" "$ret"
772 return 1
773 fi
775 (cd $testroot/wt && got rebase newbranch \
776 > $testroot/stdout 2> $testroot/stderr)
778 echo -n > $testroot/stdout.expected
779 cmp -s $testroot/stdout.expected $testroot/stdout
780 ret=$?
781 if [ $ret -ne 0 ]; then
782 diff -u $testroot/stdout.expected $testroot/stdout
783 test_done "$testroot" "$ret"
784 return 1
785 fi
787 echo -n "got: cannot rebase branch which contains changes outside " \
788 > $testroot/stderr.expected
789 echo "of this work tree's path prefix" >> $testroot/stderr.expected
790 cmp -s $testroot/stderr.expected $testroot/stderr
791 ret=$?
792 if [ $ret -ne 0 ]; then
793 diff -u $testroot/stderr.expected $testroot/stderr
794 test_done "$testroot" "$ret"
795 return 1
796 fi
798 # rebase should succeed when using a complete work tree
799 got checkout $testroot/repo $testroot/wt2 > /dev/null
800 ret=$?
801 if [ $ret -ne 0 ]; then
802 test_done "$testroot" "$ret"
803 return 1
804 fi
806 (cd $testroot/wt2 && got rebase newbranch \
807 > $testroot/stdout 2> $testroot/stderr)
809 (cd $testroot/repo && git checkout -q newbranch)
810 local new_commit1=`git_show_parent_commit $testroot/repo`
811 local new_commit2=`git_show_head $testroot/repo`
813 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
814 local short_new_commit2=`trim_obj_id 28 $new_commit2`
816 echo "G gamma/delta" > $testroot/stdout.expected
817 echo -n "$short_orig_commit2 -> $short_new_commit2" \
818 >> $testroot/stdout.expected
819 echo ": committing to delta on newbranch" \
820 >> $testroot/stdout.expected
821 echo "Switching work tree to refs/heads/newbranch" \
822 >> $testroot/stdout.expected
824 cmp -s $testroot/stdout.expected $testroot/stdout
825 ret=$?
826 if [ $ret -ne 0 ]; then
827 diff -u $testroot/stdout.expected $testroot/stdout
828 test_done "$testroot" "$ret"
829 return 1
830 fi
832 # the first work tree should remain usable
833 (cd $testroot/wt && got update -b master \
834 > $testroot/stdout 2> $testroot/stderr)
835 ret=$?
836 if [ $ret -ne 0 ]; then
837 echo "update failed unexpectedly" >&2
838 test_done "$testroot" "1"
839 return 1
840 fi
842 echo 'Already up-to-date' > $testroot/stdout.expected
843 cmp -s $testroot/stdout.expected $testroot/stdout
844 ret=$?
845 if [ $ret -ne 0 ]; then
846 diff -u $testroot/stdout.expected $testroot/stdout
847 fi
848 test_done "$testroot" "$ret"
851 test_rebase_preserves_logmsg() {
852 local testroot=`test_init rebase_preserves_logmsg`
854 (cd $testroot/repo && git checkout -q -b newbranch)
855 echo "modified delta on branch" > $testroot/repo/gamma/delta
856 git_commit $testroot/repo -m "modified delta on newbranch"
858 echo "modified alpha on branch" > $testroot/repo/alpha
859 git_commit $testroot/repo -m "modified alpha on newbranch"
861 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
862 > $testroot/log.expected)
864 local orig_commit1=`git_show_parent_commit $testroot/repo`
865 local orig_commit2=`git_show_head $testroot/repo`
867 (cd $testroot/repo && git checkout -q master)
868 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
869 git_commit $testroot/repo -m "committing to zeta on master"
870 local master_commit=`git_show_head $testroot/repo`
872 got checkout $testroot/repo $testroot/wt > /dev/null
873 ret=$?
874 if [ $ret -ne 0 ]; then
875 test_done "$testroot" "$ret"
876 return 1
877 fi
879 (cd $testroot/wt && got rebase newbranch > /dev/null \
880 2> $testroot/stderr)
882 (cd $testroot/repo && git checkout -q newbranch)
883 local new_commit1=`git_show_parent_commit $testroot/repo`
884 local new_commit2=`git_show_head $testroot/repo`
886 echo -n > $testroot/stderr.expected
887 cmp -s $testroot/stderr.expected $testroot/stderr
888 ret=$?
889 if [ $ret -ne 0 ]; then
890 diff -u $testroot/stderr.expected $testroot/stderr
891 test_done "$testroot" "$ret"
892 return 1
893 fi
895 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
896 > $testroot/log)
897 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
898 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
899 cmp -s $testroot/log.expected $testroot/log
900 ret=$?
901 if [ $ret -ne 0 ]; then
902 diff -u $testroot/log.expected $testroot/log
903 fi
905 test_done "$testroot" "$ret"
908 test_rebase_no_commits_to_rebase() {
909 local testroot=`test_init rebase_no_commits_to_rebase`
911 got checkout $testroot/repo $testroot/wt > /dev/null
912 ret=$?
913 if [ $ret -ne 0 ]; then
914 test_done "$testroot" "$ret"
915 return 1
916 fi
918 (cd $testroot/wt && got branch -n newbranch)
920 echo "modified alpha on master" > $testroot/wt/alpha
921 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
922 > /dev/null)
923 (cd $testroot/wt && got update > /dev/null)
925 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
926 2> $testroot/stderr)
928 echo "got: no commits to rebase" > $testroot/stderr.expected
929 cmp -s $testroot/stderr.expected $testroot/stderr
930 ret=$?
931 if [ $ret -ne 0 ]; then
932 diff -u $testroot/stderr.expected $testroot/stderr
933 test_done "$testroot" "$ret"
934 return 1
935 fi
937 echo -n > $testroot/stdout.expected
938 cmp -s $testroot/stdout.expected $testroot/stdout
939 ret=$?
940 if [ $ret -ne 0 ]; then
941 diff -u $testroot/stdout.expected $testroot/stdout
942 test_done "$testroot" "$ret"
943 return 1
944 fi
946 (cd $testroot/wt && got update > $testroot/stdout)
947 echo "Already up-to-date" > $testroot/stdout.expected
948 cmp -s $testroot/stdout.expected $testroot/stdout
949 ret=$?
950 if [ $ret -ne 0 ]; then
951 diff -u $testroot/stdout.expected $testroot/stdout
952 fi
953 test_done "$testroot" "$ret"
956 test_rebase_forward() {
957 local testroot=`test_init rebase_forward`
958 local commit0=`git_show_head $testroot/repo`
960 got checkout $testroot/repo $testroot/wt > /dev/null
961 ret=$?
962 if [ $ret -ne 0 ]; then
963 test_done "$testroot" "$ret"
964 return 1
965 fi
967 echo "change alpha 1" > $testroot/wt/alpha
968 (cd $testroot/wt && got commit -m 'test rebase_forward' \
969 > /dev/null)
970 local commit1=`git_show_head $testroot/repo`
972 echo "change alpha 2" > $testroot/wt/alpha
973 (cd $testroot/wt && got commit -m 'test rebase_forward' \
974 > /dev/null)
975 local commit2=`git_show_head $testroot/repo`
977 # Simulate a situation where fast-forward is required.
978 # We want to fast-forward master to origin/master:
979 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
980 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
981 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
982 (cd $testroot/repo && got ref -d master >/dev/null)
983 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
984 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
986 (cd $testroot/wt && got up -b origin/master > /dev/null)
988 (cd $testroot/wt && got rebase master \
989 > $testroot/stdout 2> $testroot/stderr)
991 echo "Forwarding refs/heads/master to commit $commit2" \
992 > $testroot/stdout.expected
993 echo "Switching work tree to refs/heads/master" \
994 >> $testroot/stdout.expected
995 cmp -s $testroot/stdout.expected $testroot/stdout
996 ret=$?
997 if [ $ret -ne 0 ]; then
998 diff -u $testroot/stdout.expected $testroot/stdout
999 test_done "$testroot" "$ret"
1000 return 1
1003 # Ensure that rebase operation was completed correctly
1004 (cd $testroot/wt && got rebase -a \
1005 > $testroot/stdout 2> $testroot/stderr)
1006 echo -n "" > $testroot/stdout.expected
1007 cmp -s $testroot/stdout.expected $testroot/stdout
1008 ret=$?
1009 if [ $ret -ne 0 ]; then
1010 diff -u $testroot/stdout.expected $testroot/stdout
1011 test_done "$testroot" "$ret"
1012 return 1
1014 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1015 cmp -s $testroot/stderr.expected $testroot/stderr
1016 ret=$?
1017 if [ $ret -ne 0 ]; then
1018 diff -u $testroot/stderr.expected $testroot/stderr
1019 test_done "$testroot" "$ret"
1020 return 1
1023 (cd $testroot/wt && got branch -n > $testroot/stdout)
1024 echo "master" > $testroot/stdout.expected
1025 cmp -s $testroot/stdout.expected $testroot/stdout
1026 ret=$?
1027 if [ $ret -ne 0 ]; then
1028 diff -u $testroot/stdout.expected $testroot/stdout
1029 test_done "$testroot" "$ret"
1030 return 1
1033 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1034 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1035 echo "commit $commit1" >> $testroot/stdout.expected
1036 echo "commit $commit0" >> $testroot/stdout.expected
1037 cmp -s $testroot/stdout.expected $testroot/stdout
1038 ret=$?
1039 if [ $ret -ne 0 ]; then
1040 diff -u $testroot/stdout.expected $testroot/stdout
1041 test_done "$testroot" "$ret"
1042 return 1
1045 # Forward-only rebase operations should not be backed up
1046 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1047 echo -n > $testroot/stdout.expected
1048 cmp -s $testroot/stdout.expected $testroot/stdout
1049 ret=$?
1050 if [ $ret -ne 0 ]; then
1051 diff -u $testroot/stdout.expected $testroot/stdout
1053 test_done "$testroot" "$ret"
1056 test_rebase_out_of_date() {
1057 local testroot=`test_init rebase_out_of_date`
1058 local initial_commit=`git_show_head $testroot/repo`
1060 (cd $testroot/repo && git checkout -q -b newbranch)
1061 echo "modified delta on branch" > $testroot/repo/gamma/delta
1062 git_commit $testroot/repo -m "committing to delta on newbranch"
1064 echo "modified alpha on branch" > $testroot/repo/alpha
1065 (cd $testroot/repo && git rm -q beta)
1066 echo "new file on branch" > $testroot/repo/epsilon/new
1067 (cd $testroot/repo && git add epsilon/new)
1068 git_commit $testroot/repo -m "committing more changes on newbranch"
1070 local orig_commit1=`git_show_parent_commit $testroot/repo`
1071 local orig_commit2=`git_show_head $testroot/repo`
1073 (cd $testroot/repo && git checkout -q master)
1074 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1075 git_commit $testroot/repo -m "committing to zeta on master"
1076 local master_commit1=`git_show_head $testroot/repo`
1078 (cd $testroot/repo && git checkout -q master)
1079 echo "modified beta on master" > $testroot/repo/beta
1080 git_commit $testroot/repo -m "committing to beta on master"
1081 local master_commit2=`git_show_head $testroot/repo`
1083 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1084 > /dev/null
1085 ret=$?
1086 if [ $ret -ne 0 ]; then
1087 test_done "$testroot" "$ret"
1088 return 1
1091 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1092 2> $testroot/stderr)
1094 echo -n > $testroot/stdout.expected
1095 cmp -s $testroot/stdout.expected $testroot/stdout
1096 ret=$?
1097 if [ $ret -ne 0 ]; then
1098 diff -u $testroot/stdout.expected $testroot/stdout
1099 test_done "$testroot" "$ret"
1100 return 1
1103 echo -n "got: work tree must be updated before it can be " \
1104 > $testroot/stderr.expected
1105 echo "used to rebase a branch" >> $testroot/stderr.expected
1106 cmp -s $testroot/stderr.expected $testroot/stderr
1107 ret=$?
1108 if [ $ret -ne 0 ]; then
1109 diff -u $testroot/stderr.expected $testroot/stderr
1110 test_done "$testroot" "$ret"
1111 return 1
1114 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1115 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1116 echo "commit $master_commit1" >> $testroot/stdout.expected
1117 echo "commit $initial_commit" >> $testroot/stdout.expected
1118 cmp -s $testroot/stdout.expected $testroot/stdout
1119 ret=$?
1120 if [ $ret -ne 0 ]; then
1121 diff -u $testroot/stdout.expected $testroot/stdout
1123 test_done "$testroot" "$ret"
1126 test_rebase_trims_empty_dir() {
1127 local testroot=`test_init rebase_trims_empty_dir`
1129 (cd $testroot/repo && git checkout -q -b newbranch)
1130 echo "modified delta on branch" > $testroot/repo/gamma/delta
1131 git_commit $testroot/repo -m "committing to delta on newbranch"
1133 (cd $testroot/repo && git rm -q epsilon/zeta)
1134 git_commit $testroot/repo -m "removing zeta on newbranch"
1136 local orig_commit1=`git_show_parent_commit $testroot/repo`
1137 local orig_commit2=`git_show_head $testroot/repo`
1139 (cd $testroot/repo && git checkout -q master)
1140 echo "modified alpha on master" > $testroot/repo/alpha
1141 git_commit $testroot/repo -m "committing to alpha on master"
1142 local master_commit=`git_show_head $testroot/repo`
1144 got checkout $testroot/repo $testroot/wt > /dev/null
1145 ret=$?
1146 if [ $ret -ne 0 ]; then
1147 test_done "$testroot" "$ret"
1148 return 1
1151 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1153 (cd $testroot/repo && git checkout -q newbranch)
1154 local new_commit1=`git_show_parent_commit $testroot/repo`
1155 local new_commit2=`git_show_head $testroot/repo`
1157 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1158 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1159 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1160 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1162 echo "G gamma/delta" >> $testroot/stdout.expected
1163 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1164 >> $testroot/stdout.expected
1165 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1166 echo "D epsilon/zeta" >> $testroot/stdout.expected
1167 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1168 >> $testroot/stdout.expected
1169 echo ": removing zeta on newbranch" \
1170 >> $testroot/stdout.expected
1171 echo "Switching work tree to refs/heads/newbranch" \
1172 >> $testroot/stdout.expected
1174 cmp -s $testroot/stdout.expected $testroot/stdout
1175 ret=$?
1176 if [ $ret -ne 0 ]; then
1177 diff -u $testroot/stdout.expected $testroot/stdout
1178 test_done "$testroot" "$ret"
1179 return 1
1182 echo "modified delta on branch" > $testroot/content.expected
1183 cat $testroot/wt/gamma/delta > $testroot/content
1184 cmp -s $testroot/content.expected $testroot/content
1185 ret=$?
1186 if [ $ret -ne 0 ]; then
1187 diff -u $testroot/content.expected $testroot/content
1188 test_done "$testroot" "$ret"
1189 return 1
1192 echo "modified alpha on master" > $testroot/content.expected
1193 cat $testroot/wt/alpha > $testroot/content
1194 cmp -s $testroot/content.expected $testroot/content
1195 ret=$?
1196 if [ $ret -ne 0 ]; then
1197 diff -u $testroot/content.expected $testroot/content
1198 test_done "$testroot" "$ret"
1199 return 1
1202 if [ -e $testroot/wt/epsilon ]; then
1203 echo "parent of removed zeta still exists on disk" >&2
1204 test_done "$testroot" "1"
1205 return 1
1208 (cd $testroot/wt && got status > $testroot/stdout)
1210 echo -n > $testroot/stdout.expected
1211 cmp -s $testroot/stdout.expected $testroot/stdout
1212 ret=$?
1213 if [ $ret -ne 0 ]; then
1214 diff -u $testroot/stdout.expected $testroot/stdout
1215 test_done "$testroot" "$ret"
1216 return 1
1219 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1220 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1221 echo "commit $new_commit1" >> $testroot/stdout.expected
1222 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1223 cmp -s $testroot/stdout.expected $testroot/stdout
1224 ret=$?
1225 if [ $ret -ne 0 ]; then
1226 diff -u $testroot/stdout.expected $testroot/stdout
1228 test_done "$testroot" "$ret"
1231 test_rebase_delete_missing_file() {
1232 local testroot=`test_init rebase_delete_missing_file`
1234 mkdir -p $testroot/repo/d/f/g
1235 echo "new file" > $testroot/repo/d/f/g/new
1236 (cd $testroot/repo && git add d/f/g/new)
1237 git_commit $testroot/repo -m "adding a subdir"
1238 local commit0=`git_show_head $testroot/repo`
1240 got br -r $testroot/repo -c master newbranch
1242 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1244 echo "modified delta on branch" > $testroot/wt/gamma/delta
1245 (cd $testroot/wt && got commit \
1246 -m "committing to delta on newbranch" > /dev/null)
1248 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1249 (cd $testroot/wt && got commit \
1250 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1252 (cd $testroot/repo && git checkout -q newbranch)
1253 local orig_commit1=`git_show_parent_commit $testroot/repo`
1254 local orig_commit2=`git_show_head $testroot/repo`
1256 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1257 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1259 (cd $testroot/wt && got update -b master > /dev/null)
1260 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1261 (cd $testroot/wt && got commit \
1262 -m "removing beta and d/f/g/new on master" > /dev/null)
1264 (cd $testroot/repo && git checkout -q master)
1265 local master_commit=`git_show_head $testroot/repo`
1267 (cd $testroot/wt && got update -b master > /dev/null)
1268 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1269 2> $testroot/stderr)
1270 ret=$?
1271 if [ $ret -eq 0 ]; then
1272 echo "rebase succeeded unexpectedly" >&2
1273 test_done "$testroot" "1"
1274 return 1
1277 local new_commit1=$(cd $testroot/wt && got info | \
1278 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1280 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1281 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1283 echo "G gamma/delta" >> $testroot/stdout.expected
1284 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1285 >> $testroot/stdout.expected
1286 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1287 echo "! beta" >> $testroot/stdout.expected
1288 echo "! d/f/g/new" >> $testroot/stdout.expected
1289 echo -n "Files which had incoming changes but could not be found " \
1290 >> $testroot/stdout.expected
1291 echo "in the work tree: 2" >> $testroot/stdout.expected
1292 cmp -s $testroot/stdout.expected $testroot/stdout
1293 ret=$?
1294 if [ $ret -ne 0 ]; then
1295 diff -u $testroot/stdout.expected $testroot/stdout
1296 test_done "$testroot" "$ret"
1297 return 1
1300 echo -n "got: changes destined for some files were not yet merged " \
1301 > $testroot/stderr.expected
1302 echo -n "and should be merged manually if required before the " \
1303 >> $testroot/stderr.expected
1304 echo "rebase operation is continued" >> $testroot/stderr.expected
1305 cmp -s $testroot/stderr.expected $testroot/stderr
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 diff -u $testroot/stderr.expected $testroot/stderr
1309 test_done "$testroot" "$ret"
1310 return 1
1313 # ignore the missing changes and continue
1314 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 echo "rebase failed unexpectedly" >&2
1318 test_done "$testroot" "1"
1319 return 1
1321 echo -n "$short_orig_commit2 -> no-op change" \
1322 > $testroot/stdout.expected
1323 echo ": removing beta and d/f/g/new on newbranch" \
1324 >> $testroot/stdout.expected
1325 echo "Switching work tree to refs/heads/newbranch" \
1326 >> $testroot/stdout.expected
1328 cmp -s $testroot/stdout.expected $testroot/stdout
1329 ret=$?
1330 if [ $ret -ne 0 ]; then
1331 diff -u $testroot/stdout.expected $testroot/stdout
1332 test_done "$testroot" "$ret"
1333 return 1
1336 echo "modified delta on branch" > $testroot/content.expected
1337 cat $testroot/wt/gamma/delta > $testroot/content
1338 cmp -s $testroot/content.expected $testroot/content
1339 ret=$?
1340 if [ $ret -ne 0 ]; then
1341 diff -u $testroot/content.expected $testroot/content
1342 test_done "$testroot" "$ret"
1343 return 1
1346 if [ -e $testroot/wt/beta ]; then
1347 echo "removed file beta still exists on disk" >&2
1348 test_done "$testroot" "1"
1349 return 1
1352 (cd $testroot/wt && got status > $testroot/stdout)
1354 echo -n > $testroot/stdout.expected
1355 cmp -s $testroot/stdout.expected $testroot/stdout
1356 ret=$?
1357 if [ $ret -ne 0 ]; then
1358 diff -u $testroot/stdout.expected $testroot/stdout
1359 test_done "$testroot" "$ret"
1360 return 1
1363 (cd $testroot/repo && git checkout -q newbranch)
1364 local new_commit1=`git_show_head $testroot/repo`
1365 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1367 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1368 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1369 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1370 echo "commit $commit0" >> $testroot/stdout.expected
1371 cmp -s $testroot/stdout.expected $testroot/stdout
1372 ret=$?
1373 if [ $ret -ne 0 ]; then
1374 diff -u $testroot/stdout.expected $testroot/stdout
1376 test_done "$testroot" "$ret"
1379 test_rebase_rm_add_rm_file() {
1380 local testroot=`test_init rebase_rm_add_rm_file`
1382 (cd $testroot/repo && git checkout -q -b newbranch)
1383 (cd $testroot/repo && git rm -q beta)
1384 git_commit $testroot/repo -m "removing beta from newbranch"
1385 local orig_commit1=`git_show_head $testroot/repo`
1387 echo 'restored beta' > $testroot/repo/beta
1388 (cd $testroot/repo && git add beta)
1389 git_commit $testroot/repo -m "restoring beta on newbranch"
1390 local orig_commit2=`git_show_head $testroot/repo`
1392 (cd $testroot/repo && git rm -q beta)
1393 git_commit $testroot/repo -m "removing beta from newbranch again"
1394 local orig_commit3=`git_show_head $testroot/repo`
1396 (cd $testroot/repo && git checkout -q master)
1397 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1398 git_commit $testroot/repo -m "committing to zeta on master"
1399 local master_commit=`git_show_head $testroot/repo`
1401 got checkout $testroot/repo $testroot/wt > /dev/null
1402 ret=$?
1403 if [ $ret -ne 0 ]; then
1404 test_done "$testroot" "$ret"
1405 return 1
1408 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1410 # this would error out with 'got: file index is corrupt'
1411 (cd $testroot/wt && got status > /dev/null)
1412 ret=$?
1413 if [ $ret -ne 0 ]; then
1414 echo "got status command failed unexpectedly" >&2
1415 test_done "$testroot" "$ret"
1416 return 1
1419 (cd $testroot/repo && git checkout -q newbranch)
1420 local new_commit3=`git_show_head $testroot/repo`
1421 local new_commit2=`git_show_parent_commit $testroot/repo`
1422 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1424 (cd $testroot/repo && git checkout -q newbranch)
1426 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1427 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1428 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1429 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1430 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1431 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1433 echo "D beta" > $testroot/stdout.expected
1434 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1435 >> $testroot/stdout.expected
1436 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1437 echo "A beta" >> $testroot/stdout.expected
1438 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1439 >> $testroot/stdout.expected
1440 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1441 echo "D beta" >> $testroot/stdout.expected
1442 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1443 >> $testroot/stdout.expected
1444 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1445 echo "Switching work tree to refs/heads/newbranch" \
1446 >> $testroot/stdout.expected
1448 cmp -s $testroot/stdout.expected $testroot/stdout
1449 ret=$?
1450 if [ $ret -ne 0 ]; then
1451 diff -u $testroot/stdout.expected $testroot/stdout
1452 test_done "$testroot" "$ret"
1453 return 1
1456 (cd $testroot/wt && got status > $testroot/stdout)
1457 ret=$?
1458 if [ $ret -ne 0 ]; then
1459 echo "got status command failed unexpectedly" >&2
1460 test_done "$testroot" "$ret"
1461 return 1
1464 echo -n > $testroot/stdout.expected
1465 cmp -s $testroot/stdout.expected $testroot/stdout
1466 ret=$?
1467 if [ $ret -ne 0 ]; then
1468 diff -u $testroot/stdout.expected $testroot/stdout
1469 test_done "$testroot" "$ret"
1470 return 1
1473 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1474 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1475 echo "commit $new_commit2" >> $testroot/stdout.expected
1476 echo "commit $new_commit1" >> $testroot/stdout.expected
1477 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1478 cmp -s $testroot/stdout.expected $testroot/stdout
1479 ret=$?
1480 if [ $ret -ne 0 ]; then
1481 diff -u $testroot/stdout.expected $testroot/stdout
1483 test_done "$testroot" "$ret"
1486 test_rebase_resets_committer() {
1487 local testroot=`test_init rebase_resets_committer`
1488 local commit0=`git_show_head $testroot/repo`
1489 local commit0_author_time=`git_show_author_time $testroot/repo`
1490 local committer="Flan Luck <flan_luck@openbsd.org>"
1492 (cd $testroot/repo && git checkout -q -b newbranch)
1493 echo "modified delta on branch" > $testroot/repo/gamma/delta
1494 git_commit $testroot/repo -m "committing to delta on newbranch"
1496 echo "modified alpha on branch" > $testroot/repo/alpha
1497 git_commit $testroot/repo -m "committing more changes on newbranch"
1499 local orig_commit1=`git_show_parent_commit $testroot/repo`
1500 local orig_commit2=`git_show_head $testroot/repo`
1501 local orig_author_time2=`git_show_author_time $testroot/repo`
1503 (cd $testroot/repo && git checkout -q master)
1504 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1505 git_commit $testroot/repo -m "committing to zeta on master"
1506 local master_commit=`git_show_head $testroot/repo`
1508 got checkout $testroot/repo $testroot/wt > /dev/null
1509 ret=$?
1510 if [ $ret -ne 0 ]; then
1511 test_done "$testroot" "$ret"
1512 return 1
1515 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
1516 got rebase newbranch > $testroot/stdout)
1518 (cd $testroot/repo && git checkout -q newbranch)
1519 local new_commit1=`git_show_parent_commit $testroot/repo`
1520 local new_commit2=`git_show_head $testroot/repo`
1521 local new_author_time2=`git_show_author_time $testroot/repo`
1523 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1524 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1525 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1526 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1528 echo "G gamma/delta" >> $testroot/stdout.expected
1529 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1530 >> $testroot/stdout.expected
1531 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1532 echo "G alpha" >> $testroot/stdout.expected
1533 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1534 >> $testroot/stdout.expected
1535 echo ": committing more changes on newbranch" \
1536 >> $testroot/stdout.expected
1537 echo "Switching work tree to refs/heads/newbranch" \
1538 >> $testroot/stdout.expected
1540 cmp -s $testroot/stdout.expected $testroot/stdout
1541 ret=$?
1542 if [ $ret -ne 0 ]; then
1543 diff -u $testroot/stdout.expected $testroot/stdout
1544 test_done "$testroot" "$ret"
1545 return 1
1548 # Original commit only had one author
1549 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1550 egrep '^(from|via):' > $testroot/stdout)
1551 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1552 cmp -s $testroot/stdout.expected $testroot/stdout
1553 ret=$?
1554 if [ $ret -ne 0 ]; then
1555 diff -u $testroot/stdout.expected $testroot/stdout
1556 test_done "$testroot" "$ret"
1557 return 1
1560 # Rebased commit should have new committer name added
1561 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1562 egrep '^(from|via):' > $testroot/stdout)
1563 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1564 echo "via: $committer" >> $testroot/stdout.expected
1566 cmp -s $testroot/stdout.expected $testroot/stdout
1567 ret=$?
1568 if [ $ret -ne 0 ]; then
1569 diff -u $testroot/stdout.expected $testroot/stdout
1571 test_done "$testroot" "$ret"
1574 test_rebase_no_author_info() {
1575 local testroot=`test_init rebase_no_author_info`
1576 local commit0=`git_show_head $testroot/repo`
1577 local commit0_author_time=`git_show_author_time $testroot/repo`
1578 local committer="$GOT_AUTHOR"
1580 (cd $testroot/repo && git checkout -q -b newbranch)
1581 echo "modified delta on branch" > $testroot/repo/gamma/delta
1582 git_commit $testroot/repo -m "committing to delta on newbranch"
1584 echo "modified alpha on branch" > $testroot/repo/alpha
1585 git_commit $testroot/repo -m "committing more changes on newbranch"
1587 local orig_commit1=`git_show_parent_commit $testroot/repo`
1588 local orig_commit2=`git_show_head $testroot/repo`
1589 local orig_author_time2=`git_show_author_time $testroot/repo`
1591 (cd $testroot/repo && git checkout -q master)
1592 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1593 git_commit $testroot/repo -m "committing to zeta on master"
1594 local master_commit=`git_show_head $testroot/repo`
1596 got checkout $testroot/repo $testroot/wt > /dev/null
1597 ret=$?
1598 if [ $ret -ne 0 ]; then
1599 test_done "$testroot" "$ret"
1600 return 1
1603 # unset in a subshell to avoid affecting our environment
1604 (unset GOT_AUTHOR && cd $testroot/wt && \
1605 got rebase newbranch > $testroot/stdout)
1607 (cd $testroot/repo && git checkout -q newbranch)
1608 local new_commit1=`git_show_parent_commit $testroot/repo`
1609 local new_commit2=`git_show_head $testroot/repo`
1610 local new_author_time2=`git_show_author_time $testroot/repo`
1612 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1613 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1614 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1615 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1617 echo "G gamma/delta" >> $testroot/stdout.expected
1618 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1619 >> $testroot/stdout.expected
1620 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1621 echo "G alpha" >> $testroot/stdout.expected
1622 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1623 >> $testroot/stdout.expected
1624 echo ": committing more changes on newbranch" \
1625 >> $testroot/stdout.expected
1626 echo "Switching work tree to refs/heads/newbranch" \
1627 >> $testroot/stdout.expected
1629 cmp -s $testroot/stdout.expected $testroot/stdout
1630 ret=$?
1631 if [ $ret -ne 0 ]; then
1632 diff -u $testroot/stdout.expected $testroot/stdout
1633 test_done "$testroot" "$ret"
1634 return 1
1637 # Original commit only had one author
1638 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1639 egrep '^(from|via):' > $testroot/stdout)
1640 echo "from: $committer" > $testroot/stdout.expected
1641 cmp -s $testroot/stdout.expected $testroot/stdout
1642 ret=$?
1643 if [ $ret -ne 0 ]; then
1644 diff -u $testroot/stdout.expected $testroot/stdout
1645 test_done "$testroot" "$ret"
1646 return 1
1649 # Author info of rebased commit should match the original
1650 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1651 egrep '^(from|via):' > $testroot/stdout)
1652 echo "from: $committer" > $testroot/stdout.expected
1654 cmp -s $testroot/stdout.expected $testroot/stdout
1655 ret=$?
1656 if [ $ret -ne 0 ]; then
1657 diff -u $testroot/stdout.expected $testroot/stdout
1659 test_done "$testroot" "$ret"
1662 test_rebase_nonbranch() {
1663 local testroot=`test_init rebase_nonbranch`
1665 got ref -r $testroot/repo -c refs/heads/master \
1666 refs/remotes/origin/master >/dev/null
1668 got checkout -b master $testroot/repo $testroot/wt >/dev/null
1670 (cd $testroot/wt && got rebase origin/master > $testroot/stdout \
1671 2> $testroot/stderr)
1672 ret=$?
1673 if [ $ret -eq 0 ]; then
1674 echo "rebase succeeded unexpectedly" >&2
1675 test_done "$testroot" "1"
1676 return 1
1678 echo -n "got: will not rebase a branch which lives outside the " \
1679 > $testroot/stderr.expected
1680 echo '"refs/heads/" reference namespace' >> $testroot/stderr.expected
1681 cmp -s $testroot/stderr.expected $testroot/stderr
1682 ret=$?
1683 if [ $ret -ne 0 ]; then
1684 diff -u $testroot/stderr.expected $testroot/stderr
1686 test_done "$testroot" "$ret"
1689 test_parseargs "$@"
1690 run_test test_rebase_basic
1691 run_test test_rebase_ancestry_check
1692 run_test test_rebase_continue
1693 run_test test_rebase_abort
1694 run_test test_rebase_no_op_change
1695 run_test test_rebase_in_progress
1696 run_test test_rebase_path_prefix
1697 run_test test_rebase_preserves_logmsg
1698 run_test test_rebase_no_commits_to_rebase
1699 run_test test_rebase_forward
1700 run_test test_rebase_out_of_date
1701 run_test test_rebase_trims_empty_dir
1702 run_test test_rebase_delete_missing_file
1703 run_test test_rebase_rm_add_rm_file
1704 run_test test_rebase_resets_committer
1705 run_test test_rebase_no_author_info
1706 run_test test_rebase_nonbranch