portable: release 0.93
[got-portable.git] / regress / cmdline / rebase.sh
blob1d339f654c90ee75c99eac9cc5a7f39e8b6275ce
1 #!/bin/sh
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
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.
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
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
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
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
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
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
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
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
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
154 # We should have a backup of old commits
155 (cd $testroot/repo && got rebase -l > $testroot/stdout)
156 d_orig2=`date -u -r $orig_author_time2 +"%a %b %e %X %Y UTC"`
157 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
158 d_0=`date -u -r $commit0_author_time +"%G-%m-%d"`
159 cat > $testroot/stdout.expected <<EOF
160 -----------------------------------------------
161 commit $orig_commit2 (formerly newbranch)
162 from: $GOT_AUTHOR
163 date: $d_orig2
165 committing more changes on newbranch
167 has become commit $new_commit2 (newbranch)
168 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
169 history forked at $commit0
170 $d_0 $GOT_AUTHOR_11 adding the test tree
172 cmp -s $testroot/stdout.expected $testroot/stdout
173 ret=$?
174 if [ $ret -ne 0 ]; then
175 diff -u $testroot/stdout.expected $testroot/stdout
176 test_done "$testroot" "$ret"
177 return 1
180 # Asking for backups of a branch which has none should yield an error
181 (cd $testroot/repo && got rebase -l master \
182 > $testroot/stdout 2> $testroot/stderr)
183 echo -n > $testroot/stdout.expected
184 echo "got: refs/got/backup/rebase/master/: no such reference found" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
191 return 1
193 cmp -s $testroot/stderr.expected $testroot/stderr
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 diff -u $testroot/stderr.expected $testroot/stderr
197 test_done "$testroot" "$ret"
198 return 1
201 # Delete all backup refs
202 (cd $testroot/repo && got rebase -X \
203 > $testroot/stdout 2> $testroot/stderr)
204 echo -n "Deleted refs/got/backup/rebase/newbranch/$new_commit2: " \
205 > $testroot/stdout.expected
206 echo "$orig_commit2" >> $testroot/stdout.expected
207 echo -n > $testroot/stderr.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret=$?
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
215 cmp -s $testroot/stderr.expected $testroot/stderr
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stderr.expected $testroot/stderr
219 test_done "$testroot" "$ret"
220 return 1
223 (cd $testroot/repo && got rebase -l > $testroot/stdout)
224 echo -n > $testroot/stdout.expected
225 cmp -s $testroot/stdout.expected $testroot/stdout
226 ret=$?
227 if [ $ret -ne 0 ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
230 test_done "$testroot" "$ret"
233 test_rebase_ancestry_check() {
234 local testroot=`test_init rebase_ancestry_check`
236 got checkout $testroot/repo $testroot/wt > /dev/null
237 ret=$?
238 if [ $ret -ne 0 ]; then
239 test_done "$testroot" "$ret"
240 return 1
243 (cd $testroot/repo && git checkout -q -b newbranch)
244 echo "modified delta on branch" > $testroot/repo/gamma/delta
245 git_commit $testroot/repo -m "committing to delta on newbranch"
246 local newbranch_id=`git_show_head $testroot/repo`
248 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
249 2> $testroot/stderr)
251 echo "refs/heads/newbranch is already based on refs/heads/master" \
252 > $testroot/stdout.expected
253 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
254 >> $testroot/stdout.expected
255 echo "U gamma/delta" >> $testroot/stdout.expected
256 echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
257 >> $testroot/stdout.expected
258 cmp -s $testroot/stdout.expected $testroot/stdout
259 ret=$?
260 if [ $ret -ne 0 ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
263 return 1
266 echo -n > $testroot/stderr.expected
267 cmp -s $testroot/stderr.expected $testroot/stderr
268 ret=$?
269 if [ $ret -ne 0 ]; then
270 diff -u $testroot/stderr.expected $testroot/stderr
272 test_done "$testroot" "$ret"
275 test_rebase_continue() {
276 local testroot=`test_init rebase_continue`
277 local init_commit=`git_show_head $testroot/repo`
279 (cd $testroot/repo && git checkout -q -b newbranch)
280 echo "modified alpha on branch" > $testroot/repo/alpha
281 git_commit $testroot/repo -m "committing to alpha on newbranch"
282 local orig_commit1=`git_show_head $testroot/repo`
283 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
285 (cd $testroot/repo && git checkout -q master)
286 echo "modified alpha on master" > $testroot/repo/alpha
287 git_commit $testroot/repo -m "committing to alpha on master"
288 local master_commit=`git_show_head $testroot/repo`
290 got checkout $testroot/repo $testroot/wt > /dev/null
291 ret=$?
292 if [ $ret -ne 0 ]; then
293 test_done "$testroot" "$ret"
294 return 1
297 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
298 2> $testroot/stderr)
300 echo "C alpha" > $testroot/stdout.expected
301 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
302 echo -n "$short_orig_commit1 -> merge conflict" \
303 >> $testroot/stdout.expected
304 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
305 cmp -s $testroot/stdout.expected $testroot/stdout
306 ret=$?
307 if [ $ret -ne 0 ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
310 return 1
313 echo "got: conflicts must be resolved before rebasing can continue" \
314 > $testroot/stderr.expected
315 cmp -s $testroot/stderr.expected $testroot/stderr
316 ret=$?
317 if [ $ret -ne 0 ]; then
318 diff -u $testroot/stderr.expected $testroot/stderr
319 test_done "$testroot" "$ret"
320 return 1
323 echo '<<<<<<<' > $testroot/content.expected
324 echo "modified alpha on master" >> $testroot/content.expected
325 echo "||||||| 3-way merge base: commit $init_commit" \
326 >> $testroot/content.expected
327 echo "alpha" >> $testroot/content.expected
328 echo "=======" >> $testroot/content.expected
329 echo "modified alpha on branch" >> $testroot/content.expected
330 echo ">>>>>>> merged change: commit $orig_commit1" \
331 >> $testroot/content.expected
332 cat $testroot/wt/alpha > $testroot/content
333 cmp -s $testroot/content.expected $testroot/content
334 ret=$?
335 if [ $ret -ne 0 ]; then
336 diff -u $testroot/content.expected $testroot/content
337 test_done "$testroot" "$ret"
338 return 1
341 (cd $testroot/wt && got status > $testroot/stdout)
343 echo "C alpha" > $testroot/stdout.expected
344 cmp -s $testroot/stdout.expected $testroot/stdout
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
349 return 1
352 # resolve the conflict
353 echo "modified alpha on branch and master" > $testroot/wt/alpha
355 # test interaction of 'got stage' and rebase -c
356 (cd $testroot/wt && got stage alpha > /dev/null)
357 (cd $testroot/wt && got rebase -c > $testroot/stdout \
358 2> $testroot/stderr)
359 ret=$?
360 if [ $ret -eq 0 ]; then
361 echo "rebase succeeded unexpectedly" >&2
362 test_done "$testroot" "1"
363 return 1
365 echo -n "got: work tree contains files with staged changes; " \
366 > $testroot/stderr.expected
367 echo "these changes must be committed or unstaged first" \
368 >> $testroot/stderr.expected
369 cmp -s $testroot/stderr.expected $testroot/stderr
370 ret=$?
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stderr.expected $testroot/stderr
373 test_done "$testroot" "$ret"
374 return 1
377 (cd $testroot/wt && got unstage alpha > /dev/null)
378 (cd $testroot/wt && got rebase -c > $testroot/stdout)
380 (cd $testroot/repo && git checkout -q newbranch)
381 local new_commit1=`git_show_head $testroot/repo`
382 local short_new_commit1=`trim_obj_id 28 $new_commit1`
384 echo -n "$short_orig_commit1 -> $short_new_commit1" \
385 > $testroot/stdout.expected
386 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
387 echo "Switching work tree to refs/heads/newbranch" \
388 >> $testroot/stdout.expected
390 cmp -s $testroot/stdout.expected $testroot/stdout
391 ret=$?
392 if [ $ret -ne 0 ]; then
393 diff -u $testroot/stdout.expected $testroot/stdout
394 test_done "$testroot" "$ret"
395 return 1
399 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
400 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
401 echo "commit $master_commit (master)" >> $testroot/stdout.expected
402 cmp -s $testroot/stdout.expected $testroot/stdout
403 ret=$?
404 if [ $ret -ne 0 ]; then
405 diff -u $testroot/stdout.expected $testroot/stdout
407 test_done "$testroot" "$ret"
410 test_rebase_abort() {
411 local testroot=`test_init rebase_abort`
413 local init_commit=`git_show_head $testroot/repo`
415 (cd $testroot/repo && git checkout -q -b newbranch)
416 echo "modified beta on branch" > $testroot/repo/beta
417 git_commit $testroot/repo -m "committing to beta on newbranch"
418 local orig_commit1=`git_show_head $testroot/repo`
419 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
421 echo "modified alpha on branch" > $testroot/repo/alpha
422 echo "new file on branch" > $testroot/repo/epsilon/new
423 (cd $testroot/repo && git add epsilon/new)
424 git_commit $testroot/repo \
425 -m "changing alpha and adding new on newbranch"
426 local orig_commit2=`git_show_head $testroot/repo`
427 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
429 (cd $testroot/repo && git checkout -q master)
430 echo "modified alpha on master" > $testroot/repo/alpha
431 git_commit $testroot/repo -m "committing to alpha on master"
432 local master_commit=`git_show_head $testroot/repo`
434 got checkout $testroot/repo $testroot/wt > /dev/null
435 ret=$?
436 if [ $ret -ne 0 ]; then
437 test_done "$testroot" "$ret"
438 return 1
441 # unrelated unversioned file in work tree
442 touch $testroot/wt/unversioned-file
444 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
445 2> $testroot/stderr)
447 new_commit1=$(cd $testroot/wt && got info beta | \
448 grep '^based on commit:' | cut -d' ' -f4)
449 local short_new_commit1=`trim_obj_id 28 $new_commit1`
451 echo "G beta" > $testroot/stdout.expected
452 echo -n "$short_orig_commit1 -> $short_new_commit1" \
453 >> $testroot/stdout.expected
454 echo ": committing to beta on newbranch" >> $testroot/stdout.expected
455 echo "C alpha" >> $testroot/stdout.expected
456 echo "A epsilon/new" >> $testroot/stdout.expected
457 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
458 echo -n "$short_orig_commit2 -> merge conflict" \
459 >> $testroot/stdout.expected
460 echo ": changing alpha and adding new on newbranch" \
461 >> $testroot/stdout.expected
462 cmp -s $testroot/stdout.expected $testroot/stdout
463 ret=$?
464 if [ $ret -ne 0 ]; then
465 diff -u $testroot/stdout.expected $testroot/stdout
466 test_done "$testroot" "$ret"
467 return 1
470 echo "got: conflicts must be resolved before rebasing can continue" \
471 > $testroot/stderr.expected
472 cmp -s $testroot/stderr.expected $testroot/stderr
473 ret=$?
474 if [ $ret -ne 0 ]; then
475 diff -u $testroot/stderr.expected $testroot/stderr
476 test_done "$testroot" "$ret"
477 return 1
480 echo '<<<<<<<' > $testroot/content.expected
481 echo "modified alpha on master" >> $testroot/content.expected
482 echo "||||||| 3-way merge base: commit $orig_commit1" \
483 >> $testroot/content.expected
484 echo "alpha" >> $testroot/content.expected
485 echo "=======" >> $testroot/content.expected
486 echo "modified alpha on branch" >> $testroot/content.expected
487 echo ">>>>>>> merged change: commit $orig_commit2" \
488 >> $testroot/content.expected
489 cat $testroot/wt/alpha > $testroot/content
490 cmp -s $testroot/content.expected $testroot/content
491 ret=$?
492 if [ $ret -ne 0 ]; then
493 diff -u $testroot/content.expected $testroot/content
494 test_done "$testroot" "$ret"
495 return 1
498 # unrelated file in work tree added during conflict resolution
499 touch $testroot/wt/added-file
500 (cd $testroot/wt && got add added-file > /dev/null)
502 (cd $testroot/wt && got status > $testroot/stdout)
504 echo "A added-file" > $testroot/stdout.expected
505 echo "C alpha" >> $testroot/stdout.expected
506 echo "A epsilon/new" >> $testroot/stdout.expected
507 echo "? unversioned-file" >> $testroot/stdout.expected
508 cmp -s $testroot/stdout.expected $testroot/stdout
509 ret=$?
510 if [ $ret -ne 0 ]; then
511 diff -u $testroot/stdout.expected $testroot/stdout
512 test_done "$testroot" "$ret"
513 return 1
516 (cd $testroot/wt && got rebase -a > $testroot/stdout)
518 (cd $testroot/repo && git checkout -q newbranch)
520 echo "Switching work tree to refs/heads/master" \
521 > $testroot/stdout.expected
522 echo 'R added-file' >> $testroot/stdout.expected
523 echo 'R alpha' >> $testroot/stdout.expected
524 echo 'R epsilon/new' >> $testroot/stdout.expected
525 echo 'G added-file' >> $testroot/stdout.expected
526 echo 'U beta' >> $testroot/stdout.expected
527 echo "Rebase of refs/heads/newbranch aborted" \
528 >> $testroot/stdout.expected
530 cmp -s $testroot/stdout.expected $testroot/stdout
531 ret=$?
532 if [ $ret -ne 0 ]; then
533 diff -u $testroot/stdout.expected $testroot/stdout
534 test_done "$testroot" "$ret"
535 return 1
538 echo "modified alpha on master" > $testroot/content.expected
539 cat $testroot/wt/alpha > $testroot/content
540 cmp -s $testroot/content.expected $testroot/content
541 ret=$?
542 if [ $ret -ne 0 ]; then
543 diff -u $testroot/content.expected $testroot/content
544 test_done "$testroot" "$ret"
545 return 1
548 (cd $testroot/wt && got log -l3 -c newbranch \
549 | grep ^commit > $testroot/stdout)
550 echo "commit $orig_commit2 (newbranch)" > $testroot/stdout.expected
551 echo "commit $orig_commit1" >> $testroot/stdout.expected
552 echo "commit $init_commit" >> $testroot/stdout.expected
553 cmp -s $testroot/stdout.expected $testroot/stdout
554 ret=$?
555 if [ $ret -ne 0 ]; then
556 diff -u $testroot/stdout.expected $testroot/stdout
557 test_done "$testroot" "$ret"
558 return 1
561 (cd $testroot/wt && got info .| \
562 grep '^based on commit:' | sort | uniq > $testroot/stdout)
563 echo "based on commit: $master_commit" > $testroot/stdout.expected
564 cmp -s $testroot/stdout.expected $testroot/stdout
565 ret=$?
566 if [ $ret -ne 0 ]; then
567 diff -u $testroot/stdout.expected $testroot/stdout
568 test_done "$testroot" "$ret"
569 return 1
572 (cd $testroot/wt && got status > $testroot/stdout)
573 echo "? added-file" > $testroot/stdout.expected
574 echo "? unversioned-file" >> $testroot/stdout.expected
575 cmp -s $testroot/stdout.expected $testroot/stdout
576 ret=$?
577 if [ $ret -ne 0 ]; then
578 diff -u $testroot/stdout.expected $testroot/stdout
579 test_done "$testroot" "$ret"
580 return 1
583 cat $testroot/wt/beta > $testroot/content
584 echo 'beta' > $testroot/content.expected
585 cmp -s $testroot/content.expected $testroot/content
586 ret=$?
587 if [ $ret -ne 0 ]; then
588 diff -u $testroot/content.expected $testroot/content
589 test_done "$testroot" "$ret"
590 return 1
593 # A subsequent update should be a no-op.
594 (cd $testroot/wt && got update > $testroot/stdout)
595 echo 'Already up-to-date' > $testroot/stdout.expected
596 cmp -s $testroot/stdout.expected $testroot/stdout
597 ret=$?
598 if [ $ret -ne 0 ]; then
599 diff -u $testroot/stdout.expected $testroot/stdout
601 test_done "$testroot" "$ret"
604 test_rebase_no_op_change() {
605 local testroot=`test_init rebase_no_op_change`
606 local init_commit=`git_show_head $testroot/repo`
608 (cd $testroot/repo && git checkout -q -b newbranch)
609 echo "modified alpha on branch" > $testroot/repo/alpha
610 git_commit $testroot/repo -m "committing to alpha on newbranch"
611 local orig_commit1=`git_show_head $testroot/repo`
612 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
614 (cd $testroot/repo && git checkout -q master)
615 echo "modified alpha on master" > $testroot/repo/alpha
616 git_commit $testroot/repo -m "committing to alpha on master"
617 local master_commit=`git_show_head $testroot/repo`
619 got checkout $testroot/repo $testroot/wt > /dev/null
620 ret=$?
621 if [ $ret -ne 0 ]; then
622 test_done "$testroot" "$ret"
623 return 1
626 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
627 2> $testroot/stderr)
629 echo "C alpha" > $testroot/stdout.expected
630 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
631 echo -n "$short_orig_commit1 -> merge conflict" \
632 >> $testroot/stdout.expected
633 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
634 cmp -s $testroot/stdout.expected $testroot/stdout
635 ret=$?
636 if [ $ret -ne 0 ]; then
637 diff -u $testroot/stdout.expected $testroot/stdout
638 test_done "$testroot" "$ret"
639 return 1
642 echo "got: conflicts must be resolved before rebasing can continue" \
643 > $testroot/stderr.expected
644 cmp -s $testroot/stderr.expected $testroot/stderr
645 ret=$?
646 if [ $ret -ne 0 ]; then
647 diff -u $testroot/stderr.expected $testroot/stderr
648 test_done "$testroot" "$ret"
649 return 1
652 echo '<<<<<<<' > $testroot/content.expected
653 echo "modified alpha on master" >> $testroot/content.expected
654 echo "||||||| 3-way merge base: commit $init_commit" \
655 >> $testroot/content.expected
656 echo "alpha" >> $testroot/content.expected
657 echo "=======" >> $testroot/content.expected
658 echo "modified alpha on branch" >> $testroot/content.expected
659 echo ">>>>>>> merged change: commit $orig_commit1" \
660 >> $testroot/content.expected
661 cat $testroot/wt/alpha > $testroot/content
662 cmp -s $testroot/content.expected $testroot/content
663 ret=$?
664 if [ $ret -ne 0 ]; then
665 diff -u $testroot/content.expected $testroot/content
666 test_done "$testroot" "$ret"
667 return 1
670 (cd $testroot/wt && got status > $testroot/stdout)
672 echo "C alpha" > $testroot/stdout.expected
673 cmp -s $testroot/stdout.expected $testroot/stdout
674 ret=$?
675 if [ $ret -ne 0 ]; then
676 diff -u $testroot/stdout.expected $testroot/stdout
677 test_done "$testroot" "$ret"
678 return 1
681 # resolve the conflict
682 echo "modified alpha on master" > $testroot/wt/alpha
684 (cd $testroot/wt && got rebase -c > $testroot/stdout)
686 (cd $testroot/repo && git checkout -q newbranch)
687 local new_commit1=`git_show_head $testroot/repo`
689 echo -n "$short_orig_commit1 -> no-op change" \
690 > $testroot/stdout.expected
691 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
692 echo "Switching work tree to refs/heads/newbranch" \
693 >> $testroot/stdout.expected
695 cmp -s $testroot/stdout.expected $testroot/stdout
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 diff -u $testroot/stdout.expected $testroot/stdout
699 test_done "$testroot" "$ret"
700 return 1
704 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
705 echo "commit $master_commit (master, newbranch)" \
706 > $testroot/stdout.expected
707 echo "commit $init_commit" >> $testroot/stdout.expected
708 cmp -s $testroot/stdout.expected $testroot/stdout
709 ret=$?
710 if [ $ret -ne 0 ]; then
711 diff -u $testroot/stdout.expected $testroot/stdout
713 test_done "$testroot" "$ret"
716 test_rebase_in_progress() {
717 local testroot=`test_init rebase_in_progress`
718 local init_commit=`git_show_head $testroot/repo`
720 (cd $testroot/repo && git checkout -q -b newbranch)
721 echo "modified alpha on branch" > $testroot/repo/alpha
722 git_commit $testroot/repo -m "committing to alpha on newbranch"
723 local orig_commit1=`git_show_head $testroot/repo`
724 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
726 (cd $testroot/repo && git checkout -q master)
727 echo "modified alpha on master" > $testroot/repo/alpha
728 git_commit $testroot/repo -m "committing to alpha on master"
729 local master_commit=`git_show_head $testroot/repo`
731 got checkout $testroot/repo $testroot/wt > /dev/null
732 ret=$?
733 if [ $ret -ne 0 ]; then
734 test_done "$testroot" "$ret"
735 return 1
738 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
739 2> $testroot/stderr)
741 echo "C alpha" > $testroot/stdout.expected
742 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
743 echo -n "$short_orig_commit1 -> merge conflict" \
744 >> $testroot/stdout.expected
745 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
746 cmp -s $testroot/stdout.expected $testroot/stdout
747 ret=$?
748 if [ $ret -ne 0 ]; then
749 diff -u $testroot/stdout.expected $testroot/stdout
750 test_done "$testroot" "$ret"
751 return 1
754 echo "got: conflicts must be resolved before rebasing can continue" \
755 > $testroot/stderr.expected
756 cmp -s $testroot/stderr.expected $testroot/stderr
757 ret=$?
758 if [ $ret -ne 0 ]; then
759 diff -u $testroot/stderr.expected $testroot/stderr
760 test_done "$testroot" "$ret"
761 return 1
764 echo '<<<<<<<' > $testroot/content.expected
765 echo "modified alpha on master" >> $testroot/content.expected
766 echo "||||||| 3-way merge base: commit $init_commit" \
767 >> $testroot/content.expected
768 echo "alpha" >> $testroot/content.expected
769 echo "=======" >> $testroot/content.expected
770 echo "modified alpha on branch" >> $testroot/content.expected
771 echo ">>>>>>> merged change: commit $orig_commit1" \
772 >> $testroot/content.expected
773 cat $testroot/wt/alpha > $testroot/content
774 cmp -s $testroot/content.expected $testroot/content
775 ret=$?
776 if [ $ret -ne 0 ]; then
777 diff -u $testroot/content.expected $testroot/content
778 test_done "$testroot" "$ret"
779 return 1
782 (cd $testroot/wt && got status > $testroot/stdout)
784 echo "C alpha" > $testroot/stdout.expected
785 cmp -s $testroot/stdout.expected $testroot/stdout
786 ret=$?
787 if [ $ret -ne 0 ]; then
788 diff -u $testroot/stdout.expected $testroot/stdout
789 test_done "$testroot" "$ret"
790 return 1
793 for cmd in update commit; do
794 (cd $testroot/wt && got $cmd > $testroot/stdout \
795 2> $testroot/stderr)
797 echo -n > $testroot/stdout.expected
798 cmp -s $testroot/stdout.expected $testroot/stdout
799 ret=$?
800 if [ $ret -ne 0 ]; then
801 diff -u $testroot/stdout.expected $testroot/stdout
802 test_done "$testroot" "$ret"
803 return 1
806 echo -n "got: a rebase operation is in progress in this " \
807 > $testroot/stderr.expected
808 echo "work tree and must be continued or aborted first" \
809 >> $testroot/stderr.expected
810 cmp -s $testroot/stderr.expected $testroot/stderr
811 ret=$?
812 if [ $ret -ne 0 ]; then
813 diff -u $testroot/stderr.expected $testroot/stderr
814 test_done "$testroot" "$ret"
815 return 1
817 done
819 test_done "$testroot" "$ret"
822 test_rebase_path_prefix() {
823 local testroot=`test_init rebase_path_prefix`
825 (cd $testroot/repo && git checkout -q -b newbranch)
826 echo "modified delta on branch" > $testroot/repo/gamma/delta
827 git_commit $testroot/repo -m "committing to delta on newbranch"
829 local orig_commit1=`git_show_parent_commit $testroot/repo`
830 local orig_commit2=`git_show_head $testroot/repo`
832 (cd $testroot/repo && git checkout -q master)
833 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
834 git_commit $testroot/repo -m "committing to zeta on master"
835 local master_commit=`git_show_head $testroot/repo`
837 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
838 ret=$?
839 if [ $ret -ne 0 ]; then
840 test_done "$testroot" "$ret"
841 return 1
844 (cd $testroot/wt && got rebase newbranch \
845 > $testroot/stdout 2> $testroot/stderr)
847 echo -n > $testroot/stdout.expected
848 cmp -s $testroot/stdout.expected $testroot/stdout
849 ret=$?
850 if [ $ret -ne 0 ]; then
851 diff -u $testroot/stdout.expected $testroot/stdout
852 test_done "$testroot" "$ret"
853 return 1
856 echo -n "got: cannot rebase branch which contains changes outside " \
857 > $testroot/stderr.expected
858 echo "of this work tree's path prefix" >> $testroot/stderr.expected
859 cmp -s $testroot/stderr.expected $testroot/stderr
860 ret=$?
861 if [ $ret -ne 0 ]; then
862 diff -u $testroot/stderr.expected $testroot/stderr
863 test_done "$testroot" "$ret"
864 return 1
867 # rebase should succeed when using a complete work tree
868 got checkout $testroot/repo $testroot/wt2 > /dev/null
869 ret=$?
870 if [ $ret -ne 0 ]; then
871 test_done "$testroot" "$ret"
872 return 1
875 (cd $testroot/wt2 && got rebase newbranch \
876 > $testroot/stdout 2> $testroot/stderr)
878 (cd $testroot/repo && git checkout -q newbranch)
879 local new_commit1=`git_show_parent_commit $testroot/repo`
880 local new_commit2=`git_show_head $testroot/repo`
882 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
883 local short_new_commit2=`trim_obj_id 28 $new_commit2`
885 echo "G gamma/delta" > $testroot/stdout.expected
886 echo -n "$short_orig_commit2 -> $short_new_commit2" \
887 >> $testroot/stdout.expected
888 echo ": committing to delta on newbranch" \
889 >> $testroot/stdout.expected
890 echo "Switching work tree to refs/heads/newbranch" \
891 >> $testroot/stdout.expected
893 cmp -s $testroot/stdout.expected $testroot/stdout
894 ret=$?
895 if [ $ret -ne 0 ]; then
896 diff -u $testroot/stdout.expected $testroot/stdout
897 test_done "$testroot" "$ret"
898 return 1
901 # the first work tree should remain usable
902 (cd $testroot/wt && got update -b master \
903 > $testroot/stdout 2> $testroot/stderr)
904 ret=$?
905 if [ $ret -ne 0 ]; then
906 echo "update failed unexpectedly" >&2
907 test_done "$testroot" "1"
908 return 1
911 echo 'Already up-to-date' > $testroot/stdout.expected
912 cmp -s $testroot/stdout.expected $testroot/stdout
913 ret=$?
914 if [ $ret -ne 0 ]; then
915 diff -u $testroot/stdout.expected $testroot/stdout
917 test_done "$testroot" "$ret"
920 test_rebase_preserves_logmsg() {
921 local testroot=`test_init rebase_preserves_logmsg`
923 (cd $testroot/repo && git checkout -q -b newbranch)
924 echo "modified delta on branch" > $testroot/repo/gamma/delta
925 git_commit $testroot/repo -m "modified delta on newbranch"
927 echo "modified alpha on branch" > $testroot/repo/alpha
928 git_commit $testroot/repo -m "modified alpha on newbranch"
930 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
931 > $testroot/log.expected)
933 local orig_commit1=`git_show_parent_commit $testroot/repo`
934 local orig_commit2=`git_show_head $testroot/repo`
936 (cd $testroot/repo && git checkout -q master)
937 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
938 git_commit $testroot/repo -m "committing to zeta on master"
939 local master_commit=`git_show_head $testroot/repo`
941 got checkout $testroot/repo $testroot/wt > /dev/null
942 ret=$?
943 if [ $ret -ne 0 ]; then
944 test_done "$testroot" "$ret"
945 return 1
948 (cd $testroot/wt && got rebase newbranch > /dev/null \
949 2> $testroot/stderr)
951 (cd $testroot/repo && git checkout -q newbranch)
952 local new_commit1=`git_show_parent_commit $testroot/repo`
953 local new_commit2=`git_show_head $testroot/repo`
955 echo -n > $testroot/stderr.expected
956 cmp -s $testroot/stderr.expected $testroot/stderr
957 ret=$?
958 if [ $ret -ne 0 ]; then
959 diff -u $testroot/stderr.expected $testroot/stderr
960 test_done "$testroot" "$ret"
961 return 1
964 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
965 > $testroot/log)
966 ed -s $testroot/log.expected <<-EOF
967 ,s/$orig_commit1/$new_commit1/
968 ,s/$orig_commit2/$new_commit2/
971 cmp -s $testroot/log.expected $testroot/log
972 ret=$?
973 if [ $ret -ne 0 ]; then
974 diff -u $testroot/log.expected $testroot/log
977 test_done "$testroot" "$ret"
980 test_rebase_no_commits_to_rebase() {
981 local testroot=`test_init rebase_no_commits_to_rebase`
983 got checkout $testroot/repo $testroot/wt > /dev/null
984 ret=$?
985 if [ $ret -ne 0 ]; then
986 test_done "$testroot" "$ret"
987 return 1
990 # Create an unrelated branch with 'got import'.
991 mkdir -p $testroot/newtree
992 echo "new file" > $testroot/newtree/newfile
993 got import -m new -b newbranch -r $testroot/repo \
994 $testroot/newtree > /dev/null
996 echo "modified alpha on master" > $testroot/wt/alpha
997 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
998 > /dev/null)
999 (cd $testroot/wt && got update > /dev/null)
1001 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1002 2> $testroot/stderr)
1004 echo -n "got: specified branch shares no common ancestry " \
1005 > $testroot/stderr.expected
1006 echo "with work tree's branch" >> $testroot/stderr.expected
1007 cmp -s $testroot/stderr.expected $testroot/stderr
1008 ret=$?
1009 if [ $ret -ne 0 ]; then
1010 diff -u $testroot/stderr.expected $testroot/stderr
1011 test_done "$testroot" "$ret"
1012 return 1
1015 echo -n > $testroot/stdout.expected
1016 cmp -s $testroot/stdout.expected $testroot/stdout
1017 ret=$?
1018 if [ $ret -ne 0 ]; then
1019 diff -u $testroot/stdout.expected $testroot/stdout
1020 test_done "$testroot" "$ret"
1021 return 1
1024 (cd $testroot/wt && got update > $testroot/stdout)
1025 echo "Already up-to-date" > $testroot/stdout.expected
1026 cmp -s $testroot/stdout.expected $testroot/stdout
1027 ret=$?
1028 if [ $ret -ne 0 ]; then
1029 diff -u $testroot/stdout.expected $testroot/stdout
1031 test_done "$testroot" "$ret"
1034 test_rebase_forward() {
1035 local testroot=`test_init rebase_forward`
1036 local commit0=`git_show_head $testroot/repo`
1038 got checkout $testroot/repo $testroot/wt > /dev/null
1039 ret=$?
1040 if [ $ret -ne 0 ]; then
1041 test_done "$testroot" "$ret"
1042 return 1
1045 echo "change alpha 1" > $testroot/wt/alpha
1046 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1047 > /dev/null)
1048 local commit1=`git_show_head $testroot/repo`
1050 echo "change alpha 2" > $testroot/wt/alpha
1051 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1052 > /dev/null)
1053 local commit2=`git_show_head $testroot/repo`
1055 # Simulate a situation where fast-forward is required.
1056 # We want to fast-forward master to origin/master:
1057 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1058 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1059 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1060 (cd $testroot/repo && got ref -d master >/dev/null)
1061 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1062 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1064 (cd $testroot/wt && got up -b origin/master > /dev/null)
1066 (cd $testroot/wt && got rebase master \
1067 > $testroot/stdout 2> $testroot/stderr)
1069 echo "Forwarding refs/heads/master to commit $commit2" \
1070 > $testroot/stdout.expected
1071 echo "Switching work tree to refs/heads/master" \
1072 >> $testroot/stdout.expected
1073 cmp -s $testroot/stdout.expected $testroot/stdout
1074 ret=$?
1075 if [ $ret -ne 0 ]; then
1076 diff -u $testroot/stdout.expected $testroot/stdout
1077 test_done "$testroot" "$ret"
1078 return 1
1081 # Ensure that rebase operation was completed correctly
1082 (cd $testroot/wt && got rebase -a \
1083 > $testroot/stdout 2> $testroot/stderr)
1084 echo -n "" > $testroot/stdout.expected
1085 cmp -s $testroot/stdout.expected $testroot/stdout
1086 ret=$?
1087 if [ $ret -ne 0 ]; then
1088 diff -u $testroot/stdout.expected $testroot/stdout
1089 test_done "$testroot" "$ret"
1090 return 1
1092 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1093 cmp -s $testroot/stderr.expected $testroot/stderr
1094 ret=$?
1095 if [ $ret -ne 0 ]; then
1096 diff -u $testroot/stderr.expected $testroot/stderr
1097 test_done "$testroot" "$ret"
1098 return 1
1101 (cd $testroot/wt && got branch -n > $testroot/stdout)
1102 echo "master" > $testroot/stdout.expected
1103 cmp -s $testroot/stdout.expected $testroot/stdout
1104 ret=$?
1105 if [ $ret -ne 0 ]; then
1106 diff -u $testroot/stdout.expected $testroot/stdout
1107 test_done "$testroot" "$ret"
1108 return 1
1111 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1112 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1113 echo "commit $commit1" >> $testroot/stdout.expected
1114 echo "commit $commit0" >> $testroot/stdout.expected
1115 cmp -s $testroot/stdout.expected $testroot/stdout
1116 ret=$?
1117 if [ $ret -ne 0 ]; then
1118 diff -u $testroot/stdout.expected $testroot/stdout
1119 test_done "$testroot" "$ret"
1120 return 1
1123 # Forward-only rebase operations should not be backed up
1124 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1125 echo -n > $testroot/stdout.expected
1126 cmp -s $testroot/stdout.expected $testroot/stdout
1127 ret=$?
1128 if [ $ret -ne 0 ]; then
1129 diff -u $testroot/stdout.expected $testroot/stdout
1131 test_done "$testroot" "$ret"
1134 test_rebase_forward_path_prefix() {
1135 local testroot=`test_init rebase_forward_path_prefix`
1136 local commit0=`git_show_head $testroot/repo`
1138 got checkout $testroot/repo $testroot/wt-full > /dev/null
1139 ret=$?
1140 if [ $ret -ne 0 ]; then
1141 test_done "$testroot" "$ret"
1142 return 1
1145 echo "change alpha 1" > $testroot/wt-full/alpha
1146 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1147 > /dev/null)
1148 local commit1=`git_show_head $testroot/repo`
1150 echo "change alpha 2" > $testroot/wt-full/alpha
1151 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1152 > /dev/null)
1153 local commit2=`git_show_head $testroot/repo`
1155 # Simulate a situation where fast-forward is required.
1156 # We want to fast-forward master to origin/master:
1157 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1158 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1159 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1160 (cd $testroot/repo && got ref -d master >/dev/null)
1161 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1162 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1164 # Work tree which uses a path-prefix and will be used for rebasing
1165 got checkout -p epsilon -b origin/master $testroot/repo $testroot/wt \
1166 > /dev/null
1167 ret=$?
1168 if [ $ret -ne 0 ]; then
1169 test_done "$testroot" "$ret"
1170 return 1
1173 (cd $testroot/wt && got rebase master \
1174 > $testroot/stdout 2> $testroot/stderr)
1176 echo "Forwarding refs/heads/master to commit $commit2" \
1177 > $testroot/stdout.expected
1178 echo "Switching work tree to refs/heads/master" \
1179 >> $testroot/stdout.expected
1180 cmp -s $testroot/stdout.expected $testroot/stdout
1181 ret=$?
1182 if [ $ret -ne 0 ]; then
1183 diff -u $testroot/stdout.expected $testroot/stdout
1184 test_done "$testroot" "$ret"
1185 return 1
1188 # Ensure that rebase operation was completed correctly
1189 (cd $testroot/wt && got rebase -a \
1190 > $testroot/stdout 2> $testroot/stderr)
1191 echo -n "" > $testroot/stdout.expected
1192 cmp -s $testroot/stdout.expected $testroot/stdout
1193 ret=$?
1194 if [ $ret -ne 0 ]; then
1195 diff -u $testroot/stdout.expected $testroot/stdout
1196 test_done "$testroot" "$ret"
1197 return 1
1199 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1200 cmp -s $testroot/stderr.expected $testroot/stderr
1201 ret=$?
1202 if [ $ret -ne 0 ]; then
1203 diff -u $testroot/stderr.expected $testroot/stderr
1204 test_done "$testroot" "$ret"
1205 return 1
1208 (cd $testroot/wt && got branch -n > $testroot/stdout)
1209 echo "master" > $testroot/stdout.expected
1210 cmp -s $testroot/stdout.expected $testroot/stdout
1211 ret=$?
1212 if [ $ret -ne 0 ]; then
1213 diff -u $testroot/stdout.expected $testroot/stdout
1214 test_done "$testroot" "$ret"
1215 return 1
1218 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1219 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1220 echo "commit $commit1" >> $testroot/stdout.expected
1221 echo "commit $commit0" >> $testroot/stdout.expected
1222 cmp -s $testroot/stdout.expected $testroot/stdout
1223 ret=$?
1224 if [ $ret -ne 0 ]; then
1225 diff -u $testroot/stdout.expected $testroot/stdout
1226 test_done "$testroot" "$ret"
1227 return 1
1230 # Forward-only rebase operations should not be backed up
1231 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1232 echo -n > $testroot/stdout.expected
1233 cmp -s $testroot/stdout.expected $testroot/stdout
1234 ret=$?
1235 if [ $ret -ne 0 ]; then
1236 diff -u $testroot/stdout.expected $testroot/stdout
1238 test_done "$testroot" "$ret"
1241 test_rebase_out_of_date() {
1242 local testroot=`test_init rebase_out_of_date`
1243 local initial_commit=`git_show_head $testroot/repo`
1245 (cd $testroot/repo && git checkout -q -b newbranch)
1246 echo "modified delta on branch" > $testroot/repo/gamma/delta
1247 git_commit $testroot/repo -m "committing to delta on newbranch"
1249 echo "modified alpha on branch" > $testroot/repo/alpha
1250 (cd $testroot/repo && git rm -q beta)
1251 echo "new file on branch" > $testroot/repo/epsilon/new
1252 (cd $testroot/repo && git add epsilon/new)
1253 git_commit $testroot/repo -m "committing more changes on newbranch"
1255 local orig_commit1=`git_show_parent_commit $testroot/repo`
1256 local orig_commit2=`git_show_head $testroot/repo`
1258 (cd $testroot/repo && git checkout -q master)
1259 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1260 git_commit $testroot/repo -m "committing to zeta on master"
1261 local master_commit1=`git_show_head $testroot/repo`
1263 (cd $testroot/repo && git checkout -q master)
1264 echo "modified beta on master" > $testroot/repo/beta
1265 git_commit $testroot/repo -m "committing to beta on master"
1266 local master_commit2=`git_show_head $testroot/repo`
1268 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1269 > /dev/null
1270 ret=$?
1271 if [ $ret -ne 0 ]; then
1272 test_done "$testroot" "$ret"
1273 return 1
1276 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1277 2> $testroot/stderr)
1279 echo -n > $testroot/stdout.expected
1280 cmp -s $testroot/stdout.expected $testroot/stdout
1281 ret=$?
1282 if [ $ret -ne 0 ]; then
1283 diff -u $testroot/stdout.expected $testroot/stdout
1284 test_done "$testroot" "$ret"
1285 return 1
1288 echo -n "got: work tree must be updated before it can be " \
1289 > $testroot/stderr.expected
1290 echo "used to rebase a branch" >> $testroot/stderr.expected
1291 cmp -s $testroot/stderr.expected $testroot/stderr
1292 ret=$?
1293 if [ $ret -ne 0 ]; then
1294 diff -u $testroot/stderr.expected $testroot/stderr
1295 test_done "$testroot" "$ret"
1296 return 1
1299 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1300 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1301 echo "commit $master_commit1" >> $testroot/stdout.expected
1302 echo "commit $initial_commit" >> $testroot/stdout.expected
1303 cmp -s $testroot/stdout.expected $testroot/stdout
1304 ret=$?
1305 if [ $ret -ne 0 ]; then
1306 diff -u $testroot/stdout.expected $testroot/stdout
1308 test_done "$testroot" "$ret"
1311 test_rebase_trims_empty_dir() {
1312 local testroot=`test_init rebase_trims_empty_dir`
1314 (cd $testroot/repo && git checkout -q -b newbranch)
1315 echo "modified delta on branch" > $testroot/repo/gamma/delta
1316 git_commit $testroot/repo -m "committing to delta on newbranch"
1318 (cd $testroot/repo && git rm -q epsilon/zeta)
1319 git_commit $testroot/repo -m "removing zeta on newbranch"
1321 local orig_commit1=`git_show_parent_commit $testroot/repo`
1322 local orig_commit2=`git_show_head $testroot/repo`
1324 (cd $testroot/repo && git checkout -q master)
1325 echo "modified alpha on master" > $testroot/repo/alpha
1326 git_commit $testroot/repo -m "committing to alpha on master"
1327 local master_commit=`git_show_head $testroot/repo`
1329 got checkout $testroot/repo $testroot/wt > /dev/null
1330 ret=$?
1331 if [ $ret -ne 0 ]; then
1332 test_done "$testroot" "$ret"
1333 return 1
1336 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1338 (cd $testroot/repo && git checkout -q newbranch)
1339 local new_commit1=`git_show_parent_commit $testroot/repo`
1340 local new_commit2=`git_show_head $testroot/repo`
1342 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1343 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1344 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1345 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1347 echo "G gamma/delta" >> $testroot/stdout.expected
1348 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1349 >> $testroot/stdout.expected
1350 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1351 echo "D epsilon/zeta" >> $testroot/stdout.expected
1352 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1353 >> $testroot/stdout.expected
1354 echo ": removing zeta on newbranch" \
1355 >> $testroot/stdout.expected
1356 echo "Switching work tree to refs/heads/newbranch" \
1357 >> $testroot/stdout.expected
1359 cmp -s $testroot/stdout.expected $testroot/stdout
1360 ret=$?
1361 if [ $ret -ne 0 ]; then
1362 diff -u $testroot/stdout.expected $testroot/stdout
1363 test_done "$testroot" "$ret"
1364 return 1
1367 echo "modified delta on branch" > $testroot/content.expected
1368 cat $testroot/wt/gamma/delta > $testroot/content
1369 cmp -s $testroot/content.expected $testroot/content
1370 ret=$?
1371 if [ $ret -ne 0 ]; then
1372 diff -u $testroot/content.expected $testroot/content
1373 test_done "$testroot" "$ret"
1374 return 1
1377 echo "modified alpha on master" > $testroot/content.expected
1378 cat $testroot/wt/alpha > $testroot/content
1379 cmp -s $testroot/content.expected $testroot/content
1380 ret=$?
1381 if [ $ret -ne 0 ]; then
1382 diff -u $testroot/content.expected $testroot/content
1383 test_done "$testroot" "$ret"
1384 return 1
1387 if [ -e $testroot/wt/epsilon ]; then
1388 echo "parent of removed zeta still exists on disk" >&2
1389 test_done "$testroot" "1"
1390 return 1
1393 (cd $testroot/wt && got status > $testroot/stdout)
1395 echo -n > $testroot/stdout.expected
1396 cmp -s $testroot/stdout.expected $testroot/stdout
1397 ret=$?
1398 if [ $ret -ne 0 ]; then
1399 diff -u $testroot/stdout.expected $testroot/stdout
1400 test_done "$testroot" "$ret"
1401 return 1
1404 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1405 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1406 echo "commit $new_commit1" >> $testroot/stdout.expected
1407 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1408 cmp -s $testroot/stdout.expected $testroot/stdout
1409 ret=$?
1410 if [ $ret -ne 0 ]; then
1411 diff -u $testroot/stdout.expected $testroot/stdout
1413 test_done "$testroot" "$ret"
1416 test_rebase_delete_missing_file() {
1417 local testroot=`test_init rebase_delete_missing_file`
1419 mkdir -p $testroot/repo/d/f/g
1420 echo "new file" > $testroot/repo/d/f/g/new
1421 (cd $testroot/repo && git add d/f/g/new)
1422 git_commit $testroot/repo -m "adding a subdir"
1423 local commit0=`git_show_head $testroot/repo`
1425 got br -r $testroot/repo -c master newbranch
1427 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1429 echo "modified delta on branch" > $testroot/wt/gamma/delta
1430 (cd $testroot/wt && got commit \
1431 -m "committing to delta on newbranch" > /dev/null)
1433 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1434 (cd $testroot/wt && got commit \
1435 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1437 (cd $testroot/repo && git checkout -q newbranch)
1438 local orig_commit1=`git_show_parent_commit $testroot/repo`
1439 local orig_commit2=`git_show_head $testroot/repo`
1441 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1442 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1444 (cd $testroot/wt && got update -b master > /dev/null)
1445 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1446 (cd $testroot/wt && got commit \
1447 -m "removing beta and d/f/g/new on master" > /dev/null)
1449 (cd $testroot/repo && git checkout -q master)
1450 local master_commit=`git_show_head $testroot/repo`
1452 (cd $testroot/wt && got update -b master > /dev/null)
1453 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1454 2> $testroot/stderr)
1455 ret=$?
1456 if [ $ret -eq 0 ]; then
1457 echo "rebase succeeded unexpectedly" >&2
1458 test_done "$testroot" "1"
1459 return 1
1462 local new_commit1=$(cd $testroot/wt && got info | \
1463 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1465 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1466 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1468 echo "G gamma/delta" >> $testroot/stdout.expected
1469 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1470 >> $testroot/stdout.expected
1471 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1472 echo "! beta" >> $testroot/stdout.expected
1473 echo "! d/f/g/new" >> $testroot/stdout.expected
1474 echo -n "Files which had incoming changes but could not be found " \
1475 >> $testroot/stdout.expected
1476 echo "in the work tree: 2" >> $testroot/stdout.expected
1477 cmp -s $testroot/stdout.expected $testroot/stdout
1478 ret=$?
1479 if [ $ret -ne 0 ]; then
1480 diff -u $testroot/stdout.expected $testroot/stdout
1481 test_done "$testroot" "$ret"
1482 return 1
1485 echo -n "got: changes destined for some files were not yet merged " \
1486 > $testroot/stderr.expected
1487 echo -n "and should be merged manually if required before the " \
1488 >> $testroot/stderr.expected
1489 echo "rebase operation is continued" >> $testroot/stderr.expected
1490 cmp -s $testroot/stderr.expected $testroot/stderr
1491 ret=$?
1492 if [ $ret -ne 0 ]; then
1493 diff -u $testroot/stderr.expected $testroot/stderr
1494 test_done "$testroot" "$ret"
1495 return 1
1498 # ignore the missing changes and continue
1499 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1500 ret=$?
1501 if [ $ret -ne 0 ]; then
1502 echo "rebase failed unexpectedly" >&2
1503 test_done "$testroot" "1"
1504 return 1
1506 echo -n "$short_orig_commit2 -> no-op change" \
1507 > $testroot/stdout.expected
1508 echo ": removing beta and d/f/g/new on newbranch" \
1509 >> $testroot/stdout.expected
1510 echo "Switching work tree to refs/heads/newbranch" \
1511 >> $testroot/stdout.expected
1513 cmp -s $testroot/stdout.expected $testroot/stdout
1514 ret=$?
1515 if [ $ret -ne 0 ]; then
1516 diff -u $testroot/stdout.expected $testroot/stdout
1517 test_done "$testroot" "$ret"
1518 return 1
1521 echo "modified delta on branch" > $testroot/content.expected
1522 cat $testroot/wt/gamma/delta > $testroot/content
1523 cmp -s $testroot/content.expected $testroot/content
1524 ret=$?
1525 if [ $ret -ne 0 ]; then
1526 diff -u $testroot/content.expected $testroot/content
1527 test_done "$testroot" "$ret"
1528 return 1
1531 if [ -e $testroot/wt/beta ]; then
1532 echo "removed file beta still exists on disk" >&2
1533 test_done "$testroot" "1"
1534 return 1
1537 (cd $testroot/wt && got status > $testroot/stdout)
1539 echo -n > $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 (cd $testroot/repo && git checkout -q newbranch)
1549 local new_commit1=`git_show_head $testroot/repo`
1550 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1552 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1553 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1554 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1555 echo "commit $commit0" >> $testroot/stdout.expected
1556 cmp -s $testroot/stdout.expected $testroot/stdout
1557 ret=$?
1558 if [ $ret -ne 0 ]; then
1559 diff -u $testroot/stdout.expected $testroot/stdout
1561 test_done "$testroot" "$ret"
1564 test_rebase_rm_add_rm_file() {
1565 local testroot=`test_init rebase_rm_add_rm_file`
1567 (cd $testroot/repo && git checkout -q -b newbranch)
1568 (cd $testroot/repo && git rm -q beta)
1569 git_commit $testroot/repo -m "removing beta from newbranch"
1570 local orig_commit1=`git_show_head $testroot/repo`
1572 echo 'restored beta' > $testroot/repo/beta
1573 (cd $testroot/repo && git add beta)
1574 git_commit $testroot/repo -m "restoring beta on newbranch"
1575 local orig_commit2=`git_show_head $testroot/repo`
1577 (cd $testroot/repo && git rm -q beta)
1578 git_commit $testroot/repo -m "removing beta from newbranch again"
1579 local orig_commit3=`git_show_head $testroot/repo`
1581 (cd $testroot/repo && git checkout -q master)
1582 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1583 git_commit $testroot/repo -m "committing to zeta on master"
1584 local master_commit=`git_show_head $testroot/repo`
1586 got checkout $testroot/repo $testroot/wt > /dev/null
1587 ret=$?
1588 if [ $ret -ne 0 ]; then
1589 test_done "$testroot" "$ret"
1590 return 1
1593 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1595 # this would error out with 'got: file index is corrupt'
1596 (cd $testroot/wt && got status > /dev/null)
1597 ret=$?
1598 if [ $ret -ne 0 ]; then
1599 echo "got status command failed unexpectedly" >&2
1600 test_done "$testroot" "$ret"
1601 return 1
1604 (cd $testroot/repo && git checkout -q newbranch)
1605 local new_commit3=`git_show_head $testroot/repo`
1606 local new_commit2=`git_show_parent_commit $testroot/repo`
1607 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1609 (cd $testroot/repo && git checkout -q newbranch)
1611 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1612 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1613 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1614 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1615 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1616 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1618 echo "D beta" > $testroot/stdout.expected
1619 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1620 >> $testroot/stdout.expected
1621 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1622 echo "A beta" >> $testroot/stdout.expected
1623 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1624 >> $testroot/stdout.expected
1625 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1626 echo "D beta" >> $testroot/stdout.expected
1627 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1628 >> $testroot/stdout.expected
1629 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1630 echo "Switching work tree to refs/heads/newbranch" \
1631 >> $testroot/stdout.expected
1633 cmp -s $testroot/stdout.expected $testroot/stdout
1634 ret=$?
1635 if [ $ret -ne 0 ]; then
1636 diff -u $testroot/stdout.expected $testroot/stdout
1637 test_done "$testroot" "$ret"
1638 return 1
1641 (cd $testroot/wt && got status > $testroot/stdout)
1642 ret=$?
1643 if [ $ret -ne 0 ]; then
1644 echo "got status command failed unexpectedly" >&2
1645 test_done "$testroot" "$ret"
1646 return 1
1649 echo -n > $testroot/stdout.expected
1650 cmp -s $testroot/stdout.expected $testroot/stdout
1651 ret=$?
1652 if [ $ret -ne 0 ]; then
1653 diff -u $testroot/stdout.expected $testroot/stdout
1654 test_done "$testroot" "$ret"
1655 return 1
1658 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1659 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1660 echo "commit $new_commit2" >> $testroot/stdout.expected
1661 echo "commit $new_commit1" >> $testroot/stdout.expected
1662 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1663 cmp -s $testroot/stdout.expected $testroot/stdout
1664 ret=$?
1665 if [ $ret -ne 0 ]; then
1666 diff -u $testroot/stdout.expected $testroot/stdout
1668 test_done "$testroot" "$ret"
1671 test_rebase_resets_committer() {
1672 local testroot=`test_init rebase_resets_committer`
1673 local commit0=`git_show_head $testroot/repo`
1674 local commit0_author_time=`git_show_author_time $testroot/repo`
1675 local committer="Flan Luck <flan_luck@openbsd.org>"
1677 (cd $testroot/repo && git checkout -q -b newbranch)
1678 echo "modified delta on branch" > $testroot/repo/gamma/delta
1679 git_commit $testroot/repo -m "committing to delta on newbranch"
1681 echo "modified alpha on branch" > $testroot/repo/alpha
1682 git_commit $testroot/repo -m "committing more changes on newbranch"
1684 local orig_commit1=`git_show_parent_commit $testroot/repo`
1685 local orig_commit2=`git_show_head $testroot/repo`
1686 local orig_author_time2=`git_show_author_time $testroot/repo`
1688 (cd $testroot/repo && git checkout -q master)
1689 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1690 git_commit $testroot/repo -m "committing to zeta on master"
1691 local master_commit=`git_show_head $testroot/repo`
1693 got checkout $testroot/repo $testroot/wt > /dev/null
1694 ret=$?
1695 if [ $ret -ne 0 ]; then
1696 test_done "$testroot" "$ret"
1697 return 1
1700 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
1701 got rebase newbranch > $testroot/stdout)
1703 (cd $testroot/repo && git checkout -q newbranch)
1704 local new_commit1=`git_show_parent_commit $testroot/repo`
1705 local new_commit2=`git_show_head $testroot/repo`
1706 local new_author_time2=`git_show_author_time $testroot/repo`
1708 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1709 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1710 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1711 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1713 echo "G gamma/delta" >> $testroot/stdout.expected
1714 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1715 >> $testroot/stdout.expected
1716 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1717 echo "G alpha" >> $testroot/stdout.expected
1718 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1719 >> $testroot/stdout.expected
1720 echo ": committing more changes on newbranch" \
1721 >> $testroot/stdout.expected
1722 echo "Switching work tree to refs/heads/newbranch" \
1723 >> $testroot/stdout.expected
1725 cmp -s $testroot/stdout.expected $testroot/stdout
1726 ret=$?
1727 if [ $ret -ne 0 ]; then
1728 diff -u $testroot/stdout.expected $testroot/stdout
1729 test_done "$testroot" "$ret"
1730 return 1
1733 # Original commit only had one author
1734 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1735 egrep '^(from|via):' > $testroot/stdout)
1736 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1737 cmp -s $testroot/stdout.expected $testroot/stdout
1738 ret=$?
1739 if [ $ret -ne 0 ]; then
1740 diff -u $testroot/stdout.expected $testroot/stdout
1741 test_done "$testroot" "$ret"
1742 return 1
1745 # Rebased commit should have new committer name added
1746 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1747 egrep '^(from|via):' > $testroot/stdout)
1748 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1749 echo "via: $committer" >> $testroot/stdout.expected
1751 cmp -s $testroot/stdout.expected $testroot/stdout
1752 ret=$?
1753 if [ $ret -ne 0 ]; then
1754 diff -u $testroot/stdout.expected $testroot/stdout
1756 test_done "$testroot" "$ret"
1759 test_rebase_no_author_info() {
1760 local testroot=`test_init rebase_no_author_info`
1761 local commit0=`git_show_head $testroot/repo`
1762 local commit0_author_time=`git_show_author_time $testroot/repo`
1763 local committer="$GOT_AUTHOR"
1765 (cd $testroot/repo && git checkout -q -b newbranch)
1766 echo "modified delta on branch" > $testroot/repo/gamma/delta
1767 git_commit $testroot/repo -m "committing to delta on newbranch"
1769 echo "modified alpha on branch" > $testroot/repo/alpha
1770 git_commit $testroot/repo -m "committing more changes on newbranch"
1772 local orig_commit1=`git_show_parent_commit $testroot/repo`
1773 local orig_commit2=`git_show_head $testroot/repo`
1774 local orig_author_time2=`git_show_author_time $testroot/repo`
1776 (cd $testroot/repo && git checkout -q master)
1777 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1778 git_commit $testroot/repo -m "committing to zeta on master"
1779 local master_commit=`git_show_head $testroot/repo`
1781 got checkout $testroot/repo $testroot/wt > /dev/null
1782 ret=$?
1783 if [ $ret -ne 0 ]; then
1784 test_done "$testroot" "$ret"
1785 return 1
1788 # unset in a subshell to avoid affecting our environment
1789 (unset GOT_AUTHOR && cd $testroot/wt && \
1790 got rebase newbranch > $testroot/stdout)
1792 (cd $testroot/repo && git checkout -q newbranch)
1793 local new_commit1=`git_show_parent_commit $testroot/repo`
1794 local new_commit2=`git_show_head $testroot/repo`
1795 local new_author_time2=`git_show_author_time $testroot/repo`
1797 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1798 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1799 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1800 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1802 echo "G gamma/delta" >> $testroot/stdout.expected
1803 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1804 >> $testroot/stdout.expected
1805 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1806 echo "G alpha" >> $testroot/stdout.expected
1807 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1808 >> $testroot/stdout.expected
1809 echo ": committing more changes on newbranch" \
1810 >> $testroot/stdout.expected
1811 echo "Switching work tree to refs/heads/newbranch" \
1812 >> $testroot/stdout.expected
1814 cmp -s $testroot/stdout.expected $testroot/stdout
1815 ret=$?
1816 if [ $ret -ne 0 ]; then
1817 diff -u $testroot/stdout.expected $testroot/stdout
1818 test_done "$testroot" "$ret"
1819 return 1
1822 # Original commit only had one author
1823 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1824 egrep '^(from|via):' > $testroot/stdout)
1825 echo "from: $committer" > $testroot/stdout.expected
1826 cmp -s $testroot/stdout.expected $testroot/stdout
1827 ret=$?
1828 if [ $ret -ne 0 ]; then
1829 diff -u $testroot/stdout.expected $testroot/stdout
1830 test_done "$testroot" "$ret"
1831 return 1
1834 # Author info of rebased commit should match the original
1835 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1836 egrep '^(from|via):' > $testroot/stdout)
1837 echo "from: $committer" > $testroot/stdout.expected
1839 cmp -s $testroot/stdout.expected $testroot/stdout
1840 ret=$?
1841 if [ $ret -ne 0 ]; then
1842 diff -u $testroot/stdout.expected $testroot/stdout
1844 test_done "$testroot" "$ret"
1847 test_rebase_nonbranch() {
1848 local testroot=`test_init rebase_nonbranch`
1850 got ref -r $testroot/repo -c refs/heads/master \
1851 refs/remotes/origin/master >/dev/null
1853 got checkout -b master $testroot/repo $testroot/wt >/dev/null
1855 (cd $testroot/wt && got rebase origin/master > $testroot/stdout \
1856 2> $testroot/stderr)
1857 ret=$?
1858 if [ $ret -eq 0 ]; then
1859 echo "rebase succeeded unexpectedly" >&2
1860 test_done "$testroot" "1"
1861 return 1
1863 echo -n "got: will not rebase a branch which lives outside the " \
1864 > $testroot/stderr.expected
1865 echo '"refs/heads/" reference namespace' >> $testroot/stderr.expected
1866 cmp -s $testroot/stderr.expected $testroot/stderr
1867 ret=$?
1868 if [ $ret -ne 0 ]; then
1869 diff -u $testroot/stderr.expected $testroot/stderr
1871 test_done "$testroot" "$ret"
1874 test_rebase_umask() {
1875 local testroot=`test_init rebase_umask`
1876 local commit0=`git_show_head "$testroot/repo"`
1878 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1879 (cd "$testroot/wt" && got branch newbranch) >/dev/null
1881 echo "modified alpha on branch" >$testroot/wt/alpha
1882 (cd "$testroot/wt" && got commit -m 'modified alpha on newbranch') \
1883 >/dev/null
1885 (cd "$testroot/wt" && got update -b master) >/dev/null
1886 ret=$?
1887 if [ $ret -ne 0 ]; then
1888 echo "got update failed!" >&2
1889 test_done "$testroot" $ret
1890 return 1
1893 echo "modified beta on master" >$testroot/wt/beta
1894 (cd "$testroot/wt" && got commit -m 'modified beta on master') \
1895 >/dev/null
1896 (cd "$testroot/wt" && got update) >/dev/null
1898 # using a subshell to avoid clobbering global umask
1899 (umask 077 && cd "$testroot/wt" && got rebase newbranch) >/dev/null
1900 ret=$?
1901 if [ $ret -ne 0 ]; then
1902 echo "got rebase failed" >&2
1903 test_done "$testroot" $ret
1904 return 1
1907 ls -l "$testroot/wt/alpha" | grep -q ^-rw-------
1908 if [ $? -ne 0 ]; then
1909 echo "alpha is not 0600 after rebase" >&2
1910 ls -l "$testroot/wt/alpha" >&2
1911 test_done "$testroot" 1
1912 return 1
1915 test_done "$testroot" 0
1918 test_rebase_out_of_date2() {
1919 local testroot=`test_init rebase_out_of_date2`
1920 local commit0=`git_show_head $testroot/repo`
1921 local commit0_author_time=`git_show_author_time $testroot/repo`
1923 (cd $testroot/repo && git checkout -q -b newbranch)
1924 echo "modified delta on branch" > $testroot/repo/gamma/delta
1925 git_commit $testroot/repo -m "committing to delta on newbranch"
1927 local orig_commit1=`git_show_parent_commit $testroot/repo`
1928 local orig_commit2=`git_show_head $testroot/repo`
1929 local orig_author_time2=`git_show_author_time $testroot/repo`
1931 (cd $testroot/repo && git checkout -q master)
1932 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1933 git_commit $testroot/repo -m "committing to zeta on master"
1934 local master_commit=`git_show_head $testroot/repo`
1936 got checkout $testroot/repo $testroot/wt > /dev/null
1937 ret=$?
1938 if [ $ret -ne 0 ]; then
1939 test_done "$testroot" "$ret"
1940 return 1
1943 # Backdate the file alpha to an earlier version.
1944 # This sets the work tree's base commit ID back to $commit0,
1945 # which is out-of-date with respect to the master branch.
1946 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
1948 # Rebase into an out-of-date work tree should be refused.
1949 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1950 2> $testroot/stderr)
1951 ret=$?
1952 if [ $ret -eq 0 ]; then
1953 echo "rebase succeeded unexpectedly" >&2
1954 test_done "$testroot" "1"
1955 return 1
1957 echo -n > $testroot/stdout.expected
1958 echo -n "got: work tree must be updated before it can be used to " \
1959 > $testroot/stderr.expected
1960 echo "rebase a branch" >> $testroot/stderr.expected
1961 cmp -s $testroot/stderr.expected $testroot/stderr
1962 ret=$?
1963 if [ $ret -ne 0 ]; then
1964 diff -u $testroot/stderr.expected $testroot/stderr
1966 test_done "$testroot" "$ret"
1969 test_rebase_one_commit() {
1970 local testroot=`test_init rebase_one_commit`
1972 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1973 test_done "$testroot" 1
1974 return 1
1977 (cd $testroot/wt && got branch newbranch) >/dev/null
1979 echo "modified alpha on newbranch" >$testroot/wt/alpha
1980 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
1981 (cd $testroot/wt && got update) >/dev/null
1982 local commit=`git_show_branch_head $testroot/repo newbranch`
1984 echo -n '' > $testroot/stderr.expected
1986 (cd $testroot/wt && got rebase master >$testroot/stdout \
1987 2> $testroot/stderr)
1988 ret=$?
1989 if [ $ret -ne 0 ]; then
1990 echo "rebase comand failed unexpectedly" >&2
1991 diff -u $testroot/stderr.expected $testroot/stderr
1992 test_done "$testroot" "1"
1993 return 1
1996 echo "Forwarding refs/heads/master to commit $commit" \
1997 >$testroot/stdout.expected
1998 echo "Switching work tree to refs/heads/master" \
1999 >> $testroot/stdout.expected
2001 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2002 diff -u $testroot/stdout.expected $testroot/stdout
2003 test_done "$testroot" 1
2004 return 1
2007 test_done "$testroot" 0
2010 test_parseargs "$@"
2011 run_test test_rebase_basic
2012 run_test test_rebase_ancestry_check
2013 run_test test_rebase_continue
2014 run_test test_rebase_abort
2015 run_test test_rebase_no_op_change
2016 run_test test_rebase_in_progress
2017 run_test test_rebase_path_prefix
2018 run_test test_rebase_preserves_logmsg
2019 run_test test_rebase_no_commits_to_rebase
2020 run_test test_rebase_forward
2021 run_test test_rebase_forward_path_prefix
2022 run_test test_rebase_out_of_date
2023 run_test test_rebase_trims_empty_dir
2024 run_test test_rebase_delete_missing_file
2025 run_test test_rebase_rm_add_rm_file
2026 run_test test_rebase_resets_committer
2027 run_test test_rebase_no_author_info
2028 run_test test_rebase_nonbranch
2029 run_test test_rebase_umask
2030 run_test test_rebase_out_of_date2
2031 run_test test_rebase_one_commit