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 alpha on branch" > $testroot/repo/alpha
417 git_commit $testroot/repo -m "committing to alpha on newbranch"
418 local orig_commit1=`git_show_head $testroot/repo`
419 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
421 (cd $testroot/repo && git checkout -q master)
422 echo "modified alpha on master" > $testroot/repo/alpha
423 git_commit $testroot/repo -m "committing to alpha on master"
424 local master_commit=`git_show_head $testroot/repo`
426 got checkout $testroot/repo $testroot/wt > /dev/null
427 ret=$?
428 if [ $ret -ne 0 ]; then
429 test_done "$testroot" "$ret"
430 return 1
431 fi
433 # unrelated unversioned file in work tree
434 touch $testroot/wt/unversioned-file
436 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
437 2> $testroot/stderr)
439 echo "C alpha" > $testroot/stdout.expected
440 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
441 echo -n "$short_orig_commit1 -> merge conflict" \
442 >> $testroot/stdout.expected
443 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
444 cmp -s $testroot/stdout.expected $testroot/stdout
445 ret=$?
446 if [ $ret -ne 0 ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout
448 test_done "$testroot" "$ret"
449 return 1
450 fi
452 echo "got: conflicts must be resolved before rebasing can continue" \
453 > $testroot/stderr.expected
454 cmp -s $testroot/stderr.expected $testroot/stderr
455 ret=$?
456 if [ $ret -ne 0 ]; then
457 diff -u $testroot/stderr.expected $testroot/stderr
458 test_done "$testroot" "$ret"
459 return 1
460 fi
462 echo '<<<<<<<' > $testroot/content.expected
463 echo "modified alpha on master" >> $testroot/content.expected
464 echo "||||||| 3-way merge base: commit $init_commit" \
465 >> $testroot/content.expected
466 echo "alpha" >> $testroot/content.expected
467 echo "=======" >> $testroot/content.expected
468 echo "modified alpha on branch" >> $testroot/content.expected
469 echo ">>>>>>> merged change: commit $orig_commit1" \
470 >> $testroot/content.expected
471 cat $testroot/wt/alpha > $testroot/content
472 cmp -s $testroot/content.expected $testroot/content
473 ret=$?
474 if [ $ret -ne 0 ]; then
475 diff -u $testroot/content.expected $testroot/content
476 test_done "$testroot" "$ret"
477 return 1
478 fi
480 (cd $testroot/wt && got status > $testroot/stdout)
482 echo "C alpha" > $testroot/stdout.expected
483 echo "? unversioned-file" >> $testroot/stdout.expected
484 cmp -s $testroot/stdout.expected $testroot/stdout
485 ret=$?
486 if [ $ret -ne 0 ]; then
487 diff -u $testroot/stdout.expected $testroot/stdout
488 test_done "$testroot" "$ret"
489 return 1
490 fi
492 (cd $testroot/wt && got rebase -a > $testroot/stdout)
494 (cd $testroot/repo && git checkout -q newbranch)
496 echo "Switching work tree to refs/heads/master" \
497 > $testroot/stdout.expected
498 echo 'R alpha' >> $testroot/stdout.expected
499 echo "Rebase of refs/heads/newbranch aborted" \
500 >> $testroot/stdout.expected
502 cmp -s $testroot/stdout.expected $testroot/stdout
503 ret=$?
504 if [ $ret -ne 0 ]; then
505 diff -u $testroot/stdout.expected $testroot/stdout
506 test_done "$testroot" "$ret"
507 return 1
508 fi
510 echo "modified alpha on master" > $testroot/content.expected
511 cat $testroot/wt/alpha > $testroot/content
512 cmp -s $testroot/content.expected $testroot/content
513 ret=$?
514 if [ $ret -ne 0 ]; then
515 diff -u $testroot/content.expected $testroot/content
516 test_done "$testroot" "$ret"
517 return 1
518 fi
520 (cd $testroot/wt && got log -l3 -c newbranch \
521 | grep ^commit > $testroot/stdout)
522 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
523 echo "commit $init_commit" >> $testroot/stdout.expected
524 cmp -s $testroot/stdout.expected $testroot/stdout
525 ret=$?
526 if [ $ret -ne 0 ]; then
527 diff -u $testroot/stdout.expected $testroot/stdout
528 fi
529 test_done "$testroot" "$ret"
532 test_rebase_no_op_change() {
533 local testroot=`test_init rebase_no_op_change`
534 local init_commit=`git_show_head $testroot/repo`
536 (cd $testroot/repo && git checkout -q -b newbranch)
537 echo "modified alpha on branch" > $testroot/repo/alpha
538 git_commit $testroot/repo -m "committing to alpha on newbranch"
539 local orig_commit1=`git_show_head $testroot/repo`
540 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
542 (cd $testroot/repo && git checkout -q master)
543 echo "modified alpha on master" > $testroot/repo/alpha
544 git_commit $testroot/repo -m "committing to alpha on master"
545 local master_commit=`git_show_head $testroot/repo`
547 got checkout $testroot/repo $testroot/wt > /dev/null
548 ret=$?
549 if [ $ret -ne 0 ]; then
550 test_done "$testroot" "$ret"
551 return 1
552 fi
554 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
555 2> $testroot/stderr)
557 echo "C alpha" > $testroot/stdout.expected
558 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
559 echo -n "$short_orig_commit1 -> merge conflict" \
560 >> $testroot/stdout.expected
561 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
562 cmp -s $testroot/stdout.expected $testroot/stdout
563 ret=$?
564 if [ $ret -ne 0 ]; then
565 diff -u $testroot/stdout.expected $testroot/stdout
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 echo "got: conflicts must be resolved before rebasing can continue" \
571 > $testroot/stderr.expected
572 cmp -s $testroot/stderr.expected $testroot/stderr
573 ret=$?
574 if [ $ret -ne 0 ]; then
575 diff -u $testroot/stderr.expected $testroot/stderr
576 test_done "$testroot" "$ret"
577 return 1
578 fi
580 echo '<<<<<<<' > $testroot/content.expected
581 echo "modified alpha on master" >> $testroot/content.expected
582 echo "||||||| 3-way merge base: commit $init_commit" \
583 >> $testroot/content.expected
584 echo "alpha" >> $testroot/content.expected
585 echo "=======" >> $testroot/content.expected
586 echo "modified alpha on branch" >> $testroot/content.expected
587 echo ">>>>>>> merged change: commit $orig_commit1" \
588 >> $testroot/content.expected
589 cat $testroot/wt/alpha > $testroot/content
590 cmp -s $testroot/content.expected $testroot/content
591 ret=$?
592 if [ $ret -ne 0 ]; then
593 diff -u $testroot/content.expected $testroot/content
594 test_done "$testroot" "$ret"
595 return 1
596 fi
598 (cd $testroot/wt && got status > $testroot/stdout)
600 echo "C alpha" > $testroot/stdout.expected
601 cmp -s $testroot/stdout.expected $testroot/stdout
602 ret=$?
603 if [ $ret -ne 0 ]; then
604 diff -u $testroot/stdout.expected $testroot/stdout
605 test_done "$testroot" "$ret"
606 return 1
607 fi
609 # resolve the conflict
610 echo "modified alpha on master" > $testroot/wt/alpha
612 (cd $testroot/wt && got rebase -c > $testroot/stdout)
614 (cd $testroot/repo && git checkout -q newbranch)
615 local new_commit1=`git_show_head $testroot/repo`
617 echo -n "$short_orig_commit1 -> no-op change" \
618 > $testroot/stdout.expected
619 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
620 echo "Switching work tree to refs/heads/newbranch" \
621 >> $testroot/stdout.expected
623 cmp -s $testroot/stdout.expected $testroot/stdout
624 ret=$?
625 if [ $ret -ne 0 ]; then
626 diff -u $testroot/stdout.expected $testroot/stdout
627 test_done "$testroot" "$ret"
628 return 1
629 fi
632 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
633 echo "commit $master_commit (master, newbranch)" \
634 > $testroot/stdout.expected
635 echo "commit $init_commit" >> $testroot/stdout.expected
636 cmp -s $testroot/stdout.expected $testroot/stdout
637 ret=$?
638 if [ $ret -ne 0 ]; then
639 diff -u $testroot/stdout.expected $testroot/stdout
640 fi
641 test_done "$testroot" "$ret"
644 test_rebase_in_progress() {
645 local testroot=`test_init rebase_in_progress`
646 local init_commit=`git_show_head $testroot/repo`
648 (cd $testroot/repo && git checkout -q -b newbranch)
649 echo "modified alpha on branch" > $testroot/repo/alpha
650 git_commit $testroot/repo -m "committing to alpha on newbranch"
651 local orig_commit1=`git_show_head $testroot/repo`
652 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
654 (cd $testroot/repo && git checkout -q master)
655 echo "modified alpha on master" > $testroot/repo/alpha
656 git_commit $testroot/repo -m "committing to alpha on master"
657 local master_commit=`git_show_head $testroot/repo`
659 got checkout $testroot/repo $testroot/wt > /dev/null
660 ret=$?
661 if [ $ret -ne 0 ]; then
662 test_done "$testroot" "$ret"
663 return 1
664 fi
666 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
667 2> $testroot/stderr)
669 echo "C alpha" > $testroot/stdout.expected
670 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
671 echo -n "$short_orig_commit1 -> merge conflict" \
672 >> $testroot/stdout.expected
673 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
674 cmp -s $testroot/stdout.expected $testroot/stdout
675 ret=$?
676 if [ $ret -ne 0 ]; then
677 diff -u $testroot/stdout.expected $testroot/stdout
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 echo "got: conflicts must be resolved before rebasing can continue" \
683 > $testroot/stderr.expected
684 cmp -s $testroot/stderr.expected $testroot/stderr
685 ret=$?
686 if [ $ret -ne 0 ]; then
687 diff -u $testroot/stderr.expected $testroot/stderr
688 test_done "$testroot" "$ret"
689 return 1
690 fi
692 echo '<<<<<<<' > $testroot/content.expected
693 echo "modified alpha on master" >> $testroot/content.expected
694 echo "||||||| 3-way merge base: commit $init_commit" \
695 >> $testroot/content.expected
696 echo "alpha" >> $testroot/content.expected
697 echo "=======" >> $testroot/content.expected
698 echo "modified alpha on branch" >> $testroot/content.expected
699 echo ">>>>>>> merged change: commit $orig_commit1" \
700 >> $testroot/content.expected
701 cat $testroot/wt/alpha > $testroot/content
702 cmp -s $testroot/content.expected $testroot/content
703 ret=$?
704 if [ $ret -ne 0 ]; then
705 diff -u $testroot/content.expected $testroot/content
706 test_done "$testroot" "$ret"
707 return 1
708 fi
710 (cd $testroot/wt && got status > $testroot/stdout)
712 echo "C alpha" > $testroot/stdout.expected
713 cmp -s $testroot/stdout.expected $testroot/stdout
714 ret=$?
715 if [ $ret -ne 0 ]; then
716 diff -u $testroot/stdout.expected $testroot/stdout
717 test_done "$testroot" "$ret"
718 return 1
719 fi
721 for cmd in update commit; do
722 (cd $testroot/wt && got $cmd > $testroot/stdout \
723 2> $testroot/stderr)
725 echo -n > $testroot/stdout.expected
726 cmp -s $testroot/stdout.expected $testroot/stdout
727 ret=$?
728 if [ $ret -ne 0 ]; then
729 diff -u $testroot/stdout.expected $testroot/stdout
730 test_done "$testroot" "$ret"
731 return 1
732 fi
734 echo -n "got: a rebase operation is in progress in this " \
735 > $testroot/stderr.expected
736 echo "work tree and must be continued or aborted first" \
737 >> $testroot/stderr.expected
738 cmp -s $testroot/stderr.expected $testroot/stderr
739 ret=$?
740 if [ $ret -ne 0 ]; then
741 diff -u $testroot/stderr.expected $testroot/stderr
742 test_done "$testroot" "$ret"
743 return 1
744 fi
745 done
747 test_done "$testroot" "$ret"
750 test_rebase_path_prefix() {
751 local testroot=`test_init rebase_path_prefix`
753 (cd $testroot/repo && git checkout -q -b newbranch)
754 echo "modified delta on branch" > $testroot/repo/gamma/delta
755 git_commit $testroot/repo -m "committing to delta on newbranch"
757 local orig_commit1=`git_show_parent_commit $testroot/repo`
758 local orig_commit2=`git_show_head $testroot/repo`
760 (cd $testroot/repo && git checkout -q master)
761 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
762 git_commit $testroot/repo -m "committing to zeta on master"
763 local master_commit=`git_show_head $testroot/repo`
765 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
766 ret=$?
767 if [ $ret -ne 0 ]; then
768 test_done "$testroot" "$ret"
769 return 1
770 fi
772 (cd $testroot/wt && got rebase newbranch \
773 > $testroot/stdout 2> $testroot/stderr)
775 echo -n > $testroot/stdout.expected
776 cmp -s $testroot/stdout.expected $testroot/stdout
777 ret=$?
778 if [ $ret -ne 0 ]; then
779 diff -u $testroot/stdout.expected $testroot/stdout
780 test_done "$testroot" "$ret"
781 return 1
782 fi
784 echo -n "got: cannot rebase branch which contains changes outside " \
785 > $testroot/stderr.expected
786 echo "of this work tree's path prefix" >> $testroot/stderr.expected
787 cmp -s $testroot/stderr.expected $testroot/stderr
788 ret=$?
789 if [ $ret -ne 0 ]; then
790 diff -u $testroot/stderr.expected $testroot/stderr
791 test_done "$testroot" "$ret"
792 return 1
793 fi
795 # rebase should succeed when using a complete work tree
796 got checkout $testroot/repo $testroot/wt2 > /dev/null
797 ret=$?
798 if [ $ret -ne 0 ]; then
799 test_done "$testroot" "$ret"
800 return 1
801 fi
803 (cd $testroot/wt2 && got rebase newbranch \
804 > $testroot/stdout 2> $testroot/stderr)
806 (cd $testroot/repo && git checkout -q newbranch)
807 local new_commit1=`git_show_parent_commit $testroot/repo`
808 local new_commit2=`git_show_head $testroot/repo`
810 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
811 local short_new_commit2=`trim_obj_id 28 $new_commit2`
813 echo "G gamma/delta" > $testroot/stdout.expected
814 echo -n "$short_orig_commit2 -> $short_new_commit2" \
815 >> $testroot/stdout.expected
816 echo ": committing to delta on newbranch" \
817 >> $testroot/stdout.expected
818 echo "Switching work tree to refs/heads/newbranch" \
819 >> $testroot/stdout.expected
821 cmp -s $testroot/stdout.expected $testroot/stdout
822 ret=$?
823 if [ $ret -ne 0 ]; then
824 diff -u $testroot/stdout.expected $testroot/stdout
825 test_done "$testroot" "$ret"
826 return 1
827 fi
829 # the first work tree should remain usable
830 (cd $testroot/wt && got update -b master \
831 > $testroot/stdout 2> $testroot/stderr)
832 ret=$?
833 if [ $ret -ne 0 ]; then
834 echo "update failed unexpectedly" >&2
835 test_done "$testroot" "1"
836 return 1
837 fi
839 echo 'Already up-to-date' > $testroot/stdout.expected
840 cmp -s $testroot/stdout.expected $testroot/stdout
841 ret=$?
842 if [ $ret -ne 0 ]; then
843 diff -u $testroot/stdout.expected $testroot/stdout
844 fi
845 test_done "$testroot" "$ret"
848 test_rebase_preserves_logmsg() {
849 local testroot=`test_init rebase_preserves_logmsg`
851 (cd $testroot/repo && git checkout -q -b newbranch)
852 echo "modified delta on branch" > $testroot/repo/gamma/delta
853 git_commit $testroot/repo -m "modified delta on newbranch"
855 echo "modified alpha on branch" > $testroot/repo/alpha
856 git_commit $testroot/repo -m "modified alpha on newbranch"
858 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
859 > $testroot/log.expected)
861 local orig_commit1=`git_show_parent_commit $testroot/repo`
862 local orig_commit2=`git_show_head $testroot/repo`
864 (cd $testroot/repo && git checkout -q master)
865 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
866 git_commit $testroot/repo -m "committing to zeta on master"
867 local master_commit=`git_show_head $testroot/repo`
869 got checkout $testroot/repo $testroot/wt > /dev/null
870 ret=$?
871 if [ $ret -ne 0 ]; then
872 test_done "$testroot" "$ret"
873 return 1
874 fi
876 (cd $testroot/wt && got rebase newbranch > /dev/null \
877 2> $testroot/stderr)
879 (cd $testroot/repo && git checkout -q newbranch)
880 local new_commit1=`git_show_parent_commit $testroot/repo`
881 local new_commit2=`git_show_head $testroot/repo`
883 echo -n > $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
890 fi
892 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
893 > $testroot/log)
894 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
895 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
896 cmp -s $testroot/log.expected $testroot/log
897 ret=$?
898 if [ $ret -ne 0 ]; then
899 diff -u $testroot/log.expected $testroot/log
900 fi
902 test_done "$testroot" "$ret"
905 test_rebase_no_commits_to_rebase() {
906 local testroot=`test_init rebase_no_commits_to_rebase`
908 got checkout $testroot/repo $testroot/wt > /dev/null
909 ret=$?
910 if [ $ret -ne 0 ]; then
911 test_done "$testroot" "$ret"
912 return 1
913 fi
915 # Create an unrelated branch with 'got import'.
916 mkdir -p $testroot/newtree
917 echo "new file" > $testroot/newtree/newfile
918 got import -m new -b newbranch -r $testroot/repo \
919 $testroot/newtree > /dev/null
921 echo "modified alpha on master" > $testroot/wt/alpha
922 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
923 > /dev/null)
924 (cd $testroot/wt && got update > /dev/null)
926 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
927 2> $testroot/stderr)
929 echo -n "got: specified branch shares no common ancestry " \
930 > $testroot/stderr.expected
931 echo "with work tree's branch" >> $testroot/stderr.expected
932 cmp -s $testroot/stderr.expected $testroot/stderr
933 ret=$?
934 if [ $ret -ne 0 ]; then
935 diff -u $testroot/stderr.expected $testroot/stderr
936 test_done "$testroot" "$ret"
937 return 1
938 fi
940 echo -n > $testroot/stdout.expected
941 cmp -s $testroot/stdout.expected $testroot/stdout
942 ret=$?
943 if [ $ret -ne 0 ]; then
944 diff -u $testroot/stdout.expected $testroot/stdout
945 test_done "$testroot" "$ret"
946 return 1
947 fi
949 (cd $testroot/wt && got update > $testroot/stdout)
950 echo "Already up-to-date" > $testroot/stdout.expected
951 cmp -s $testroot/stdout.expected $testroot/stdout
952 ret=$?
953 if [ $ret -ne 0 ]; then
954 diff -u $testroot/stdout.expected $testroot/stdout
955 fi
956 test_done "$testroot" "$ret"
959 test_rebase_forward() {
960 local testroot=`test_init rebase_forward`
961 local commit0=`git_show_head $testroot/repo`
963 got checkout $testroot/repo $testroot/wt > /dev/null
964 ret=$?
965 if [ $ret -ne 0 ]; then
966 test_done "$testroot" "$ret"
967 return 1
968 fi
970 echo "change alpha 1" > $testroot/wt/alpha
971 (cd $testroot/wt && got commit -m 'test rebase_forward' \
972 > /dev/null)
973 local commit1=`git_show_head $testroot/repo`
975 echo "change alpha 2" > $testroot/wt/alpha
976 (cd $testroot/wt && got commit -m 'test rebase_forward' \
977 > /dev/null)
978 local commit2=`git_show_head $testroot/repo`
980 # Simulate a situation where fast-forward is required.
981 # We want to fast-forward master to origin/master:
982 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
983 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
984 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
985 (cd $testroot/repo && got ref -d master >/dev/null)
986 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
987 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
989 (cd $testroot/wt && got up -b origin/master > /dev/null)
991 (cd $testroot/wt && got rebase master \
992 > $testroot/stdout 2> $testroot/stderr)
994 echo "Forwarding refs/heads/master to commit $commit2" \
995 > $testroot/stdout.expected
996 echo "Switching work tree to refs/heads/master" \
997 >> $testroot/stdout.expected
998 cmp -s $testroot/stdout.expected $testroot/stdout
999 ret=$?
1000 if [ $ret -ne 0 ]; then
1001 diff -u $testroot/stdout.expected $testroot/stdout
1002 test_done "$testroot" "$ret"
1003 return 1
1006 # Ensure that rebase operation was completed correctly
1007 (cd $testroot/wt && got rebase -a \
1008 > $testroot/stdout 2> $testroot/stderr)
1009 echo -n "" > $testroot/stdout.expected
1010 cmp -s $testroot/stdout.expected $testroot/stdout
1011 ret=$?
1012 if [ $ret -ne 0 ]; then
1013 diff -u $testroot/stdout.expected $testroot/stdout
1014 test_done "$testroot" "$ret"
1015 return 1
1017 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1018 cmp -s $testroot/stderr.expected $testroot/stderr
1019 ret=$?
1020 if [ $ret -ne 0 ]; then
1021 diff -u $testroot/stderr.expected $testroot/stderr
1022 test_done "$testroot" "$ret"
1023 return 1
1026 (cd $testroot/wt && got branch -n > $testroot/stdout)
1027 echo "master" > $testroot/stdout.expected
1028 cmp -s $testroot/stdout.expected $testroot/stdout
1029 ret=$?
1030 if [ $ret -ne 0 ]; then
1031 diff -u $testroot/stdout.expected $testroot/stdout
1032 test_done "$testroot" "$ret"
1033 return 1
1036 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1037 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1038 echo "commit $commit1" >> $testroot/stdout.expected
1039 echo "commit $commit0" >> $testroot/stdout.expected
1040 cmp -s $testroot/stdout.expected $testroot/stdout
1041 ret=$?
1042 if [ $ret -ne 0 ]; then
1043 diff -u $testroot/stdout.expected $testroot/stdout
1044 test_done "$testroot" "$ret"
1045 return 1
1048 # Forward-only rebase operations should not be backed up
1049 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1050 echo -n > $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_path_prefix() {
1060 local testroot=`test_init rebase_forward_path_prefix`
1061 local commit0=`git_show_head $testroot/repo`
1063 got checkout $testroot/repo $testroot/wt-full > /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-full/alpha
1071 (cd $testroot/wt-full && got commit -m 'test rebase_forward' \
1072 > /dev/null)
1073 local commit1=`git_show_head $testroot/repo`
1075 echo "change alpha 2" > $testroot/wt-full/alpha
1076 (cd $testroot/wt-full && 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 # Work tree which uses a path-prefix and will be used for rebasing
1090 got checkout -p epsilon -b origin/master $testroot/repo $testroot/wt \
1091 > /dev/null
1092 ret=$?
1093 if [ $ret -ne 0 ]; then
1094 test_done "$testroot" "$ret"
1095 return 1
1098 (cd $testroot/wt && got rebase master \
1099 > $testroot/stdout 2> $testroot/stderr)
1101 echo "Forwarding refs/heads/master to commit $commit2" \
1102 > $testroot/stdout.expected
1103 echo "Switching work tree to refs/heads/master" \
1104 >> $testroot/stdout.expected
1105 cmp -s $testroot/stdout.expected $testroot/stdout
1106 ret=$?
1107 if [ $ret -ne 0 ]; then
1108 diff -u $testroot/stdout.expected $testroot/stdout
1109 test_done "$testroot" "$ret"
1110 return 1
1113 # Ensure that rebase operation was completed correctly
1114 (cd $testroot/wt && got rebase -a \
1115 > $testroot/stdout 2> $testroot/stderr)
1116 echo -n "" > $testroot/stdout.expected
1117 cmp -s $testroot/stdout.expected $testroot/stdout
1118 ret=$?
1119 if [ $ret -ne 0 ]; then
1120 diff -u $testroot/stdout.expected $testroot/stdout
1121 test_done "$testroot" "$ret"
1122 return 1
1124 echo "got: rebase operation not in progress" > $testroot/stderr.expected
1125 cmp -s $testroot/stderr.expected $testroot/stderr
1126 ret=$?
1127 if [ $ret -ne 0 ]; then
1128 diff -u $testroot/stderr.expected $testroot/stderr
1129 test_done "$testroot" "$ret"
1130 return 1
1133 (cd $testroot/wt && got branch -n > $testroot/stdout)
1134 echo "master" > $testroot/stdout.expected
1135 cmp -s $testroot/stdout.expected $testroot/stdout
1136 ret=$?
1137 if [ $ret -ne 0 ]; then
1138 diff -u $testroot/stdout.expected $testroot/stdout
1139 test_done "$testroot" "$ret"
1140 return 1
1143 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1144 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
1145 echo "commit $commit1" >> $testroot/stdout.expected
1146 echo "commit $commit0" >> $testroot/stdout.expected
1147 cmp -s $testroot/stdout.expected $testroot/stdout
1148 ret=$?
1149 if [ $ret -ne 0 ]; then
1150 diff -u $testroot/stdout.expected $testroot/stdout
1151 test_done "$testroot" "$ret"
1152 return 1
1155 # Forward-only rebase operations should not be backed up
1156 (cd $testroot/repo && got rebase -l > $testroot/stdout)
1157 echo -n > $testroot/stdout.expected
1158 cmp -s $testroot/stdout.expected $testroot/stdout
1159 ret=$?
1160 if [ $ret -ne 0 ]; then
1161 diff -u $testroot/stdout.expected $testroot/stdout
1163 test_done "$testroot" "$ret"
1166 test_rebase_out_of_date() {
1167 local testroot=`test_init rebase_out_of_date`
1168 local initial_commit=`git_show_head $testroot/repo`
1170 (cd $testroot/repo && git checkout -q -b newbranch)
1171 echo "modified delta on branch" > $testroot/repo/gamma/delta
1172 git_commit $testroot/repo -m "committing to delta on newbranch"
1174 echo "modified alpha on branch" > $testroot/repo/alpha
1175 (cd $testroot/repo && git rm -q beta)
1176 echo "new file on branch" > $testroot/repo/epsilon/new
1177 (cd $testroot/repo && git add epsilon/new)
1178 git_commit $testroot/repo -m "committing more changes on newbranch"
1180 local orig_commit1=`git_show_parent_commit $testroot/repo`
1181 local orig_commit2=`git_show_head $testroot/repo`
1183 (cd $testroot/repo && git checkout -q master)
1184 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1185 git_commit $testroot/repo -m "committing to zeta on master"
1186 local master_commit1=`git_show_head $testroot/repo`
1188 (cd $testroot/repo && git checkout -q master)
1189 echo "modified beta on master" > $testroot/repo/beta
1190 git_commit $testroot/repo -m "committing to beta on master"
1191 local master_commit2=`git_show_head $testroot/repo`
1193 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1194 > /dev/null
1195 ret=$?
1196 if [ $ret -ne 0 ]; then
1197 test_done "$testroot" "$ret"
1198 return 1
1201 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1202 2> $testroot/stderr)
1204 echo -n > $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 echo -n "got: work tree must be updated before it can be " \
1214 > $testroot/stderr.expected
1215 echo "used to rebase a branch" >> $testroot/stderr.expected
1216 cmp -s $testroot/stderr.expected $testroot/stderr
1217 ret=$?
1218 if [ $ret -ne 0 ]; then
1219 diff -u $testroot/stderr.expected $testroot/stderr
1220 test_done "$testroot" "$ret"
1221 return 1
1224 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1225 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1226 echo "commit $master_commit1" >> $testroot/stdout.expected
1227 echo "commit $initial_commit" >> $testroot/stdout.expected
1228 cmp -s $testroot/stdout.expected $testroot/stdout
1229 ret=$?
1230 if [ $ret -ne 0 ]; then
1231 diff -u $testroot/stdout.expected $testroot/stdout
1233 test_done "$testroot" "$ret"
1236 test_rebase_trims_empty_dir() {
1237 local testroot=`test_init rebase_trims_empty_dir`
1239 (cd $testroot/repo && git checkout -q -b newbranch)
1240 echo "modified delta on branch" > $testroot/repo/gamma/delta
1241 git_commit $testroot/repo -m "committing to delta on newbranch"
1243 (cd $testroot/repo && git rm -q epsilon/zeta)
1244 git_commit $testroot/repo -m "removing zeta on newbranch"
1246 local orig_commit1=`git_show_parent_commit $testroot/repo`
1247 local orig_commit2=`git_show_head $testroot/repo`
1249 (cd $testroot/repo && git checkout -q master)
1250 echo "modified alpha on master" > $testroot/repo/alpha
1251 git_commit $testroot/repo -m "committing to alpha on master"
1252 local master_commit=`git_show_head $testroot/repo`
1254 got checkout $testroot/repo $testroot/wt > /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)
1263 (cd $testroot/repo && git checkout -q newbranch)
1264 local new_commit1=`git_show_parent_commit $testroot/repo`
1265 local new_commit2=`git_show_head $testroot/repo`
1267 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1268 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1269 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1270 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1272 echo "G gamma/delta" >> $testroot/stdout.expected
1273 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1274 >> $testroot/stdout.expected
1275 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1276 echo "D epsilon/zeta" >> $testroot/stdout.expected
1277 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1278 >> $testroot/stdout.expected
1279 echo ": removing zeta on newbranch" \
1280 >> $testroot/stdout.expected
1281 echo "Switching work tree to refs/heads/newbranch" \
1282 >> $testroot/stdout.expected
1284 cmp -s $testroot/stdout.expected $testroot/stdout
1285 ret=$?
1286 if [ $ret -ne 0 ]; then
1287 diff -u $testroot/stdout.expected $testroot/stdout
1288 test_done "$testroot" "$ret"
1289 return 1
1292 echo "modified delta on branch" > $testroot/content.expected
1293 cat $testroot/wt/gamma/delta > $testroot/content
1294 cmp -s $testroot/content.expected $testroot/content
1295 ret=$?
1296 if [ $ret -ne 0 ]; then
1297 diff -u $testroot/content.expected $testroot/content
1298 test_done "$testroot" "$ret"
1299 return 1
1302 echo "modified alpha on master" > $testroot/content.expected
1303 cat $testroot/wt/alpha > $testroot/content
1304 cmp -s $testroot/content.expected $testroot/content
1305 ret=$?
1306 if [ $ret -ne 0 ]; then
1307 diff -u $testroot/content.expected $testroot/content
1308 test_done "$testroot" "$ret"
1309 return 1
1312 if [ -e $testroot/wt/epsilon ]; then
1313 echo "parent of removed zeta still exists on disk" >&2
1314 test_done "$testroot" "1"
1315 return 1
1318 (cd $testroot/wt && got status > $testroot/stdout)
1320 echo -n > $testroot/stdout.expected
1321 cmp -s $testroot/stdout.expected $testroot/stdout
1322 ret=$?
1323 if [ $ret -ne 0 ]; then
1324 diff -u $testroot/stdout.expected $testroot/stdout
1325 test_done "$testroot" "$ret"
1326 return 1
1329 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1330 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1331 echo "commit $new_commit1" >> $testroot/stdout.expected
1332 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1333 cmp -s $testroot/stdout.expected $testroot/stdout
1334 ret=$?
1335 if [ $ret -ne 0 ]; then
1336 diff -u $testroot/stdout.expected $testroot/stdout
1338 test_done "$testroot" "$ret"
1341 test_rebase_delete_missing_file() {
1342 local testroot=`test_init rebase_delete_missing_file`
1344 mkdir -p $testroot/repo/d/f/g
1345 echo "new file" > $testroot/repo/d/f/g/new
1346 (cd $testroot/repo && git add d/f/g/new)
1347 git_commit $testroot/repo -m "adding a subdir"
1348 local commit0=`git_show_head $testroot/repo`
1350 got br -r $testroot/repo -c master newbranch
1352 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1354 echo "modified delta on branch" > $testroot/wt/gamma/delta
1355 (cd $testroot/wt && got commit \
1356 -m "committing to delta on newbranch" > /dev/null)
1358 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1359 (cd $testroot/wt && got commit \
1360 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1362 (cd $testroot/repo && git checkout -q newbranch)
1363 local orig_commit1=`git_show_parent_commit $testroot/repo`
1364 local orig_commit2=`git_show_head $testroot/repo`
1366 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1367 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1369 (cd $testroot/wt && got update -b master > /dev/null)
1370 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1371 (cd $testroot/wt && got commit \
1372 -m "removing beta and d/f/g/new on master" > /dev/null)
1374 (cd $testroot/repo && git checkout -q master)
1375 local master_commit=`git_show_head $testroot/repo`
1377 (cd $testroot/wt && got update -b master > /dev/null)
1378 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1379 2> $testroot/stderr)
1380 ret=$?
1381 if [ $ret -eq 0 ]; then
1382 echo "rebase succeeded unexpectedly" >&2
1383 test_done "$testroot" "1"
1384 return 1
1387 local new_commit1=$(cd $testroot/wt && got info | \
1388 grep '^work tree base commit: ' | cut -d: -f2 | tr -d ' ')
1390 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1391 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1393 echo "G gamma/delta" >> $testroot/stdout.expected
1394 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1395 >> $testroot/stdout.expected
1396 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1397 echo "! beta" >> $testroot/stdout.expected
1398 echo "! d/f/g/new" >> $testroot/stdout.expected
1399 echo -n "Files which had incoming changes but could not be found " \
1400 >> $testroot/stdout.expected
1401 echo "in the work tree: 2" >> $testroot/stdout.expected
1402 cmp -s $testroot/stdout.expected $testroot/stdout
1403 ret=$?
1404 if [ $ret -ne 0 ]; then
1405 diff -u $testroot/stdout.expected $testroot/stdout
1406 test_done "$testroot" "$ret"
1407 return 1
1410 echo -n "got: changes destined for some files were not yet merged " \
1411 > $testroot/stderr.expected
1412 echo -n "and should be merged manually if required before the " \
1413 >> $testroot/stderr.expected
1414 echo "rebase operation is continued" >> $testroot/stderr.expected
1415 cmp -s $testroot/stderr.expected $testroot/stderr
1416 ret=$?
1417 if [ $ret -ne 0 ]; then
1418 diff -u $testroot/stderr.expected $testroot/stderr
1419 test_done "$testroot" "$ret"
1420 return 1
1423 # ignore the missing changes and continue
1424 (cd $testroot/wt && got rebase -c > $testroot/stdout)
1425 ret=$?
1426 if [ $ret -ne 0 ]; then
1427 echo "rebase failed unexpectedly" >&2
1428 test_done "$testroot" "1"
1429 return 1
1431 echo -n "$short_orig_commit2 -> no-op change" \
1432 > $testroot/stdout.expected
1433 echo ": removing beta and d/f/g/new on newbranch" \
1434 >> $testroot/stdout.expected
1435 echo "Switching work tree to refs/heads/newbranch" \
1436 >> $testroot/stdout.expected
1438 cmp -s $testroot/stdout.expected $testroot/stdout
1439 ret=$?
1440 if [ $ret -ne 0 ]; then
1441 diff -u $testroot/stdout.expected $testroot/stdout
1442 test_done "$testroot" "$ret"
1443 return 1
1446 echo "modified delta on branch" > $testroot/content.expected
1447 cat $testroot/wt/gamma/delta > $testroot/content
1448 cmp -s $testroot/content.expected $testroot/content
1449 ret=$?
1450 if [ $ret -ne 0 ]; then
1451 diff -u $testroot/content.expected $testroot/content
1452 test_done "$testroot" "$ret"
1453 return 1
1456 if [ -e $testroot/wt/beta ]; then
1457 echo "removed file beta still exists on disk" >&2
1458 test_done "$testroot" "1"
1459 return 1
1462 (cd $testroot/wt && got status > $testroot/stdout)
1464 echo -n > $testroot/stdout.expected
1465 cmp -s $testroot/stdout.expected $testroot/stdout
1466 ret=$?
1467 if [ $ret -ne 0 ]; then
1468 diff -u $testroot/stdout.expected $testroot/stdout
1469 test_done "$testroot" "$ret"
1470 return 1
1473 (cd $testroot/repo && git checkout -q newbranch)
1474 local new_commit1=`git_show_head $testroot/repo`
1475 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1477 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1478 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1479 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1480 echo "commit $commit0" >> $testroot/stdout.expected
1481 cmp -s $testroot/stdout.expected $testroot/stdout
1482 ret=$?
1483 if [ $ret -ne 0 ]; then
1484 diff -u $testroot/stdout.expected $testroot/stdout
1486 test_done "$testroot" "$ret"
1489 test_rebase_rm_add_rm_file() {
1490 local testroot=`test_init rebase_rm_add_rm_file`
1492 (cd $testroot/repo && git checkout -q -b newbranch)
1493 (cd $testroot/repo && git rm -q beta)
1494 git_commit $testroot/repo -m "removing beta from newbranch"
1495 local orig_commit1=`git_show_head $testroot/repo`
1497 echo 'restored beta' > $testroot/repo/beta
1498 (cd $testroot/repo && git add beta)
1499 git_commit $testroot/repo -m "restoring beta on newbranch"
1500 local orig_commit2=`git_show_head $testroot/repo`
1502 (cd $testroot/repo && git rm -q beta)
1503 git_commit $testroot/repo -m "removing beta from newbranch again"
1504 local orig_commit3=`git_show_head $testroot/repo`
1506 (cd $testroot/repo && git checkout -q master)
1507 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1508 git_commit $testroot/repo -m "committing to zeta on master"
1509 local master_commit=`git_show_head $testroot/repo`
1511 got checkout $testroot/repo $testroot/wt > /dev/null
1512 ret=$?
1513 if [ $ret -ne 0 ]; then
1514 test_done "$testroot" "$ret"
1515 return 1
1518 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1520 # this would error out with 'got: file index is corrupt'
1521 (cd $testroot/wt && got status > /dev/null)
1522 ret=$?
1523 if [ $ret -ne 0 ]; then
1524 echo "got status command failed unexpectedly" >&2
1525 test_done "$testroot" "$ret"
1526 return 1
1529 (cd $testroot/repo && git checkout -q newbranch)
1530 local new_commit3=`git_show_head $testroot/repo`
1531 local new_commit2=`git_show_parent_commit $testroot/repo`
1532 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1534 (cd $testroot/repo && git checkout -q newbranch)
1536 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1537 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1538 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1539 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1540 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1541 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1543 echo "D beta" > $testroot/stdout.expected
1544 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1545 >> $testroot/stdout.expected
1546 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1547 echo "A beta" >> $testroot/stdout.expected
1548 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1549 >> $testroot/stdout.expected
1550 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1551 echo "D beta" >> $testroot/stdout.expected
1552 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1553 >> $testroot/stdout.expected
1554 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1555 echo "Switching work tree to refs/heads/newbranch" \
1556 >> $testroot/stdout.expected
1558 cmp -s $testroot/stdout.expected $testroot/stdout
1559 ret=$?
1560 if [ $ret -ne 0 ]; then
1561 diff -u $testroot/stdout.expected $testroot/stdout
1562 test_done "$testroot" "$ret"
1563 return 1
1566 (cd $testroot/wt && got status > $testroot/stdout)
1567 ret=$?
1568 if [ $ret -ne 0 ]; then
1569 echo "got status command failed unexpectedly" >&2
1570 test_done "$testroot" "$ret"
1571 return 1
1574 echo -n > $testroot/stdout.expected
1575 cmp -s $testroot/stdout.expected $testroot/stdout
1576 ret=$?
1577 if [ $ret -ne 0 ]; then
1578 diff -u $testroot/stdout.expected $testroot/stdout
1579 test_done "$testroot" "$ret"
1580 return 1
1583 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1584 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1585 echo "commit $new_commit2" >> $testroot/stdout.expected
1586 echo "commit $new_commit1" >> $testroot/stdout.expected
1587 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1588 cmp -s $testroot/stdout.expected $testroot/stdout
1589 ret=$?
1590 if [ $ret -ne 0 ]; then
1591 diff -u $testroot/stdout.expected $testroot/stdout
1593 test_done "$testroot" "$ret"
1596 test_rebase_resets_committer() {
1597 local testroot=`test_init rebase_resets_committer`
1598 local commit0=`git_show_head $testroot/repo`
1599 local commit0_author_time=`git_show_author_time $testroot/repo`
1600 local committer="Flan Luck <flan_luck@openbsd.org>"
1602 (cd $testroot/repo && git checkout -q -b newbranch)
1603 echo "modified delta on branch" > $testroot/repo/gamma/delta
1604 git_commit $testroot/repo -m "committing to delta on newbranch"
1606 echo "modified alpha on branch" > $testroot/repo/alpha
1607 git_commit $testroot/repo -m "committing more changes on newbranch"
1609 local orig_commit1=`git_show_parent_commit $testroot/repo`
1610 local orig_commit2=`git_show_head $testroot/repo`
1611 local orig_author_time2=`git_show_author_time $testroot/repo`
1613 (cd $testroot/repo && git checkout -q master)
1614 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1615 git_commit $testroot/repo -m "committing to zeta on master"
1616 local master_commit=`git_show_head $testroot/repo`
1618 got checkout $testroot/repo $testroot/wt > /dev/null
1619 ret=$?
1620 if [ $ret -ne 0 ]; then
1621 test_done "$testroot" "$ret"
1622 return 1
1625 (cd $testroot/wt && env GOT_AUTHOR="$committer" \
1626 got rebase newbranch > $testroot/stdout)
1628 (cd $testroot/repo && git checkout -q newbranch)
1629 local new_commit1=`git_show_parent_commit $testroot/repo`
1630 local new_commit2=`git_show_head $testroot/repo`
1631 local new_author_time2=`git_show_author_time $testroot/repo`
1633 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1634 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1635 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1636 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1638 echo "G gamma/delta" >> $testroot/stdout.expected
1639 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1640 >> $testroot/stdout.expected
1641 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1642 echo "G alpha" >> $testroot/stdout.expected
1643 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1644 >> $testroot/stdout.expected
1645 echo ": committing more changes on newbranch" \
1646 >> $testroot/stdout.expected
1647 echo "Switching work tree to refs/heads/newbranch" \
1648 >> $testroot/stdout.expected
1650 cmp -s $testroot/stdout.expected $testroot/stdout
1651 ret=$?
1652 if [ $ret -ne 0 ]; then
1653 diff -u $testroot/stdout.expected $testroot/stdout
1654 test_done "$testroot" "$ret"
1655 return 1
1658 # Original commit only had one author
1659 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1660 egrep '^(from|via):' > $testroot/stdout)
1661 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1662 cmp -s $testroot/stdout.expected $testroot/stdout
1663 ret=$?
1664 if [ $ret -ne 0 ]; then
1665 diff -u $testroot/stdout.expected $testroot/stdout
1666 test_done "$testroot" "$ret"
1667 return 1
1670 # Rebased commit should have new committer name added
1671 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1672 egrep '^(from|via):' > $testroot/stdout)
1673 echo "from: $GOT_AUTHOR" > $testroot/stdout.expected
1674 echo "via: $committer" >> $testroot/stdout.expected
1676 cmp -s $testroot/stdout.expected $testroot/stdout
1677 ret=$?
1678 if [ $ret -ne 0 ]; then
1679 diff -u $testroot/stdout.expected $testroot/stdout
1681 test_done "$testroot" "$ret"
1684 test_rebase_no_author_info() {
1685 local testroot=`test_init rebase_no_author_info`
1686 local commit0=`git_show_head $testroot/repo`
1687 local commit0_author_time=`git_show_author_time $testroot/repo`
1688 local committer="$GOT_AUTHOR"
1690 (cd $testroot/repo && git checkout -q -b newbranch)
1691 echo "modified delta on branch" > $testroot/repo/gamma/delta
1692 git_commit $testroot/repo -m "committing to delta on newbranch"
1694 echo "modified alpha on branch" > $testroot/repo/alpha
1695 git_commit $testroot/repo -m "committing more changes on newbranch"
1697 local orig_commit1=`git_show_parent_commit $testroot/repo`
1698 local orig_commit2=`git_show_head $testroot/repo`
1699 local orig_author_time2=`git_show_author_time $testroot/repo`
1701 (cd $testroot/repo && git checkout -q master)
1702 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1703 git_commit $testroot/repo -m "committing to zeta on master"
1704 local master_commit=`git_show_head $testroot/repo`
1706 got checkout $testroot/repo $testroot/wt > /dev/null
1707 ret=$?
1708 if [ $ret -ne 0 ]; then
1709 test_done "$testroot" "$ret"
1710 return 1
1713 # unset in a subshell to avoid affecting our environment
1714 (unset GOT_AUTHOR && cd $testroot/wt && \
1715 got rebase newbranch > $testroot/stdout)
1717 (cd $testroot/repo && git checkout -q newbranch)
1718 local new_commit1=`git_show_parent_commit $testroot/repo`
1719 local new_commit2=`git_show_head $testroot/repo`
1720 local new_author_time2=`git_show_author_time $testroot/repo`
1722 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1723 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1724 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1725 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1727 echo "G gamma/delta" >> $testroot/stdout.expected
1728 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1729 >> $testroot/stdout.expected
1730 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1731 echo "G alpha" >> $testroot/stdout.expected
1732 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1733 >> $testroot/stdout.expected
1734 echo ": committing more changes on newbranch" \
1735 >> $testroot/stdout.expected
1736 echo "Switching work tree to refs/heads/newbranch" \
1737 >> $testroot/stdout.expected
1739 cmp -s $testroot/stdout.expected $testroot/stdout
1740 ret=$?
1741 if [ $ret -ne 0 ]; then
1742 diff -u $testroot/stdout.expected $testroot/stdout
1743 test_done "$testroot" "$ret"
1744 return 1
1747 # Original commit only had one author
1748 (cd $testroot/repo && got log -l1 -c $orig_commit2 | \
1749 egrep '^(from|via):' > $testroot/stdout)
1750 echo "from: $committer" > $testroot/stdout.expected
1751 cmp -s $testroot/stdout.expected $testroot/stdout
1752 ret=$?
1753 if [ $ret -ne 0 ]; then
1754 diff -u $testroot/stdout.expected $testroot/stdout
1755 test_done "$testroot" "$ret"
1756 return 1
1759 # Author info of rebased commit should match the original
1760 (cd $testroot/repo && got log -l1 -c $new_commit2 | \
1761 egrep '^(from|via):' > $testroot/stdout)
1762 echo "from: $committer" > $testroot/stdout.expected
1764 cmp -s $testroot/stdout.expected $testroot/stdout
1765 ret=$?
1766 if [ $ret -ne 0 ]; then
1767 diff -u $testroot/stdout.expected $testroot/stdout
1769 test_done "$testroot" "$ret"
1772 test_rebase_nonbranch() {
1773 local testroot=`test_init rebase_nonbranch`
1775 got ref -r $testroot/repo -c refs/heads/master \
1776 refs/remotes/origin/master >/dev/null
1778 got checkout -b master $testroot/repo $testroot/wt >/dev/null
1780 (cd $testroot/wt && got rebase origin/master > $testroot/stdout \
1781 2> $testroot/stderr)
1782 ret=$?
1783 if [ $ret -eq 0 ]; then
1784 echo "rebase succeeded unexpectedly" >&2
1785 test_done "$testroot" "1"
1786 return 1
1788 echo -n "got: will not rebase a branch which lives outside the " \
1789 > $testroot/stderr.expected
1790 echo '"refs/heads/" reference namespace' >> $testroot/stderr.expected
1791 cmp -s $testroot/stderr.expected $testroot/stderr
1792 ret=$?
1793 if [ $ret -ne 0 ]; then
1794 diff -u $testroot/stderr.expected $testroot/stderr
1796 test_done "$testroot" "$ret"
1799 test_rebase_umask() {
1800 local testroot=`test_init rebase_umask`
1801 local commit0=`git_show_head "$testroot/repo"`
1803 got checkout "$testroot/repo" "$testroot/wt" >/dev/null
1804 (cd "$testroot/wt" && got branch newbranch) >/dev/null
1806 echo "modified alpha on branch" >$testroot/wt/alpha
1807 (cd "$testroot/wt" && got commit -m 'modified alpha on newbranch') \
1808 >/dev/null
1810 (cd "$testroot/wt" && got update -b master) >/dev/null
1811 ret=$?
1812 if [ $ret -ne 0 ]; then
1813 echo "got update failed!" >&2
1814 test_done "$testroot" $ret
1815 return 1
1818 echo "modified beta on master" >$testroot/wt/beta
1819 (cd "$testroot/wt" && got commit -m 'modified beta on master') \
1820 >/dev/null
1821 (cd "$testroot/wt" && got update) >/dev/null
1823 # using a subshell to avoid clobbering global umask
1824 (umask 077 && cd "$testroot/wt" && got rebase newbranch) >/dev/null
1825 ret=$?
1826 if [ $ret -ne 0 ]; then
1827 echo "got rebase failed" >&2
1828 test_done "$testroot" $ret
1829 return 1
1832 ls -l "$testroot/wt/alpha" | grep -q ^-rw-------
1833 if [ $? -ne 0 ]; then
1834 echo "alpha is not 0600 after rebase" >&2
1835 ls -l "$testroot/wt/alpha" >&2
1836 test_done "$testroot" 1
1837 return 1
1840 test_done "$testroot" 0
1843 test_rebase_out_of_date2() {
1844 local testroot=`test_init rebase_out_of_date2`
1845 local commit0=`git_show_head $testroot/repo`
1846 local commit0_author_time=`git_show_author_time $testroot/repo`
1848 (cd $testroot/repo && git checkout -q -b newbranch)
1849 echo "modified delta on branch" > $testroot/repo/gamma/delta
1850 git_commit $testroot/repo -m "committing to delta on newbranch"
1852 local orig_commit1=`git_show_parent_commit $testroot/repo`
1853 local orig_commit2=`git_show_head $testroot/repo`
1854 local orig_author_time2=`git_show_author_time $testroot/repo`
1856 (cd $testroot/repo && git checkout -q master)
1857 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1858 git_commit $testroot/repo -m "committing to zeta on master"
1859 local master_commit=`git_show_head $testroot/repo`
1861 got checkout $testroot/repo $testroot/wt > /dev/null
1862 ret=$?
1863 if [ $ret -ne 0 ]; then
1864 test_done "$testroot" "$ret"
1865 return 1
1868 # Backdate the file alpha to an earlier version.
1869 # This sets the work tree's base commit ID back to $commit0,
1870 # which is out-of-date with respect to the master branch.
1871 (cd $testroot/wt && got update -c $commit0 alpha > /dev/null)
1873 # Rebase into an out-of-date work tree should be refused.
1874 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1875 2> $testroot/stderr)
1876 ret=$?
1877 if [ $ret -eq 0 ]; then
1878 echo "rebase succeeded unexpectedly" >&2
1879 test_done "$testroot" "1"
1880 return 1
1882 echo -n > $testroot/stdout.expected
1883 echo -n "got: work tree must be updated before it can be used to " \
1884 > $testroot/stderr.expected
1885 echo "rebase a branch" >> $testroot/stderr.expected
1886 cmp -s $testroot/stderr.expected $testroot/stderr
1887 ret=$?
1888 if [ $ret -ne 0 ]; then
1889 diff -u $testroot/stderr.expected $testroot/stderr
1891 test_done "$testroot" "$ret"
1894 test_rebase_one_commit() {
1895 local testroot=`test_init rebase_one_commit`
1897 if ! got checkout $testroot/repo $testroot/wt >/dev/null; then
1898 test_done "$testroot" 1
1899 return 1
1902 (cd $testroot/wt && got branch newbranch) >/dev/null
1904 echo "modified alpha on newbranch" >$testroot/wt/alpha
1905 (cd $testroot/wt && got commit -m 'edit alpha') >/dev/null
1906 (cd $testroot/wt && got update) >/dev/null
1907 local commit=`git_show_branch_head $testroot/repo newbranch`
1909 echo -n '' > $testroot/stderr.expected
1911 (cd $testroot/wt && got rebase master >$testroot/stdout \
1912 2> $testroot/stderr)
1913 ret=$?
1914 if [ $ret -ne 0 ]; then
1915 echo "rebase comand failed unexpectedly" >&2
1916 diff -u $testroot/stderr.expected $testroot/stderr
1917 test_done "$testroot" "1"
1918 return 1
1921 echo "Forwarding refs/heads/master to commit $commit" \
1922 >$testroot/stdout.expected
1923 echo "Switching work tree to refs/heads/master" \
1924 >> $testroot/stdout.expected
1926 if ! cmp -s $testroot/stdout.expected $testroot/stdout; then
1927 diff -u $testroot/stdout.expected $testroot/stdout
1928 test_done "$testroot" 1
1929 return 1
1932 test_done "$testroot" 0
1935 test_parseargs "$@"
1936 run_test test_rebase_basic
1937 run_test test_rebase_ancestry_check
1938 run_test test_rebase_continue
1939 run_test test_rebase_abort
1940 run_test test_rebase_no_op_change
1941 run_test test_rebase_in_progress
1942 run_test test_rebase_path_prefix
1943 run_test test_rebase_preserves_logmsg
1944 run_test test_rebase_no_commits_to_rebase
1945 run_test test_rebase_forward
1946 run_test test_rebase_forward_path_prefix
1947 run_test test_rebase_out_of_date
1948 run_test test_rebase_trims_empty_dir
1949 run_test test_rebase_delete_missing_file
1950 run_test test_rebase_rm_add_rm_file
1951 run_test test_rebase_resets_committer
1952 run_test test_rebase_no_author_info
1953 run_test test_rebase_nonbranch
1954 run_test test_rebase_umask
1955 run_test test_rebase_out_of_date2
1956 run_test test_rebase_one_commit