2009-01-05 18:35:16 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git rebase --root
|
|
|
|
|
|
|
|
Tests if git rebase --root --onto <newparent> can rebase the root commit.
|
|
|
|
'
|
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
|
|
|
|
|
2009-01-05 18:35:16 +01:00
|
|
|
. ./test-lib.sh
|
2009-01-30 23:47:00 +01:00
|
|
|
|
2009-01-30 23:47:01 +01:00
|
|
|
log_with_names () {
|
|
|
|
git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
|
|
|
|
git name-rev --stdin --name-only --refs=refs/heads/$1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-05 18:35:16 +01:00
|
|
|
test_expect_success 'prepare repository' '
|
2009-01-27 23:35:09 +01:00
|
|
|
test_commit 1 A &&
|
|
|
|
test_commit 2 A &&
|
2009-01-05 18:35:16 +01:00
|
|
|
git symbolic-ref HEAD refs/heads/other &&
|
|
|
|
rm .git/index &&
|
2009-01-27 23:35:09 +01:00
|
|
|
test_commit 3 B &&
|
|
|
|
test_commit 1b A 1 &&
|
|
|
|
test_commit 4 B
|
2009-01-05 18:35:16 +01:00
|
|
|
'
|
|
|
|
|
2012-06-26 16:51:55 +02:00
|
|
|
test_expect_success 'rebase --root fails with too many args' '
|
|
|
|
git checkout -B fail other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
test_must_fail git rebase --onto main --root fail fail
|
2012-06-26 16:51:55 +02:00
|
|
|
'
|
|
|
|
|
2009-01-05 18:35:16 +01:00
|
|
|
test_expect_success 'setup pre-rebase hook' '
|
|
|
|
mkdir -p .git/hooks &&
|
|
|
|
cat >.git/hooks/pre-rebase <<EOF &&
|
|
|
|
#!$SHELL_PATH
|
|
|
|
echo "\$1,\$2" >.git/PRE-REBASE-INPUT
|
|
|
|
EOF
|
|
|
|
chmod +x .git/hooks/pre-rebase
|
|
|
|
'
|
|
|
|
cat > expect <<EOF
|
|
|
|
4
|
|
|
|
3
|
|
|
|
2
|
|
|
|
1
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'rebase --root --onto <newbase>' '
|
2012-06-26 16:51:55 +02:00
|
|
|
git checkout -b work other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
git rebase --root --onto main &&
|
2009-01-05 18:35:16 +01:00
|
|
|
git log --pretty=tformat:"%s" > rebased &&
|
|
|
|
test_cmp expect rebased
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pre-rebase got correct input (1)' '
|
|
|
|
test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase --root --onto <newbase> <branch>' '
|
|
|
|
git branch work2 other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
git rebase --root --onto main work2 &&
|
2009-01-05 18:35:16 +01:00
|
|
|
git log --pretty=tformat:"%s" > rebased2 &&
|
|
|
|
test_cmp expect rebased2
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pre-rebase got correct input (2)' '
|
|
|
|
test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
|
|
|
|
'
|
|
|
|
|
2009-01-02 23:28:28 +01:00
|
|
|
test_expect_success 'rebase -i --root --onto <newbase>' '
|
|
|
|
git checkout -b work3 other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
git rebase -i --root --onto main &&
|
2009-01-02 23:28:28 +01:00
|
|
|
git log --pretty=tformat:"%s" > rebased3 &&
|
|
|
|
test_cmp expect rebased3
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pre-rebase got correct input (3)' '
|
|
|
|
test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
|
|
|
|
git branch work4 other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
git rebase -i --root --onto main work4 &&
|
2009-01-02 23:28:28 +01:00
|
|
|
git log --pretty=tformat:"%s" > rebased4 &&
|
|
|
|
test_cmp expect rebased4
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pre-rebase got correct input (4)' '
|
|
|
|
test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'set up merge history' '
|
|
|
|
git checkout other^ &&
|
|
|
|
git checkout -b side &&
|
2009-01-27 23:35:09 +01:00
|
|
|
test_commit 5 C &&
|
2009-01-02 23:28:28 +01:00
|
|
|
git checkout other &&
|
|
|
|
git merge side
|
|
|
|
'
|
|
|
|
|
2009-01-30 23:47:01 +01:00
|
|
|
cat > expect-side <<'EOF'
|
|
|
|
commit work6 work6~1 work6^2
|
|
|
|
Merge branch 'side' into other
|
|
|
|
commit work6^2 work6~2
|
|
|
|
5
|
|
|
|
commit work6~1 work6~2
|
|
|
|
4
|
|
|
|
commit work6~2 work6~3
|
|
|
|
3
|
|
|
|
commit work6~3 work6~4
|
|
|
|
2
|
|
|
|
commit work6~4
|
|
|
|
1
|
2009-01-02 23:28:28 +01:00
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'set up second root and merge' '
|
|
|
|
git symbolic-ref HEAD refs/heads/third &&
|
|
|
|
rm .git/index &&
|
|
|
|
rm A B C &&
|
2009-01-27 23:35:09 +01:00
|
|
|
test_commit 6 D &&
|
2009-01-02 23:28:28 +01:00
|
|
|
git checkout other &&
|
merge: refuse to create too cool a merge by default
While it makes sense to allow merging unrelated histories of two
projects that started independently into one, in the way "gitk" was
merged to "git" itself aka "the coolest merge ever", such a merge is
still an unusual event. Worse, if somebody creates an independent
history by starting from a tarball of an established project and
sends a pull request to the original project, "git merge" however
happily creates such a merge without any sign of something unusual
is happening.
Teach "git merge" to refuse to create such a merge by default,
unless the user passes a new "--allow-unrelated-histories" option to
tell it that the user is aware that two unrelated projects are
merged.
Because such a "two project merge" is a rare event, a configuration
option to always allow such a merge is not added.
We could add the same option to "git pull" and have it passed
through to underlying "git merge". I do not have a fundamental
opposition against such a feature, but this commit does not do so
and instead leaves it as low-hanging fruit for others, because such
a "two project merge" would be done after fetching the other project
into some location in the working tree of an existing project and
making sure how well they fit together, it is sufficient to allow a
local merge without such an option pass-through from "git pull" to
"git merge". Many tests that are updated by this patch does the
pass-through manually by turning:
git pull something
into its equivalent:
git fetch something &&
git merge --allow-unrelated-histories FETCH_HEAD
If somebody is inclined to add such an option, updated tests in this
change need to be adjusted back to:
git pull --allow-unrelated-histories something
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-03-18 21:21:09 +01:00
|
|
|
git merge --allow-unrelated-histories third
|
2009-01-02 23:28:28 +01:00
|
|
|
'
|
|
|
|
|
2009-01-30 23:47:01 +01:00
|
|
|
cat > expect-third <<'EOF'
|
|
|
|
commit work7 work7~1 work7^2
|
|
|
|
Merge branch 'third' into other
|
|
|
|
commit work7^2 work7~4
|
|
|
|
6
|
|
|
|
commit work7~1 work7~2 work7~1^2
|
|
|
|
Merge branch 'side' into other
|
|
|
|
commit work7~1^2 work7~3
|
|
|
|
5
|
|
|
|
commit work7~2 work7~3
|
|
|
|
4
|
|
|
|
commit work7~3 work7~4
|
|
|
|
3
|
|
|
|
commit work7~4 work7~5
|
|
|
|
2
|
|
|
|
commit work7~5
|
|
|
|
1
|
2009-01-02 23:28:28 +01:00
|
|
|
EOF
|
|
|
|
|
2009-01-05 18:35:16 +01:00
|
|
|
test_expect_success 'setup pre-rebase hook that fails' '
|
|
|
|
mkdir -p .git/hooks &&
|
|
|
|
cat >.git/hooks/pre-rebase <<EOF &&
|
|
|
|
#!$SHELL_PATH
|
|
|
|
false
|
|
|
|
EOF
|
|
|
|
chmod +x .git/hooks/pre-rebase
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pre-rebase hook stops rebase' '
|
|
|
|
git checkout -b stops1 other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
test_must_fail git rebase --root --onto main &&
|
2010-10-31 02:46:54 +01:00
|
|
|
test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
|
2009-01-05 18:35:16 +01:00
|
|
|
test 0 = $(git rev-list other...stops1 | wc -l)
|
|
|
|
'
|
|
|
|
|
2009-01-02 23:28:28 +01:00
|
|
|
test_expect_success 'pre-rebase hook stops rebase -i' '
|
|
|
|
git checkout -b stops2 other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
test_must_fail git rebase --root --onto main &&
|
2010-10-31 02:46:54 +01:00
|
|
|
test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
|
2009-01-02 23:28:28 +01:00
|
|
|
test 0 = $(git rev-list other...stops2 | wc -l)
|
|
|
|
'
|
|
|
|
|
2009-01-26 10:05:22 +01:00
|
|
|
test_expect_success 'remove pre-rebase hook' '
|
|
|
|
rm -f .git/hooks/pre-rebase
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'set up a conflict' '
|
2020-11-19 00:44:25 +01:00
|
|
|
git checkout main &&
|
2009-01-26 10:05:22 +01:00
|
|
|
echo conflict > B &&
|
|
|
|
git add B &&
|
|
|
|
git commit -m conflict
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase --root with conflict (first part)' '
|
|
|
|
git checkout -b conflict1 other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
test_must_fail git rebase --root --onto main &&
|
2009-01-26 10:05:22 +01:00
|
|
|
git ls-files -u | grep "B$"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fix the conflict' '
|
|
|
|
echo 3 > B &&
|
|
|
|
git add B
|
|
|
|
'
|
|
|
|
|
|
|
|
cat > expect-conflict <<EOF
|
|
|
|
6
|
|
|
|
5
|
|
|
|
4
|
|
|
|
3
|
|
|
|
conflict
|
|
|
|
2
|
|
|
|
1
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'rebase --root with conflict (second part)' '
|
|
|
|
git rebase --continue &&
|
|
|
|
git log --pretty=tformat:"%s" > conflict1 &&
|
|
|
|
test_cmp expect-conflict conflict1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase -i --root with conflict (first part)' '
|
|
|
|
git checkout -b conflict2 other &&
|
2020-11-19 00:44:25 +01:00
|
|
|
test_must_fail git rebase -i --root --onto main &&
|
2009-01-26 10:05:22 +01:00
|
|
|
git ls-files -u | grep "B$"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fix the conflict' '
|
|
|
|
echo 3 > B &&
|
|
|
|
git add B
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase -i --root with conflict (second part)' '
|
|
|
|
git rebase --continue &&
|
|
|
|
git log --pretty=tformat:"%s" > conflict2 &&
|
|
|
|
test_cmp expect-conflict conflict2
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >expect-conflict-p <<\EOF
|
|
|
|
commit conflict3 conflict3~1 conflict3^2
|
|
|
|
Merge branch 'third' into other
|
|
|
|
commit conflict3^2 conflict3~4
|
|
|
|
6
|
|
|
|
commit conflict3~1 conflict3~2 conflict3~1^2
|
|
|
|
Merge branch 'side' into other
|
|
|
|
commit conflict3~1^2 conflict3~3
|
|
|
|
5
|
|
|
|
commit conflict3~2 conflict3~3
|
|
|
|
4
|
|
|
|
commit conflict3~3 conflict3~4
|
|
|
|
3
|
|
|
|
commit conflict3~4 conflict3~5
|
|
|
|
conflict
|
|
|
|
commit conflict3~5 conflict3~6
|
|
|
|
2
|
|
|
|
commit conflict3~6
|
|
|
|
1
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'fix the conflict' '
|
|
|
|
echo 3 > B &&
|
|
|
|
git add B
|
|
|
|
'
|
|
|
|
|
2009-01-05 18:35:16 +01:00
|
|
|
test_done
|