2008-09-29 22:28:57 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright(C) 2008 Stephen Habermann & Andreas Ericsson
|
|
|
|
#
|
|
|
|
test_description='git rebase -p should preserve merges
|
|
|
|
|
|
|
|
Run "git rebase -p" and check that merges are properly carried along
|
|
|
|
'
|
2020-11-19 00:44:25 +01: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-19 00:44:19 +01:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2008-09-29 22:28:57 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2018-10-31 21:02:02 +01:00
|
|
|
if ! test_have_prereq REBASE_P; then
|
|
|
|
skip_all='skipping git rebase -p tests, as asked for'
|
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
2008-09-29 22:28:57 +02:00
|
|
|
GIT_AUTHOR_EMAIL=bogus_email_address
|
|
|
|
export GIT_AUTHOR_EMAIL
|
|
|
|
|
2008-12-15 11:05:30 +01:00
|
|
|
# Clone 2 (conflicting merge):
|
|
|
|
#
|
2020-11-19 00:44:25 +01:00
|
|
|
# A1--A2--B3 <-- origin/main
|
2008-12-15 11:05:30 +01:00
|
|
|
# \ \
|
|
|
|
# B1------M <-- topic
|
|
|
|
# \
|
|
|
|
# B2 <-- origin/topic
|
|
|
|
#
|
git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
'git rebase' uses 'git merge' to preserve merges (-p). This preserves
the original merge commit correctly, except when the original merge
commit was created by 'git merge --no-ff'. In this case, 'git rebase'
will fail to preserve the merge, because during 'git rebase', 'git
merge' will simply fast-forward and skip the commit. For example:
B
/ \
A---M
/
---o---O---P---Q
If we try to rebase M onto P, we lose the merge commit and this happens:
A---B
/
---o---O---P---Q
To correct this, we simply do a "no fast-forward" on all merge commits
when rebasing. Since by the time we decided to do a 'git merge' inside
'git rebase', it means there was a merge originally, so 'git merge'
should always create a merge commit regardless of what the merge
branches look like. This way, when rebase M onto P from the above
example, we get:
B
/ \
A---M
/
---o---O---P---Q
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-28 06:35:55 +02:00
|
|
|
# Clone 3 (no-ff merge):
|
|
|
|
#
|
2020-11-19 00:44:25 +01:00
|
|
|
# A1--A2--B3 <-- origin/main
|
git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
'git rebase' uses 'git merge' to preserve merges (-p). This preserves
the original merge commit correctly, except when the original merge
commit was created by 'git merge --no-ff'. In this case, 'git rebase'
will fail to preserve the merge, because during 'git rebase', 'git
merge' will simply fast-forward and skip the commit. For example:
B
/ \
A---M
/
---o---O---P---Q
If we try to rebase M onto P, we lose the merge commit and this happens:
A---B
/
---o---O---P---Q
To correct this, we simply do a "no fast-forward" on all merge commits
when rebasing. Since by the time we decided to do a 'git merge' inside
'git rebase', it means there was a merge originally, so 'git merge'
should always create a merge commit regardless of what the merge
branches look like. This way, when rebase M onto P from the above
example, we get:
B
/ \
A---M
/
---o---O---P---Q
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-28 06:35:55 +02:00
|
|
|
# \
|
|
|
|
# B1------M <-- topic
|
|
|
|
# \ /
|
|
|
|
# \--A3 <-- topic2
|
|
|
|
# \
|
|
|
|
# B2 <-- origin/topic
|
2013-08-21 20:48:57 +02:00
|
|
|
#
|
|
|
|
# Clone 4 (same as Clone 3)
|
2008-09-29 22:28:57 +02:00
|
|
|
|
|
|
|
test_expect_success 'setup for merge-preserving rebase' \
|
|
|
|
'echo First > A &&
|
|
|
|
git add A &&
|
2009-11-28 19:38:55 +01:00
|
|
|
git commit -m "Add A1" &&
|
2008-09-29 22:28:57 +02:00
|
|
|
git checkout -b topic &&
|
|
|
|
echo Second > B &&
|
|
|
|
git add B &&
|
2009-11-28 19:38:55 +01:00
|
|
|
git commit -m "Add B1" &&
|
2020-11-19 00:44:25 +01:00
|
|
|
git checkout -f main &&
|
2008-09-29 22:28:57 +02:00
|
|
|
echo Third >> A &&
|
2009-11-28 19:38:55 +01:00
|
|
|
git commit -a -m "Modify A2" &&
|
2008-12-15 11:05:30 +01:00
|
|
|
echo Fifth > B &&
|
|
|
|
git add B &&
|
|
|
|
git commit -m "Add different B" &&
|
2008-09-29 22:28:57 +02:00
|
|
|
|
2008-12-15 11:05:30 +01:00
|
|
|
git clone ./. clone2 &&
|
2010-09-07 03:42:54 +02:00
|
|
|
(
|
|
|
|
cd clone2 &&
|
|
|
|
git checkout -b topic origin/topic &&
|
2020-11-19 00:44:25 +01:00
|
|
|
test_must_fail git merge origin/main &&
|
2010-09-07 03:42:54 +02:00
|
|
|
echo Resolved >B &&
|
|
|
|
git add B &&
|
2020-11-19 00:44:25 +01:00
|
|
|
git commit -m "Merge origin/main into topic"
|
2010-09-06 20:39:54 +02:00
|
|
|
) &&
|
2008-09-29 22:28:57 +02:00
|
|
|
|
git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
'git rebase' uses 'git merge' to preserve merges (-p). This preserves
the original merge commit correctly, except when the original merge
commit was created by 'git merge --no-ff'. In this case, 'git rebase'
will fail to preserve the merge, because during 'git rebase', 'git
merge' will simply fast-forward and skip the commit. For example:
B
/ \
A---M
/
---o---O---P---Q
If we try to rebase M onto P, we lose the merge commit and this happens:
A---B
/
---o---O---P---Q
To correct this, we simply do a "no fast-forward" on all merge commits
when rebasing. Since by the time we decided to do a 'git merge' inside
'git rebase', it means there was a merge originally, so 'git merge'
should always create a merge commit regardless of what the merge
branches look like. This way, when rebase M onto P from the above
example, we get:
B
/ \
A---M
/
---o---O---P---Q
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-28 06:35:55 +02:00
|
|
|
git clone ./. clone3 &&
|
|
|
|
(
|
|
|
|
cd clone3 &&
|
|
|
|
git checkout -b topic2 origin/topic &&
|
|
|
|
echo Sixth > A &&
|
|
|
|
git commit -a -m "Modify A3" &&
|
|
|
|
git checkout -b topic origin/topic &&
|
|
|
|
git merge --no-ff topic2
|
|
|
|
) &&
|
|
|
|
|
2013-08-21 20:48:57 +02:00
|
|
|
git clone ./. clone4 &&
|
|
|
|
(
|
|
|
|
cd clone4 &&
|
|
|
|
git checkout -b topic2 origin/topic &&
|
|
|
|
echo Sixth > A &&
|
|
|
|
git commit -a -m "Modify A3" &&
|
|
|
|
git checkout -b topic origin/topic &&
|
|
|
|
git merge --no-ff topic2
|
|
|
|
) &&
|
|
|
|
|
2008-09-29 22:28:57 +02:00
|
|
|
git checkout topic &&
|
|
|
|
echo Fourth >> B &&
|
|
|
|
git commit -a -m "Modify B2"
|
|
|
|
'
|
|
|
|
|
2008-12-15 11:05:31 +01:00
|
|
|
test_expect_success '--continue works after a conflict' '
|
2008-12-15 11:05:30 +01:00
|
|
|
(
|
|
|
|
cd clone2 &&
|
|
|
|
git fetch &&
|
|
|
|
test_must_fail git rebase -p origin/topic &&
|
|
|
|
test 2 = $(git ls-files B | wc -l) &&
|
|
|
|
echo Resolved again > B &&
|
|
|
|
test_must_fail git rebase --continue &&
|
2008-12-22 22:16:51 +01:00
|
|
|
grep "^@@@ " .git/rebase-merge/patch &&
|
2008-12-15 11:05:30 +01:00
|
|
|
git add B &&
|
|
|
|
git rebase --continue &&
|
|
|
|
test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
|
|
|
|
test 1 = $(git rev-list --all --pretty=oneline | grep "Add different" | wc -l) &&
|
|
|
|
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge origin" | wc -l)
|
|
|
|
)
|
2008-09-29 22:28:57 +02:00
|
|
|
'
|
|
|
|
|
git-rebase--interactive.sh: preserve-merges fails on merges created with no-ff
'git rebase' uses 'git merge' to preserve merges (-p). This preserves
the original merge commit correctly, except when the original merge
commit was created by 'git merge --no-ff'. In this case, 'git rebase'
will fail to preserve the merge, because during 'git rebase', 'git
merge' will simply fast-forward and skip the commit. For example:
B
/ \
A---M
/
---o---O---P---Q
If we try to rebase M onto P, we lose the merge commit and this happens:
A---B
/
---o---O---P---Q
To correct this, we simply do a "no fast-forward" on all merge commits
when rebasing. Since by the time we decided to do a 'git merge' inside
'git rebase', it means there was a merge originally, so 'git merge'
should always create a merge commit regardless of what the merge
branches look like. This way, when rebase M onto P from the above
example, we get:
B
/ \
A---M
/
---o---O---P---Q
Signed-off-by: Andrew Wong <andrew.kw.w@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-04-28 06:35:55 +02:00
|
|
|
test_expect_success 'rebase -p preserves no-ff merges' '
|
|
|
|
(
|
|
|
|
cd clone3 &&
|
|
|
|
git fetch &&
|
|
|
|
git rebase -p origin/topic &&
|
|
|
|
test 3 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) &&
|
|
|
|
test 1 = $(git rev-list --all --pretty=oneline | grep "Merge branch" | wc -l)
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2013-08-21 20:48:57 +02:00
|
|
|
test_expect_success 'rebase -p ignores merge.log config' '
|
|
|
|
(
|
|
|
|
cd clone4 &&
|
|
|
|
git fetch &&
|
|
|
|
git -c merge.log=1 rebase -p origin/topic &&
|
|
|
|
echo >expected &&
|
|
|
|
git log --format="%b" -1 >current &&
|
|
|
|
test_cmp expected current
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2008-09-29 22:28:57 +02:00
|
|
|
test_done
|