avoid needless use of STAILQ_FOREACH_SAFE, we are not removing elements here
[got.git] / regress / cmdline / rebase.sh
blob84c24828bea9475f7b0841d4f7fe0ffec5264646
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 git -C $testroot/repo 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 git -C $testroot/repo rm -q beta
30 echo "new file on branch" > $testroot/repo/epsilon/new
31 git -C $testroot/repo 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 git -C $testroot/repo 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 master > $testroot/stdout \
51 2> $testroot/stderr)
52 echo -n "got: cannot rebase refs/heads/master onto itself: " \
53 > $testroot/stderr.expected
54 echo "update -b required" >> $testroot/stderr.expected
55 cmp -s $testroot/stderr.expected $testroot/stderr
56 ret=$?
57 if [ $ret -ne 0 ]; then
58 diff -u $testroot/stderr.expected $testroot/stderr
59 test_done "$testroot" "$ret"
60 return 1
63 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
65 git -C $testroot/repo checkout -q newbranch
66 local new_commit1=`git_show_parent_commit $testroot/repo`
67 local new_commit2=`git_show_head $testroot/repo`
68 local new_author_time2=`git_show_author_time $testroot/repo`
70 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
71 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
72 local short_new_commit1=`trim_obj_id 12 $new_commit1`
73 local short_new_commit2=`trim_obj_id 12 $new_commit2`
75 echo "G gamma/delta" >> $testroot/stdout.expected
76 echo -n "$short_orig_commit1 -> $short_new_commit1" \
77 >> $testroot/stdout.expected
78 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
79 echo "G alpha" >> $testroot/stdout.expected
80 echo "D beta" >> $testroot/stdout.expected
81 echo "A epsilon/new" >> $testroot/stdout.expected
82 echo -n "$short_orig_commit2 -> $short_new_commit2" \
83 >> $testroot/stdout.expected
84 echo ": committing more changes on newbranch" \
85 >> $testroot/stdout.expected
86 echo "Switching work tree to refs/heads/newbranch" \
87 >> $testroot/stdout.expected
89 cmp -s $testroot/stdout.expected $testroot/stdout
90 ret=$?
91 if [ $ret -ne 0 ]; then
92 diff -u $testroot/stdout.expected $testroot/stdout
93 test_done "$testroot" "$ret"
94 return 1
97 echo "modified delta on branch" > $testroot/content.expected
98 cat $testroot/wt/gamma/delta > $testroot/content
99 cmp -s $testroot/content.expected $testroot/content
100 ret=$?
101 if [ $ret -ne 0 ]; then
102 diff -u $testroot/content.expected $testroot/content
103 test_done "$testroot" "$ret"
104 return 1
107 echo "modified alpha on branch" > $testroot/content.expected
108 cat $testroot/wt/alpha > $testroot/content
109 cmp -s $testroot/content.expected $testroot/content
110 ret=$?
111 if [ $ret -ne 0 ]; then
112 diff -u $testroot/content.expected $testroot/content
113 test_done "$testroot" "$ret"
114 return 1
117 if [ -e $testroot/wt/beta ]; then
118 echo "removed file beta still exists on disk" >&2
119 test_done "$testroot" "1"
120 return 1
123 echo "new file on branch" > $testroot/content.expected
124 cat $testroot/wt/epsilon/new > $testroot/content
125 cmp -s $testroot/content.expected $testroot/content
126 ret=$?
127 if [ $ret -ne 0 ]; then
128 diff -u $testroot/content.expected $testroot/content
129 test_done "$testroot" "$ret"
130 return 1
133 (cd $testroot/wt && got status > $testroot/stdout)
135 echo -n > $testroot/stdout.expected
136 cmp -s $testroot/stdout.expected $testroot/stdout
137 ret=$?
138 if [ $ret -ne 0 ]; then
139 diff -u $testroot/stdout.expected $testroot/stdout
140 test_done "$testroot" "$ret"
141 return 1
144 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
145 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
146 echo "commit $new_commit1" >> $testroot/stdout.expected
147 echo "commit $master_commit (master)" >> $testroot/stdout.expected
148 cmp -s $testroot/stdout.expected $testroot/stdout
149 ret=$?
150 if [ $ret -ne 0 ]; then
151 diff -u $testroot/stdout.expected $testroot/stdout
152 test_done "$testroot" "$ret"
153 return 1
156 (cd $testroot/wt && got update > $testroot/stdout)
158 echo 'Already up-to-date' > $testroot/stdout.expected
159 cmp -s $testroot/stdout.expected $testroot/stdout
160 ret=$?
161 if [ $ret -ne 0 ]; then
162 diff -u $testroot/stdout.expected $testroot/stdout
163 test_done "$testroot" "$ret"
164 return 1
167 # We should have a backup of old commits
168 (cd $testroot/repo && got rebase -l > $testroot/stdout)
169 d_orig2=`date -u -r $orig_author_time2 +"%a %b %e %X %Y UTC"`
170 d_new2=`date -u -r $new_author_time2 +"%F"`
171 d_0=`date -u -r $commit0_author_time +"%F"`
172 cat > $testroot/stdout.expected <<EOF
173 -----------------------------------------------
174 commit $orig_commit2 (formerly newbranch)
175 from: $GOT_AUTHOR
176 date: $d_orig2
178 committing more changes on newbranch
180 has become commit $new_commit2 (newbranch)
181 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
182 history forked at $commit0
183 $d_0 $GOT_AUTHOR_11 adding the test tree
185 cmp -s $testroot/stdout.expected $testroot/stdout
186 ret=$?
187 if [ $ret -ne 0 ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$ret"
190 return 1
193 # Asking for backups of a branch which has none should yield an error
194 (cd $testroot/repo && got rebase -l master \
195 > $testroot/stdout 2> $testroot/stderr)
196 echo -n > $testroot/stdout.expected
197 echo "got: refs/got/backup/rebase/master/: no such reference found" \
198 > $testroot/stderr.expected
199 cmp -s $testroot/stdout.expected $testroot/stdout
200 ret=$?
201 if [ $ret -ne 0 ]; then
202 diff -u $testroot/stdout.expected $testroot/stdout
203 test_done "$testroot" "$ret"
204 return 1
206 cmp -s $testroot/stderr.expected $testroot/stderr
207 ret=$?
208 if [ $ret -ne 0 ]; then
209 diff -u $testroot/stderr.expected $testroot/stderr
210 test_done "$testroot" "$ret"
211 return 1
214 # Delete all backup refs
215 (cd $testroot/repo && got rebase -X \
216 > $testroot/stdout 2> $testroot/stderr)
217 echo -n "Deleted refs/got/backup/rebase/newbranch/$new_commit2: " \
218 > $testroot/stdout.expected
219 echo "$orig_commit2" >> $testroot/stdout.expected
220 echo -n > $testroot/stderr.expected
221 cmp -s $testroot/stdout.expected $testroot/stdout
222 ret=$?
223 if [ $ret -ne 0 ]; then
224 diff -u $testroot/stdout.expected $testroot/stdout
225 test_done "$testroot" "$ret"
226 return 1
228 cmp -s $testroot/stderr.expected $testroot/stderr
229 ret=$?
230 if [ $ret -ne 0 ]; then
231 diff -u $testroot/stderr.expected $testroot/stderr
232 test_done "$testroot" "$ret"
233 return 1
236 (cd $testroot/repo && got rebase -l > $testroot/stdout)
237 echo -n > $testroot/stdout.expected
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret=$?
240 if [ $ret -ne 0 ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
243 test_done "$testroot" "$ret"
246 test_rebase_ancestry_check() {
247 local testroot=`test_init rebase_ancestry_check`
249 got checkout $testroot/repo $testroot/wt > /dev/null
250 ret=$?
251 if [ $ret -ne 0 ]; then
252 test_done "$testroot" "$ret"
253 return 1
256 git -C $testroot/repo checkout -q -b newbranch
257 echo "modified delta on branch" > $testroot/repo/gamma/delta
258 git_commit $testroot/repo -m "committing to delta on newbranch"
259 local newbranch_id=`git_show_head $testroot/repo`
261 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
262 2> $testroot/stderr)
264 echo "refs/heads/newbranch is already based on refs/heads/master" \
265 > $testroot/stdout.expected
266 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
267 >> $testroot/stdout.expected
268 echo "U gamma/delta" >> $testroot/stdout.expected
269 echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
270 >> $testroot/stdout.expected
271 cmp -s $testroot/stdout.expected $testroot/stdout
272 ret=$?
273 if [ $ret -ne 0 ]; then
274 diff -u $testroot/stdout.expected $testroot/stdout
275 test_done "$testroot" "$ret"
276 return 1
279 echo -n > $testroot/stderr.expected
280 cmp -s $testroot/stderr.expected $testroot/stderr
281 ret=$?
282 if [ $ret -ne 0 ]; then
283 diff -u $testroot/stderr.expected $testroot/stderr
285 test_done "$testroot" "$ret"
288 test_rebase_continue() {
289 local testroot=`test_init rebase_continue`
290 local init_commit=`git_show_head $testroot/repo`
292 git -C $testroot/repo checkout -q -b newbranch
293 echo "modified alpha on branch" > $testroot/repo/alpha
294 git_commit $testroot/repo -m "committing to alpha on newbranch"
295 local orig_commit1=`git_show_head $testroot/repo`
296 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
298 git -C $testroot/repo checkout -q master
299 echo "modified alpha on master" > $testroot/repo/alpha
300 git_commit $testroot/repo -m "committing to alpha on master"
301 local master_commit=`git_show_head $testroot/repo`
303 got checkout $testroot/repo $testroot/wt > /dev/null
304 ret=$?
305 if [ $ret -ne 0 ]; then
306 test_done "$testroot" "$ret"
307 return 1
310 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
311 2> $testroot/stderr)
313 echo "C alpha" > $testroot/stdout.expected
314 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
315 echo -n "$short_orig_commit1 -> merge conflict" \
316 >> $testroot/stdout.expected
317 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
318 cmp -s $testroot/stdout.expected $testroot/stdout
319 ret=$?
320 if [ $ret -ne 0 ]; then
321 diff -u $testroot/stdout.expected $testroot/stdout
322 test_done "$testroot" "$ret"
323 return 1
326 echo "got: conflicts must be resolved before rebasing can continue" \
327 > $testroot/stderr.expected
328 cmp -s $testroot/stderr.expected $testroot/stderr
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 diff -u $testroot/stderr.expected $testroot/stderr
332 test_done "$testroot" "$ret"
333 return 1
336 echo '<<<<<<<' > $testroot/content.expected
337 echo "modified alpha on master" >> $testroot/content.expected
338 echo "||||||| 3-way merge base: commit $init_commit" \
339 >> $testroot/content.expected
340 echo "alpha" >> $testroot/content.expected
341 echo "=======" >> $testroot/content.expected
342 echo "modified alpha on branch" >> $testroot/content.expected
343 echo ">>>>>>> merged change: commit $orig_commit1" \
344 >> $testroot/content.expected
345 cat $testroot/wt/alpha > $testroot/content
346 cmp -s $testroot/content.expected $testroot/content
347 ret=$?
348 if [ $ret -ne 0 ]; then
349 diff -u $testroot/content.expected $testroot/content
350 test_done "$testroot" "$ret"
351 return 1
354 (cd $testroot/wt && got status > $testroot/stdout)
356 cat > $testroot/stdout.expected <<EOF
357 C alpha
358 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
360 cmp -s $testroot/stdout.expected $testroot/stdout
361 ret=$?
362 if [ $ret -ne 0 ]; then
363 diff -u $testroot/stdout.expected $testroot/stdout
364 test_done "$testroot" "$ret"
365 return 1
368 # resolve the conflict
369 echo "modified alpha on branch and master" > $testroot/wt/alpha
371 # test interaction of 'got stage' and rebase -c
372 (cd $testroot/wt && got stage alpha > /dev/null)
373 (cd $testroot/wt && got rebase -c > $testroot/stdout \
374 2> $testroot/stderr)
375 ret=$?
376 if [ $ret -eq 0 ]; then
377 echo "rebase succeeded unexpectedly" >&2
378 test_done "$testroot" "1"
379 return 1
381 echo -n "got: work tree contains files with staged changes; " \
382 > $testroot/stderr.expected
383 echo "these changes must be committed or unstaged first" \
384 >> $testroot/stderr.expected
385 cmp -s $testroot/stderr.expected $testroot/stderr
386 ret=$?
387 if [ $ret -ne 0 ]; then
388 diff -u $testroot/stderr.expected $testroot/stderr
389 test_done "$testroot" "$ret"
390 return 1
393 (cd $testroot/wt && got unstage alpha > /dev/null)
394 (cd $testroot/wt && got rebase -c > $testroot/stdout)
396 git -C $testroot/repo checkout -q newbranch
397 local new_commit1=`git_show_head $testroot/repo`
398 local short_new_commit1=`trim_obj_id 12 $new_commit1`
400 echo -n "$short_orig_commit1 -> $short_new_commit1" \
401 > $testroot/stdout.expected
402 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
403 echo "Switching work tree to refs/heads/newbranch" \
404 >> $testroot/stdout.expected
406 cmp -s $testroot/stdout.expected $testroot/stdout
407 ret=$?
408 if [ $ret -ne 0 ]; then
409 diff -u $testroot/stdout.expected $testroot/stdout
410 test_done "$testroot" "$ret"
411 return 1
415 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
416 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
417 echo "commit $master_commit (master)" >> $testroot/stdout.expected
418 cmp -s $testroot/stdout.expected $testroot/stdout
419 ret=$?
420 if [ $ret -ne 0 ]; then
421 diff -u $testroot/stdout.expected $testroot/stdout
423 test_done "$testroot" "$ret"
426 test_rebase_abort() {
427 local testroot=`test_init rebase_abort`
429 local init_commit=`git_show_head $testroot/repo`
431 git -C $testroot/repo checkout -q -b newbranch
432 echo "modified beta on branch" > $testroot/repo/beta
433 git_commit $testroot/repo -m "committing to beta on newbranch"
434 local orig_commit1=`git_show_head $testroot/repo`
435 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
437 echo "modified alpha on branch" > $testroot/repo/alpha
438 echo "new file on branch" > $testroot/repo/epsilon/new
439 git -C $testroot/repo add epsilon/new
440 git_commit $testroot/repo \
441 -m "changing alpha and adding new on newbranch"
442 local orig_commit2=`git_show_head $testroot/repo`
443 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
445 git -C $testroot/repo checkout -q master
446 echo "modified alpha on master" > $testroot/repo/alpha
447 git_commit $testroot/repo -m "committing to alpha on master"
448 local master_commit=`git_show_head $testroot/repo`
450 got checkout $testroot/repo $testroot/wt > /dev/null
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 test_done "$testroot" "$ret"
454 return 1
457 # unrelated unversioned file in work tree
458 touch $testroot/wt/unversioned-file
460 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
461 2> $testroot/stderr)
463 new_commit1=$(cd $testroot/wt && got info beta | \
464 grep '^based on commit:' | cut -d' ' -f4)
465 local short_new_commit1=`trim_obj_id 12 $new_commit1`
467 echo "G beta" > $testroot/stdout.expected
468 echo -n "$short_orig_commit1 -> $short_new_commit1" \
469 >> $testroot/stdout.expected
470 echo ": committing to beta on newbranch" >> $testroot/stdout.expected
471 echo "C alpha" >> $testroot/stdout.expected
472 echo "A epsilon/new" >> $testroot/stdout.expected
473 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
474 echo -n "$short_orig_commit2 -> merge conflict" \
475 >> $testroot/stdout.expected
476 echo ": changing alpha and adding new on newbranch" \
477 >> $testroot/stdout.expected
478 cmp -s $testroot/stdout.expected $testroot/stdout
479 ret=$?
480 if [ $ret -ne 0 ]; then
481 diff -u $testroot/stdout.expected $testroot/stdout
482 test_done "$testroot" "$ret"
483 return 1
486 echo "got: conflicts must be resolved before rebasing can continue" \
487 > $testroot/stderr.expected
488 cmp -s $testroot/stderr.expected $testroot/stderr
489 ret=$?
490 if [ $ret -ne 0 ]; then
491 diff -u $testroot/stderr.expected $testroot/stderr
492 test_done "$testroot" "$ret"
493 return 1
496 echo '<<<<<<<' > $testroot/content.expected
497 echo "modified alpha on master" >> $testroot/content.expected
498 echo "||||||| 3-way merge base: commit $orig_commit1" \
499 >> $testroot/content.expected
500 echo "alpha" >> $testroot/content.expected
501 echo "=======" >> $testroot/content.expected
502 echo "modified alpha on branch" >> $testroot/content.expected
503 echo ">>>>>>> merged change: commit $orig_commit2" \
504 >> $testroot/content.expected
505 cat $testroot/wt/alpha > $testroot/content
506 cmp -s $testroot/content.expected $testroot/content
507 ret=$?
508 if [ $ret -ne 0 ]; then
509 diff -u $testroot/content.expected $testroot/content
510 test_done "$testroot" "$ret"
511 return 1
514 # unrelated file in work tree added during conflict resolution
515 touch $testroot/wt/added-file
516 (cd $testroot/wt && got add added-file > /dev/null)
518 (cd $testroot/wt && got status > $testroot/stdout)
520 cat > $testroot/stdout.expected <<EOF
521 A added-file
522 C alpha
523 A epsilon/new
524 ? unversioned-file
525 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
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 test_done "$testroot" "$ret"
532 return 1
535 (cd $testroot/wt && got rebase -a > $testroot/stdout)
537 git -C $testroot/repo checkout -q newbranch
539 echo "Switching work tree to refs/heads/master" \
540 > $testroot/stdout.expected
541 echo 'R added-file' >> $testroot/stdout.expected
542 echo 'R alpha' >> $testroot/stdout.expected
543 echo 'R epsilon/new' >> $testroot/stdout.expected
544 echo 'G added-file' >> $testroot/stdout.expected
545 echo 'U beta' >> $testroot/stdout.expected
546 echo "Rebase of refs/heads/newbranch aborted" \
547 >> $testroot/stdout.expected
549 cmp -s $testroot/stdout.expected $testroot/stdout
550 ret=$?
551 if [ $ret -ne 0 ]; then
552 diff -u $testroot/stdout.expected $testroot/stdout
553 test_done "$testroot" "$ret"
554 return 1
557 echo "modified alpha on master" > $testroot/content.expected
558 cat $testroot/wt/alpha > $testroot/content
559 cmp -s $testroot/content.expected $testroot/content
560 ret=$?
561 if [ $ret -ne 0 ]; then
562 diff -u $testroot/content.expected $testroot/content
563 test_done "$testroot" "$ret"
564 return 1
567 (cd $testroot/wt && got log -l3 -c newbranch \
568 | grep ^commit > $testroot/stdout)
569 echo "commit $orig_commit2 (newbranch)" > $testroot/stdout.expected
570 echo "commit $orig_commit1" >> $testroot/stdout.expected
571 echo "commit $init_commit" >> $testroot/stdout.expected
572 cmp -s $testroot/stdout.expected $testroot/stdout
573 ret=$?
574 if [ $ret -ne 0 ]; then
575 diff -u $testroot/stdout.expected $testroot/stdout
576 test_done "$testroot" "$ret"
577 return 1
580 (cd $testroot/wt && got info .| \
581 grep '^based on commit:' | sort | uniq > $testroot/stdout)
582 echo "based on commit: $master_commit" > $testroot/stdout.expected
583 cmp -s $testroot/stdout.expected $testroot/stdout
584 ret=$?
585 if [ $ret -ne 0 ]; then
586 diff -u $testroot/stdout.expected $testroot/stdout
587 test_done "$testroot" "$ret"
588 return 1
591 (cd $testroot/wt && got status > $testroot/stdout)
592 echo "? added-file" > $testroot/stdout.expected
593 echo "? unversioned-file" >> $testroot/stdout.expected
594 cmp -s $testroot/stdout.expected $testroot/stdout
595 ret=$?
596 if [ $ret -ne 0 ]; then
597 diff -u $testroot/stdout.expected $testroot/stdout
598 test_done "$testroot" "$ret"
599 return 1
602 cat $testroot/wt/beta > $testroot/content
603 echo 'beta' > $testroot/content.expected
604 cmp -s $testroot/content.expected $testroot/content
605 ret=$?
606 if [ $ret -ne 0 ]; then
607 diff -u $testroot/content.expected $testroot/content
608 test_done "$testroot" "$ret"
609 return 1
612 # A subsequent update should be a no-op.
613 (cd $testroot/wt && got update > $testroot/stdout)
614 echo 'Already up-to-date' > $testroot/stdout.expected
615 cmp -s $testroot/stdout.expected $testroot/stdout
616 ret=$?
617 if [ $ret -ne 0 ]; then
618 diff -u $testroot/stdout.expected $testroot/stdout
620 test_done "$testroot" "$ret"
623 test_rebase_no_op_change() {
624 local testroot=`test_init rebase_no_op_change`
625 local init_commit=`git_show_head $testroot/repo`
627 git -C $testroot/repo checkout -q -b newbranch
628 echo "modified alpha on branch" > $testroot/repo/alpha
629 git_commit $testroot/repo -m "committing to alpha on newbranch"
630 local orig_commit1=`git_show_head $testroot/repo`
631 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
633 git -C $testroot/repo checkout -q master
634 echo "modified alpha on master" > $testroot/repo/alpha
635 git_commit $testroot/repo -m "committing to alpha on master"
636 local master_commit=`git_show_head $testroot/repo`
638 got checkout $testroot/repo $testroot/wt > /dev/null
639 ret=$?
640 if [ $ret -ne 0 ]; then
641 test_done "$testroot" "$ret"
642 return 1
645 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
646 2> $testroot/stderr)
648 echo "C alpha" > $testroot/stdout.expected
649 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
650 echo -n "$short_orig_commit1 -> merge conflict" \
651 >> $testroot/stdout.expected
652 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
653 cmp -s $testroot/stdout.expected $testroot/stdout
654 ret=$?
655 if [ $ret -ne 0 ]; then
656 diff -u $testroot/stdout.expected $testroot/stdout
657 test_done "$testroot" "$ret"
658 return 1
661 echo "got: conflicts must be resolved before rebasing can continue" \
662 > $testroot/stderr.expected
663 cmp -s $testroot/stderr.expected $testroot/stderr
664 ret=$?
665 if [ $ret -ne 0 ]; then
666 diff -u $testroot/stderr.expected $testroot/stderr
667 test_done "$testroot" "$ret"
668 return 1
671 echo '<<<<<<<' > $testroot/content.expected
672 echo "modified alpha on master" >> $testroot/content.expected
673 echo "||||||| 3-way merge base: commit $init_commit" \
674 >> $testroot/content.expected
675 echo "alpha" >> $testroot/content.expected
676 echo "=======" >> $testroot/content.expected
677 echo "modified alpha on branch" >> $testroot/content.expected
678 echo ">>>>>>> merged change: commit $orig_commit1" \
679 >> $testroot/content.expected
680 cat $testroot/wt/alpha > $testroot/content
681 cmp -s $testroot/content.expected $testroot/content
682 ret=$?
683 if [ $ret -ne 0 ]; then
684 diff -u $testroot/content.expected $testroot/content
685 test_done "$testroot" "$ret"
686 return 1
689 (cd $testroot/wt && got status > $testroot/stdout)
691 cat > $testroot/stdout.expected <<EOF
692 C alpha
693 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
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
703 # resolve the conflict
704 echo "modified alpha on master" > $testroot/wt/alpha
706 (cd $testroot/wt && got rebase -c > $testroot/stdout)
708 git -C $testroot/repo checkout -q newbranch
709 local new_commit1=`git_show_head $testroot/repo`
711 echo -n "$short_orig_commit1 -> no-op change" \
712 > $testroot/stdout.expected
713 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
714 echo "Switching work tree to refs/heads/newbranch" \
715 >> $testroot/stdout.expected
717 cmp -s $testroot/stdout.expected $testroot/stdout
718 ret=$?
719 if [ $ret -ne 0 ]; then
720 diff -u $testroot/stdout.expected $testroot/stdout
721 test_done "$testroot" "$ret"
722 return 1
726 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
727 echo "commit $master_commit (master, newbranch)" \
728 > $testroot/stdout.expected
729 echo "commit $init_commit" >> $testroot/stdout.expected
730 cmp -s $testroot/stdout.expected $testroot/stdout
731 ret=$?
732 if [ $ret -ne 0 ]; then
733 diff -u $testroot/stdout.expected $testroot/stdout
735 test_done "$testroot" "$ret"
738 test_rebase_in_progress() {
739 local testroot=`test_init rebase_in_progress`
740 local init_commit=`git_show_head $testroot/repo`
742 git -C $testroot/repo checkout -q -b newbranch
743 echo "modified alpha on branch" > $testroot/repo/alpha
744 git_commit $testroot/repo -m "committing to alpha on newbranch"
745 local orig_commit1=`git_show_head $testroot/repo`
746 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
748 git -C $testroot/repo checkout -q master
749 echo "modified alpha on master" > $testroot/repo/alpha
750 git_commit $testroot/repo -m "committing to alpha on master"
751 local master_commit=`git_show_head $testroot/repo`
753 got checkout $testroot/repo $testroot/wt > /dev/null
754 ret=$?
755 if [ $ret -ne 0 ]; then
756 test_done "$testroot" "$ret"
757 return 1
760 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
761 2> $testroot/stderr)
763 echo "C alpha" > $testroot/stdout.expected
764 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
765 echo -n "$short_orig_commit1 -> merge conflict" \
766 >> $testroot/stdout.expected
767 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
768 cmp -s $testroot/stdout.expected $testroot/stdout
769 ret=$?
770 if [ $ret -ne 0 ]; then
771 diff -u $testroot/stdout.expected $testroot/stdout
772 test_done "$testroot" "$ret"
773 return 1
776 echo "got: conflicts must be resolved before rebasing can continue" \
777 > $testroot/stderr.expected
778 cmp -s $testroot/stderr.expected $testroot/stderr
779 ret=$?
780 if [ $ret -ne 0 ]; then
781 diff -u $testroot/stderr.expected $testroot/stderr
782 test_done "$testroot" "$ret"
783 return 1
786 echo '<<<<<<<' > $testroot/content.expected
787 echo "modified alpha on master" >> $testroot/content.expected
788 echo "||||||| 3-way merge base: commit $init_commit" \
789 >> $testroot/content.expected
790 echo "alpha" >> $testroot/content.expected
791 echo "=======" >> $testroot/content.expected
792 echo "modified alpha on branch" >> $testroot/content.expected
793 echo ">>>>>>> merged change: commit $orig_commit1" \
794 >> $testroot/content.expected
795 cat $testroot/wt/alpha > $testroot/content
796 cmp -s $testroot/content.expected $testroot/content
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 diff -u $testroot/content.expected $testroot/content
800 test_done "$testroot" "$ret"
801 return 1
804 (cd $testroot/wt && got status > $testroot/stdout)
806 cat > $testroot/stdout.expected <<EOF
807 C alpha
808 Work tree is rebasing refs/heads/newbranch onto refs/heads/master
810 cmp -s $testroot/stdout.expected $testroot/stdout
811 ret=$?
812 if [ $ret -ne 0 ]; then
813 diff -u $testroot/stdout.expected $testroot/stdout
814 test_done "$testroot" "$ret"
815 return 1
818 for cmd in update commit; do
819 (cd $testroot/wt && got $cmd > $testroot/stdout \
820 2> $testroot/stderr)
822 echo -n > $testroot/stdout.expected
823 cmp -s $testroot/stdout.expected $testroot/stdout
824 ret=$?
825 if [ $ret -ne 0 ]; then
826 diff -u $testroot/stdout.expected $testroot/stdout
827 test_done "$testroot" "$ret"
828 return 1
831 echo -n "got: a rebase operation is in progress in this " \
832 > $testroot/stderr.expected
833 echo "work tree and must be continued or aborted first" \
834 >> $testroot/stderr.expected
835 cmp -s $testroot/stderr.expected $testroot/stderr
836 ret=$?
837 if [ $ret -ne 0 ]; then
838 diff -u $testroot/stderr.expected $testroot/stderr
839 test_done "$testroot" "$ret"
840 return 1
842 done
844 test_done "$testroot" "$ret"
847 test_rebase_path_prefix() {
848 local testroot=`test_init rebase_path_prefix`
850 git -C $testroot/repo checkout -q -b newbranch
851 echo "modified delta on branch" > $testroot/repo/gamma/delta
852 git_commit $testroot/repo -m "committing to delta on newbranch"
854 local orig_commit1=`git_show_parent_commit $testroot/repo`
855 local orig_commit2=`git_show_head $testroot/repo`
857 git -C $testroot/repo checkout -q master
858 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
859 git_commit $testroot/repo -m "committing to zeta on master"
860 local master_commit=`git_show_head $testroot/repo`
862 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
863 ret=$?
864 if [ $ret -ne 0 ]; then
865 test_done "$testroot" "$ret"
866 return 1
869 (cd $testroot/wt && got rebase newbranch \
870 > $testroot/stdout 2> $testroot/stderr)
872 echo -n > $testroot/stdout.expected
873 cmp -s $testroot/stdout.expected $testroot/stdout
874 ret=$?
875 if [ $ret -ne 0 ]; then
876 diff -u $testroot/stdout.expected $testroot/stdout
877 test_done "$testroot" "$ret"
878 return 1
881 echo -n "got: cannot rebase branch which contains changes outside " \
882 > $testroot/stderr.expected
883 echo "of this work tree's path prefix" >> $testroot/stderr.expected
884 cmp -s $testroot/stderr.expected $testroot/stderr
885 ret=$?
886 if [ $ret -ne 0 ]; then
887 diff -u $testroot/stderr.expected $testroot/stderr
888 test_done "$testroot" "$ret"
889 return 1
892 # rebase should succeed when using a complete work tree
893 got checkout $testroot/repo $testroot/wt2 > /dev/null
894 ret=$?
895 if [ $ret -ne 0 ]; then
896 test_done "$testroot" "$ret"
897 return 1
900 (cd $testroot/wt2 && got rebase newbranch \
901 > $testroot/stdout 2> $testroot/stderr)
903 git -C $testroot/repo checkout -q newbranch
904 local new_commit1=`git_show_parent_commit $testroot/repo`
905 local new_commit2=`git_show_head $testroot/repo`
907 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
908 local short_new_commit2=`trim_obj_id 12 $new_commit2`
910 echo "G gamma/delta" > $testroot/stdout.expected
911 echo -n "$short_orig_commit2 -> $short_new_commit2" \
912 >> $testroot/stdout.expected
913 echo ": committing to delta on newbranch" \
914 >> $testroot/stdout.expected
915 echo "Switching work tree to refs/heads/newbranch" \
916 >> $testroot/stdout.expected
918 cmp -s $testroot/stdout.expected $testroot/stdout
919 ret=$?
920 if [ $ret -ne 0 ]; then
921 diff -u $testroot/stdout.expected $testroot/stdout
922 test_done "$testroot" "$ret"
923 return 1
926 # the first work tree should remain usable
927 (cd $testroot/wt && got update -b master \
928 > $testroot/stdout 2> $testroot/stderr)
929 ret=$?
930 if [ $ret -ne 0 ]; then
931 echo "update failed unexpectedly" >&2
932 test_done "$testroot" "1"
933 return 1
936 echo 'Already up-to-date' > $testroot/stdout.expected
937 cmp -s $testroot/stdout.expected $testroot/stdout
938 ret=$?
939 if [ $ret -ne 0 ]; then
940 diff -u $testroot/stdout.expected $testroot/stdout
942 test_done "$testroot" "$ret"
945 test_rebase_preserves_logmsg() {
946 local testroot=`test_init rebase_preserves_logmsg`
948 git -C $testroot/repo checkout -q -b newbranch
949 echo "modified delta on branch" > $testroot/repo/gamma/delta
950 git_commit $testroot/repo -m "modified delta on newbranch"
952 echo "modified alpha on branch" > $testroot/repo/alpha
953 git_commit $testroot/repo -m "modified alpha on newbranch"
955 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
956 > $testroot/log.expected)
958 local orig_commit1=`git_show_parent_commit $testroot/repo`
959 local orig_commit2=`git_show_head $testroot/repo`
961 git -C $testroot/repo checkout -q master
962 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
963 git_commit $testroot/repo -m "committing to zeta on master"
964 local master_commit=`git_show_head $testroot/repo`
966 got checkout $testroot/repo $testroot/wt > /dev/null
967 ret=$?
968 if [ $ret -ne 0 ]; then
969 test_done "$testroot" "$ret"
970 return 1
973 (cd $testroot/wt && got rebase newbranch > /dev/null \
974 2> $testroot/stderr)
976 git -C $testroot/repo checkout -q newbranch
977 local new_commit1=`git_show_parent_commit $testroot/repo`
978 local new_commit2=`git_show_head $testroot/repo`
980 echo -n > $testroot/stderr.expected
981 cmp -s $testroot/stderr.expected $testroot/stderr
982 ret=$?
983 if [ $ret -ne 0 ]; then
984 diff -u $testroot/stderr.expected $testroot/stderr
985 test_done "$testroot" "$ret"
986 return 1
989 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
990 > $testroot/log)
991 ed -s $testroot/log.expected <<-EOF
992 ,s/$orig_commit1/$new_commit1/
993 ,s/$orig_commit2/$new_commit2/
996 cmp -s $testroot/log.expected $testroot/log
997 ret=$?
998 if [ $ret -ne 0 ]; then
999 diff -u $testroot/log.expected $testroot/log
1002 test_done "$testroot" "$ret"
1005 test_rebase_no_commits_to_rebase() {
1006 local testroot=`test_init rebase_no_commits_to_rebase`
1008 got checkout $testroot/repo $testroot/wt > /dev/null
1009 ret=$?
1010 if [ $ret -ne 0 ]; then
1011 test_done "$testroot" "$ret"
1012 return 1
1015 # Create an unrelated branch with 'got import'.
1016 mkdir -p $testroot/newtree
1017 echo "new file" > $testroot/newtree/newfile
1018 got import -m new -b newbranch -r $testroot/repo \
1019 $testroot/newtree > /dev/null
1021 echo "modified alpha on master" > $testroot/wt/alpha
1022 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
1023 > /dev/null)
1024 (cd $testroot/wt && got update > /dev/null)
1026 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1027 2> $testroot/stderr)
1029 echo -n "got: specified branch shares no common ancestry " \
1030 > $testroot/stderr.expected
1031 echo "with work tree's branch" >> $testroot/stderr.expected
1032 cmp -s $testroot/stderr.expected $testroot/stderr
1033 ret=$?
1034 if [ $ret -ne 0 ]; then
1035 diff -u $testroot/stderr.expected $testroot/stderr
1036 test_done "$testroot" "$ret"
1037 return 1
1040 echo -n > $testroot/stdout.expected
1041 cmp -s $testroot/stdout.expected $testroot/stdout
1042 ret=$?
1043 if [ $ret -ne 0 ]; then
1044 diff -u $testroot/stdout.expected $testroot/stdout
1045 test_done "$testroot" "$ret"
1046 return 1
1049 (cd $testroot/wt && got update > $testroot/stdout)
1050 echo "Already up-to-date" > $testroot/stdout.expected
1051 cmp -s $testroot/stdout.expected $testroot/stdout
1052 ret=$?
1053 if [ $ret -ne 0 ]; then
1054 diff -u $testroot/stdout.expected $testroot/stdout
1056 test_done "$testroot" "$ret"
1059 test_rebase_forward() {
1060 local testroot=`test_init rebase_forward`
1061 local commit0=`git_show_head $testroot/repo`
1063 got checkout $testroot/repo $testroot/wt > /dev/null
1064 ret=$?
1065 if [ $ret -ne 0 ]; then
1066 test_done "$testroot" "$ret"
1067 return 1
1070 echo "change alpha 1" > $testroot/wt/alpha
1071 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1072 > /dev/null)
1073 local commit1=`git_show_head $testroot/repo`
1075 echo "change alpha 2" > $testroot/wt/alpha
1076 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1077 > /dev/null)
1078 local commit2=`git_show_head $testroot/repo`
1080 # Simulate a situation where fast-forward is required.
1081 # We want to fast-forward master to origin/master:
1082 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1083 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1084 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1085 (cd $testroot/repo && got ref -d master >/dev/null)
1086 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1087 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1089 (cd $testroot/wt && got up -b origin/master > /dev/null)
1091 (cd $testroot/wt && got rebase master \
1092 > $testroot/stdout 2> $testroot/stderr)
1094 echo "Forwarding refs/heads/master to commit $commit2" \
1095 > $testroot/stdout.expected
1096 echo "Switching work tree to refs/heads/master" \
1097 >> $testroot/stdout.expected
1098 cmp -s $testroot/stdout.expected $testroot/stdout
1099 ret=$?
1100 if [ $ret -ne 0 ]; then
1101 diff -u $testroot/stdout.expected $testroot/stdout
1102 test_done "$testroot" "$ret"
1103 return 1
1106 # Ensure that rebase operation was completed correctly
1107 (cd $testroot/wt && got rebase -a \
1108 > $testroot/stdout 2> $testroot/stderr)
1109 echo -n "" > $testroot/stdout.expected
1110 cmp -s $testroot/stdout.expected $testroot/stdout
1111 ret=$?
1112 if [ $ret -ne 0 ]; then
1113 diff -u $testroot/stdout.expected $testroot/stdout
1114 test_done "$testroot" "$ret"
1115 return 1
1117 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1118 cmp -s $testroot/stderr.expected $testroot/stderr
1119 ret=$?
1120 if [ $ret -ne 0 ]; then
1121 diff -u $testroot/stderr.expected $testroot/stderr
1122 test_done "$testroot" "$ret"
1123 return 1
1126 (cd $testroot/wt && got branch -n > $testroot/stdout)
1127 echo "master" > $testroot/stdout.expected
1128 cmp -s $testroot/stdout.expected $testroot/stdout
1129 ret=$?
1130 if [ $ret -ne 0 ]; then
1131 diff -u $testroot/stdout.expected $testroot/stdout
1132 test_done "$testroot" "$ret"
1133 return 1
1136 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1137 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1138 echo "commit $commit1" >> $testroot/stdout.expected
1139 echo "commit $commit0" >> $testroot/stdout.expected
1140 cmp -s $testroot/stdout.expected $testroot/stdout
1141 ret=$?
1142 if [ $ret -ne 0 ]; then
1143 diff -u $testroot/stdout.expected $testroot/stdout
1144 test_done "$testroot" "$ret"
1145 return 1
1148 # Forward-only rebase operations should not be backed up
1149 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1150 echo -n > $testroot/stdout.expected
1151 cmp -s $testroot/stdout.expected $testroot/stdout
1152 ret=$?
1153 if [ $ret -ne 0 ]; then
1154 diff -u $testroot/stdout.expected $testroot/stdout
1156 test_done "$testroot" "$ret"
1159 test_rebase_forward_path_prefix() {
1160 local testroot=`test_init rebase_forward_path_prefix`
1161 local commit0=`git_show_head $testroot/repo`
1163 got checkout $testroot/repo $testroot/wt-full > /dev/null
1164 ret=$?
1165 if [ $ret -ne 0 ]; then
1166 test_done "$testroot" "$ret"
1167 return 1
1170 echo "change alpha 1" > $testroot/wt-full/alpha
1171 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1172 > /dev/null)
1173 local commit1=`git_show_head $testroot/repo`
1175 echo "change alpha 2" > $testroot/wt-full/alpha
1176 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1177 > /dev/null)
1178 local commit2=`git_show_head $testroot/repo`
1180 # Simulate a situation where fast-forward is required.
1181 # We want to fast-forward master to origin/master:
1182 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1183 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1184 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1185 (cd $testroot/repo && got ref -d master >/dev/null)
1186 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1187 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1189 # Work tree which uses a path-prefix and will be used for rebasing
1190 got checkout -p epsilon -b origin/master $testroot/repo $testroot/wt \
1191 > /dev/null
1192 ret=$?
1193 if [ $ret -ne 0 ]; then
1194 test_done "$testroot" "$ret"
1195 return 1
1198 (cd $testroot/wt && got rebase master \
1199 > $testroot/stdout 2> $testroot/stderr)
1201 echo "Forwarding refs/heads/master to commit $commit2" \
1202 > $testroot/stdout.expected
1203 echo "Switching work tree to refs/heads/master" \
1204 >> $testroot/stdout.expected
1205 cmp -s $testroot/stdout.expected $testroot/stdout
1206 ret=$?
1207 if [ $ret -ne 0 ]; then
1208 diff -u $testroot/stdout.expected $testroot/stdout
1209 test_done "$testroot" "$ret"
1210 return 1
1213 # Ensure that rebase operation was completed correctly
1214 (cd $testroot/wt && got rebase -a \
1215 > $testroot/stdout 2> $testroot/stderr)
1216 echo -n "" > $testroot/stdout.expected
1217 cmp -s $testroot/stdout.expected $testroot/stdout
1218 ret=$?
1219 if [ $ret -ne 0 ]; then
1220 diff -u $testroot/stdout.expected $testroot/stdout
1221 test_done "$testroot" "$ret"
1222 return 1
1224 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1225 cmp -s $testroot/stderr.expected $testroot/stderr
1226 ret=$?
1227 if [ $ret -ne 0 ]; then
1228 diff -u $testroot/stderr.expected $testroot/stderr
1229 test_done "$testroot" "$ret"
1230 return 1
1233 (cd $testroot/wt && got branch -n > $testroot/stdout)
1234 echo "master" > $testroot/stdout.expected
1235 cmp -s $testroot/stdout.expected $testroot/stdout
1236 ret=$?
1237 if [ $ret -ne 0 ]; then
1238 diff -u $testroot/stdout.expected $testroot/stdout
1239 test_done "$testroot" "$ret"
1240 return 1
1243 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1244 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1245 echo "commit $commit1" >> $testroot/stdout.expected
1246 echo "commit $commit0" >> $testroot/stdout.expected
1247 cmp -s $testroot/stdout.expected $testroot/stdout
1248 ret=$?
1249 if [ $ret -ne 0 ]; then
1250 diff -u $testroot/stdout.expected $testroot/stdout
1251 test_done "$testroot" "$ret"
1252 return 1
1255 # Forward-only rebase operations should not be backed up
1256 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1257 echo -n > $testroot/stdout.expected
1258 cmp -s $testroot/stdout.expected $testroot/stdout
1259 ret=$?
1260 if [ $ret -ne 0 ]; then
1261 diff -u $testroot/stdout.expected $testroot/stdout
1263 test_done "$testroot" "$ret"
1266 test_rebase_out_of_date() {
1267 local testroot=`test_init rebase_out_of_date`
1268 local initial_commit=`git_show_head $testroot/repo`
1270 git -C $testroot/repo checkout -q -b newbranch
1271 echo "modified delta on branch" > $testroot/repo/gamma/delta
1272 git_commit $testroot/repo -m "committing to delta on newbranch"
1274 echo "modified alpha on branch" > $testroot/repo/alpha
1275 git -C $testroot/repo rm -q beta
1276 echo "new file on branch" > $testroot/repo/epsilon/new
1277 git -C $testroot/repo add epsilon/new
1278 git_commit $testroot/repo -m "committing more changes on newbranch"
1280 local orig_commit1=`git_show_parent_commit $testroot/repo`
1281 local orig_commit2=`git_show_head $testroot/repo`
1283 git -C $testroot/repo checkout -q master
1284 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1285 git_commit $testroot/repo -m "committing to zeta on master"
1286 local master_commit1=`git_show_head $testroot/repo`
1288 git -C $testroot/repo checkout -q master
1289 echo "modified beta on master" > $testroot/repo/beta
1290 git_commit $testroot/repo -m "committing to beta on master"
1291 local master_commit2=`git_show_head $testroot/repo`
1293 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1294 > /dev/null
1295 ret=$?
1296 if [ $ret -ne 0 ]; then
1297 test_done "$testroot" "$ret"
1298 return 1
1301 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1302 2> $testroot/stderr)
1304 echo -n > $testroot/stdout.expected
1305 cmp -s $testroot/stdout.expected $testroot/stdout
1306 ret=$?
1307 if [ $ret -ne 0 ]; then
1308 diff -u $testroot/stdout.expected $testroot/stdout
1309 test_done "$testroot" "$ret"
1310 return 1
1313 echo -n "got: work tree must be updated before it can be " \
1314 > $testroot/stderr.expected
1315 echo "used to rebase a branch" >> $testroot/stderr.expected
1316 cmp -s $testroot/stderr.expected $testroot/stderr
1317 ret=$?
1318 if [ $ret -ne 0 ]; then
1319 diff -u $testroot/stderr.expected $testroot/stderr
1320 test_done "$testroot" "$ret"
1321 return 1
1324 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1325 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1326 echo "commit $master_commit1" >> $testroot/stdout.expected
1327 echo "commit $initial_commit" >> $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
1333 test_done "$testroot" "$ret"
1336 test_rebase_trims_empty_dir() {
1337 local testroot=`test_init rebase_trims_empty_dir`
1339 git -C $testroot/repo checkout -q -b newbranch
1340 echo "modified delta on branch" > $testroot/repo/gamma/delta
1341 git_commit $testroot/repo -m "committing to delta on newbranch"
1343 git -C $testroot/repo rm -q epsilon/zeta
1344 git_commit $testroot/repo -m "removing zeta on newbranch"
1346 local orig_commit1=`git_show_parent_commit $testroot/repo`
1347 local orig_commit2=`git_show_head $testroot/repo`
1349 git -C $testroot/repo checkout -q master
1350 echo "modified alpha on master" > $testroot/repo/alpha
1351 git_commit $testroot/repo -m "committing to alpha on master"
1352 local master_commit=`git_show_head $testroot/repo`
1354 got checkout $testroot/repo $testroot/wt > /dev/null
1355 ret=$?
1356 if [ $ret -ne 0 ]; then
1357 test_done "$testroot" "$ret"
1358 return 1
1361 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1363 git -C $testroot/repo checkout -q newbranch
1364 local new_commit1=`git_show_parent_commit $testroot/repo`
1365 local new_commit2=`git_show_head $testroot/repo`
1367 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
1368 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
1369 local short_new_commit1=`trim_obj_id 12 $new_commit1`
1370 local short_new_commit2=`trim_obj_id 12 $new_commit2`
1372 echo "G gamma/delta" >> $testroot/stdout.expected
1373 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1374 >> $testroot/stdout.expected
1375 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1376 echo "D epsilon/zeta" >> $testroot/stdout.expected
1377 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1378 >> $testroot/stdout.expected
1379 echo ": removing zeta on newbranch" \
1380 >> $testroot/stdout.expected
1381 echo "Switching work tree to refs/heads/newbranch" \
1382 >> $testroot/stdout.expected
1384 cmp -s $testroot/stdout.expected $testroot/stdout
1385 ret=$?
1386 if [ $ret -ne 0 ]; then
1387 diff -u $testroot/stdout.expected $testroot/stdout
1388 test_done "$testroot" "$ret"
1389 return 1
1392 echo "modified delta on branch" > $testroot/content.expected
1393 cat $testroot/wt/gamma/delta > $testroot/content
1394 cmp -s $testroot/content.expected $testroot/content
1395 ret=$?
1396 if [ $ret -ne 0 ]; then
1397 diff -u $testroot/content.expected $testroot/content
1398 test_done "$testroot" "$ret"
1399 return 1
1402 echo "modified alpha on master" > $testroot/content.expected
1403 cat $testroot/wt/alpha > $testroot/content
1404 cmp -s $testroot/content.expected $testroot/content
1405 ret=$?
1406 if [ $ret -ne 0 ]; then
1407 diff -u $testroot/content.expected $testroot/content
1408 test_done "$testroot" "$ret"
1409 return 1
1412 if [ -e $testroot/wt/epsilon ]; then
1413 echo "parent of removed zeta still exists on disk" >&2
1414 test_done "$testroot" "1"
1415 return 1
1418 (cd $testroot/wt && got status > $testroot/stdout)
1420 echo -n > $testroot/stdout.expected
1421 cmp -s $testroot/stdout.expected $testroot/stdout
1422 ret=$?
1423 if [ $ret -ne 0 ]; then
1424 diff -u $testroot/stdout.expected $testroot/stdout
1425 test_done "$testroot" "$ret"
1426 return 1
1429 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1430 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1431 echo "commit $new_commit1" >> $testroot/stdout.expected
1432 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1433 cmp -s $testroot/stdout.expected $testroot/stdout
1434 ret=$?
1435 if [ $ret -ne 0 ]; then
1436 diff -u $testroot/stdout.expected $testroot/stdout
1438 test_done "$testroot" "$ret"
1441 test_rebase_delete_missing_file() {
1442 local testroot=`test_init rebase_delete_missing_file`
1444 mkdir -p $testroot/repo/d/f/g
1445 echo "new file" > $testroot/repo/d/f/g/new
1446 git -C $testroot/repo add d/f/g/new
1447 git_commit $testroot/repo -m "adding a subdir"
1448 local commit0=`git_show_head $testroot/repo`
1450 got br -r $testroot/repo -c master newbranch
1452 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1454 echo "modified delta on branch" > $testroot/wt/gamma/delta
1455 (cd $testroot/wt && got commit \
1456 -m "committing to delta on newbranch" > /dev/null)
1458 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1459 (cd $testroot/wt && got commit \
1460 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1462 git -C $testroot/repo checkout -q newbranch
1463 local orig_commit1=`git_show_parent_commit $testroot/repo`
1464 local orig_commit2=`git_show_head $testroot/repo`
1466 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
1467 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
1469 (cd $testroot/wt && got update -b master > /dev/null)
1470 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1471 (cd $testroot/wt && got commit \
1472 -m "removing beta and d/f/g/new on master" > /dev/null)
1474 git -C $testroot/repo checkout -q master
1475 local master_commit=`git_show_head $testroot/repo`
1477 (cd $testroot/wt && got update -b master > /dev/null)
1478 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1479 2> $testroot/stderr)
1480 ret=$?
1481 if [ $ret -eq 0 ]; then
1482 echo "rebase succeeded unexpectedly" >&2
1483 test_done "$testroot" "1"
1484 return 1
1487 local new_commit1=$(cd $testroot/wt && got info | \
1488 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1490 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
1491 local short_new_commit1=`trim_obj_id 12 $new_commit1`
1493 echo "G gamma/delta" >> $testroot/stdout.expected
1494 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1495 >> $testroot/stdout.expected
1496 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1497 echo "! beta" >> $testroot/stdout.expected
1498 echo "! d/f/g/new" >> $testroot/stdout.expected
1499 echo -n "Files which had incoming changes but could not be found " \
1500 >> $testroot/stdout.expected
1501 echo "in the work tree: 2" >> $testroot/stdout.expected
1502 cmp -s $testroot/stdout.expected $testroot/stdout
1503 ret=$?
1504 if [ $ret -ne 0 ]; then
1505 diff -u $testroot/stdout.expected $testroot/stdout
1506 test_done "$testroot" "$ret"
1507 return 1
1510 echo -n "got: changes destined for some files were not yet merged " \
1511 > $testroot/stderr.expected
1512 echo -n "and should be merged manually if required before the " \
1513 >> $testroot/stderr.expected
1514 echo "rebase operation is continued" >> $testroot/stderr.expected
1515 cmp -s $testroot/stderr.expected $testroot/stderr
1516 ret=$?
1517 if [ $ret -ne 0 ]; then
1518 diff -u $testroot/stderr.expected $testroot/stderr
1519 test_done "$testroot" "$ret"
1520 return 1
1523 # ignore the missing changes and continue
1524 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1525 ret=$?
1526 if [ $ret -ne 0 ]; then
1527 echo "rebase failed unexpectedly" >&2
1528 test_done "$testroot" "1"
1529 return 1
1531 echo -n "$short_orig_commit2 -> no-op change" \
1532 > $testroot/stdout.expected
1533 echo ": removing beta and d/f/g/new on newbranch" \
1534 >> $testroot/stdout.expected
1535 echo "Switching work tree to refs/heads/newbranch" \
1536 >> $testroot/stdout.expected
1538 cmp -s $testroot/stdout.expected $testroot/stdout
1539 ret=$?
1540 if [ $ret -ne 0 ]; then
1541 diff -u $testroot/stdout.expected $testroot/stdout
1542 test_done "$testroot" "$ret"
1543 return 1
1546 echo "modified delta on branch" > $testroot/content.expected
1547 cat $testroot/wt/gamma/delta > $testroot/content
1548 cmp -s $testroot/content.expected $testroot/content
1549 ret=$?
1550 if [ $ret -ne 0 ]; then
1551 diff -u $testroot/content.expected $testroot/content
1552 test_done "$testroot" "$ret"
1553 return 1
1556 if [ -e $testroot/wt/beta ]; then
1557 echo "removed file beta still exists on disk" >&2
1558 test_done "$testroot" "1"
1559 return 1
1562 (cd $testroot/wt && got status > $testroot/stdout)
1564 echo -n > $testroot/stdout.expected
1565 cmp -s $testroot/stdout.expected $testroot/stdout
1566 ret=$?
1567 if [ $ret -ne 0 ]; then
1568 diff -u $testroot/stdout.expected $testroot/stdout
1569 test_done "$testroot" "$ret"
1570 return 1
1573 git -C $testroot/repo checkout -q newbranch
1574 local new_commit1=`git_show_head $testroot/repo`
1575 local short_new_commit1=`trim_obj_id 12 $new_commit1`
1577 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1578 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1579 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1580 echo "commit $commit0" >> $testroot/stdout.expected
1581 cmp -s $testroot/stdout.expected $testroot/stdout
1582 ret=$?
1583 if [ $ret -ne 0 ]; then
1584 diff -u $testroot/stdout.expected $testroot/stdout
1586 test_done "$testroot" "$ret"
1589 test_rebase_rm_add_rm_file() {
1590 local testroot=`test_init rebase_rm_add_rm_file`
1592 git -C $testroot/repo checkout -q -b newbranch
1593 git -C $testroot/repo rm -q beta
1594 git_commit $testroot/repo -m "removing beta from newbranch"
1595 local orig_commit1=`git_show_head $testroot/repo`
1597 echo 'restored beta' > $testroot/repo/beta
1598 git -C $testroot/repo add beta
1599 git_commit $testroot/repo -m "restoring beta on newbranch"
1600 local orig_commit2=`git_show_head $testroot/repo`
1602 git -C $testroot/repo rm -q beta
1603 git_commit $testroot/repo -m "removing beta from newbranch again"
1604 local orig_commit3=`git_show_head $testroot/repo`
1606 git -C $testroot/repo checkout -q master
1607 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1608 git_commit $testroot/repo -m "committing to zeta on master"
1609 local master_commit=`git_show_head $testroot/repo`
1611 got checkout $testroot/repo $testroot/wt > /dev/null
1612 ret=$?
1613 if [ $ret -ne 0 ]; then
1614 test_done "$testroot" "$ret"
1615 return 1
1618 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1620 # this would error out with 'got: file index is corrupt'
1621 (cd $testroot/wt && got status > /dev/null)
1622 ret=$?
1623 if [ $ret -ne 0 ]; then
1624 echo "got status command failed unexpectedly" >&2
1625 test_done "$testroot" "$ret"
1626 return 1
1629 git -C $testroot/repo checkout -q newbranch
1630 local new_commit3=`git_show_head $testroot/repo`
1631 local new_commit2=`git_show_parent_commit $testroot/repo`
1632 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1634 git -C $testroot/repo checkout -q newbranch
1636 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
1637 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
1638 local short_orig_commit3=`trim_obj_id 12 $orig_commit3`
1639 local short_new_commit1=`trim_obj_id 12 $new_commit1`
1640 local short_new_commit2=`trim_obj_id 12 $new_commit2`
1641 local short_new_commit3=`trim_obj_id 12 $new_commit3`
1643 echo "D beta" > $testroot/stdout.expected
1644 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1645 >> $testroot/stdout.expected
1646 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1647 echo "A beta" >> $testroot/stdout.expected
1648 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1649 >> $testroot/stdout.expected
1650 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1651 echo "D beta" >> $testroot/stdout.expected
1652 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1653 >> $testroot/stdout.expected
1654 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1655 echo "Switching work tree to refs/heads/newbranch" \
1656 >> $testroot/stdout.expected
1658 cmp -s $testroot/stdout.expected $testroot/stdout
1659 ret=$?
1660 if [ $ret -ne 0 ]; then
1661 diff -u $testroot/stdout.expected $testroot/stdout
1662 test_done "$testroot" "$ret"
1663 return 1
1666 (cd $testroot/wt && got status > $testroot/stdout)
1667 ret=$?
1668 if [ $ret -ne 0 ]; then
1669 echo "got status command failed unexpectedly" >&2
1670 test_done "$testroot" "$ret"
1671 return 1
1674 echo -n > $testroot/stdout.expected
1675 cmp -s $testroot/stdout.expected $testroot/stdout
1676 ret=$?
1677 if [ $ret -ne 0 ]; then
1678 diff -u $testroot/stdout.expected $testroot/stdout
1679 test_done "$testroot" "$ret"
1680 return 1
1683 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1684 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1685 echo "commit $new_commit2" >> $testroot/stdout.expected
1686 echo "commit $new_commit1" >> $testroot/stdout.expected
1687 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1688 cmp -s $testroot/stdout.expected $testroot/stdout
1689 ret=$?
1690 if [ $ret -ne 0 ]; then
1691 diff -u $testroot/stdout.expected $testroot/stdout
1693 test_done "$testroot" "$ret"
1696 test_rebase_resets_committer() {
1697 local testroot=`test_init rebase_resets_committer`
1698 local commit0=`git_show_head $testroot/repo`
1699 local commit0_author_time=`git_show_author_time $testroot/repo`
1700 local committer="Flan Luck <flan_luck@openbsd.org>"
1702 git -C $testroot/repo checkout -q -b newbranch
1703 echo "modified delta on branch" > $testroot/repo/gamma/delta
1704 git_commit $testroot/repo -m "committing to delta on newbranch"
1706 echo "modified alpha on branch" > $testroot/repo/alpha
1707 git_commit $testroot/repo -m "committing more changes on newbranch"
1709 local orig_commit1=`git_show_parent_commit $testroot/repo`
1710 local orig_commit2=`git_show_head $testroot/repo`
1711 local orig_author_time2=`git_show_author_time $testroot/repo`
1713 git -C $testroot/repo checkout -q master
1714 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1715 git_commit $testroot/repo -m "committing to zeta on master"
1716 local master_commit=`git_show_head $testroot/repo`
1718 got checkout $testroot/repo $testroot/wt > /dev/null
1719 ret=$?
1720 if [ $ret -ne 0 ]; then
1721 test_done "$testroot" "$ret"
1722 return 1
1725 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
1726 got rebase newbranch > $testroot/stdout)
1728 git -C $testroot/repo checkout -q newbranch
1729 local new_commit1=`git_show_parent_commit $testroot/repo`
1730 local new_commit2=`git_show_head $testroot/repo`
1731 local new_author_time2=`git_show_author_time $testroot/repo`
1733 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
1734 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
1735 local short_new_commit1=`trim_obj_id 12 $new_commit1`
1736 local short_new_commit2=`trim_obj_id 12 $new_commit2`
1738 echo "G gamma/delta" >> $testroot/stdout.expected
1739 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1740 >> $testroot/stdout.expected
1741 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1742 echo "G alpha" >> $testroot/stdout.expected
1743 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1744 >> $testroot/stdout.expected
1745 echo ": committing more changes on newbranch" \
1746 >> $testroot/stdout.expected
1747 echo "Switching work tree to refs/heads/newbranch" \
1748 >> $testroot/stdout.expected
1750 cmp -s $testroot/stdout.expected $testroot/stdout
1751 ret=$?
1752 if [ $ret -ne 0 ]; then
1753 diff -u $testroot/stdout.expected $testroot/stdout
1754 test_done "$testroot" "$ret"
1755 return 1
1758 # Original commit only had one author
1759 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1760 egrep '^(from|via):' > $testroot/stdout)
1761 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1762 cmp -s $testroot/stdout.expected $testroot/stdout
1763 ret=$?
1764 if [ $ret -ne 0 ]; then
1765 diff -u $testroot/stdout.expected $testroot/stdout
1766 test_done "$testroot" "$ret"
1767 return 1
1770 # Rebased commit should have new committer name added
1771 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1772 egrep '^(from|via):' > $testroot/stdout)
1773 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1774 echo "via: $committer" >> $testroot/stdout.expected
1776 cmp -s $testroot/stdout.expected $testroot/stdout
1777 ret=$?
1778 if [ $ret -ne 0 ]; then
1779 diff -u $testroot/stdout.expected $testroot/stdout
1781 test_done "$testroot" "$ret"
1784 test_rebase_no_author_info() {
1785 local testroot=`test_init rebase_no_author_info`
1786 local commit0=`git_show_head $testroot/repo`
1787 local commit0_author_time=`git_show_author_time $testroot/repo`
1788 local committer="$GOT_AUTHOR"
1790 git -C $testroot/repo checkout -q -b newbranch
1791 echo "modified delta on branch" > $testroot/repo/gamma/delta
1792 git_commit $testroot/repo -m "committing to delta on newbranch"
1794 echo "modified alpha on branch" > $testroot/repo/alpha
1795 git_commit $testroot/repo -m "committing more changes on newbranch"
1797 local orig_commit1=`git_show_parent_commit $testroot/repo`
1798 local orig_commit2=`git_show_head $testroot/repo`
1799 local orig_author_time2=`git_show_author_time $testroot/repo`
1801 git -C $testroot/repo checkout -q master
1802 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1803 git_commit $testroot/repo -m "committing to zeta on master"
1804 local master_commit=`git_show_head $testroot/repo`
1806 got checkout $testroot/repo $testroot/wt > /dev/null
1807 ret=$?
1808 if [ $ret -ne 0 ]; then
1809 test_done "$testroot" "$ret"
1810 return 1
1813 # unset in a subshell to avoid affecting our environment
1814 (unset GOT_AUTHOR && cd $testroot/wt && \
1815 got rebase newbranch > $testroot/stdout)
1817 git -C $testroot/repo checkout -q newbranch
1818 local new_commit1=`git_show_parent_commit $testroot/repo`
1819 local new_commit2=`git_show_head $testroot/repo`
1820 local new_author_time2=`git_show_author_time $testroot/repo`
1822 local short_orig_commit1=`trim_obj_id 12 $orig_commit1`
1823 local short_orig_commit2=`trim_obj_id 12 $orig_commit2`
1824 local short_new_commit1=`trim_obj_id 12 $new_commit1`
1825 local short_new_commit2=`trim_obj_id 12 $new_commit2`
1827 echo "G gamma/delta" >> $testroot/stdout.expected
1828 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1829 >> $testroot/stdout.expected
1830 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1831 echo "G alpha" >> $testroot/stdout.expected
1832 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1833 >> $testroot/stdout.expected
1834 echo ": committing more changes on newbranch" \
1835 >> $testroot/stdout.expected
1836 echo "Switching work tree to refs/heads/newbranch" \
1837 >> $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
1843 test_done "$testroot" "$ret"
1844 return 1
1847 # Original commit only had one author
1848 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1849 egrep '^(from|via):' > $testroot/stdout)
1850 echo "from: $committer" > $testroot/stdout.expected
1851 cmp -s $testroot/stdout.expected $testroot/stdout
1852 ret=$?
1853 if [ $ret -ne 0 ]; then
1854 diff -u $testroot/stdout.expected $testroot/stdout
1855 test_done "$testroot" "$ret"
1856 return 1
1859 # Author info of rebased commit should match the original
1860 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1861 egrep '^(from|via):' > $testroot/stdout)
1862 echo "from: $committer" > $testroot/stdout.expected
1864 cmp -s $testroot/stdout.expected $testroot/stdout
1865 ret=$?
1866 if [ $ret -ne 0 ]; then
1867 diff -u $testroot/stdout.expected $testroot/stdout
1869 test_done "$testroot" "$ret"
1872 test_rebase_nonbranch() {
1873 local testroot=`test_init rebase_nonbranch`
1875 got ref -r $testroot/repo -c refs/heads/master \
1876 refs/remotes/origin/master >/dev/null
1878 got checkout -b master $testroot/repo $testroot/wt >/dev/null
1880 (cd $testroot/wt && got rebase origin/master > $testroot/stdout \
1881 2> $testroot/stderr)
1882 ret=$?
1883 if [ $ret -eq 0 ]; then
1884 echo "rebase succeeded unexpectedly" >&2
1885 test_done "$testroot" "1"
1886 return 1
1888 echo -n "got: will not rebase a branch which lives outside the " \
1889 > $testroot/stderr.expected
1890 echo '"refs/heads/" reference namespace' >> $testroot/stderr.expected
1891 cmp -s $testroot/stderr.expected $testroot/stderr
1892 ret=$?
1893 if [ $ret -ne 0 ]; then
1894 diff -u $testroot/stderr.expected $testroot/stderr
1896 test_done "$testroot" "$ret"
1899 test_rebase_umask() {
1900 local testroot=`test_init rebase_umask`
1901 local commit0=`git_show_head "$testroot/repo"`
1903 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1904 (cd "$testroot/wt" && got branch newbranch) >/dev/null
1906 echo "modified alpha on branch" >$testroot/wt/alpha
1907 (cd "$testroot/wt" && got commit -m 'modified alpha on newbranch') \
1908 >/dev/null
1910 (cd "$testroot/wt" && got update -b master) >/dev/null
1911 ret=$?
1912 if [ $ret -ne 0 ]; then
1913 echo "got update failed!" >&2
1914 test_done "$testroot" $ret
1915 return 1
1918 echo "modified beta on master" >$testroot/wt/beta
1919 (cd "$testroot/wt" && got commit -m 'modified beta on master') \
1920 >/dev/null
1921 (cd "$testroot/wt" && got update) >/dev/null
1923 # using a subshell to avoid clobbering global umask
1924 (umask 077 && cd "$testroot/wt" && got rebase newbranch) >/dev/null
1925 ret=$?
1926 if [ $ret -ne 0 ]; then
1927 echo "got rebase failed" >&2
1928 test_done "$testroot" $ret
1929 return 1
1932 ls -l "$testroot/wt/alpha" | grep -q ^-rw-------
1933 if [ $? -ne 0 ]; then
1934 echo "alpha is not 0600 after rebase" >&2
1935 ls -l "$testroot/wt/alpha" >&2
1936 test_done "$testroot" 1
1937 return 1
1940 test_done "$testroot" 0
1943 test_rebase_out_of_date2() {
1944 local testroot=`test_init rebase_out_of_date2`
1945 local commit0=`git_show_head $testroot/repo`
1946 local commit0_author_time=`git_show_author_time $testroot/repo`
1948 git -C $testroot/repo checkout -q -b newbranch
1949 echo "modified delta on branch" > $testroot/repo/gamma/delta
1950 git_commit $testroot/repo -m "committing to delta on newbranch"
1952 local orig_commit1=`git_show_parent_commit $testroot/repo`
1953 local orig_commit2=`git_show_head $testroot/repo`
1954 local orig_author_time2=`git_show_author_time $testroot/repo`
1956 git -C $testroot/repo checkout -q master
1957 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1958 git_commit $testroot/repo -m "committing to zeta on master"
1959 local master_commit=`git_show_head $testroot/repo`
1961 got checkout $testroot/repo $testroot/wt > /dev/null
1962 ret=$?
1963 if [ $ret -ne 0 ]; then
1964 test_done "$testroot" "$ret"
1965 return 1
1968 # Backdate the file alpha to an earlier version.
1969 # This sets the work tree's base commit ID back to $commit0,
1970 # which is out-of-date with respect to the master branch.
1971 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
1973 # Rebase into an out-of-date work tree should be refused.
1974 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1975 2> $testroot/stderr)
1976 ret=$?
1977 if [ $ret -eq 0 ]; then
1978 echo "rebase succeeded unexpectedly" >&2
1979 test_done "$testroot" "1"
1980 return 1
1982 echo -n > $testroot/stdout.expected
1983 echo -n "got: work tree must be updated before it can be used to " \
1984 > $testroot/stderr.expected
1985 echo "rebase a branch" >> $testroot/stderr.expected
1986 cmp -s $testroot/stderr.expected $testroot/stderr
1987 ret=$?
1988 if [ $ret -ne 0 ]; then
1989 diff -u $testroot/stderr.expected $testroot/stderr
1991 test_done "$testroot" "$ret"
1994 test_rebase_one_commit() {
1995 local testroot=`test_init rebase_one_commit`
1997 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1998 test_done "$testroot" 1
1999 return 1
2002 (cd $testroot/wt && got branch newbranch) >/dev/null
2004 echo "modified alpha on newbranch" >$testroot/wt/alpha
2005 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
2006 (cd $testroot/wt && got update) >/dev/null
2007 local commit=`git_show_branch_head $testroot/repo newbranch`
2009 echo -n '' > $testroot/stderr.expected
2011 (cd $testroot/wt && got rebase master >$testroot/stdout \
2012 2> $testroot/stderr)
2013 ret=$?
2014 if [ $ret -ne 0 ]; then
2015 echo "rebase command failed unexpectedly" >&2
2016 diff -u $testroot/stderr.expected $testroot/stderr
2017 test_done "$testroot" "1"
2018 return 1
2021 echo "Forwarding refs/heads/master to commit $commit" \
2022 >$testroot/stdout.expected
2023 echo "Switching work tree to refs/heads/master" \
2024 >> $testroot/stdout.expected
2026 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2027 diff -u $testroot/stdout.expected $testroot/stdout
2028 test_done "$testroot" 1
2029 return 1
2032 test_done "$testroot" 0
2035 test_rebase_merge_commit() {
2036 local testroot=`test_init rebase_merge_commit`
2037 local commit0=`git_show_branch_head $testroot/repo master`
2039 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
2040 test_done "$testroot" 1
2041 return 1
2044 echo "modified delta on master" >$testroot/wt/gamma/delta
2045 (cd $testroot/wt && got commit -m 'edit delta') >/dev/null
2046 local commit1=`git_show_branch_head $testroot/repo master`
2048 (cd $testroot/wt && got branch -c $commit0 newbranch1) >/dev/null
2049 echo "modified alpha on newbranch1" >$testroot/wt/alpha
2050 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
2051 (cd $testroot/wt && got update) >/dev/null
2052 local commit2=`git_show_branch_head $testroot/repo master`
2054 echo "modified alpha on newbranch1 again" >$testroot/wt/alpha
2055 (cd $testroot/wt && got commit -m 'edit alpha again') >/dev/null
2056 (cd $testroot/wt && got update) >/dev/null
2057 local commit3=`git_show_branch_head $testroot/repo newbranch1`
2059 (cd $testroot/wt && got branch -c $commit0 newbranch2) >/dev/null
2060 echo "modified beta on newbranch2" >$testroot/wt/beta
2061 (cd $testroot/wt && got commit -m 'edit beta') >/dev/null
2062 (cd $testroot/wt && got update) >/dev/null
2063 local commit4=`git_show_branch_head $testroot/repo newbranch2`
2065 echo "modified beta on newbranch2 again" >$testroot/wt/beta
2066 (cd $testroot/wt && got commit -m 'edit beta again') >/dev/null
2067 (cd $testroot/wt && got update) >/dev/null
2068 local commit5=`git_show_branch_head $testroot/repo newbranch2`
2070 echo -n '' > $testroot/stderr.expected
2072 (cd $testroot/wt && got merge newbranch1 >$testroot/stdout \
2073 2> $testroot/stderr)
2074 ret=$?
2075 if [ $ret -ne 0 ]; then
2076 echo "merge command failed unexpectedly" >&2
2077 diff -u $testroot/stderr.expected $testroot/stderr
2078 test_done "$testroot" "1"
2079 return 1
2082 local merge_commit=`git_show_branch_head $testroot/repo newbranch2`
2084 echo "G alpha" >> $testroot/stdout.expected
2085 echo -n "Merged refs/heads/newbranch1 into refs/heads/newbranch2: " \
2086 >> $testroot/stdout.expected
2087 echo $merge_commit >> $testroot/stdout.expected
2089 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2090 diff -u $testroot/stdout.expected $testroot/stdout
2091 test_done "$testroot" 1
2092 return 1
2095 (cd $testroot/wt && got update -b master) >/dev/null
2096 (cd $testroot/wt && got rebase newbranch2) > $testroot/stdout
2098 local new_commit5=`git_show_parent_commit $testroot/repo newbranch2`
2099 local short_orig_commit5=`trim_obj_id 12 $commit5`
2100 local short_new_commit5=`trim_obj_id 12 $new_commit5`
2102 local new_commit4=`git_show_parent_commit $testroot/repo $new_commit5`
2103 local short_orig_commit4=`trim_obj_id 12 $commit4`
2104 local short_new_commit4=`trim_obj_id 12 $new_commit4`
2106 local new_merge_commit=`git_show_branch_head $testroot/repo newbranch2`
2107 local short_orig_merge_commit=`trim_obj_id 12 $merge_commit`
2108 local short_new_merge_commit=`trim_obj_id 12 $new_merge_commit`
2110 echo "G beta"> $testroot/stdout.expected
2111 echo "$short_orig_commit4 -> $short_new_commit4: edit beta" \
2112 >> $testroot/stdout.expected
2113 echo "G beta" >> $testroot/stdout.expected
2114 echo "$short_orig_commit5 -> $short_new_commit5: edit beta again" \
2115 >> $testroot/stdout.expected
2116 echo "G alpha" >> $testroot/stdout.expected
2117 echo -n "$short_orig_merge_commit -> $short_new_merge_commit: " \
2118 >> $testroot/stdout.expected
2119 echo "merge refs/heads/newbranch1 into refs/head" \
2120 >> $testroot/stdout.expected
2121 echo "Switching work tree to refs/heads/newbranch2" \
2122 >> $testroot/stdout.expected
2124 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2125 diff -u $testroot/stdout.expected $testroot/stdout
2126 test_done "$testroot" 1
2127 return 1
2130 test_done "$testroot" 0
2133 test_rebase_across_merge_commit() {
2134 local testroot=`test_init rebase_across_merge_commit`
2135 local commit0=`git_show_branch_head $testroot/repo master`
2137 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
2138 test_done "$testroot" 1
2139 return 1
2142 echo "modified delta on master" >$testroot/wt/gamma/delta
2143 (cd $testroot/wt && got commit -m 'edit delta') >/dev/null
2144 local commit1=`git_show_branch_head $testroot/repo master`
2146 (cd $testroot/wt && got branch -c $commit0 newbranch1) >/dev/null
2147 echo "modified alpha on newbranch1" >$testroot/wt/alpha
2148 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
2149 (cd $testroot/wt && got update) >/dev/null
2150 local commit2=`git_show_branch_head $testroot/repo master`
2152 echo "modified alpha on newbranch1 again" >$testroot/wt/alpha
2153 (cd $testroot/wt && got commit -m 'edit alpha again') >/dev/null
2154 (cd $testroot/wt && got update) >/dev/null
2155 local commit3=`git_show_branch_head $testroot/repo newbranch1`
2157 (cd $testroot/wt && got branch -c $commit0 newbranch2) >/dev/null
2158 echo "modified beta on newbranch2" >$testroot/wt/beta
2159 (cd $testroot/wt && got commit -m 'edit beta') >/dev/null
2160 (cd $testroot/wt && got update) >/dev/null
2161 local commit4=`git_show_branch_head $testroot/repo newbranch2`
2163 echo "modified beta on newbranch2 again" >$testroot/wt/beta
2164 (cd $testroot/wt && got commit -m 'edit beta again') >/dev/null
2165 (cd $testroot/wt && got update) >/dev/null
2166 local commit5=`git_show_branch_head $testroot/repo newbranch2`
2168 echo -n '' > $testroot/stderr.expected
2170 (cd $testroot/wt && got merge newbranch1 >$testroot/stdout \
2171 2> $testroot/stderr)
2172 ret=$?
2173 if [ $ret -ne 0 ]; then
2174 echo "merge command failed unexpectedly" >&2
2175 diff -u $testroot/stderr.expected $testroot/stderr
2176 test_done "$testroot" "1"
2177 return 1
2180 local merge_commit=`git_show_branch_head $testroot/repo newbranch2`
2182 echo "G alpha" >> $testroot/stdout.expected
2183 echo -n "Merged refs/heads/newbranch1 into refs/heads/newbranch2: " \
2184 >> $testroot/stdout.expected
2185 echo $merge_commit >> $testroot/stdout.expected
2187 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2188 diff -u $testroot/stdout.expected $testroot/stdout
2189 test_done "$testroot" 1
2190 return 1
2193 (cd $testroot/wt && got rebase master) > $testroot/stdout
2195 local new_commit1=`git_show_head $testroot/repo`
2196 local short_orig_commit1=`trim_obj_id 12 $commit1`
2197 local short_new_commit1=`trim_obj_id 12 $new_commit1`
2199 echo "G gamma/delta"> $testroot/stdout.expected
2200 echo "$short_orig_commit1 -> $short_new_commit1: edit delta" \
2201 >> $testroot/stdout.expected
2202 echo "Switching work tree to refs/heads/master" \
2203 >> $testroot/stdout.expected
2205 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2206 diff -u $testroot/stdout.expected $testroot/stdout
2207 test_done "$testroot" 1
2208 return 1
2211 test_done "$testroot" 0
2214 test_rebase_merged_history_traversal() {
2215 local testroot=`test_init rebase_merged_history_traversal`
2216 local commit0=`git_show_branch_head $testroot/repo master`
2218 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
2219 test_done "$testroot" 1
2220 return 1
2223 (cd $testroot/wt && got branch -c $commit0 newbranch1) >/dev/null
2224 echo "modified alpha on newbranch1" >$testroot/wt/alpha
2225 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
2226 (cd $testroot/wt && got update) >/dev/null
2227 local commit2=`git_show_branch_head $testroot/repo master`
2229 echo "modified alpha on newbranch1 again" >$testroot/wt/alpha
2230 (cd $testroot/wt && got commit -m 'edit alpha again') >/dev/null
2231 (cd $testroot/wt && got update) >/dev/null
2232 local commit3=`git_show_branch_head $testroot/repo newbranch1`
2234 echo -n '' > $testroot/stderr.expected
2236 (cd $testroot/wt && got update -b master) >/dev/null
2237 (cd $testroot/wt && got merge -M newbranch1 >$testroot/stdout \
2238 2> $testroot/stderr)
2239 ret=$?
2240 if [ $ret -ne 0 ]; then
2241 echo "merge command failed unexpectedly" >&2
2242 diff -u $testroot/stderr.expected $testroot/stderr
2243 test_done "$testroot" "1"
2244 return 1
2247 local merge_commit=`git_show_head $testroot/repo`
2249 echo "G alpha" > $testroot/stdout.expected
2250 echo -n "Merged refs/heads/newbranch1 into refs/heads/master: " \
2251 >> $testroot/stdout.expected
2252 echo $merge_commit >> $testroot/stdout.expected
2253 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2254 diff -u $testroot/stdout.expected $testroot/stdout
2255 test_done "$testroot" 1
2256 return 1
2259 echo "modified delta on master" >$testroot/wt/gamma/delta
2260 (cd $testroot/wt && got commit -m 'edit delta') >/dev/null
2261 local commit1=`git_show_branch_head $testroot/repo master`
2263 (cd $testroot/wt && got branch newbranch2) >/dev/null
2264 (cd $testroot/wt && got rebase newbranch1) > $testroot/stdout
2266 echo "Forwarding refs/heads/newbranch1 to commit $commit1" > \
2267 $testroot/stdout.expected
2268 echo "Switching work tree to refs/heads/newbranch1" \
2269 >> $testroot/stdout.expected
2271 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
2272 diff -u $testroot/stdout.expected $testroot/stdout
2273 test_done "$testroot" "1"
2274 return 1
2277 test_done "$testroot" "$ret"
2280 test_parseargs "$@"
2281 run_test test_rebase_basic
2282 run_test test_rebase_ancestry_check
2283 run_test test_rebase_continue
2284 run_test test_rebase_abort
2285 run_test test_rebase_no_op_change
2286 run_test test_rebase_in_progress
2287 run_test test_rebase_path_prefix
2288 run_test test_rebase_preserves_logmsg
2289 run_test test_rebase_no_commits_to_rebase
2290 run_test test_rebase_forward
2291 run_test test_rebase_forward_path_prefix
2292 run_test test_rebase_out_of_date
2293 run_test test_rebase_trims_empty_dir
2294 run_test test_rebase_delete_missing_file
2295 run_test test_rebase_rm_add_rm_file
2296 run_test test_rebase_resets_committer
2297 run_test test_rebase_no_author_info
2298 run_test test_rebase_nonbranch
2299 run_test test_rebase_umask
2300 run_test test_rebase_out_of_date2
2301 run_test test_rebase_one_commit
2302 run_test test_rebase_merge_commit
2303 run_test test_rebase_across_merge_commit
2304 run_test test_rebase_merged_history_traversal