mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
414d924beb
A common scenario is if a user is working on a topic branch and they wish to make some changes to intermediate commits or autosquash, they would run something such as git rebase -i --onto master... master in order to preserve the merge base. This is useful when contributing a patch series to the Git mailing list, one often starts on top of the current 'master'. While developing the patches, 'master' is also developed further and it is sometimes not the best idea to keep rebasing on top of 'master', but to keep the base commit as-is. In addition to this, a user wishing to test individual commits in a topic branch without changing anything may run git rebase -x ./test.sh master... master Since rebasing onto the merge base of the branch and the upstream is such a common case, introduce the --keep-base option as a shortcut. This allows us to rewrite the above as git rebase -i --keep-base master and git rebase -x ./test.sh --keep-base master respectively. Add tests to ensure --keep-base works correctly in the normal case and fails when there are multiple merge bases, both in regular and interactive mode. Also, test to make sure conflicting options cause rebase to fail. While we're adding test cases, add a missing set_fake_editor call to 'rebase -i --onto master...side'. While we're documenting the --keep-base option, change an instance of "merge-base" to "merge base", which is the consistent spelling. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
125 lines
4.6 KiB
Bash
Executable file
125 lines
4.6 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2019 Denton Liu
|
|
#
|
|
|
|
test_description='ensure rebase fast-forwards commits when possible'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success setup '
|
|
test_commit A &&
|
|
test_commit B &&
|
|
test_commit C &&
|
|
test_commit D &&
|
|
git checkout -t -b side
|
|
'
|
|
|
|
test_rebase_same_head () {
|
|
status_n="$1" &&
|
|
shift &&
|
|
what_n="$1" &&
|
|
shift &&
|
|
cmp_n="$1" &&
|
|
shift &&
|
|
status_f="$1" &&
|
|
shift &&
|
|
what_f="$1" &&
|
|
shift &&
|
|
cmp_f="$1" &&
|
|
shift &&
|
|
test_rebase_same_head_ $status_n $what_n $cmp_n "" "$*" &&
|
|
test_rebase_same_head_ $status_f $what_f $cmp_f " --no-ff" "$*"
|
|
}
|
|
|
|
test_rebase_same_head_ () {
|
|
status="$1" &&
|
|
shift &&
|
|
what="$1" &&
|
|
shift &&
|
|
cmp="$1" &&
|
|
shift &&
|
|
flag="$1"
|
|
shift &&
|
|
test_expect_$status "git rebase$flag $* with $changes is $what with $cmp HEAD" "
|
|
oldhead=\$(git rev-parse HEAD) &&
|
|
test_when_finished 'git reset --hard \$oldhead' &&
|
|
git rebase$flag $* >stdout &&
|
|
if test $what = work
|
|
then
|
|
# Must check this case first, for 'is up to
|
|
# date, rebase forced[...]rewinding head' cases
|
|
test_i18ngrep 'rewinding head' stdout
|
|
elif test $what = noop
|
|
then
|
|
test_i18ngrep 'is up to date' stdout &&
|
|
test_i18ngrep ! 'rebase forced' stdout
|
|
elif test $what = noop-force
|
|
then
|
|
test_i18ngrep 'is up to date, rebase forced' stdout
|
|
fi &&
|
|
newhead=\$(git rev-parse HEAD) &&
|
|
if test $cmp = same
|
|
then
|
|
test_cmp_rev \$oldhead \$newhead
|
|
elif test $cmp = diff
|
|
then
|
|
! test_cmp_rev \$oldhead \$newhead
|
|
fi
|
|
"
|
|
}
|
|
|
|
changes='no changes'
|
|
test_rebase_same_head success noop same success work same
|
|
test_rebase_same_head success noop same success noop-force same master
|
|
test_rebase_same_head success noop same success noop-force diff --onto B B
|
|
test_rebase_same_head success noop same success noop-force diff --onto B... B
|
|
test_rebase_same_head success noop same success noop-force same --onto master... master
|
|
test_rebase_same_head success noop same success noop-force same --keep-base master
|
|
test_rebase_same_head success noop same success noop-force same --keep-base
|
|
test_rebase_same_head success noop same success noop-force same --no-fork-point
|
|
test_rebase_same_head success noop same success noop-force same --keep-base --no-fork-point
|
|
test_rebase_same_head success noop same success work same --fork-point master
|
|
test_rebase_same_head success noop same success work diff --fork-point --onto B B
|
|
test_rebase_same_head success noop same success work diff --fork-point --onto B... B
|
|
test_rebase_same_head success noop same success work same --fork-point --onto master... master
|
|
test_rebase_same_head success noop same success work same --keep-base --keep-base master
|
|
|
|
test_expect_success 'add work same to side' '
|
|
test_commit E
|
|
'
|
|
|
|
changes='our changes'
|
|
test_rebase_same_head success noop same success work same
|
|
test_rebase_same_head success noop same success noop-force same master
|
|
test_rebase_same_head success noop same success noop-force diff --onto B B
|
|
test_rebase_same_head success noop same success noop-force diff --onto B... B
|
|
test_rebase_same_head success noop same success noop-force same --onto master... master
|
|
test_rebase_same_head success noop same success noop-force same --keep-base master
|
|
test_rebase_same_head success noop same success noop-force same --keep-base
|
|
test_rebase_same_head success noop same success noop-force same --no-fork-point
|
|
test_rebase_same_head success noop same success noop-force same --keep-base --no-fork-point
|
|
test_rebase_same_head success noop same success work same --fork-point master
|
|
test_rebase_same_head success noop same success work diff --fork-point --onto B B
|
|
test_rebase_same_head success noop same success work diff --fork-point --onto B... B
|
|
test_rebase_same_head success noop same success work same --fork-point --onto master... master
|
|
test_rebase_same_head success noop same success work same --fork-point --keep-base master
|
|
|
|
test_expect_success 'add work same to upstream' '
|
|
git checkout master &&
|
|
test_commit F &&
|
|
git checkout side
|
|
'
|
|
|
|
changes='our and their changes'
|
|
test_rebase_same_head success noop same success noop-force diff --onto B B
|
|
test_rebase_same_head success noop same success noop-force diff --onto B... B
|
|
test_rebase_same_head success noop same success work diff --onto master... master
|
|
test_rebase_same_head success noop same success work diff --keep-base master
|
|
test_rebase_same_head success noop same success work diff --keep-base
|
|
test_rebase_same_head failure work same success work diff --fork-point --onto B B
|
|
test_rebase_same_head failure work same success work diff --fork-point --onto B... B
|
|
test_rebase_same_head success noop same success work diff --fork-point --onto master... master
|
|
test_rebase_same_head success noop same success work diff --fork-point --keep-base master
|
|
|
|
test_done
|