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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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" != "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"
247 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
248 2> $testroot/stderr)
250 echo -n > $testroot/stdout.expected
251 cmp -s $testroot/stdout.expected $testroot/stdout
252 ret="$?"
253 if [ "$ret" != "0" ]; then
254 diff -u $testroot/stdout.expected $testroot/stdout
255 test_done "$testroot" "$ret"
256 return 1
257 fi
259 echo "got: refs/heads/newbranch is already based on refs/heads/master" \
260 > $testroot/stderr.expected
261 cmp -s $testroot/stderr.expected $testroot/stderr
262 ret="$?"
263 if [ "$ret" != "0" ]; then
264 diff -u $testroot/stderr.expected $testroot/stderr
265 fi
266 test_done "$testroot" "$ret"
269 test_rebase_continue() {
270 local testroot=`test_init rebase_continue`
271 local init_commit=`git_show_head $testroot/repo`
273 (cd $testroot/repo && git checkout -q -b newbranch)
274 echo "modified alpha on branch" > $testroot/repo/alpha
275 git_commit $testroot/repo -m "committing to alpha on newbranch"
276 local orig_commit1=`git_show_head $testroot/repo`
277 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
279 (cd $testroot/repo && git checkout -q master)
280 echo "modified alpha on master" > $testroot/repo/alpha
281 git_commit $testroot/repo -m "committing to alpha on master"
282 local master_commit=`git_show_head $testroot/repo`
284 got checkout $testroot/repo $testroot/wt > /dev/null
285 ret="$?"
286 if [ "$ret" != "0" ]; then
287 test_done "$testroot" "$ret"
288 return 1
289 fi
291 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
292 2> $testroot/stderr)
294 echo "C alpha" > $testroot/stdout.expected
295 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
296 echo -n "$short_orig_commit1 -> merge conflict" \
297 >> $testroot/stdout.expected
298 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
299 cmp -s $testroot/stdout.expected $testroot/stdout
300 ret="$?"
301 if [ "$ret" != "0" ]; then
302 diff -u $testroot/stdout.expected $testroot/stdout
303 test_done "$testroot" "$ret"
304 return 1
305 fi
307 echo "got: conflicts must be resolved before rebasing can continue" \
308 > $testroot/stderr.expected
309 cmp -s $testroot/stderr.expected $testroot/stderr
310 ret="$?"
311 if [ "$ret" != "0" ]; then
312 diff -u $testroot/stderr.expected $testroot/stderr
313 test_done "$testroot" "$ret"
314 return 1
315 fi
317 echo '<<<<<<<' > $testroot/content.expected
318 echo "modified alpha on master" >> $testroot/content.expected
319 echo "||||||| 3-way merge base: commit $init_commit" \
320 >> $testroot/content.expected
321 echo "alpha" >> $testroot/content.expected
322 echo "=======" >> $testroot/content.expected
323 echo "modified alpha on branch" >> $testroot/content.expected
324 echo ">>>>>>> merged change: commit $orig_commit1" \
325 >> $testroot/content.expected
326 cat $testroot/wt/alpha > $testroot/content
327 cmp -s $testroot/content.expected $testroot/content
328 ret="$?"
329 if [ "$ret" != "0" ]; then
330 diff -u $testroot/content.expected $testroot/content
331 test_done "$testroot" "$ret"
332 return 1
333 fi
335 (cd $testroot/wt && got status > $testroot/stdout)
337 echo "C alpha" > $testroot/stdout.expected
338 cmp -s $testroot/stdout.expected $testroot/stdout
339 ret="$?"
340 if [ "$ret" != "0" ]; then
341 diff -u $testroot/stdout.expected $testroot/stdout
342 test_done "$testroot" "$ret"
343 return 1
344 fi
346 # resolve the conflict
347 echo "modified alpha on branch and master" > $testroot/wt/alpha
349 # test interaction of 'got stage' and rebase -c
350 (cd $testroot/wt && got stage alpha > /dev/null)
351 (cd $testroot/wt && got rebase -c > $testroot/stdout \
352 2> $testroot/stderr)
353 ret="$?"
354 if [ "$ret" = "0" ]; then
355 echo "rebase succeeded unexpectedly" >&2
356 test_done "$testroot" "1"
357 return 1
358 fi
359 echo -n "got: work tree contains files with staged changes; " \
360 > $testroot/stderr.expected
361 echo "these changes must be committed or unstaged first" \
362 >> $testroot/stderr.expected
363 cmp -s $testroot/stderr.expected $testroot/stderr
364 ret="$?"
365 if [ "$ret" != "0" ]; then
366 diff -u $testroot/stderr.expected $testroot/stderr
367 test_done "$testroot" "$ret"
368 return 1
369 fi
371 (cd $testroot/wt && got unstage alpha > /dev/null)
372 (cd $testroot/wt && got rebase -c > $testroot/stdout)
374 (cd $testroot/repo && git checkout -q newbranch)
375 local new_commit1=`git_show_head $testroot/repo`
376 local short_new_commit1=`trim_obj_id 28 $new_commit1`
378 echo -n "$short_orig_commit1 -> $short_new_commit1" \
379 > $testroot/stdout.expected
380 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
381 echo "Switching work tree to refs/heads/newbranch" \
382 >> $testroot/stdout.expected
384 cmp -s $testroot/stdout.expected $testroot/stdout
385 ret="$?"
386 if [ "$ret" != "0" ]; then
387 diff -u $testroot/stdout.expected $testroot/stdout
388 test_done "$testroot" "$ret"
389 return 1
390 fi
393 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
394 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
395 echo "commit $master_commit (master)" >> $testroot/stdout.expected
396 cmp -s $testroot/stdout.expected $testroot/stdout
397 ret="$?"
398 if [ "$ret" != "0" ]; then
399 diff -u $testroot/stdout.expected $testroot/stdout
400 fi
401 test_done "$testroot" "$ret"
404 test_rebase_abort() {
405 local testroot=`test_init rebase_abort`
407 local init_commit=`git_show_head $testroot/repo`
409 (cd $testroot/repo && git checkout -q -b newbranch)
410 echo "modified alpha on branch" > $testroot/repo/alpha
411 git_commit $testroot/repo -m "committing to alpha on newbranch"
412 local orig_commit1=`git_show_head $testroot/repo`
413 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
415 (cd $testroot/repo && git checkout -q master)
416 echo "modified alpha on master" > $testroot/repo/alpha
417 git_commit $testroot/repo -m "committing to alpha on master"
418 local master_commit=`git_show_head $testroot/repo`
420 got checkout $testroot/repo $testroot/wt > /dev/null
421 ret="$?"
422 if [ "$ret" != "0" ]; then
423 test_done "$testroot" "$ret"
424 return 1
425 fi
427 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
428 2> $testroot/stderr)
430 echo "C alpha" > $testroot/stdout.expected
431 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
432 echo -n "$short_orig_commit1 -> merge conflict" \
433 >> $testroot/stdout.expected
434 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
435 cmp -s $testroot/stdout.expected $testroot/stdout
436 ret="$?"
437 if [ "$ret" != "0" ]; then
438 diff -u $testroot/stdout.expected $testroot/stdout
439 test_done "$testroot" "$ret"
440 return 1
441 fi
443 echo "got: conflicts must be resolved before rebasing can continue" \
444 > $testroot/stderr.expected
445 cmp -s $testroot/stderr.expected $testroot/stderr
446 ret="$?"
447 if [ "$ret" != "0" ]; then
448 diff -u $testroot/stderr.expected $testroot/stderr
449 test_done "$testroot" "$ret"
450 return 1
451 fi
453 echo '<<<<<<<' > $testroot/content.expected
454 echo "modified alpha on master" >> $testroot/content.expected
455 echo "||||||| 3-way merge base: commit $init_commit" \
456 >> $testroot/content.expected
457 echo "alpha" >> $testroot/content.expected
458 echo "=======" >> $testroot/content.expected
459 echo "modified alpha on branch" >> $testroot/content.expected
460 echo ">>>>>>> merged change: commit $orig_commit1" \
461 >> $testroot/content.expected
462 cat $testroot/wt/alpha > $testroot/content
463 cmp -s $testroot/content.expected $testroot/content
464 ret="$?"
465 if [ "$ret" != "0" ]; then
466 diff -u $testroot/content.expected $testroot/content
467 test_done "$testroot" "$ret"
468 return 1
469 fi
471 (cd $testroot/wt && got status > $testroot/stdout)
473 echo "C alpha" > $testroot/stdout.expected
474 cmp -s $testroot/stdout.expected $testroot/stdout
475 ret="$?"
476 if [ "$ret" != "0" ]; then
477 diff -u $testroot/stdout.expected $testroot/stdout
478 test_done "$testroot" "$ret"
479 return 1
480 fi
482 (cd $testroot/wt && got rebase -a > $testroot/stdout)
484 (cd $testroot/repo && git checkout -q newbranch)
486 echo "Switching work tree to refs/heads/master" \
487 > $testroot/stdout.expected
488 echo 'R alpha' >> $testroot/stdout.expected
489 echo "Rebase of refs/heads/newbranch aborted" \
490 >> $testroot/stdout.expected
492 cmp -s $testroot/stdout.expected $testroot/stdout
493 ret="$?"
494 if [ "$ret" != "0" ]; then
495 diff -u $testroot/stdout.expected $testroot/stdout
496 test_done "$testroot" "$ret"
497 return 1
498 fi
500 echo "modified alpha on master" > $testroot/content.expected
501 cat $testroot/wt/alpha > $testroot/content
502 cmp -s $testroot/content.expected $testroot/content
503 ret="$?"
504 if [ "$ret" != "0" ]; then
505 diff -u $testroot/content.expected $testroot/content
506 test_done "$testroot" "$ret"
507 return 1
508 fi
510 (cd $testroot/wt && got log -l3 -c newbranch \
511 | grep ^commit > $testroot/stdout)
512 echo "commit $orig_commit1 (newbranch)" > $testroot/stdout.expected
513 echo "commit $init_commit" >> $testroot/stdout.expected
514 cmp -s $testroot/stdout.expected $testroot/stdout
515 ret="$?"
516 if [ "$ret" != "0" ]; then
517 diff -u $testroot/stdout.expected $testroot/stdout
518 fi
519 test_done "$testroot" "$ret"
522 test_rebase_no_op_change() {
523 local testroot=`test_init rebase_no_op_change`
524 local init_commit=`git_show_head $testroot/repo`
526 (cd $testroot/repo && git checkout -q -b newbranch)
527 echo "modified alpha on branch" > $testroot/repo/alpha
528 git_commit $testroot/repo -m "committing to alpha on newbranch"
529 local orig_commit1=`git_show_head $testroot/repo`
530 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
532 (cd $testroot/repo && git checkout -q master)
533 echo "modified alpha on master" > $testroot/repo/alpha
534 git_commit $testroot/repo -m "committing to alpha on master"
535 local master_commit=`git_show_head $testroot/repo`
537 got checkout $testroot/repo $testroot/wt > /dev/null
538 ret="$?"
539 if [ "$ret" != "0" ]; then
540 test_done "$testroot" "$ret"
541 return 1
542 fi
544 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
545 2> $testroot/stderr)
547 echo "C alpha" > $testroot/stdout.expected
548 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
549 echo -n "$short_orig_commit1 -> merge conflict" \
550 >> $testroot/stdout.expected
551 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
552 cmp -s $testroot/stdout.expected $testroot/stdout
553 ret="$?"
554 if [ "$ret" != "0" ]; then
555 diff -u $testroot/stdout.expected $testroot/stdout
556 test_done "$testroot" "$ret"
557 return 1
558 fi
560 echo "got: conflicts must be resolved before rebasing can continue" \
561 > $testroot/stderr.expected
562 cmp -s $testroot/stderr.expected $testroot/stderr
563 ret="$?"
564 if [ "$ret" != "0" ]; then
565 diff -u $testroot/stderr.expected $testroot/stderr
566 test_done "$testroot" "$ret"
567 return 1
568 fi
570 echo '<<<<<<<' > $testroot/content.expected
571 echo "modified alpha on master" >> $testroot/content.expected
572 echo "||||||| 3-way merge base: commit $init_commit" \
573 >> $testroot/content.expected
574 echo "alpha" >> $testroot/content.expected
575 echo "=======" >> $testroot/content.expected
576 echo "modified alpha on branch" >> $testroot/content.expected
577 echo ">>>>>>> merged change: commit $orig_commit1" \
578 >> $testroot/content.expected
579 cat $testroot/wt/alpha > $testroot/content
580 cmp -s $testroot/content.expected $testroot/content
581 ret="$?"
582 if [ "$ret" != "0" ]; then
583 diff -u $testroot/content.expected $testroot/content
584 test_done "$testroot" "$ret"
585 return 1
586 fi
588 (cd $testroot/wt && got status > $testroot/stdout)
590 echo "C alpha" > $testroot/stdout.expected
591 cmp -s $testroot/stdout.expected $testroot/stdout
592 ret="$?"
593 if [ "$ret" != "0" ]; then
594 diff -u $testroot/stdout.expected $testroot/stdout
595 test_done "$testroot" "$ret"
596 return 1
597 fi
599 # resolve the conflict
600 echo "modified alpha on master" > $testroot/wt/alpha
602 (cd $testroot/wt && got rebase -c > $testroot/stdout)
604 (cd $testroot/repo && git checkout -q newbranch)
605 local new_commit1=`git_show_head $testroot/repo`
607 echo -n "$short_orig_commit1 -> no-op change" \
608 > $testroot/stdout.expected
609 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
610 echo "Switching work tree to refs/heads/newbranch" \
611 >> $testroot/stdout.expected
613 cmp -s $testroot/stdout.expected $testroot/stdout
614 ret="$?"
615 if [ "$ret" != "0" ]; then
616 diff -u $testroot/stdout.expected $testroot/stdout
617 test_done "$testroot" "$ret"
618 return 1
619 fi
622 (cd $testroot/wt && got log -l2 | grep ^commit > $testroot/stdout)
623 echo "commit $master_commit (master, newbranch)" \
624 > $testroot/stdout.expected
625 echo "commit $init_commit" >> $testroot/stdout.expected
626 cmp -s $testroot/stdout.expected $testroot/stdout
627 ret="$?"
628 if [ "$ret" != "0" ]; then
629 diff -u $testroot/stdout.expected $testroot/stdout
630 fi
631 test_done "$testroot" "$ret"
634 test_rebase_in_progress() {
635 local testroot=`test_init rebase_in_progress`
636 local init_commit=`git_show_head $testroot/repo`
638 (cd $testroot/repo && git checkout -q -b newbranch)
639 echo "modified alpha on branch" > $testroot/repo/alpha
640 git_commit $testroot/repo -m "committing to alpha on newbranch"
641 local orig_commit1=`git_show_head $testroot/repo`
642 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
644 (cd $testroot/repo && git checkout -q master)
645 echo "modified alpha on master" > $testroot/repo/alpha
646 git_commit $testroot/repo -m "committing to alpha on master"
647 local master_commit=`git_show_head $testroot/repo`
649 got checkout $testroot/repo $testroot/wt > /dev/null
650 ret="$?"
651 if [ "$ret" != "0" ]; then
652 test_done "$testroot" "$ret"
653 return 1
654 fi
656 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
657 2> $testroot/stderr)
659 echo "C alpha" > $testroot/stdout.expected
660 echo "Files with new merge conflicts: 1" >> $testroot/stdout.expected
661 echo -n "$short_orig_commit1 -> merge conflict" \
662 >> $testroot/stdout.expected
663 echo ": committing to alpha on newbranch" >> $testroot/stdout.expected
664 cmp -s $testroot/stdout.expected $testroot/stdout
665 ret="$?"
666 if [ "$ret" != "0" ]; then
667 diff -u $testroot/stdout.expected $testroot/stdout
668 test_done "$testroot" "$ret"
669 return 1
670 fi
672 echo "got: conflicts must be resolved before rebasing can continue" \
673 > $testroot/stderr.expected
674 cmp -s $testroot/stderr.expected $testroot/stderr
675 ret="$?"
676 if [ "$ret" != "0" ]; then
677 diff -u $testroot/stderr.expected $testroot/stderr
678 test_done "$testroot" "$ret"
679 return 1
680 fi
682 echo '<<<<<<<' > $testroot/content.expected
683 echo "modified alpha on master" >> $testroot/content.expected
684 echo "||||||| 3-way merge base: commit $init_commit" \
685 >> $testroot/content.expected
686 echo "alpha" >> $testroot/content.expected
687 echo "=======" >> $testroot/content.expected
688 echo "modified alpha on branch" >> $testroot/content.expected
689 echo ">>>>>>> merged change: commit $orig_commit1" \
690 >> $testroot/content.expected
691 cat $testroot/wt/alpha > $testroot/content
692 cmp -s $testroot/content.expected $testroot/content
693 ret="$?"
694 if [ "$ret" != "0" ]; then
695 diff -u $testroot/content.expected $testroot/content
696 test_done "$testroot" "$ret"
697 return 1
698 fi
700 (cd $testroot/wt && got status > $testroot/stdout)
702 echo "C alpha" > $testroot/stdout.expected
703 cmp -s $testroot/stdout.expected $testroot/stdout
704 ret="$?"
705 if [ "$ret" != "0" ]; then
706 diff -u $testroot/stdout.expected $testroot/stdout
707 test_done "$testroot" "$ret"
708 return 1
709 fi
711 for cmd in update commit; do
712 (cd $testroot/wt && got $cmd > $testroot/stdout \
713 2> $testroot/stderr)
715 echo -n > $testroot/stdout.expected
716 cmp -s $testroot/stdout.expected $testroot/stdout
717 ret="$?"
718 if [ "$ret" != "0" ]; then
719 diff -u $testroot/stdout.expected $testroot/stdout
720 test_done "$testroot" "$ret"
721 return 1
722 fi
724 echo -n "got: a rebase operation is in progress in this " \
725 > $testroot/stderr.expected
726 echo "work tree and must be continued or aborted first" \
727 >> $testroot/stderr.expected
728 cmp -s $testroot/stderr.expected $testroot/stderr
729 ret="$?"
730 if [ "$ret" != "0" ]; then
731 diff -u $testroot/stderr.expected $testroot/stderr
732 test_done "$testroot" "$ret"
733 return 1
734 fi
735 done
737 test_done "$testroot" "$ret"
740 test_rebase_path_prefix() {
741 local testroot=`test_init rebase_path_prefix`
743 (cd $testroot/repo && git checkout -q -b newbranch)
744 echo "modified delta on branch" > $testroot/repo/gamma/delta
745 git_commit $testroot/repo -m "committing to delta on newbranch"
747 local orig_commit1=`git_show_parent_commit $testroot/repo`
748 local orig_commit2=`git_show_head $testroot/repo`
750 (cd $testroot/repo && git checkout -q master)
751 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
752 git_commit $testroot/repo -m "committing to zeta on master"
753 local master_commit=`git_show_head $testroot/repo`
755 got checkout -p epsilon $testroot/repo $testroot/wt > /dev/null
756 ret="$?"
757 if [ "$ret" != "0" ]; then
758 test_done "$testroot" "$ret"
759 return 1
760 fi
762 (cd $testroot/wt && got rebase newbranch \
763 > $testroot/stdout 2> $testroot/stderr)
765 echo -n > $testroot/stdout.expected
766 cmp -s $testroot/stdout.expected $testroot/stdout
767 ret="$?"
768 if [ "$ret" != "0" ]; then
769 diff -u $testroot/stdout.expected $testroot/stdout
770 test_done "$testroot" "$ret"
771 return 1
772 fi
774 echo -n "got: cannot rebase branch which contains changes outside " \
775 > $testroot/stderr.expected
776 echo "of this work tree's path prefix" >> $testroot/stderr.expected
777 cmp -s $testroot/stderr.expected $testroot/stderr
778 ret="$?"
779 if [ "$ret" != "0" ]; then
780 diff -u $testroot/stderr.expected $testroot/stderr
781 fi
782 test_done "$testroot" "$ret"
785 test_rebase_preserves_logmsg() {
786 local testroot=`test_init rebase_preserves_logmsg`
788 (cd $testroot/repo && git checkout -q -b newbranch)
789 echo "modified delta on branch" > $testroot/repo/gamma/delta
790 git_commit $testroot/repo -m "modified delta on newbranch"
792 echo "modified alpha on branch" > $testroot/repo/alpha
793 git_commit $testroot/repo -m "modified alpha on newbranch"
795 (cd $testroot/repo && got log -c newbranch -l2 | grep -v ^date: \
796 > $testroot/log.expected)
798 local orig_commit1=`git_show_parent_commit $testroot/repo`
799 local orig_commit2=`git_show_head $testroot/repo`
801 (cd $testroot/repo && git checkout -q master)
802 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
803 git_commit $testroot/repo -m "committing to zeta on master"
804 local master_commit=`git_show_head $testroot/repo`
806 got checkout $testroot/repo $testroot/wt > /dev/null
807 ret="$?"
808 if [ "$ret" != "0" ]; then
809 test_done "$testroot" "$ret"
810 return 1
811 fi
813 (cd $testroot/wt && got rebase newbranch > /dev/null \
814 2> $testroot/stderr)
816 (cd $testroot/repo && git checkout -q newbranch)
817 local new_commit1=`git_show_parent_commit $testroot/repo`
818 local new_commit2=`git_show_head $testroot/repo`
820 echo -n > $testroot/stderr.expected
821 cmp -s $testroot/stderr.expected $testroot/stderr
822 ret="$?"
823 if [ "$ret" != "0" ]; then
824 diff -u $testroot/stderr.expected $testroot/stderr
825 test_done "$testroot" "$ret"
826 return 1
827 fi
829 (cd $testroot/wt && got log -c newbranch -l2 | grep -v ^date: \
830 > $testroot/log)
831 sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected
832 sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected
833 cmp -s $testroot/log.expected $testroot/log
834 ret="$?"
835 if [ "$ret" != "0" ]; then
836 diff -u $testroot/log.expected $testroot/log
837 fi
839 test_done "$testroot" "$ret"
842 test_rebase_no_commits_to_rebase() {
843 local testroot=`test_init rebase_no_commits_to_rebase`
845 got checkout $testroot/repo $testroot/wt > /dev/null
846 ret="$?"
847 if [ "$ret" != "0" ]; then
848 test_done "$testroot" "$ret"
849 return 1
850 fi
852 (cd $testroot/wt && got branch -n newbranch)
854 echo "modified alpha on master" > $testroot/wt/alpha
855 (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
856 > /dev/null)
857 (cd $testroot/wt && got update > /dev/null)
859 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
860 2> $testroot/stderr)
862 echo "got: no commits to rebase" > $testroot/stderr.expected
863 cmp -s $testroot/stderr.expected $testroot/stderr
864 ret="$?"
865 if [ "$ret" != "0" ]; then
866 diff -u $testroot/stderr.expected $testroot/stderr
867 test_done "$testroot" "$ret"
868 return 1
869 fi
871 echo "Rebase of refs/heads/newbranch aborted" \
872 > $testroot/stdout.expected
873 cmp -s $testroot/stdout.expected $testroot/stdout
874 ret="$?"
875 if [ "$ret" != "0" ]; then
876 diff -u $testroot/stdout.expected $testroot/stdout
877 test_done "$testroot" "$ret"
878 return 1
879 fi
881 (cd $testroot/wt && got update > $testroot/stdout)
882 echo "Already up-to-date" > $testroot/stdout.expected
883 cmp -s $testroot/stdout.expected $testroot/stdout
884 ret="$?"
885 if [ "$ret" != "0" ]; then
886 diff -u $testroot/stdout.expected $testroot/stdout
887 fi
888 test_done "$testroot" "$ret"
891 test_rebase_forward() {
892 local testroot=`test_init rebase_forward`
893 local commit0=`git_show_head $testroot/repo`
895 got checkout $testroot/repo $testroot/wt > /dev/null
896 ret="$?"
897 if [ "$ret" != "0" ]; then
898 test_done "$testroot" "$ret"
899 return 1
900 fi
902 echo "change alpha 1" > $testroot/wt/alpha
903 (cd $testroot/wt && got commit -m 'test rebase_forward' \
904 > /dev/null)
905 local commit1=`git_show_head $testroot/repo`
907 echo "change alpha 2" > $testroot/wt/alpha
908 (cd $testroot/wt && got commit -m 'test rebase_forward' \
909 > /dev/null)
910 local commit2=`git_show_head $testroot/repo`
912 # Simulate a situation where fast-forward is required.
913 # We want to fast-forward master to origin/master:
914 # commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
915 # commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
916 # commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
917 (cd $testroot/repo && got ref -d master >/dev/null)
918 (cd $testroot/repo && got ref -c $commit1 refs/heads/master)
919 (cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
921 (cd $testroot/wt && got up -b origin/master > /dev/null)
923 (cd $testroot/wt && got rebase master \
924 > $testroot/stdout 2> $testroot/stderr)
926 echo "Forwarding refs/heads/master to commit $commit2" \
927 > $testroot/stdout.expected
928 echo "Switching work tree to refs/heads/master" \
929 >> $testroot/stdout.expected
930 cmp -s $testroot/stdout.expected $testroot/stdout
931 ret="$?"
932 if [ "$ret" != "0" ]; then
933 diff -u $testroot/stdout.expected $testroot/stdout
934 test_done "$testroot" "$ret"
935 return 1
936 fi
938 # Ensure that rebase operation was completed correctly
939 (cd $testroot/wt && got rebase -a \
940 > $testroot/stdout 2> $testroot/stderr)
941 echo -n "" > $testroot/stdout.expected
942 cmp -s $testroot/stdout.expected $testroot/stdout
943 ret="$?"
944 if [ "$ret" != "0" ]; then
945 diff -u $testroot/stdout.expected $testroot/stdout
946 test_done "$testroot" "$ret"
947 return 1
948 fi
949 echo "got: rebase operation not in progress" > $testroot/stderr.expected
950 cmp -s $testroot/stderr.expected $testroot/stderr
951 ret="$?"
952 if [ "$ret" != "0" ]; then
953 diff -u $testroot/stderr.expected $testroot/stderr
954 test_done "$testroot" "$ret"
955 return 1
956 fi
958 (cd $testroot/wt && got branch -n > $testroot/stdout)
959 echo "master" > $testroot/stdout.expected
960 cmp -s $testroot/stdout.expected $testroot/stdout
961 ret="$?"
962 if [ "$ret" != "0" ]; then
963 diff -u $testroot/stdout.expected $testroot/stdout
964 test_done "$testroot" "$ret"
965 return 1
966 fi
968 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
969 echo "commit $commit2 (master, origin/master)" > $testroot/stdout.expected
970 echo "commit $commit1" >> $testroot/stdout.expected
971 echo "commit $commit0" >> $testroot/stdout.expected
972 cmp -s $testroot/stdout.expected $testroot/stdout
973 ret="$?"
974 if [ "$ret" != "0" ]; then
975 diff -u $testroot/stdout.expected $testroot/stdout
976 test_done "$testroot" "$ret"
977 return 1
978 fi
980 # Forward-only rebase operations should not be backed up
981 (cd $testroot/repo && got rebase -l > $testroot/stdout)
982 echo -n > $testroot/stdout.expected
983 cmp -s $testroot/stdout.expected $testroot/stdout
984 ret="$?"
985 if [ "$ret" != "0" ]; then
986 diff -u $testroot/stdout.expected $testroot/stdout
987 fi
988 test_done "$testroot" "$ret"
991 test_rebase_out_of_date() {
992 local testroot=`test_init rebase_out_of_date`
993 local initial_commit=`git_show_head $testroot/repo`
995 (cd $testroot/repo && git checkout -q -b newbranch)
996 echo "modified delta on branch" > $testroot/repo/gamma/delta
997 git_commit $testroot/repo -m "committing to delta on newbranch"
999 echo "modified alpha on branch" > $testroot/repo/alpha
1000 (cd $testroot/repo && git rm -q beta)
1001 echo "new file on branch" > $testroot/repo/epsilon/new
1002 (cd $testroot/repo && git add epsilon/new)
1003 git_commit $testroot/repo -m "committing more changes on newbranch"
1005 local orig_commit1=`git_show_parent_commit $testroot/repo`
1006 local orig_commit2=`git_show_head $testroot/repo`
1008 (cd $testroot/repo && git checkout -q master)
1009 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1010 git_commit $testroot/repo -m "committing to zeta on master"
1011 local master_commit1=`git_show_head $testroot/repo`
1013 (cd $testroot/repo && git checkout -q master)
1014 echo "modified beta on master" > $testroot/repo/beta
1015 git_commit $testroot/repo -m "committing to beta on master"
1016 local master_commit2=`git_show_head $testroot/repo`
1018 got checkout -c $master_commit1 $testroot/repo $testroot/wt \
1019 > /dev/null
1020 ret="$?"
1021 if [ "$ret" != "0" ]; then
1022 test_done "$testroot" "$ret"
1023 return 1
1026 (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
1027 2> $testroot/stderr)
1029 echo -n > $testroot/stdout.expected
1030 cmp -s $testroot/stdout.expected $testroot/stdout
1031 ret="$?"
1032 if [ "$ret" != "0" ]; then
1033 diff -u $testroot/stdout.expected $testroot/stdout
1034 test_done "$testroot" "$ret"
1035 return 1
1038 echo -n "got: work tree must be updated before it can be " \
1039 > $testroot/stderr.expected
1040 echo "used to rebase a branch" >> $testroot/stderr.expected
1041 cmp -s $testroot/stderr.expected $testroot/stderr
1042 ret="$?"
1043 if [ "$ret" != "0" ]; then
1044 diff -u $testroot/stderr.expected $testroot/stderr
1045 test_done "$testroot" "$ret"
1046 return 1
1049 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1050 echo "commit $master_commit2 (master)" > $testroot/stdout.expected
1051 echo "commit $master_commit1" >> $testroot/stdout.expected
1052 echo "commit $initial_commit" >> $testroot/stdout.expected
1053 cmp -s $testroot/stdout.expected $testroot/stdout
1054 ret="$?"
1055 if [ "$ret" != "0" ]; then
1056 diff -u $testroot/stdout.expected $testroot/stdout
1058 test_done "$testroot" "$ret"
1061 test_rebase_trims_empty_dir() {
1062 local testroot=`test_init rebase_trims_empty_dir`
1064 (cd $testroot/repo && git checkout -q -b newbranch)
1065 echo "modified delta on branch" > $testroot/repo/gamma/delta
1066 git_commit $testroot/repo -m "committing to delta on newbranch"
1068 (cd $testroot/repo && git rm -q epsilon/zeta)
1069 git_commit $testroot/repo -m "removing zeta on newbranch"
1071 local orig_commit1=`git_show_parent_commit $testroot/repo`
1072 local orig_commit2=`git_show_head $testroot/repo`
1074 (cd $testroot/repo && git checkout -q master)
1075 echo "modified alpha on master" > $testroot/repo/alpha
1076 git_commit $testroot/repo -m "committing to alpha on master"
1077 local master_commit=`git_show_head $testroot/repo`
1079 got checkout $testroot/repo $testroot/wt > /dev/null
1080 ret="$?"
1081 if [ "$ret" != "0" ]; then
1082 test_done "$testroot" "$ret"
1083 return 1
1086 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1088 (cd $testroot/repo && git checkout -q newbranch)
1089 local new_commit1=`git_show_parent_commit $testroot/repo`
1090 local new_commit2=`git_show_head $testroot/repo`
1092 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1093 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1094 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1095 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1097 echo "G gamma/delta" >> $testroot/stdout.expected
1098 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1099 >> $testroot/stdout.expected
1100 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1101 echo "D epsilon/zeta" >> $testroot/stdout.expected
1102 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1103 >> $testroot/stdout.expected
1104 echo ": removing zeta on newbranch" \
1105 >> $testroot/stdout.expected
1106 echo "Switching work tree to refs/heads/newbranch" \
1107 >> $testroot/stdout.expected
1109 cmp -s $testroot/stdout.expected $testroot/stdout
1110 ret="$?"
1111 if [ "$ret" != "0" ]; then
1112 diff -u $testroot/stdout.expected $testroot/stdout
1113 test_done "$testroot" "$ret"
1114 return 1
1117 echo "modified delta on branch" > $testroot/content.expected
1118 cat $testroot/wt/gamma/delta > $testroot/content
1119 cmp -s $testroot/content.expected $testroot/content
1120 ret="$?"
1121 if [ "$ret" != "0" ]; then
1122 diff -u $testroot/content.expected $testroot/content
1123 test_done "$testroot" "$ret"
1124 return 1
1127 echo "modified alpha on master" > $testroot/content.expected
1128 cat $testroot/wt/alpha > $testroot/content
1129 cmp -s $testroot/content.expected $testroot/content
1130 ret="$?"
1131 if [ "$ret" != "0" ]; then
1132 diff -u $testroot/content.expected $testroot/content
1133 test_done "$testroot" "$ret"
1134 return 1
1137 if [ -e $testroot/wt/epsilon ]; then
1138 echo "parent of removed zeta still exists on disk" >&2
1139 test_done "$testroot" "1"
1140 return 1
1143 (cd $testroot/wt && got status > $testroot/stdout)
1145 echo -n > $testroot/stdout.expected
1146 cmp -s $testroot/stdout.expected $testroot/stdout
1147 ret="$?"
1148 if [ "$ret" != "0" ]; then
1149 diff -u $testroot/stdout.expected $testroot/stdout
1150 test_done "$testroot" "$ret"
1151 return 1
1154 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1155 echo "commit $new_commit2 (newbranch)" > $testroot/stdout.expected
1156 echo "commit $new_commit1" >> $testroot/stdout.expected
1157 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1158 cmp -s $testroot/stdout.expected $testroot/stdout
1159 ret="$?"
1160 if [ "$ret" != "0" ]; then
1161 diff -u $testroot/stdout.expected $testroot/stdout
1163 test_done "$testroot" "$ret"
1166 test_rebase_delete_missing_file() {
1167 local testroot=`test_init rebase_delete_missing_file`
1169 mkdir -p $testroot/repo/d/f/g
1170 echo "new file" > $testroot/repo/d/f/g/new
1171 (cd $testroot/repo && git add d/f/g/new)
1172 git_commit $testroot/repo -m "adding a subdir"
1173 local commit0=`git_show_head $testroot/repo`
1175 got br -r $testroot/repo -c master newbranch
1177 got checkout -b newbranch $testroot/repo $testroot/wt > /dev/null
1179 echo "modified delta on branch" > $testroot/wt/gamma/delta
1180 (cd $testroot/wt && got commit \
1181 -m "committing to delta on newbranch" > /dev/null)
1183 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1184 (cd $testroot/wt && got commit \
1185 -m "removing beta and d/f/g/new on newbranch" > /dev/null)
1187 (cd $testroot/repo && git checkout -q newbranch)
1188 local orig_commit1=`git_show_parent_commit $testroot/repo`
1189 local orig_commit2=`git_show_head $testroot/repo`
1191 (cd $testroot/wt && got update -b master > /dev/null)
1192 (cd $testroot/wt && got rm beta d/f/g/new > /dev/null)
1193 (cd $testroot/wt && got commit \
1194 -m "removing beta and d/f/g/new on master" > /dev/null)
1196 (cd $testroot/repo && git checkout -q master)
1197 local master_commit=`git_show_head $testroot/repo`
1199 (cd $testroot/wt && got update -b master > /dev/null)
1200 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1202 (cd $testroot/repo && git checkout -q newbranch)
1203 local new_commit1=`git_show_head $testroot/repo`
1205 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1206 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1207 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1209 echo "G gamma/delta" >> $testroot/stdout.expected
1210 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1211 >> $testroot/stdout.expected
1212 echo ": committing to delta on newbranch" >> $testroot/stdout.expected
1213 echo "! beta" >> $testroot/stdout.expected
1214 echo "! d/f/g/new" >> $testroot/stdout.expected
1215 echo -n "$short_orig_commit2 -> no-op change" \
1216 >> $testroot/stdout.expected
1217 echo ": removing beta and d/f/g/new on newbranch" \
1218 >> $testroot/stdout.expected
1219 echo "Switching work tree to refs/heads/newbranch" \
1220 >> $testroot/stdout.expected
1222 cmp -s $testroot/stdout.expected $testroot/stdout
1223 ret="$?"
1224 if [ "$ret" != "0" ]; then
1225 diff -u $testroot/stdout.expected $testroot/stdout
1226 test_done "$testroot" "$ret"
1227 return 1
1230 echo "modified delta on branch" > $testroot/content.expected
1231 cat $testroot/wt/gamma/delta > $testroot/content
1232 cmp -s $testroot/content.expected $testroot/content
1233 ret="$?"
1234 if [ "$ret" != "0" ]; then
1235 diff -u $testroot/content.expected $testroot/content
1236 test_done "$testroot" "$ret"
1237 return 1
1240 if [ -e $testroot/wt/beta ]; then
1241 echo "removed file beta still exists on disk" >&2
1242 test_done "$testroot" "1"
1243 return 1
1246 (cd $testroot/wt && got status > $testroot/stdout)
1248 echo -n > $testroot/stdout.expected
1249 cmp -s $testroot/stdout.expected $testroot/stdout
1250 ret="$?"
1251 if [ "$ret" != "0" ]; then
1252 diff -u $testroot/stdout.expected $testroot/stdout
1253 test_done "$testroot" "$ret"
1254 return 1
1257 (cd $testroot/wt && got log -l3 | grep ^commit > $testroot/stdout)
1258 echo "commit $new_commit1 (newbranch)" > $testroot/stdout.expected
1259 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1260 echo "commit $commit0" >> $testroot/stdout.expected
1261 cmp -s $testroot/stdout.expected $testroot/stdout
1262 ret="$?"
1263 if [ "$ret" != "0" ]; then
1264 diff -u $testroot/stdout.expected $testroot/stdout
1266 test_done "$testroot" "$ret"
1269 test_rebase_rm_add_rm_file() {
1270 local testroot=`test_init rebase_rm_add_rm_file`
1272 (cd $testroot/repo && git checkout -q -b newbranch)
1273 (cd $testroot/repo && git rm -q beta)
1274 git_commit $testroot/repo -m "removing beta from newbranch"
1275 local orig_commit1=`git_show_head $testroot/repo`
1277 echo 'restored beta' > $testroot/repo/beta
1278 (cd $testroot/repo && git add beta)
1279 git_commit $testroot/repo -m "restoring beta on newbranch"
1280 local orig_commit2=`git_show_head $testroot/repo`
1282 (cd $testroot/repo && git rm -q beta)
1283 git_commit $testroot/repo -m "removing beta from newbranch again"
1284 local orig_commit3=`git_show_head $testroot/repo`
1286 (cd $testroot/repo && git checkout -q master)
1287 echo "modified zeta on master" > $testroot/repo/epsilon/zeta
1288 git_commit $testroot/repo -m "committing to zeta on master"
1289 local master_commit=`git_show_head $testroot/repo`
1291 got checkout $testroot/repo $testroot/wt > /dev/null
1292 ret="$?"
1293 if [ "$ret" != "0" ]; then
1294 test_done "$testroot" "$ret"
1295 return 1
1298 (cd $testroot/wt && got rebase newbranch > $testroot/stdout)
1300 # this would error out with 'got: file index is corrupt'
1301 (cd $testroot/wt && got status > /dev/null)
1302 ret="$?"
1303 if [ "$ret" != "0" ]; then
1304 echo "got status command failed unexpectedly" >&2
1305 test_done "$testroot" "$ret"
1306 return 1
1309 (cd $testroot/repo && git checkout -q newbranch)
1310 local new_commit3=`git_show_head $testroot/repo`
1311 local new_commit2=`git_show_parent_commit $testroot/repo`
1312 local new_commit1=`git_show_parent_commit $testroot/repo $new_commit2`
1314 (cd $testroot/repo && git checkout -q newbranch)
1316 local short_orig_commit1=`trim_obj_id 28 $orig_commit1`
1317 local short_orig_commit2=`trim_obj_id 28 $orig_commit2`
1318 local short_orig_commit3=`trim_obj_id 28 $orig_commit3`
1319 local short_new_commit1=`trim_obj_id 28 $new_commit1`
1320 local short_new_commit2=`trim_obj_id 28 $new_commit2`
1321 local short_new_commit3=`trim_obj_id 28 $new_commit3`
1323 echo "D beta" > $testroot/stdout.expected
1324 echo -n "$short_orig_commit1 -> $short_new_commit1" \
1325 >> $testroot/stdout.expected
1326 echo ": removing beta from newbranch" >> $testroot/stdout.expected
1327 echo "A beta" >> $testroot/stdout.expected
1328 echo -n "$short_orig_commit2 -> $short_new_commit2" \
1329 >> $testroot/stdout.expected
1330 echo ": restoring beta on newbranch" >> $testroot/stdout.expected
1331 echo "D beta" >> $testroot/stdout.expected
1332 echo -n "$short_orig_commit3 -> $short_new_commit3" \
1333 >> $testroot/stdout.expected
1334 echo ": removing beta from newbranch again" >> $testroot/stdout.expected
1335 echo "Switching work tree to refs/heads/newbranch" \
1336 >> $testroot/stdout.expected
1338 cmp -s $testroot/stdout.expected $testroot/stdout
1339 ret="$?"
1340 if [ "$ret" != "0" ]; then
1341 diff -u $testroot/stdout.expected $testroot/stdout
1342 test_done "$testroot" "$ret"
1343 return 1
1346 (cd $testroot/wt && got status > $testroot/stdout)
1347 ret="$?"
1348 if [ "$ret" != "0" ]; then
1349 echo "got status command failed unexpectedly" >&2
1350 test_done "$testroot" "$ret"
1351 return 1
1354 echo -n > $testroot/stdout.expected
1355 cmp -s $testroot/stdout.expected $testroot/stdout
1356 ret="$?"
1357 if [ "$ret" != "0" ]; then
1358 diff -u $testroot/stdout.expected $testroot/stdout
1359 test_done "$testroot" "$ret"
1360 return 1
1363 (cd $testroot/wt && got log -l4 | grep ^commit > $testroot/stdout)
1364 echo "commit $new_commit3 (newbranch)" > $testroot/stdout.expected
1365 echo "commit $new_commit2" >> $testroot/stdout.expected
1366 echo "commit $new_commit1" >> $testroot/stdout.expected
1367 echo "commit $master_commit (master)" >> $testroot/stdout.expected
1368 cmp -s $testroot/stdout.expected $testroot/stdout
1369 ret="$?"
1370 if [ "$ret" != "0" ]; then
1371 diff -u $testroot/stdout.expected $testroot/stdout
1373 test_done "$testroot" "$ret"
1376 test_parseargs "$@"
1377 run_test test_rebase_basic
1378 run_test test_rebase_ancestry_check
1379 run_test test_rebase_continue
1380 run_test test_rebase_abort
1381 run_test test_rebase_no_op_change
1382 run_test test_rebase_in_progress
1383 run_test test_rebase_path_prefix
1384 run_test test_rebase_preserves_logmsg
1385 run_test test_rebase_no_commits_to_rebase
1386 run_test test_rebase_forward
1387 run_test test_rebase_out_of_date
1388 run_test test_rebase_trims_empty_dir
1389 run_test test_rebase_delete_missing_file
1390 run_test test_rebase_rm_add_rm_file