зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
9f21e97ddc
Коммит
230a456638
|
@ -482,6 +482,25 @@ get_saved_options () {
|
|||
test -f "$DOTEST"/rebase-root && REBASE_ROOT=t
|
||||
}
|
||||
|
||||
LF='
|
||||
'
|
||||
parse_onto () {
|
||||
case "$1" in
|
||||
*...*)
|
||||
if left=${1%...*} right=${1#*...} &&
|
||||
onto=$(git merge-base --all ${left:-HEAD} ${right:-HEAD})
|
||||
then
|
||||
case "$onto" in
|
||||
?*"$LF"?* | '')
|
||||
exit 1 ;;
|
||||
esac
|
||||
echo "$onto"
|
||||
exit 0
|
||||
fi
|
||||
esac
|
||||
git rev-parse --verify "$1^0"
|
||||
}
|
||||
|
||||
while test $# != 0
|
||||
do
|
||||
case "$1" in
|
||||
|
@ -589,7 +608,7 @@ first and then run 'git rebase --continue' again."
|
|||
;;
|
||||
--onto)
|
||||
shift
|
||||
ONTO=$(git rev-parse --verify "$1") ||
|
||||
ONTO=$(parse_onto "$1") ||
|
||||
die "Does not point to a valid commit: $1"
|
||||
;;
|
||||
--)
|
||||
|
|
|
@ -72,4 +72,34 @@ test_expect_success 'rebase --onto master...side' '
|
|||
test_must_fail git rebase --onto master...side J
|
||||
'
|
||||
|
||||
test_expect_success 'rebase -i --onto master...topic' '
|
||||
git reset --hard &&
|
||||
git checkout topic &&
|
||||
git reset --hard G &&
|
||||
set_fake_editor &&
|
||||
EXPECT_COUNT=1 git rebase -i --onto master...topic F &&
|
||||
git rev-parse HEAD^1 >actual &&
|
||||
git rev-parse C^0 >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'rebase -i --onto master...' '
|
||||
git reset --hard &&
|
||||
git checkout topic &&
|
||||
git reset --hard G &&
|
||||
set_fake_editor &&
|
||||
EXPECT_COUNT=1 git rebase -i --onto master... F &&
|
||||
git rev-parse HEAD^1 >actual &&
|
||||
git rev-parse C^0 >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'rebase -i --onto master...side' '
|
||||
git reset --hard &&
|
||||
git checkout side &&
|
||||
git reset --hard K &&
|
||||
|
||||
test_must_fail git rebase -i --onto master...side J
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Загрузка…
Ссылка в новой задаче