2019-08-25 09:12:00 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2019 Denton Liu
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='ensure rebase fast-forwards commits when possible'
|
|
|
|
|
2020-11-18 23:44:25 +00:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 23:44:19 +00:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2023-02-06 19:08:13 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2019-08-25 09:12:00 +00:00
|
|
|
. ./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 () {
|
2019-08-27 05:37:53 +00:00
|
|
|
status_n="$1" &&
|
|
|
|
shift &&
|
|
|
|
what_n="$1" &&
|
|
|
|
shift &&
|
|
|
|
cmp_n="$1" &&
|
|
|
|
shift &&
|
|
|
|
status_f="$1" &&
|
|
|
|
shift &&
|
|
|
|
what_f="$1" &&
|
|
|
|
shift &&
|
|
|
|
cmp_f="$1" &&
|
|
|
|
shift &&
|
2020-03-30 12:42:36 +00:00
|
|
|
test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --apply" "$*" &&
|
|
|
|
test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --apply --no-ff" "$*"
|
|
|
|
test_rebase_same_head_ $status_n $what_n $cmp_n 0 " --merge" "$*" &&
|
|
|
|
test_rebase_same_head_ $status_f $what_f $cmp_f 0 " --merge --no-ff" "$*"
|
|
|
|
test_rebase_same_head_ $status_n $what_n $cmp_n 1 " --merge" "$*" &&
|
|
|
|
test_rebase_same_head_ $status_f $what_f $cmp_f 1 " --merge --no-ff" "$*"
|
2019-08-27 05:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_rebase_same_head_ () {
|
2019-08-25 09:12:00 +00:00
|
|
|
status="$1" &&
|
|
|
|
shift &&
|
2019-08-25 09:12:02 +00:00
|
|
|
what="$1" &&
|
|
|
|
shift &&
|
|
|
|
cmp="$1" &&
|
|
|
|
shift &&
|
2020-03-30 12:42:36 +00:00
|
|
|
abbreviate="$1" &&
|
|
|
|
shift &&
|
2019-08-27 05:37:53 +00:00
|
|
|
flag="$1"
|
|
|
|
shift &&
|
2020-03-30 12:42:36 +00:00
|
|
|
if test $abbreviate -eq 1
|
|
|
|
then
|
|
|
|
msg="git rebase$flag $* (rebase.abbreviateCommands = true) with $changes is $what with $cmp HEAD"
|
|
|
|
else
|
|
|
|
msg="git rebase$flag $* with $changes is $what with $cmp HEAD"
|
|
|
|
fi &&
|
|
|
|
test_expect_$status "$msg" "
|
|
|
|
if test $abbreviate -eq 1
|
|
|
|
then
|
|
|
|
test_config rebase.abbreviateCommands true
|
|
|
|
fi &&
|
2019-08-25 09:12:00 +00:00
|
|
|
oldhead=\$(git rev-parse HEAD) &&
|
|
|
|
test_when_finished 'git reset --hard \$oldhead' &&
|
2020-07-10 17:19:51 +00:00
|
|
|
git reflog HEAD >expect &&
|
2019-08-27 05:37:53 +00:00
|
|
|
git rebase$flag $* >stdout &&
|
2020-07-10 17:19:51 +00:00
|
|
|
git reflog HEAD >actual &&
|
2019-08-25 09:12:02 +00:00
|
|
|
if test $what = work
|
|
|
|
then
|
2020-02-15 21:36:30 +00:00
|
|
|
old=\$(wc -l <expect) &&
|
2020-07-10 17:19:51 +00:00
|
|
|
test_line_count '-gt' \$old actual
|
2019-08-25 09:12:02 +00:00
|
|
|
elif test $what = noop
|
|
|
|
then
|
2020-07-10 17:19:51 +00:00
|
|
|
test_cmp expect actual
|
2019-08-25 09:12:02 +00:00
|
|
|
fi &&
|
2019-08-25 09:12:00 +00:00
|
|
|
newhead=\$(git rev-parse HEAD) &&
|
2019-08-25 09:12:02 +00:00
|
|
|
if test $cmp = same
|
|
|
|
then
|
|
|
|
test_cmp_rev \$oldhead \$newhead
|
|
|
|
elif test $cmp = diff
|
|
|
|
then
|
2019-11-12 23:07:45 +00:00
|
|
|
test_cmp_rev ! \$oldhead \$newhead
|
2019-08-25 09:12:02 +00:00
|
|
|
fi
|
2019-08-25 09:12:00 +00:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
changes='no changes'
|
2019-08-27 05:38:01 +00:00
|
|
|
test_rebase_same_head success noop same success work same
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same main
|
2020-02-15 21:36:30 +00:00
|
|
|
test_rebase_same_head success noop same success work diff --onto B B
|
|
|
|
test_rebase_same_head success noop same success work diff --onto B... B
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same --onto main... main
|
|
|
|
test_rebase_same_head success noop same success work same --keep-base main
|
2020-02-15 21:36:30 +00:00
|
|
|
test_rebase_same_head success noop same success work same --keep-base
|
|
|
|
test_rebase_same_head success noop same success work same --no-fork-point
|
|
|
|
test_rebase_same_head success noop same success work same --keep-base --no-fork-point
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same --fork-point main
|
2019-08-27 05:38:01 +00:00
|
|
|
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
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same --fork-point --onto main... main
|
|
|
|
test_rebase_same_head success noop same success work same --keep-base --keep-base main
|
2019-08-25 09:12:00 +00:00
|
|
|
|
2019-08-25 09:12:02 +00:00
|
|
|
test_expect_success 'add work same to side' '
|
2019-08-25 09:12:00 +00:00
|
|
|
test_commit E
|
|
|
|
'
|
|
|
|
|
|
|
|
changes='our changes'
|
2019-08-27 05:38:01 +00:00
|
|
|
test_rebase_same_head success noop same success work same
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same main
|
2020-02-15 21:36:30 +00:00
|
|
|
test_rebase_same_head success noop same success work diff --onto B B
|
|
|
|
test_rebase_same_head success noop same success work diff --onto B... B
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same --onto main... main
|
|
|
|
test_rebase_same_head success noop same success work same --keep-base main
|
2020-02-15 21:36:30 +00:00
|
|
|
test_rebase_same_head success noop same success work same --keep-base
|
|
|
|
test_rebase_same_head success noop same success work same --no-fork-point
|
|
|
|
test_rebase_same_head success noop same success work same --keep-base --no-fork-point
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same --fork-point main
|
2019-08-27 05:38:01 +00:00
|
|
|
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
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work same --fork-point --onto main... main
|
|
|
|
test_rebase_same_head success noop same success work same --fork-point --keep-base main
|
2019-08-25 09:12:00 +00:00
|
|
|
|
2019-08-25 09:12:02 +00:00
|
|
|
test_expect_success 'add work same to upstream' '
|
2020-11-18 23:44:25 +00:00
|
|
|
git checkout main &&
|
2019-08-25 09:12:00 +00:00
|
|
|
test_commit F &&
|
|
|
|
git checkout side
|
|
|
|
'
|
|
|
|
|
|
|
|
changes='our and their changes'
|
2020-02-15 21:36:30 +00:00
|
|
|
test_rebase_same_head success noop same success work diff --onto B B
|
|
|
|
test_rebase_same_head success noop same success work diff --onto B... B
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work diff --onto main... main
|
|
|
|
test_rebase_same_head success noop same success work diff --keep-base main
|
rebase: teach rebase --keep-base
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>
2019-08-27 05:38:06 +00:00
|
|
|
test_rebase_same_head success noop same success work diff --keep-base
|
2019-08-27 05:37:53 +00:00
|
|
|
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
|
2020-11-18 23:44:25 +00:00
|
|
|
test_rebase_same_head success noop same success work diff --fork-point --onto main... main
|
|
|
|
test_rebase_same_head success noop same success work diff --fork-point --keep-base main
|
2019-08-25 09:12:00 +00:00
|
|
|
|
|
|
|
test_done
|