Skip to content

Commit 230a456

Browse files
Nanako Shiraishigitster
authored andcommitted
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: しらいし ななこ <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9f21e97 commit 230a456

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

git-rebase--interactive.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,25 @@ get_saved_options () {
482482
test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
483483
}
484484

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+
485504
while test $# != 0
486505
do
487506
case "$1" in
@@ -589,7 +608,7 @@ first and then run 'git rebase --continue' again."
589608
;;
590609
--onto)
591610
shift
592-
ONTO=$(git rev-parse --verify "$1") ||
611+
ONTO=$(parse_onto "$1") ||
593612
die "Does not point to a valid commit: $1"
594613
;;
595614
--)

t/t3415-rebase-onto-threedots.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,34 @@ test_expect_success 'rebase --onto master...side' '
7272
test_must_fail git rebase --onto master...side J
7373
'
7474

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+
75105
test_done

0 commit comments

Comments
 (0)