rebase -i: teach --onto A...B syntax
When rewriting commits on a topic branch, sometimes it is easier to compare the version of commits before and after the rewrite if they are based on the same commit that forked from the upstream. An earlier commit by Junio (fixed up by the previous commit) gives "--onto A...B" syntax to rebase command, and rebases on top of the merge base between A and B; teach the same to the interactive version, too. Signed-off-by: しらいし ななこ <nanako3@lavabit.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nanako Shiraishi committed
Jan 7, 2010 at 20:05 UTC
230a4566382860fc26a3f8d578a41c6504cf865f
2 files changed
+50
-1
git-rebase--interactive.sh
+20
-1
@@ -482,6 +482,25 @@ get_saved_options () {
482
test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
483
}
484
485
+LF='
486
+'
487
+parse_onto () {
488
+ case "$1" in
489
+ *...*)
490
+ if left=${1%...*} right=${1#*...} &&
491
+ onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
492
+ then
493
+ case "$onto" in
494
+ ?*"$LF"?* | '')
495
+ exit 1 ;;
496
+ esac
497
+ echo "$onto"
498
+ exit 0
499
+ fi
500
+ esac
501
+ git rev-parse --verify "$1^0"
502
+}
503
+
504
while test $# != 0
505
do
506
case "$1" in
@@ -589,7 +608,7 @@ first and then run 'git rebase --continue' again."
608
;;
609
--onto)
610
shift
592
- ONTO=$(git rev-parse --verify "$1") ||
611
+ ONTO=$(parse_onto "$1") ||
612
die "Does not point to a valid commit: $1"
613
;;
614
--)
t/t3415-rebase-onto-threedots.sh
+30
@@ -72,4 +72,34 @@ test_expect_success 'rebase --onto master...side' '
72
test_must_fail git rebase --onto master...side J
73
'
74
75
+test_expect_success 'rebase -i --onto master...topic' '
76
+ git reset --hard &&
77
+ git checkout topic &&
78
+ git reset --hard G &&
79
+ set_fake_editor &&
80
+ EXPECT_COUNT=1 git rebase -i --onto master...topic F &&
81
+ git rev-parse HEAD^1 >actual &&
82
+ git rev-parse C^0 >expect &&
83
+ test_cmp expect actual
84
+'
85
+
86
+test_expect_success 'rebase -i --onto master...' '
87
+ git reset --hard &&
88
+ git checkout topic &&
89
+ git reset --hard G &&
90
+ set_fake_editor &&
91
+ EXPECT_COUNT=1 git rebase -i --onto master... F &&
92
+ git rev-parse HEAD^1 >actual &&
93
+ git rev-parse C^0 >expect &&
94
+ test_cmp expect actual
95
+'
96
+
97
+test_expect_success 'rebase -i --onto master...side' '
98
+ git reset --hard &&
99
+ git checkout side &&
100
+ git reset --hard K &&
101
+
102
+ test_must_fail git rebase -i --onto master...side J
103
+'
104
+
105
test_done