Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019, 2020 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_rebase_basic() {
20 local testroot=`test_init rebase_basic`
21 local commit0=`git_show_head $testroot/repo`
22 local commit0_author_time=`git_show_author_time $testroot/repo`
24 (cd $testroot/repo && git checkout -q -b newbranch)
25 echo "modified delta on branch" > $testroot/repo/gamma/delta
26 git_commit $testroot/repo -m "committing to delta on newbranch"
28 echo "modified alpha on branch" > $testroot/repo/alpha
29 (cd $testroot/repo && git rm -q beta)
30 echo "new file on branch" > $testroot/repo/epsilon/new
31 (cd $testroot/repo && git add epsilon/new)
32 git_commit $testroot/repo -m "committing more changes on newbranch"
34 local orig_commit1=`git_show_parent_commit $testroot/repo`
35 local orig_commit2=`git_show_head $testroot/repo`
36 local orig_author_time2=`git_show_author_time $testroot/repo`
38 (cd $testroot/repo && git checkout -q master)
39 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
40 git_commit $testroot/repo -m "committing to zeta on master"
41 local master_commit=`git_show_head $testroot/repo`
43 got checkout $testroot/repo $testroot/wt > /dev/null
44 ret=$?
45 if [ $ret -ne 0 ]; then
46 test_done "$testroot" "$ret"
47 return 1
48 fi
50 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
52 (cd $testroot/repo && git checkout -q newbranch)
53 local new_commit1=`git_show_parent_commit $testroot/repo`
54 local new_commit2=`git_show_head $testroot/repo`
55 local new_author_time2=`git_show_author_time $testroot/repo`
57 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
58 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
59 local short_new_commit1=`trim_obj_id 28 $new_commit1`
60 local short_new_commit2=`trim_obj_id 28 $new_commit2`
62 echo "G gamma/delta" >> $testroot/stdout.expected
63 echo -n "$short_orig_commit1 -> $short_new_commit1" \
64 >> $testroot/stdout.expected
65 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
66 echo "G alpha" >> $testroot/stdout.expected
67 echo "D beta" >> $testroot/stdout.expected
68 echo "A epsilon/new" >> $testroot/stdout.expected
69 echo -n "$short_orig_commit2 -> $short_new_commit2" \
70 >> $testroot/stdout.expected
71 echo ": committing more changes on newbranch" \
72 >> $testroot/stdout.expected
73 echo "Switching work tree to refs/heads/newbranch" \
74 >> $testroot/stdout.expected
76 cmp -s $testroot/stdout.expected $testroot/stdout
77 ret=$?
78 if [ $ret -ne 0 ]; then
79 diff -u $testroot/stdout.expected $testroot/stdout
80 test_done "$testroot" "$ret"
81 return 1
82 fi
84 echo "modified delta on branch" > $testroot/content.expected
85 cat $testroot/wt/gamma/delta > $testroot/content
86 cmp -s $testroot/content.expected $testroot/content
87 ret=$?
88 if [ $ret -ne 0 ]; then
89 diff -u $testroot/content.expected $testroot/content
90 test_done "$testroot" "$ret"
91 return 1
92 fi
94 echo "modified alpha on branch" > $testroot/content.expected
95 cat $testroot/wt/alpha > $testroot/content
96 cmp -s $testroot/content.expected $testroot/content
97 ret=$?
98 if [ $ret -ne 0 ]; then
99 diff -u $testroot/content.expected $testroot/content
100 test_done "$testroot" "$ret"
101 return 1
102 fi
104 if [ -e $testroot/wt/beta ]; then
105 echo "removed file beta still exists on disk" >&2
106 test_done "$testroot" "1"
107 return 1
108 fi
110 echo "new file on branch" > $testroot/content.expected
111 cat $testroot/wt/epsilon/new > $testroot/content
112 cmp -s $testroot/content.expected $testroot/content
113 ret=$?
114 if [ $ret -ne 0 ]; then
115 diff -u $testroot/content.expected $testroot/content
116 test_done "$testroot" "$ret"
117 return 1
118 fi
120 (cd $testroot/wt && got status > $testroot/stdout)
122 echo -n > $testroot/stdout.expected
123 cmp -s $testroot/stdout.expected $testroot/stdout
124 ret=$?
125 if [ $ret -ne 0 ]; then
126 diff -u $testroot/stdout.expected $testroot/stdout
127 test_done "$testroot" "$ret"
128 return 1
129 fi
131 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
132 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
133 echo "commit $new_commit1" >> $testroot/stdout.expected
134 echo "commit $master_commit (master)" >> $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected $testroot/stdout
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
139 test_done "$testroot" "$ret"
140 return 1
141 fi
143 (cd $testroot/wt && got update > $testroot/stdout)
145 echo 'Already up-to-date' > $testroot/stdout.expected
146 cmp -s $testroot/stdout.expected $testroot/stdout
147 ret=$?
148 if [ $ret -ne 0 ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 test_done "$testroot" "$ret"
151 return 1
152 fi
154 # We should have a backup of old commits
155 (cd $testroot/repo && got rebase -l > $testroot/stdout)
156 d_orig2=`date -u -r $orig_author_time2 +"%a %b %e %X %Y UTC"`
157 d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"`
158 d_0=`date -u -r $commit0_author_time +"%G-%m-%d"`
159 cat > $testroot/stdout.expected <<EOF
160 -----------------------------------------------
161 commit $orig_commit2 (formerly newbranch)
162 from: $GOT_AUTHOR
163 date: $d_orig2
165 committing more changes on newbranch
167 has become commit $new_commit2 (newbranch)
168 $d_new2 $GOT_AUTHOR_11 committing more changes on newbranch
169 history forked at $commit0
170 $d_0 $GOT_AUTHOR_11 adding the test tree
171 EOF
172 cmp -s $testroot/stdout.expected $testroot/stdout
173 ret=$?
174 if [ $ret -ne 0 ]; then
175 diff -u $testroot/stdout.expected $testroot/stdout
176 test_done "$testroot" "$ret"
177 return 1
178 fi
180 # Asking for backups of a branch which has none should yield an error
181 (cd $testroot/repo && got rebase -l master \
182 > $testroot/stdout 2> $testroot/stderr)
183 echo -n > $testroot/stdout.expected
184 echo "got: refs/got/backup/rebase/master/: no such reference found" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stdout.expected $testroot/stdout
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 diff -u $testroot/stdout.expected $testroot/stdout
190 test_done "$testroot" "$ret"
191 return 1
192 fi
193 cmp -s $testroot/stderr.expected $testroot/stderr
194 ret=$?
195 if [ $ret -ne 0 ]; then
196 diff -u $testroot/stderr.expected $testroot/stderr
197 test_done "$testroot" "$ret"
198 return 1
199 fi
201 # Delete all backup refs
202 (cd $testroot/repo && got rebase -X \
203 > $testroot/stdout 2> $testroot/stderr)
204 echo -n "Deleted refs/got/backup/rebase/newbranch/$new_commit2: " \
205 > $testroot/stdout.expected
206 echo "$orig_commit2" >> $testroot/stdout.expected
207 echo -n > $testroot/stderr.expected
208 cmp -s $testroot/stdout.expected $testroot/stdout
209 ret=$?
210 if [ $ret -ne 0 ]; then
211 diff -u $testroot/stdout.expected $testroot/stdout
212 test_done "$testroot" "$ret"
213 return 1
214 fi
215 cmp -s $testroot/stderr.expected $testroot/stderr
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stderr.expected $testroot/stderr
219 test_done "$testroot" "$ret"
220 return 1
221 fi
223 (cd $testroot/repo && got rebase -l > $testroot/stdout)
224 echo -n > $testroot/stdout.expected
225 cmp -s $testroot/stdout.expected $testroot/stdout
226 ret=$?
227 if [ $ret -ne 0 ]; then
228 diff -u $testroot/stdout.expected $testroot/stdout
229 fi
230 test_done "$testroot" "$ret"
233 test_rebase_ancestry_check() {
234 local testroot=`test_init rebase_ancestry_check`
236 got checkout $testroot/repo $testroot/wt > /dev/null
237 ret=$?
238 if [ $ret -ne 0 ]; then
239 test_done "$testroot" "$ret"
240 return 1
241 fi
243 (cd $testroot/repo && git checkout -q -b newbranch)
244 echo "modified delta on branch" > $testroot/repo/gamma/delta
245 git_commit $testroot/repo -m "committing to delta on newbranch"
246 local newbranch_id=`git_show_head $testroot/repo`
248 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
249 2> $testroot/stderr)
251 echo "refs/heads/newbranch is already based on refs/heads/master" \
252 > $testroot/stdout.expected
253 echo "Switching work tree from refs/heads/master to refs/heads/newbranch" \
254 >> $testroot/stdout.expected
255 echo "U gamma/delta" >> $testroot/stdout.expected
256 echo "Updated to refs/heads/newbranch: ${newbranch_id}" \
257 >> $testroot/stdout.expected
258 cmp -s $testroot/stdout.expected $testroot/stdout
259 ret=$?
260 if [ $ret -ne 0 ]; then
261 diff -u $testroot/stdout.expected $testroot/stdout
262 test_done "$testroot" "$ret"
263 return 1
264 fi
266 echo -n > $testroot/stderr.expected
267 cmp -s $testroot/stderr.expected $testroot/stderr
268 ret=$?
269 if [ $ret -ne 0 ]; then
270 diff -u $testroot/stderr.expected $testroot/stderr
271 fi
272 test_done "$testroot" "$ret"
275 test_rebase_continue() {
276 local testroot=`test_init rebase_continue`
277 local init_commit=`git_show_head $testroot/repo`
279 (cd $testroot/repo && git checkout -q -b newbranch)
280 echo "modified alpha on branch" > $testroot/repo/alpha
281 git_commit $testroot/repo -m "committing to alpha on newbranch"
282 local orig_commit1=`git_show_head $testroot/repo`
283 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
285 (cd $testroot/repo && git checkout -q master)
286 echo "modified alpha on master" > $testroot/repo/alpha
287 git_commit $testroot/repo -m "committing to alpha on master"
288 local master_commit=`git_show_head $testroot/repo`
290 got checkout $testroot/repo $testroot/wt > /dev/null
291 ret=$?
292 if [ $ret -ne 0 ]; then
293 test_done "$testroot" "$ret"
294 return 1
295 fi
297 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
298 2> $testroot/stderr)
300 echo "C alpha" > $testroot/stdout.expected
301 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
302 echo -n "$short_orig_commit1 -> merge conflict" \
303 >> $testroot/stdout.expected
304 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
305 cmp -s $testroot/stdout.expected $testroot/stdout
306 ret=$?
307 if [ $ret -ne 0 ]; then
308 diff -u $testroot/stdout.expected $testroot/stdout
309 test_done "$testroot" "$ret"
310 return 1
311 fi
313 echo "got: conflicts must be resolved before rebasing can continue" \
314 > $testroot/stderr.expected
315 cmp -s $testroot/stderr.expected $testroot/stderr
316 ret=$?
317 if [ $ret -ne 0 ]; then
318 diff -u $testroot/stderr.expected $testroot/stderr
319 test_done "$testroot" "$ret"
320 return 1
321 fi
323 echo '<<<<<<<' > $testroot/content.expected
324 echo "modified alpha on master" >> $testroot/content.expected
325 echo "||||||| 3-way merge base: commit $init_commit" \
326 >> $testroot/content.expected
327 echo "alpha" >> $testroot/content.expected
328 echo "=======" >> $testroot/content.expected
329 echo "modified alpha on branch" >> $testroot/content.expected
330 echo ">>>>>>> merged change: commit $orig_commit1" \
331 >> $testroot/content.expected
332 cat $testroot/wt/alpha > $testroot/content
333 cmp -s $testroot/content.expected $testroot/content
334 ret=$?
335 if [ $ret -ne 0 ]; then
336 diff -u $testroot/content.expected $testroot/content
337 test_done "$testroot" "$ret"
338 return 1
339 fi
341 (cd $testroot/wt && got status > $testroot/stdout)
343 echo "C alpha" > $testroot/stdout.expected
344 cmp -s $testroot/stdout.expected $testroot/stdout
345 ret=$?
346 if [ $ret -ne 0 ]; then
347 diff -u $testroot/stdout.expected $testroot/stdout
348 test_done "$testroot" "$ret"
349 return 1
350 fi
352 # resolve the conflict
353 echo "modified alpha on branch and master" > $testroot/wt/alpha
355 # test interaction of 'got stage' and rebase -c
356 (cd $testroot/wt && got stage alpha > /dev/null)
357 (cd $testroot/wt && got rebase -c > $testroot/stdout \
358 2> $testroot/stderr)
359 ret=$?
360 if [ $ret -eq 0 ]; then
361 echo "rebase succeeded unexpectedly" >&2
362 test_done "$testroot" "1"
363 return 1
364 fi
365 echo -n "got: work tree contains files with staged changes; " \
366 > $testroot/stderr.expected
367 echo "these changes must be committed or unstaged first" \
368 >> $testroot/stderr.expected
369 cmp -s $testroot/stderr.expected $testroot/stderr
370 ret=$?
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stderr.expected $testroot/stderr
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 (cd $testroot/wt && got unstage alpha > /dev/null)
378 (cd $testroot/wt && got rebase -c > $testroot/stdout)
380 (cd $testroot/repo && git checkout -q newbranch)
381 local new_commit1=`git_show_head $testroot/repo`
382 local short_new_commit1=`trim_obj_id 28 $new_commit1`
384 echo -n "$short_orig_commit1 -> $short_new_commit1" \
385 > $testroot/stdout.expected
386 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
387 echo "Switching work tree to refs/heads/newbranch" \
388 >> $testroot/stdout.expected
390 cmp -s $testroot/stdout.expected $testroot/stdout
391 ret=$?
392 if [ $ret -ne 0 ]; then
393 diff -u $testroot/stdout.expected $testroot/stdout
394 test_done "$testroot" "$ret"
395 return 1
396 fi
399 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
400 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
401 echo "commit $master_commit (master)" >> $testroot/stdout.expected
402 cmp -s $testroot/stdout.expected $testroot/stdout
403 ret=$?
404 if [ $ret -ne 0 ]; then
405 diff -u $testroot/stdout.expected $testroot/stdout
406 fi
407 test_done "$testroot" "$ret"
410 test_rebase_abort() {
411 local testroot=`test_init rebase_abort`
413 local init_commit=`git_show_head $testroot/repo`
415 (cd $testroot/repo && git checkout -q -b newbranch)
416 echo "modified 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 git_commit $testroot/repo -m "committing to alpha on newbranch"
423 local orig_commit2=`git_show_head $testroot/repo`
424 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
426 (cd $testroot/repo && git checkout -q master)
427 echo "modified alpha on master" > $testroot/repo/alpha
428 git_commit $testroot/repo -m "committing to alpha on master"
429 local master_commit=`git_show_head $testroot/repo`
431 got checkout $testroot/repo $testroot/wt > /dev/null
432 ret=$?
433 if [ $ret -ne 0 ]; then
434 test_done "$testroot" "$ret"
435 return 1
436 fi
438 # unrelated unversioned file in work tree
439 touch $testroot/wt/unversioned-file
441 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
442 2> $testroot/stderr)
444 new_commit1=$(cd $testroot/wt && got info beta | \
445 grep '^based on commit:' | cut -d' ' -f4)
446 local short_new_commit1=`trim_obj_id 28 $new_commit1`
448 echo "G beta" > $testroot/stdout.expected
449 echo -n "$short_orig_commit1 -> $short_new_commit1" \
450 >> $testroot/stdout.expected
451 echo ": committing to beta on newbranch" >> $testroot/stdout.expected
452 echo "C alpha" >> $testroot/stdout.expected
453 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
454 echo -n "$short_orig_commit2 -> merge conflict" \
455 >> $testroot/stdout.expected
456 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
457 cmp -s $testroot/stdout.expected $testroot/stdout
458 ret=$?
459 if [ $ret -ne 0 ]; then
460 diff -u $testroot/stdout.expected $testroot/stdout
461 test_done "$testroot" "$ret"
462 return 1
463 fi
465 echo "got: conflicts must be resolved before rebasing can continue" \
466 > $testroot/stderr.expected
467 cmp -s $testroot/stderr.expected $testroot/stderr
468 ret=$?
469 if [ $ret -ne 0 ]; then
470 diff -u $testroot/stderr.expected $testroot/stderr
471 test_done "$testroot" "$ret"
472 return 1
473 fi
475 echo '<<<<<<<' > $testroot/content.expected
476 echo "modified alpha on master" >> $testroot/content.expected
477 echo "||||||| 3-way merge base: commit $orig_commit1" \
478 >> $testroot/content.expected
479 echo "alpha" >> $testroot/content.expected
480 echo "=======" >> $testroot/content.expected
481 echo "modified alpha on branch" >> $testroot/content.expected
482 echo ">>>>>>> merged change: commit $orig_commit2" \
483 >> $testroot/content.expected
484 cat $testroot/wt/alpha > $testroot/content
485 cmp -s $testroot/content.expected $testroot/content
486 ret=$?
487 if [ $ret -ne 0 ]; then
488 diff -u $testroot/content.expected $testroot/content
489 test_done "$testroot" "$ret"
490 return 1
491 fi
493 (cd $testroot/wt && got status > $testroot/stdout)
495 echo "C alpha" > $testroot/stdout.expected
496 echo "? unversioned-file" >> $testroot/stdout.expected
497 cmp -s $testroot/stdout.expected $testroot/stdout
498 ret=$?
499 if [ $ret -ne 0 ]; then
500 diff -u $testroot/stdout.expected $testroot/stdout
501 test_done "$testroot" "$ret"
502 return 1
503 fi
505 (cd $testroot/wt && got rebase -a > $testroot/stdout)
507 (cd $testroot/repo && git checkout -q newbranch)
509 echo "Switching work tree to refs/heads/master" \
510 > $testroot/stdout.expected
511 echo 'R alpha' >> $testroot/stdout.expected
512 echo 'U beta' >> $testroot/stdout.expected
513 echo "Rebase of refs/heads/newbranch aborted" \
514 >> $testroot/stdout.expected
516 cmp -s $testroot/stdout.expected $testroot/stdout
517 ret=$?
518 if [ $ret -ne 0 ]; then
519 diff -u $testroot/stdout.expected $testroot/stdout
520 test_done "$testroot" "$ret"
521 return 1
522 fi
524 echo "modified alpha on master" > $testroot/content.expected
525 cat $testroot/wt/alpha > $testroot/content
526 cmp -s $testroot/content.expected $testroot/content
527 ret=$?
528 if [ $ret -ne 0 ]; then
529 diff -u $testroot/content.expected $testroot/content
530 test_done "$testroot" "$ret"
531 return 1
532 fi
534 (cd $testroot/wt && got log -l3 -c newbranch \
535 | grep ^commit > $testroot/stdout)
536 echo "commit $orig_commit2 (newbranch)" > $testroot/stdout.expected
537 echo "commit $orig_commit1" >> $testroot/stdout.expected
538 echo "commit $init_commit" >> $testroot/stdout.expected
539 cmp -s $testroot/stdout.expected $testroot/stdout
540 ret=$?
541 if [ $ret -ne 0 ]; then
542 diff -u $testroot/stdout.expected $testroot/stdout
543 test_done "$testroot" "$ret"
544 return 1
545 fi
547 (cd $testroot/wt && got info .| \
548 grep '^based on commit:' | sort | uniq > $testroot/stdout)
549 echo "based on commit: $master_commit" > $testroot/stdout.expected
550 cmp -s $testroot/stdout.expected $testroot/stdout
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 diff -u $testroot/stdout.expected $testroot/stdout
554 test_done "$testroot" "$ret"
555 return 1
556 fi
558 (cd $testroot/wt && got status > $testroot/stdout)
559 echo "? unversioned-file" > $testroot/stdout.expected
560 cmp -s $testroot/stdout.expected $testroot/stdout
561 ret=$?
562 if [ $ret -ne 0 ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 test_done "$testroot" "$ret"
565 return 1
566 fi
568 cat $testroot/wt/beta > $testroot/content
569 echo 'beta' > $testroot/content.expected
570 cmp -s $testroot/content.expected $testroot/content
571 ret=$?
572 if [ $ret -ne 0 ]; then
573 diff -u $testroot/content.expected $testroot/content
574 test_done "$testroot" "$ret"
575 return 1
576 fi
578 # A subsequent update should be a no-op.
579 (cd $testroot/wt && got update > $testroot/stdout)
580 echo 'Already up-to-date' > $testroot/stdout.expected
581 cmp -s $testroot/stdout.expected $testroot/stdout
582 ret=$?
583 if [ $ret -ne 0 ]; then
584 diff -u $testroot/stdout.expected $testroot/stdout
585 fi
586 test_done "$testroot" "$ret"
589 test_rebase_no_op_change() {
590 local testroot=`test_init rebase_no_op_change`
591 local init_commit=`git_show_head $testroot/repo`
593 (cd $testroot/repo && git checkout -q -b newbranch)
594 echo "modified alpha on branch" > $testroot/repo/alpha
595 git_commit $testroot/repo -m "committing to alpha on newbranch"
596 local orig_commit1=`git_show_head $testroot/repo`
597 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
599 (cd $testroot/repo && git checkout -q master)
600 echo "modified alpha on master" > $testroot/repo/alpha
601 git_commit $testroot/repo -m "committing to alpha on master"
602 local master_commit=`git_show_head $testroot/repo`
604 got checkout $testroot/repo $testroot/wt > /dev/null
605 ret=$?
606 if [ $ret -ne 0 ]; then
607 test_done "$testroot" "$ret"
608 return 1
609 fi
611 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
612 2> $testroot/stderr)
614 echo "C alpha" > $testroot/stdout.expected
615 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
616 echo -n "$short_orig_commit1 -> merge conflict" \
617 >> $testroot/stdout.expected
618 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
619 cmp -s $testroot/stdout.expected $testroot/stdout
620 ret=$?
621 if [ $ret -ne 0 ]; then
622 diff -u $testroot/stdout.expected $testroot/stdout
623 test_done "$testroot" "$ret"
624 return 1
625 fi
627 echo "got: conflicts must be resolved before rebasing can continue" \
628 > $testroot/stderr.expected
629 cmp -s $testroot/stderr.expected $testroot/stderr
630 ret=$?
631 if [ $ret -ne 0 ]; then
632 diff -u $testroot/stderr.expected $testroot/stderr
633 test_done "$testroot" "$ret"
634 return 1
635 fi
637 echo '<<<<<<<' > $testroot/content.expected
638 echo "modified alpha on master" >> $testroot/content.expected
639 echo "||||||| 3-way merge base: commit $init_commit" \
640 >> $testroot/content.expected
641 echo "alpha" >> $testroot/content.expected
642 echo "=======" >> $testroot/content.expected
643 echo "modified alpha on branch" >> $testroot/content.expected
644 echo ">>>>>>> merged change: commit $orig_commit1" \
645 >> $testroot/content.expected
646 cat $testroot/wt/alpha > $testroot/content
647 cmp -s $testroot/content.expected $testroot/content
648 ret=$?
649 if [ $ret -ne 0 ]; then
650 diff -u $testroot/content.expected $testroot/content
651 test_done "$testroot" "$ret"
652 return 1
653 fi
655 (cd $testroot/wt && got status > $testroot/stdout)
657 echo "C alpha" > $testroot/stdout.expected
658 cmp -s $testroot/stdout.expected $testroot/stdout
659 ret=$?
660 if [ $ret -ne 0 ]; then
661 diff -u $testroot/stdout.expected $testroot/stdout
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 # resolve the conflict
667 echo "modified alpha on master" > $testroot/wt/alpha
669 (cd $testroot/wt && got rebase -c > $testroot/stdout)
671 (cd $testroot/repo && git checkout -q newbranch)
672 local new_commit1=`git_show_head $testroot/repo`
674 echo -n "$short_orig_commit1 -> no-op change" \
675 > $testroot/stdout.expected
676 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
677 echo "Switching work tree to refs/heads/newbranch" \
678 >> $testroot/stdout.expected
680 cmp -s $testroot/stdout.expected $testroot/stdout
681 ret=$?
682 if [ $ret -ne 0 ]; then
683 diff -u $testroot/stdout.expected $testroot/stdout
684 test_done "$testroot" "$ret"
685 return 1
686 fi
689 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
690 echo "commit $master_commit (master, newbranch)" \
691 > $testroot/stdout.expected
692 echo "commit $init_commit" >> $testroot/stdout.expected
693 cmp -s $testroot/stdout.expected $testroot/stdout
694 ret=$?
695 if [ $ret -ne 0 ]; then
696 diff -u $testroot/stdout.expected $testroot/stdout
697 fi
698 test_done "$testroot" "$ret"
701 test_rebase_in_progress() {
702 local testroot=`test_init rebase_in_progress`
703 local init_commit=`git_show_head $testroot/repo`
705 (cd $testroot/repo && git checkout -q -b newbranch)
706 echo "modified alpha on branch" > $testroot/repo/alpha
707 git_commit $testroot/repo -m "committing to alpha on newbranch"
708 local orig_commit1=`git_show_head $testroot/repo`
709 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
711 (cd $testroot/repo && git checkout -q master)
712 echo "modified alpha on master" > $testroot/repo/alpha
713 git_commit $testroot/repo -m "committing to alpha on master"
714 local master_commit=`git_show_head $testroot/repo`
716 got checkout $testroot/repo $testroot/wt > /dev/null
717 ret=$?
718 if [ $ret -ne 0 ]; then
719 test_done "$testroot" "$ret"
720 return 1
721 fi
723 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
724 2> $testroot/stderr)
726 echo "C alpha" > $testroot/stdout.expected
727 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
728 echo -n "$short_orig_commit1 -> merge conflict" \
729 >> $testroot/stdout.expected
730 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
731 cmp -s $testroot/stdout.expected $testroot/stdout
732 ret=$?
733 if [ $ret -ne 0 ]; then
734 diff -u $testroot/stdout.expected $testroot/stdout
735 test_done "$testroot" "$ret"
736 return 1
737 fi
739 echo "got: conflicts must be resolved before rebasing can continue" \
740 > $testroot/stderr.expected
741 cmp -s $testroot/stderr.expected $testroot/stderr
742 ret=$?
743 if [ $ret -ne 0 ]; then
744 diff -u $testroot/stderr.expected $testroot/stderr
745 test_done "$testroot" "$ret"
746 return 1
747 fi
749 echo '<<<<<<<' > $testroot/content.expected
750 echo "modified alpha on master" >> $testroot/content.expected
751 echo "||||||| 3-way merge base: commit $init_commit" \
752 >> $testroot/content.expected
753 echo "alpha" >> $testroot/content.expected
754 echo "=======" >> $testroot/content.expected
755 echo "modified alpha on branch" >> $testroot/content.expected
756 echo ">>>>>>> merged change: commit $orig_commit1" \
757 >> $testroot/content.expected
758 cat $testroot/wt/alpha > $testroot/content
759 cmp -s $testroot/content.expected $testroot/content
760 ret=$?
761 if [ $ret -ne 0 ]; then
762 diff -u $testroot/content.expected $testroot/content
763 test_done "$testroot" "$ret"
764 return 1
765 fi
767 (cd $testroot/wt && got status > $testroot/stdout)
769 echo "C alpha" > $testroot/stdout.expected
770 cmp -s $testroot/stdout.expected $testroot/stdout
771 ret=$?
772 if [ $ret -ne 0 ]; then
773 diff -u $testroot/stdout.expected $testroot/stdout
774 test_done "$testroot" "$ret"
775 return 1
776 fi
778 for cmd in update commit; do
779 (cd $testroot/wt && got $cmd > $testroot/stdout \
780 2> $testroot/stderr)
782 echo -n > $testroot/stdout.expected
783 cmp -s $testroot/stdout.expected $testroot/stdout
784 ret=$?
785 if [ $ret -ne 0 ]; then
786 diff -u $testroot/stdout.expected $testroot/stdout
787 test_done "$testroot" "$ret"
788 return 1
789 fi
791 echo -n "got: a rebase operation is in progress in this " \
792 > $testroot/stderr.expected
793 echo "work tree and must be continued or aborted first" \
794 >> $testroot/stderr.expected
795 cmp -s $testroot/stderr.expected $testroot/stderr
796 ret=$?
797 if [ $ret -ne 0 ]; then
798 diff -u $testroot/stderr.expected $testroot/stderr
799 test_done "$testroot" "$ret"
800 return 1
801 fi
802 done
804 test_done "$testroot" "$ret"
807 test_rebase_path_prefix() {
808 local testroot=`test_init rebase_path_prefix`
810 (cd $testroot/repo && git checkout -q -b newbranch)
811 echo "modified delta on branch" > $testroot/repo/gamma/delta
812 git_commit $testroot/repo -m "committing to delta on newbranch"
814 local orig_commit1=`git_show_parent_commit $testroot/repo`
815 local orig_commit2=`git_show_head $testroot/repo`
817 (cd $testroot/repo && git checkout -q master)
818 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
819 git_commit $testroot/repo -m "committing to zeta on master"
820 local master_commit=`git_show_head $testroot/repo`
822 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
823 ret=$?
824 if [ $ret -ne 0 ]; then
825 test_done "$testroot" "$ret"
826 return 1
827 fi
829 (cd $testroot/wt && got rebase newbranch \
830 > $testroot/stdout 2> $testroot/stderr)
832 echo -n > $testroot/stdout.expected
833 cmp -s $testroot/stdout.expected $testroot/stdout
834 ret=$?
835 if [ $ret -ne 0 ]; then
836 diff -u $testroot/stdout.expected $testroot/stdout
837 test_done "$testroot" "$ret"
838 return 1
839 fi
841 echo -n "got: cannot rebase branch which contains changes outside " \
842 > $testroot/stderr.expected
843 echo "of this work tree's path prefix" >> $testroot/stderr.expected
844 cmp -s $testroot/stderr.expected $testroot/stderr
845 ret=$?
846 if [ $ret -ne 0 ]; then
847 diff -u $testroot/stderr.expected $testroot/stderr
848 test_done "$testroot" "$ret"
849 return 1
850 fi
852 # rebase should succeed when using a complete work tree
853 got checkout $testroot/repo $testroot/wt2 > /dev/null
854 ret=$?
855 if [ $ret -ne 0 ]; then
856 test_done "$testroot" "$ret"
857 return 1
858 fi
860 (cd $testroot/wt2 && got rebase newbranch \
861 > $testroot/stdout 2> $testroot/stderr)
863 (cd $testroot/repo && git checkout -q newbranch)
864 local new_commit1=`git_show_parent_commit $testroot/repo`
865 local new_commit2=`git_show_head $testroot/repo`
867 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
868 local short_new_commit2=`trim_obj_id 28 $new_commit2`
870 echo "G gamma/delta" > $testroot/stdout.expected
871 echo -n "$short_orig_commit2 -> $short_new_commit2" \
872 >> $testroot/stdout.expected
873 echo ": committing to delta on newbranch" \
874 >> $testroot/stdout.expected
875 echo "Switching work tree to refs/heads/newbranch" \
876 >> $testroot/stdout.expected
878 cmp -s $testroot/stdout.expected $testroot/stdout
879 ret=$?
880 if [ $ret -ne 0 ]; then
881 diff -u $testroot/stdout.expected $testroot/stdout
882 test_done "$testroot" "$ret"
883 return 1
884 fi
886 # the first work tree should remain usable
887 (cd $testroot/wt && got update -b master \
888 > $testroot/stdout 2> $testroot/stderr)
889 ret=$?
890 if [ $ret -ne 0 ]; then
891 echo "update failed unexpectedly" >&2
892 test_done "$testroot" "1"
893 return 1
894 fi
896 echo 'Already up-to-date' > $testroot/stdout.expected
897 cmp -s $testroot/stdout.expected $testroot/stdout
898 ret=$?
899 if [ $ret -ne 0 ]; then
900 diff -u $testroot/stdout.expected $testroot/stdout
901 fi
902 test_done "$testroot" "$ret"
905 test_rebase_preserves_logmsg() {
906 local testroot=`test_init rebase_preserves_logmsg`
908 (cd $testroot/repo && git checkout -q -b newbranch)
909 echo "modified delta on branch" > $testroot/repo/gamma/delta
910 git_commit $testroot/repo -m "modified delta on newbranch"
912 echo "modified alpha on branch" > $testroot/repo/alpha
913 git_commit $testroot/repo -m "modified alpha on newbranch"
915 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
916 > $testroot/log.expected)
918 local orig_commit1=`git_show_parent_commit $testroot/repo`
919 local orig_commit2=`git_show_head $testroot/repo`
921 (cd $testroot/repo && git checkout -q master)
922 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
923 git_commit $testroot/repo -m "committing to zeta on master"
924 local master_commit=`git_show_head $testroot/repo`
926 got checkout $testroot/repo $testroot/wt > /dev/null
927 ret=$?
928 if [ $ret -ne 0 ]; then
929 test_done "$testroot" "$ret"
930 return 1
931 fi
933 (cd $testroot/wt && got rebase newbranch > /dev/null \
934 2> $testroot/stderr)
936 (cd $testroot/repo && git checkout -q newbranch)
937 local new_commit1=`git_show_parent_commit $testroot/repo`
938 local new_commit2=`git_show_head $testroot/repo`
940 echo -n > $testroot/stderr.expected
941 cmp -s $testroot/stderr.expected $testroot/stderr
942 ret=$?
943 if [ $ret -ne 0 ]; then
944 diff -u $testroot/stderr.expected $testroot/stderr
945 test_done "$testroot" "$ret"
946 return 1
947 fi
949 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
950 > $testroot/log)
951 ed -s $testroot/log.expected <<-EOF
952 ,s/$orig_commit1/$new_commit1/
953 ,s/$orig_commit2/$new_commit2/
955 EOF
956 cmp -s $testroot/log.expected $testroot/log
957 ret=$?
958 if [ $ret -ne 0 ]; then
959 diff -u $testroot/log.expected $testroot/log
960 fi
962 test_done "$testroot" "$ret"
965 test_rebase_no_commits_to_rebase() {
966 local testroot=`test_init rebase_no_commits_to_rebase`
968 got checkout $testroot/repo $testroot/wt > /dev/null
969 ret=$?
970 if [ $ret -ne 0 ]; then
971 test_done "$testroot" "$ret"
972 return 1
973 fi
975 # Create an unrelated branch with 'got import'.
976 mkdir -p $testroot/newtree
977 echo "new file" > $testroot/newtree/newfile
978 got import -m new -b newbranch -r $testroot/repo \
979 $testroot/newtree > /dev/null
981 echo "modified alpha on master" > $testroot/wt/alpha
982 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
983 > /dev/null)
984 (cd $testroot/wt && got update > /dev/null)
986 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
987 2> $testroot/stderr)
989 echo -n "got: specified branch shares no common ancestry " \
990 > $testroot/stderr.expected
991 echo "with work tree's branch" >> $testroot/stderr.expected
992 cmp -s $testroot/stderr.expected $testroot/stderr
993 ret=$?
994 if [ $ret -ne 0 ]; then
995 diff -u $testroot/stderr.expected $testroot/stderr
996 test_done "$testroot" "$ret"
997 return 1
998 fi
1000 echo -n > $testroot/stdout.expected
1001 cmp -s $testroot/stdout.expected $testroot/stdout
1002 ret=$?
1003 if [ $ret -ne 0 ]; then
1004 diff -u $testroot/stdout.expected $testroot/stdout
1005 test_done "$testroot" "$ret"
1006 return 1
1009 (cd $testroot/wt && got update > $testroot/stdout)
1010 echo "Already up-to-date" > $testroot/stdout.expected
1011 cmp -s $testroot/stdout.expected $testroot/stdout
1012 ret=$?
1013 if [ $ret -ne 0 ]; then
1014 diff -u $testroot/stdout.expected $testroot/stdout
1016 test_done "$testroot" "$ret"
1019 test_rebase_forward() {
1020 local testroot=`test_init rebase_forward`
1021 local commit0=`git_show_head $testroot/repo`
1023 got checkout $testroot/repo $testroot/wt > /dev/null
1024 ret=$?
1025 if [ $ret -ne 0 ]; then
1026 test_done "$testroot" "$ret"
1027 return 1
1030 echo "change alpha 1" > $testroot/wt/alpha
1031 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1032 > /dev/null)
1033 local commit1=`git_show_head $testroot/repo`
1035 echo "change alpha 2" > $testroot/wt/alpha
1036 (cd $testroot/wt && got commit -m 'test rebase_forward' \
1037 > /dev/null)
1038 local commit2=`git_show_head $testroot/repo`
1040 # Simulate a situation where fast-forward is required.
1041 # We want to fast-forward master to origin/master:
1042 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1043 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1044 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1045 (cd $testroot/repo && got ref -d master >/dev/null)
1046 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1047 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1049 (cd $testroot/wt && got up -b origin/master > /dev/null)
1051 (cd $testroot/wt && got rebase master \
1052 > $testroot/stdout 2> $testroot/stderr)
1054 echo "Forwarding refs/heads/master to commit $commit2" \
1055 > $testroot/stdout.expected
1056 echo "Switching work tree to refs/heads/master" \
1057 >> $testroot/stdout.expected
1058 cmp -s $testroot/stdout.expected $testroot/stdout
1059 ret=$?
1060 if [ $ret -ne 0 ]; then
1061 diff -u $testroot/stdout.expected $testroot/stdout
1062 test_done "$testroot" "$ret"
1063 return 1
1066 # Ensure that rebase operation was completed correctly
1067 (cd $testroot/wt && got rebase -a \
1068 > $testroot/stdout 2> $testroot/stderr)
1069 echo -n "" > $testroot/stdout.expected
1070 cmp -s $testroot/stdout.expected $testroot/stdout
1071 ret=$?
1072 if [ $ret -ne 0 ]; then
1073 diff -u $testroot/stdout.expected $testroot/stdout
1074 test_done "$testroot" "$ret"
1075 return 1
1077 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1078 cmp -s $testroot/stderr.expected $testroot/stderr
1079 ret=$?
1080 if [ $ret -ne 0 ]; then
1081 diff -u $testroot/stderr.expected $testroot/stderr
1082 test_done "$testroot" "$ret"
1083 return 1
1086 (cd $testroot/wt && got branch -n > $testroot/stdout)
1087 echo "master" > $testroot/stdout.expected
1088 cmp -s $testroot/stdout.expected $testroot/stdout
1089 ret=$?
1090 if [ $ret -ne 0 ]; then
1091 diff -u $testroot/stdout.expected $testroot/stdout
1092 test_done "$testroot" "$ret"
1093 return 1
1096 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1097 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1098 echo "commit $commit1" >> $testroot/stdout.expected
1099 echo "commit $commit0" >> $testroot/stdout.expected
1100 cmp -s $testroot/stdout.expected $testroot/stdout
1101 ret=$?
1102 if [ $ret -ne 0 ]; then
1103 diff -u $testroot/stdout.expected $testroot/stdout
1104 test_done "$testroot" "$ret"
1105 return 1
1108 # Forward-only rebase operations should not be backed up
1109 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1110 echo -n > $testroot/stdout.expected
1111 cmp -s $testroot/stdout.expected $testroot/stdout
1112 ret=$?
1113 if [ $ret -ne 0 ]; then
1114 diff -u $testroot/stdout.expected $testroot/stdout
1116 test_done "$testroot" "$ret"
1119 test_rebase_forward_path_prefix() {
1120 local testroot=`test_init rebase_forward_path_prefix`
1121 local commit0=`git_show_head $testroot/repo`
1123 got checkout $testroot/repo $testroot/wt-full > /dev/null
1124 ret=$?
1125 if [ $ret -ne 0 ]; then
1126 test_done "$testroot" "$ret"
1127 return 1
1130 echo "change alpha 1" > $testroot/wt-full/alpha
1131 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1132 > /dev/null)
1133 local commit1=`git_show_head $testroot/repo`
1135 echo "change alpha 2" > $testroot/wt-full/alpha
1136 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1137 > /dev/null)
1138 local commit2=`git_show_head $testroot/repo`
1140 # Simulate a situation where fast-forward is required.
1141 # We want to fast-forward master to origin/master:
1142 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
1143 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
1144 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
1145 (cd $testroot/repo && got ref -d master >/dev/null)
1146 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
1147 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
1149 # Work tree which uses a path-prefix and will be used for rebasing
1150 got checkout -p epsilon -b origin/master $testroot/repo $testroot/wt \
1151 > /dev/null
1152 ret=$?
1153 if [ $ret -ne 0 ]; then
1154 test_done "$testroot" "$ret"
1155 return 1
1158 (cd $testroot/wt && got rebase master \
1159 > $testroot/stdout 2> $testroot/stderr)
1161 echo "Forwarding refs/heads/master to commit $commit2" \
1162 > $testroot/stdout.expected
1163 echo "Switching work tree to refs/heads/master" \
1164 >> $testroot/stdout.expected
1165 cmp -s $testroot/stdout.expected $testroot/stdout
1166 ret=$?
1167 if [ $ret -ne 0 ]; then
1168 diff -u $testroot/stdout.expected $testroot/stdout
1169 test_done "$testroot" "$ret"
1170 return 1
1173 # Ensure that rebase operation was completed correctly
1174 (cd $testroot/wt && got rebase -a \
1175 > $testroot/stdout 2> $testroot/stderr)
1176 echo -n "" > $testroot/stdout.expected
1177 cmp -s $testroot/stdout.expected $testroot/stdout
1178 ret=$?
1179 if [ $ret -ne 0 ]; then
1180 diff -u $testroot/stdout.expected $testroot/stdout
1181 test_done "$testroot" "$ret"
1182 return 1
1184 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1185 cmp -s $testroot/stderr.expected $testroot/stderr
1186 ret=$?
1187 if [ $ret -ne 0 ]; then
1188 diff -u $testroot/stderr.expected $testroot/stderr
1189 test_done "$testroot" "$ret"
1190 return 1
1193 (cd $testroot/wt && got branch -n > $testroot/stdout)
1194 echo "master" > $testroot/stdout.expected
1195 cmp -s $testroot/stdout.expected $testroot/stdout
1196 ret=$?
1197 if [ $ret -ne 0 ]; then
1198 diff -u $testroot/stdout.expected $testroot/stdout
1199 test_done "$testroot" "$ret"
1200 return 1
1203 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1204 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1205 echo "commit $commit1" >> $testroot/stdout.expected
1206 echo "commit $commit0" >> $testroot/stdout.expected
1207 cmp -s $testroot/stdout.expected $testroot/stdout
1208 ret=$?
1209 if [ $ret -ne 0 ]; then
1210 diff -u $testroot/stdout.expected $testroot/stdout
1211 test_done "$testroot" "$ret"
1212 return 1
1215 # Forward-only rebase operations should not be backed up
1216 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1217 echo -n > $testroot/stdout.expected
1218 cmp -s $testroot/stdout.expected $testroot/stdout
1219 ret=$?
1220 if [ $ret -ne 0 ]; then
1221 diff -u $testroot/stdout.expected $testroot/stdout
1223 test_done "$testroot" "$ret"
1226 test_rebase_out_of_date() {
1227 local testroot=`test_init rebase_out_of_date`
1228 local initial_commit=`git_show_head $testroot/repo`
1230 (cd $testroot/repo && git checkout -q -b newbranch)
1231 echo "modified delta on branch" > $testroot/repo/gamma/delta
1232 git_commit $testroot/repo -m "committing to delta on newbranch"
1234 echo "modified alpha on branch" > $testroot/repo/alpha
1235 (cd $testroot/repo && git rm -q beta)
1236 echo "new file on branch" > $testroot/repo/epsilon/new
1237 (cd $testroot/repo && git add epsilon/new)
1238 git_commit $testroot/repo -m "committing more changes on newbranch"
1240 local orig_commit1=`git_show_parent_commit $testroot/repo`
1241 local orig_commit2=`git_show_head $testroot/repo`
1243 (cd $testroot/repo && git checkout -q master)
1244 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1245 git_commit $testroot/repo -m "committing to zeta on master"
1246 local master_commit1=`git_show_head $testroot/repo`
1248 (cd $testroot/repo && git checkout -q master)
1249 echo "modified beta on master" > $testroot/repo/beta
1250 git_commit $testroot/repo -m "committing to beta on master"
1251 local master_commit2=`git_show_head $testroot/repo`
1253 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1254 > /dev/null
1255 ret=$?
1256 if [ $ret -ne 0 ]; then
1257 test_done "$testroot" "$ret"
1258 return 1
1261 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1262 2> $testroot/stderr)
1264 echo -n > $testroot/stdout.expected
1265 cmp -s $testroot/stdout.expected $testroot/stdout
1266 ret=$?
1267 if [ $ret -ne 0 ]; then
1268 diff -u $testroot/stdout.expected $testroot/stdout
1269 test_done "$testroot" "$ret"
1270 return 1
1273 echo -n "got: work tree must be updated before it can be " \
1274 > $testroot/stderr.expected
1275 echo "used to rebase a branch" >> $testroot/stderr.expected
1276 cmp -s $testroot/stderr.expected $testroot/stderr
1277 ret=$?
1278 if [ $ret -ne 0 ]; then
1279 diff -u $testroot/stderr.expected $testroot/stderr
1280 test_done "$testroot" "$ret"
1281 return 1
1284 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1285 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1286 echo "commit $master_commit1" >> $testroot/stdout.expected
1287 echo "commit $initial_commit" >> $testroot/stdout.expected
1288 cmp -s $testroot/stdout.expected $testroot/stdout
1289 ret=$?
1290 if [ $ret -ne 0 ]; then
1291 diff -u $testroot/stdout.expected $testroot/stdout
1293 test_done "$testroot" "$ret"
1296 test_rebase_trims_empty_dir() {
1297 local testroot=`test_init rebase_trims_empty_dir`
1299 (cd $testroot/repo && git checkout -q -b newbranch)
1300 echo "modified delta on branch" > $testroot/repo/gamma/delta
1301 git_commit $testroot/repo -m "committing to delta on newbranch"
1303 (cd $testroot/repo && git rm -q epsilon/zeta)
1304 git_commit $testroot/repo -m "removing zeta on newbranch"
1306 local orig_commit1=`git_show_parent_commit $testroot/repo`
1307 local orig_commit2=`git_show_head $testroot/repo`
1309 (cd $testroot/repo && git checkout -q master)
1310 echo "modified alpha on master" > $testroot/repo/alpha
1311 git_commit $testroot/repo -m "committing to alpha on master"
1312 local master_commit=`git_show_head $testroot/repo`
1314 got checkout $testroot/repo $testroot/wt > /dev/null
1315 ret=$?
1316 if [ $ret -ne 0 ]; then
1317 test_done "$testroot" "$ret"
1318 return 1
1321 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1323 (cd $testroot/repo && git checkout -q newbranch)
1324 local new_commit1=`git_show_parent_commit $testroot/repo`
1325 local new_commit2=`git_show_head $testroot/repo`
1327 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1328 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1329 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1330 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1332 echo "G gamma/delta" >> $testroot/stdout.expected
1333 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1334 >> $testroot/stdout.expected
1335 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1336 echo "D epsilon/zeta" >> $testroot/stdout.expected
1337 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1338 >> $testroot/stdout.expected
1339 echo ": removing zeta on newbranch" \
1340 >> $testroot/stdout.expected
1341 echo "Switching work tree to refs/heads/newbranch" \
1342 >> $testroot/stdout.expected
1344 cmp -s $testroot/stdout.expected $testroot/stdout
1345 ret=$?
1346 if [ $ret -ne 0 ]; then
1347 diff -u $testroot/stdout.expected $testroot/stdout
1348 test_done "$testroot" "$ret"
1349 return 1
1352 echo "modified delta on branch" > $testroot/content.expected
1353 cat $testroot/wt/gamma/delta > $testroot/content
1354 cmp -s $testroot/content.expected $testroot/content
1355 ret=$?
1356 if [ $ret -ne 0 ]; then
1357 diff -u $testroot/content.expected $testroot/content
1358 test_done "$testroot" "$ret"
1359 return 1
1362 echo "modified alpha on master" > $testroot/content.expected
1363 cat $testroot/wt/alpha > $testroot/content
1364 cmp -s $testroot/content.expected $testroot/content
1365 ret=$?
1366 if [ $ret -ne 0 ]; then
1367 diff -u $testroot/content.expected $testroot/content
1368 test_done "$testroot" "$ret"
1369 return 1
1372 if [ -e $testroot/wt/epsilon ]; then
1373 echo "parent of removed zeta still exists on disk" >&2
1374 test_done "$testroot" "1"
1375 return 1
1378 (cd $testroot/wt && got status > $testroot/stdout)
1380 echo -n > $testroot/stdout.expected
1381 cmp -s $testroot/stdout.expected $testroot/stdout
1382 ret=$?
1383 if [ $ret -ne 0 ]; then
1384 diff -u $testroot/stdout.expected $testroot/stdout
1385 test_done "$testroot" "$ret"
1386 return 1
1389 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1390 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1391 echo "commit $new_commit1" >> $testroot/stdout.expected
1392 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1393 cmp -s $testroot/stdout.expected $testroot/stdout
1394 ret=$?
1395 if [ $ret -ne 0 ]; then
1396 diff -u $testroot/stdout.expected $testroot/stdout
1398 test_done "$testroot" "$ret"
1401 test_rebase_delete_missing_file() {
1402 local testroot=`test_init rebase_delete_missing_file`
1404 mkdir -p $testroot/repo/d/f/g
1405 echo "new file" > $testroot/repo/d/f/g/new
1406 (cd $testroot/repo && git add d/f/g/new)
1407 git_commit $testroot/repo -m "adding a subdir"
1408 local commit0=`git_show_head $testroot/repo`
1410 got br -r $testroot/repo -c master newbranch
1412 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1414 echo "modified delta on branch" > $testroot/wt/gamma/delta
1415 (cd $testroot/wt && got commit \
1416 -m "committing to delta on newbranch" > /dev/null)
1418 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1419 (cd $testroot/wt && got commit \
1420 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1422 (cd $testroot/repo && git checkout -q newbranch)
1423 local orig_commit1=`git_show_parent_commit $testroot/repo`
1424 local orig_commit2=`git_show_head $testroot/repo`
1426 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1427 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1429 (cd $testroot/wt && got update -b master > /dev/null)
1430 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1431 (cd $testroot/wt && got commit \
1432 -m "removing beta and d/f/g/new on master" > /dev/null)
1434 (cd $testroot/repo && git checkout -q master)
1435 local master_commit=`git_show_head $testroot/repo`
1437 (cd $testroot/wt && got update -b master > /dev/null)
1438 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1439 2> $testroot/stderr)
1440 ret=$?
1441 if [ $ret -eq 0 ]; then
1442 echo "rebase succeeded unexpectedly" >&2
1443 test_done "$testroot" "1"
1444 return 1
1447 local new_commit1=$(cd $testroot/wt && got info | \
1448 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1450 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1451 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1453 echo "G gamma/delta" >> $testroot/stdout.expected
1454 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1455 >> $testroot/stdout.expected
1456 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1457 echo "! beta" >> $testroot/stdout.expected
1458 echo "! d/f/g/new" >> $testroot/stdout.expected
1459 echo -n "Files which had incoming changes but could not be found " \
1460 >> $testroot/stdout.expected
1461 echo "in the work tree: 2" >> $testroot/stdout.expected
1462 cmp -s $testroot/stdout.expected $testroot/stdout
1463 ret=$?
1464 if [ $ret -ne 0 ]; then
1465 diff -u $testroot/stdout.expected $testroot/stdout
1466 test_done "$testroot" "$ret"
1467 return 1
1470 echo -n "got: changes destined for some files were not yet merged " \
1471 > $testroot/stderr.expected
1472 echo -n "and should be merged manually if required before the " \
1473 >> $testroot/stderr.expected
1474 echo "rebase operation is continued" >> $testroot/stderr.expected
1475 cmp -s $testroot/stderr.expected $testroot/stderr
1476 ret=$?
1477 if [ $ret -ne 0 ]; then
1478 diff -u $testroot/stderr.expected $testroot/stderr
1479 test_done "$testroot" "$ret"
1480 return 1
1483 # ignore the missing changes and continue
1484 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1485 ret=$?
1486 if [ $ret -ne 0 ]; then
1487 echo "rebase failed unexpectedly" >&2
1488 test_done "$testroot" "1"
1489 return 1
1491 echo -n "$short_orig_commit2 -> no-op change" \
1492 > $testroot/stdout.expected
1493 echo ": removing beta and d/f/g/new on newbranch" \
1494 >> $testroot/stdout.expected
1495 echo "Switching work tree to refs/heads/newbranch" \
1496 >> $testroot/stdout.expected
1498 cmp -s $testroot/stdout.expected $testroot/stdout
1499 ret=$?
1500 if [ $ret -ne 0 ]; then
1501 diff -u $testroot/stdout.expected $testroot/stdout
1502 test_done "$testroot" "$ret"
1503 return 1
1506 echo "modified delta on branch" > $testroot/content.expected
1507 cat $testroot/wt/gamma/delta > $testroot/content
1508 cmp -s $testroot/content.expected $testroot/content
1509 ret=$?
1510 if [ $ret -ne 0 ]; then
1511 diff -u $testroot/content.expected $testroot/content
1512 test_done "$testroot" "$ret"
1513 return 1
1516 if [ -e $testroot/wt/beta ]; then
1517 echo "removed file beta still exists on disk" >&2
1518 test_done "$testroot" "1"
1519 return 1
1522 (cd $testroot/wt && got status > $testroot/stdout)
1524 echo -n > $testroot/stdout.expected
1525 cmp -s $testroot/stdout.expected $testroot/stdout
1526 ret=$?
1527 if [ $ret -ne 0 ]; then
1528 diff -u $testroot/stdout.expected $testroot/stdout
1529 test_done "$testroot" "$ret"
1530 return 1
1533 (cd $testroot/repo && git checkout -q newbranch)
1534 local new_commit1=`git_show_head $testroot/repo`
1535 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1537 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1538 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1539 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1540 echo "commit $commit0" >> $testroot/stdout.expected
1541 cmp -s $testroot/stdout.expected $testroot/stdout
1542 ret=$?
1543 if [ $ret -ne 0 ]; then
1544 diff -u $testroot/stdout.expected $testroot/stdout
1546 test_done "$testroot" "$ret"
1549 test_rebase_rm_add_rm_file() {
1550 local testroot=`test_init rebase_rm_add_rm_file`
1552 (cd $testroot/repo && git checkout -q -b newbranch)
1553 (cd $testroot/repo && git rm -q beta)
1554 git_commit $testroot/repo -m "removing beta from newbranch"
1555 local orig_commit1=`git_show_head $testroot/repo`
1557 echo 'restored beta' > $testroot/repo/beta
1558 (cd $testroot/repo && git add beta)
1559 git_commit $testroot/repo -m "restoring beta on newbranch"
1560 local orig_commit2=`git_show_head $testroot/repo`
1562 (cd $testroot/repo && git rm -q beta)
1563 git_commit $testroot/repo -m "removing beta from newbranch again"
1564 local orig_commit3=`git_show_head $testroot/repo`
1566 (cd $testroot/repo && git checkout -q master)
1567 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1568 git_commit $testroot/repo -m "committing to zeta on master"
1569 local master_commit=`git_show_head $testroot/repo`
1571 got checkout $testroot/repo $testroot/wt > /dev/null
1572 ret=$?
1573 if [ $ret -ne 0 ]; then
1574 test_done "$testroot" "$ret"
1575 return 1
1578 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1580 # this would error out with 'got: file index is corrupt'
1581 (cd $testroot/wt && got status > /dev/null)
1582 ret=$?
1583 if [ $ret -ne 0 ]; then
1584 echo "got status command failed unexpectedly" >&2
1585 test_done "$testroot" "$ret"
1586 return 1
1589 (cd $testroot/repo && git checkout -q newbranch)
1590 local new_commit3=`git_show_head $testroot/repo`
1591 local new_commit2=`git_show_parent_commit $testroot/repo`
1592 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1594 (cd $testroot/repo && git checkout -q newbranch)
1596 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1597 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1598 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1599 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1600 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1601 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1603 echo "D beta" > $testroot/stdout.expected
1604 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1605 >> $testroot/stdout.expected
1606 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1607 echo "A beta" >> $testroot/stdout.expected
1608 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1609 >> $testroot/stdout.expected
1610 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1611 echo "D beta" >> $testroot/stdout.expected
1612 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1613 >> $testroot/stdout.expected
1614 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1615 echo "Switching work tree to refs/heads/newbranch" \
1616 >> $testroot/stdout.expected
1618 cmp -s $testroot/stdout.expected $testroot/stdout
1619 ret=$?
1620 if [ $ret -ne 0 ]; then
1621 diff -u $testroot/stdout.expected $testroot/stdout
1622 test_done "$testroot" "$ret"
1623 return 1
1626 (cd $testroot/wt && got status > $testroot/stdout)
1627 ret=$?
1628 if [ $ret -ne 0 ]; then
1629 echo "got status command failed unexpectedly" >&2
1630 test_done "$testroot" "$ret"
1631 return 1
1634 echo -n > $testroot/stdout.expected
1635 cmp -s $testroot/stdout.expected $testroot/stdout
1636 ret=$?
1637 if [ $ret -ne 0 ]; then
1638 diff -u $testroot/stdout.expected $testroot/stdout
1639 test_done "$testroot" "$ret"
1640 return 1
1643 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1644 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1645 echo "commit $new_commit2" >> $testroot/stdout.expected
1646 echo "commit $new_commit1" >> $testroot/stdout.expected
1647 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1648 cmp -s $testroot/stdout.expected $testroot/stdout
1649 ret=$?
1650 if [ $ret -ne 0 ]; then
1651 diff -u $testroot/stdout.expected $testroot/stdout
1653 test_done "$testroot" "$ret"
1656 test_rebase_resets_committer() {
1657 local testroot=`test_init rebase_resets_committer`
1658 local commit0=`git_show_head $testroot/repo`
1659 local commit0_author_time=`git_show_author_time $testroot/repo`
1660 local committer="Flan Luck <flan_luck@openbsd.org>"
1662 (cd $testroot/repo && git checkout -q -b newbranch)
1663 echo "modified delta on branch" > $testroot/repo/gamma/delta
1664 git_commit $testroot/repo -m "committing to delta on newbranch"
1666 echo "modified alpha on branch" > $testroot/repo/alpha
1667 git_commit $testroot/repo -m "committing more changes on newbranch"
1669 local orig_commit1=`git_show_parent_commit $testroot/repo`
1670 local orig_commit2=`git_show_head $testroot/repo`
1671 local orig_author_time2=`git_show_author_time $testroot/repo`
1673 (cd $testroot/repo && git checkout -q master)
1674 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1675 git_commit $testroot/repo -m "committing to zeta on master"
1676 local master_commit=`git_show_head $testroot/repo`
1678 got checkout $testroot/repo $testroot/wt > /dev/null
1679 ret=$?
1680 if [ $ret -ne 0 ]; then
1681 test_done "$testroot" "$ret"
1682 return 1
1685 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
1686 got rebase newbranch > $testroot/stdout)
1688 (cd $testroot/repo && git checkout -q newbranch)
1689 local new_commit1=`git_show_parent_commit $testroot/repo`
1690 local new_commit2=`git_show_head $testroot/repo`
1691 local new_author_time2=`git_show_author_time $testroot/repo`
1693 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1694 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1695 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1696 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1698 echo "G gamma/delta" >> $testroot/stdout.expected
1699 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1700 >> $testroot/stdout.expected
1701 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1702 echo "G alpha" >> $testroot/stdout.expected
1703 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1704 >> $testroot/stdout.expected
1705 echo ": committing more changes on newbranch" \
1706 >> $testroot/stdout.expected
1707 echo "Switching work tree to refs/heads/newbranch" \
1708 >> $testroot/stdout.expected
1710 cmp -s $testroot/stdout.expected $testroot/stdout
1711 ret=$?
1712 if [ $ret -ne 0 ]; then
1713 diff -u $testroot/stdout.expected $testroot/stdout
1714 test_done "$testroot" "$ret"
1715 return 1
1718 # Original commit only had one author
1719 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1720 egrep '^(from|via):' > $testroot/stdout)
1721 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1722 cmp -s $testroot/stdout.expected $testroot/stdout
1723 ret=$?
1724 if [ $ret -ne 0 ]; then
1725 diff -u $testroot/stdout.expected $testroot/stdout
1726 test_done "$testroot" "$ret"
1727 return 1
1730 # Rebased commit should have new committer name added
1731 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1732 egrep '^(from|via):' > $testroot/stdout)
1733 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1734 echo "via: $committer" >> $testroot/stdout.expected
1736 cmp -s $testroot/stdout.expected $testroot/stdout
1737 ret=$?
1738 if [ $ret -ne 0 ]; then
1739 diff -u $testroot/stdout.expected $testroot/stdout
1741 test_done "$testroot" "$ret"
1744 test_rebase_no_author_info() {
1745 local testroot=`test_init rebase_no_author_info`
1746 local commit0=`git_show_head $testroot/repo`
1747 local commit0_author_time=`git_show_author_time $testroot/repo`
1748 local committer="$GOT_AUTHOR"
1750 (cd $testroot/repo && git checkout -q -b newbranch)
1751 echo "modified delta on branch" > $testroot/repo/gamma/delta
1752 git_commit $testroot/repo -m "committing to delta on newbranch"
1754 echo "modified alpha on branch" > $testroot/repo/alpha
1755 git_commit $testroot/repo -m "committing more changes on newbranch"
1757 local orig_commit1=`git_show_parent_commit $testroot/repo`
1758 local orig_commit2=`git_show_head $testroot/repo`
1759 local orig_author_time2=`git_show_author_time $testroot/repo`
1761 (cd $testroot/repo && git checkout -q master)
1762 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1763 git_commit $testroot/repo -m "committing to zeta on master"
1764 local master_commit=`git_show_head $testroot/repo`
1766 got checkout $testroot/repo $testroot/wt > /dev/null
1767 ret=$?
1768 if [ $ret -ne 0 ]; then
1769 test_done "$testroot" "$ret"
1770 return 1
1773 # unset in a subshell to avoid affecting our environment
1774 (unset GOT_AUTHOR && cd $testroot/wt && \
1775 got rebase newbranch > $testroot/stdout)
1777 (cd $testroot/repo && git checkout -q newbranch)
1778 local new_commit1=`git_show_parent_commit $testroot/repo`
1779 local new_commit2=`git_show_head $testroot/repo`
1780 local new_author_time2=`git_show_author_time $testroot/repo`
1782 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1783 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1784 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1785 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1787 echo "G gamma/delta" >> $testroot/stdout.expected
1788 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1789 >> $testroot/stdout.expected
1790 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1791 echo "G alpha" >> $testroot/stdout.expected
1792 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1793 >> $testroot/stdout.expected
1794 echo ": committing more changes on newbranch" \
1795 >> $testroot/stdout.expected
1796 echo "Switching work tree to refs/heads/newbranch" \
1797 >> $testroot/stdout.expected
1799 cmp -s $testroot/stdout.expected $testroot/stdout
1800 ret=$?
1801 if [ $ret -ne 0 ]; then
1802 diff -u $testroot/stdout.expected $testroot/stdout
1803 test_done "$testroot" "$ret"
1804 return 1
1807 # Original commit only had one author
1808 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1809 egrep '^(from|via):' > $testroot/stdout)
1810 echo "from: $committer" > $testroot/stdout.expected
1811 cmp -s $testroot/stdout.expected $testroot/stdout
1812 ret=$?
1813 if [ $ret -ne 0 ]; then
1814 diff -u $testroot/stdout.expected $testroot/stdout
1815 test_done "$testroot" "$ret"
1816 return 1
1819 # Author info of rebased commit should match the original
1820 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1821 egrep '^(from|via):' > $testroot/stdout)
1822 echo "from: $committer" > $testroot/stdout.expected
1824 cmp -s $testroot/stdout.expected $testroot/stdout
1825 ret=$?
1826 if [ $ret -ne 0 ]; then
1827 diff -u $testroot/stdout.expected $testroot/stdout
1829 test_done "$testroot" "$ret"
1832 test_rebase_nonbranch() {
1833 local testroot=`test_init rebase_nonbranch`
1835 got ref -r $testroot/repo -c refs/heads/master \
1836 refs/remotes/origin/master >/dev/null
1838 got checkout -b master $testroot/repo $testroot/wt >/dev/null
1840 (cd $testroot/wt && got rebase origin/master > $testroot/stdout \
1841 2> $testroot/stderr)
1842 ret=$?
1843 if [ $ret -eq 0 ]; then
1844 echo "rebase succeeded unexpectedly" >&2
1845 test_done "$testroot" "1"
1846 return 1
1848 echo -n "got: will not rebase a branch which lives outside the " \
1849 > $testroot/stderr.expected
1850 echo '"refs/heads/" reference namespace' >> $testroot/stderr.expected
1851 cmp -s $testroot/stderr.expected $testroot/stderr
1852 ret=$?
1853 if [ $ret -ne 0 ]; then
1854 diff -u $testroot/stderr.expected $testroot/stderr
1856 test_done "$testroot" "$ret"
1859 test_rebase_umask() {
1860 local testroot=`test_init rebase_umask`
1861 local commit0=`git_show_head "$testroot/repo"`
1863 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1864 (cd "$testroot/wt" && got branch newbranch) >/dev/null
1866 echo "modified alpha on branch" >$testroot/wt/alpha
1867 (cd "$testroot/wt" && got commit -m 'modified alpha on newbranch') \
1868 >/dev/null
1870 (cd "$testroot/wt" && got update -b master) >/dev/null
1871 ret=$?
1872 if [ $ret -ne 0 ]; then
1873 echo "got update failed!" >&2
1874 test_done "$testroot" $ret
1875 return 1
1878 echo "modified beta on master" >$testroot/wt/beta
1879 (cd "$testroot/wt" && got commit -m 'modified beta on master') \
1880 >/dev/null
1881 (cd "$testroot/wt" && got update) >/dev/null
1883 # using a subshell to avoid clobbering global umask
1884 (umask 077 && cd "$testroot/wt" && got rebase newbranch) >/dev/null
1885 ret=$?
1886 if [ $ret -ne 0 ]; then
1887 echo "got rebase failed" >&2
1888 test_done "$testroot" $ret
1889 return 1
1892 ls -l "$testroot/wt/alpha" | grep -q ^-rw-------
1893 if [ $? -ne 0 ]; then
1894 echo "alpha is not 0600 after rebase" >&2
1895 ls -l "$testroot/wt/alpha" >&2
1896 test_done "$testroot" 1
1897 return 1
1900 test_done "$testroot" 0
1903 test_rebase_out_of_date2() {
1904 local testroot=`test_init rebase_out_of_date2`
1905 local commit0=`git_show_head $testroot/repo`
1906 local commit0_author_time=`git_show_author_time $testroot/repo`
1908 (cd $testroot/repo && git checkout -q -b newbranch)
1909 echo "modified delta on branch" > $testroot/repo/gamma/delta
1910 git_commit $testroot/repo -m "committing to delta on newbranch"
1912 local orig_commit1=`git_show_parent_commit $testroot/repo`
1913 local orig_commit2=`git_show_head $testroot/repo`
1914 local orig_author_time2=`git_show_author_time $testroot/repo`
1916 (cd $testroot/repo && git checkout -q master)
1917 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1918 git_commit $testroot/repo -m "committing to zeta on master"
1919 local master_commit=`git_show_head $testroot/repo`
1921 got checkout $testroot/repo $testroot/wt > /dev/null
1922 ret=$?
1923 if [ $ret -ne 0 ]; then
1924 test_done "$testroot" "$ret"
1925 return 1
1928 # Backdate the file alpha to an earlier version.
1929 # This sets the work tree's base commit ID back to $commit0,
1930 # which is out-of-date with respect to the master branch.
1931 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
1933 # Rebase into an out-of-date work tree should be refused.
1934 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1935 2> $testroot/stderr)
1936 ret=$?
1937 if [ $ret -eq 0 ]; then
1938 echo "rebase succeeded unexpectedly" >&2
1939 test_done "$testroot" "1"
1940 return 1
1942 echo -n > $testroot/stdout.expected
1943 echo -n "got: work tree must be updated before it can be used to " \
1944 > $testroot/stderr.expected
1945 echo "rebase a branch" >> $testroot/stderr.expected
1946 cmp -s $testroot/stderr.expected $testroot/stderr
1947 ret=$?
1948 if [ $ret -ne 0 ]; then
1949 diff -u $testroot/stderr.expected $testroot/stderr
1951 test_done "$testroot" "$ret"
1954 test_rebase_one_commit() {
1955 local testroot=`test_init rebase_one_commit`
1957 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1958 test_done "$testroot" 1
1959 return 1
1962 (cd $testroot/wt && got branch newbranch) >/dev/null
1964 echo "modified alpha on newbranch" >$testroot/wt/alpha
1965 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
1966 (cd $testroot/wt && got update) >/dev/null
1967 local commit=`git_show_branch_head $testroot/repo newbranch`
1969 echo -n '' > $testroot/stderr.expected
1971 (cd $testroot/wt && got rebase master >$testroot/stdout \
1972 2> $testroot/stderr)
1973 ret=$?
1974 if [ $ret -ne 0 ]; then
1975 echo "rebase comand failed unexpectedly" >&2
1976 diff -u $testroot/stderr.expected $testroot/stderr
1977 test_done "$testroot" "1"
1978 return 1
1981 echo "Forwarding refs/heads/master to commit $commit" \
1982 >$testroot/stdout.expected
1983 echo "Switching work tree to refs/heads/master" \
1984 >> $testroot/stdout.expected
1986 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
1987 diff -u $testroot/stdout.expected $testroot/stdout
1988 test_done "$testroot" 1
1989 return 1
1992 test_done "$testroot" 0
1995 test_parseargs "$@"
1996 run_test test_rebase_basic
1997 run_test test_rebase_ancestry_check
1998 run_test test_rebase_continue
1999 run_test test_rebase_abort
2000 run_test test_rebase_no_op_change
2001 run_test test_rebase_in_progress
2002 run_test test_rebase_path_prefix
2003 run_test test_rebase_preserves_logmsg
2004 run_test test_rebase_no_commits_to_rebase
2005 run_test test_rebase_forward
2006 run_test test_rebase_forward_path_prefix
2007 run_test test_rebase_out_of_date
2008 run_test test_rebase_trims_empty_dir
2009 run_test test_rebase_delete_missing_file
2010 run_test test_rebase_rm_add_rm_file
2011 run_test test_rebase_resets_committer
2012 run_test test_rebase_no_author_info
2013 run_test test_rebase_nonbranch
2014 run_test test_rebase_umask
2015 run_test test_rebase_out_of_date2
2016 run_test test_rebase_one_commit