2009-01-05 20:35:16 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git rebase --root
|
|
|
|
|
|
|
|
Tests if git rebase --root --onto <newparent> can rebase the root commit.
|
|
|
|
'
|
|
|
|
. ./test-lib.sh
|
2009-01-31 01:47:00 +03:00
|
|
|
|
2009-01-31 01:47:01 +03: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 20:35:16 +03:00
|
|
|
test_expect_success 'prepare repository' '
|
2009-01-28 01:35:09 +03:00
|
|
|
test_commit 1 A &&
|
|
|
|
test_commit 2 A &&
|
2009-01-05 20:35:16 +03:00
|
|
|
git symbolic-ref HEAD refs/heads/other &&
|
|
|
|
rm .git/index &&
|
2009-01-28 01:35:09 +03:00
|
|
|
test_commit 3 B &&
|
|
|
|
test_commit 1b A 1 &&
|
|
|
|
test_commit 4 B
|
2009-01-05 20:35:16 +03:00
|
|
|
'
|
|
|
|
|
2012-06-26 18:51:55 +04:00
|
|
|
test_expect_success 'rebase --root fails with too many args' '
|
|
|
|
git checkout -B fail other &&
|
|
|
|
test_must_fail git rebase --onto master --root fail fail
|
|
|
|
'
|
|
|
|
|
2009-01-05 20:35:16 +03: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 18:51:55 +04:00
|
|
|
git checkout -b work other &&
|
2009-01-05 20:35:16 +03:00
|
|
|
git rebase --root --onto master &&
|
|
|
|
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 &&
|
|
|
|
git rebase --root --onto master work2 &&
|
|
|
|
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-03 01:28:28 +03:00
|
|
|
test_expect_success 'rebase -i --root --onto <newbase>' '
|
|
|
|
git checkout -b work3 other &&
|
2009-01-31 01:47:00 +03:00
|
|
|
git rebase -i --root --onto master &&
|
2009-01-03 01:28:28 +03: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 &&
|
2009-01-31 01:47:00 +03:00
|
|
|
git rebase -i --root --onto master work4 &&
|
2009-01-03 01:28:28 +03: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
|
|
|
|
'
|
|
|
|
|
2018-10-31 23:02:02 +03:00
|
|
|
test_expect_success REBASE_P 'rebase -i -p with linear history' '
|
2009-01-03 01:28:28 +03:00
|
|
|
git checkout -b work5 other &&
|
2009-01-31 01:47:00 +03:00
|
|
|
git rebase -i -p --root --onto master &&
|
2009-01-03 01:28:28 +03:00
|
|
|
git log --pretty=tformat:"%s" > rebased5 &&
|
|
|
|
test_cmp expect rebased5
|
|
|
|
'
|
|
|
|
|
2018-10-31 23:02:02 +03:00
|
|
|
test_expect_success REBASE_P 'pre-rebase got correct input (5)' '
|
2009-01-03 01:28:28 +03:00
|
|
|
test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'set up merge history' '
|
|
|
|
git checkout other^ &&
|
|
|
|
git checkout -b side &&
|
2009-01-28 01:35:09 +03:00
|
|
|
test_commit 5 C &&
|
2009-01-03 01:28:28 +03:00
|
|
|
git checkout other &&
|
|
|
|
git merge side
|
|
|
|
'
|
|
|
|
|
2009-01-31 01:47:01 +03: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-03 01:28:28 +03:00
|
|
|
EOF
|
|
|
|
|
2018-10-31 23:02:02 +03:00
|
|
|
test_expect_success REBASE_P 'rebase -i -p with merge' '
|
2009-01-03 01:28:28 +03:00
|
|
|
git checkout -b work6 other &&
|
2009-01-31 01:47:00 +03:00
|
|
|
git rebase -i -p --root --onto master &&
|
2009-01-31 01:47:01 +03:00
|
|
|
log_with_names work6 > rebased6 &&
|
2009-01-03 01:28:28 +03:00
|
|
|
test_cmp expect-side rebased6
|
|
|
|
'
|
|
|
|
|
|
|
|
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-28 01:35:09 +03:00
|
|
|
test_commit 6 D &&
|
2009-01-03 01:28:28 +03: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 23:21:09 +03:00
|
|
|
git merge --allow-unrelated-histories third
|
2009-01-03 01:28:28 +03:00
|
|
|
'
|
|
|
|
|
2009-01-31 01:47:01 +03: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-03 01:28:28 +03:00
|
|
|
EOF
|
|
|
|
|
2018-10-31 23:02:02 +03:00
|
|
|
test_expect_success REBASE_P 'rebase -i -p with two roots' '
|
2009-01-03 01:28:28 +03:00
|
|
|
git checkout -b work7 other &&
|
2009-01-31 01:47:00 +03:00
|
|
|
git rebase -i -p --root --onto master &&
|
2009-01-31 01:47:01 +03:00
|
|
|
log_with_names work7 > rebased7 &&
|
2009-01-03 01:28:28 +03:00
|
|
|
test_cmp expect-third rebased7
|
|
|
|
'
|
|
|
|
|
2009-01-05 20:35:16 +03: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 &&
|
2009-01-31 01:47:00 +03:00
|
|
|
test_must_fail git rebase --root --onto master &&
|
2010-10-31 04:46:54 +03:00
|
|
|
test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
|
2009-01-05 20:35:16 +03:00
|
|
|
test 0 = $(git rev-list other...stops1 | wc -l)
|
|
|
|
'
|
|
|
|
|
2009-01-03 01:28:28 +03:00
|
|
|
test_expect_success 'pre-rebase hook stops rebase -i' '
|
|
|
|
git checkout -b stops2 other &&
|
2009-01-31 01:47:00 +03:00
|
|
|
test_must_fail git rebase --root --onto master &&
|
2010-10-31 04:46:54 +03:00
|
|
|
test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
|
2009-01-03 01:28:28 +03:00
|
|
|
test 0 = $(git rev-list other...stops2 | wc -l)
|
|
|
|
'
|
|
|
|
|
2009-01-26 12:05:22 +03:00
|
|
|
test_expect_success 'remove pre-rebase hook' '
|
|
|
|
rm -f .git/hooks/pre-rebase
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'set up a conflict' '
|
|
|
|
git checkout master &&
|
|
|
|
echo conflict > B &&
|
|
|
|
git add B &&
|
|
|
|
git commit -m conflict
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase --root with conflict (first part)' '
|
|
|
|
git checkout -b conflict1 other &&
|
|
|
|
test_must_fail git rebase --root --onto master &&
|
|
|
|
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 &&
|
2009-01-31 01:47:00 +03:00
|
|
|
test_must_fail git rebase -i --root --onto master &&
|
2009-01-26 12:05:22 +03: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
|
|
|
|
|
2018-10-31 23:02:02 +03:00
|
|
|
test_expect_success REBASE_P 'rebase -i -p --root with conflict (first part)' '
|
2009-01-26 12:05:22 +03:00
|
|
|
git checkout -b conflict3 other &&
|
2009-01-31 01:47:00 +03:00
|
|
|
test_must_fail git rebase -i -p --root --onto master &&
|
2009-01-26 12:05:22 +03:00
|
|
|
git ls-files -u | grep "B$"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fix the conflict' '
|
|
|
|
echo 3 > B &&
|
|
|
|
git add B
|
|
|
|
'
|
|
|
|
|
2018-10-31 23:02:02 +03:00
|
|
|
test_expect_success REBASE_P 'rebase -i -p --root with conflict (second part)' '
|
2009-01-26 12:05:22 +03:00
|
|
|
git rebase --continue &&
|
2009-01-31 01:47:01 +03:00
|
|
|
log_with_names conflict3 >out &&
|
2009-01-26 12:05:22 +03:00
|
|
|
test_cmp expect-conflict-p out
|
|
|
|
'
|
|
|
|
|
2009-01-05 20:35:16 +03:00
|
|
|
test_done
|