2007-04-17 09:05:00 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='per path merge controlled by merge attribute'
|
|
|
|
|
2020-11-19 00:44:38 +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
|
|
|
|
|
2022-11-08 19:17:43 +01:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2007-04-17 09:05:00 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
for f in text binary union
|
|
|
|
do
|
2015-03-25 06:29:52 +01:00
|
|
|
echo Initial >$f && git add $f || return 1
|
2007-04-17 09:05:00 +02:00
|
|
|
done &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m Initial &&
|
|
|
|
|
|
|
|
git branch side &&
|
|
|
|
for f in text binary union
|
|
|
|
do
|
2020-11-19 00:44:38 +01:00
|
|
|
echo Main >>$f && git add $f || return 1
|
2007-04-17 09:05:00 +02:00
|
|
|
done &&
|
|
|
|
test_tick &&
|
2020-11-19 00:44:38 +01:00
|
|
|
git commit -m Main &&
|
2007-04-17 09:05:00 +02:00
|
|
|
|
|
|
|
git checkout side &&
|
|
|
|
for f in text binary union
|
|
|
|
do
|
2015-03-25 06:29:52 +01:00
|
|
|
echo Side >>$f && git add $f || return 1
|
2007-04-17 09:05:00 +02:00
|
|
|
done &&
|
|
|
|
test_tick &&
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
git commit -m Side &&
|
2007-04-17 09:05:00 +02:00
|
|
|
|
2020-02-27 01:14:20 +01:00
|
|
|
git tag anchor &&
|
|
|
|
|
|
|
|
cat >./custom-merge <<-\EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
orig="$1" ours="$2" theirs="$3" exit="$4" path=$5
|
|
|
|
(
|
|
|
|
echo "orig is $orig"
|
|
|
|
echo "ours is $ours"
|
|
|
|
echo "theirs is $theirs"
|
|
|
|
echo "path is $path"
|
|
|
|
echo "=== orig ==="
|
|
|
|
cat "$orig"
|
|
|
|
echo "=== ours ==="
|
|
|
|
cat "$ours"
|
|
|
|
echo "=== theirs ==="
|
|
|
|
cat "$theirs"
|
|
|
|
) >"$ours+"
|
|
|
|
cat "$ours+" >"$ours"
|
|
|
|
rm -f "$ours+"
|
|
|
|
exit "$exit"
|
|
|
|
EOF
|
|
|
|
chmod +x ./custom-merge
|
2007-04-17 09:05:00 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success merge '
|
|
|
|
|
2021-12-09 06:11:04 +01:00
|
|
|
cat >.gitattributes <<-\EOF &&
|
|
|
|
binary -merge
|
|
|
|
union merge=union
|
|
|
|
EOF
|
2007-04-17 09:05:00 +02:00
|
|
|
|
2020-11-19 00:44:38 +01:00
|
|
|
if git merge main
|
2007-04-17 09:05:00 +02:00
|
|
|
then
|
|
|
|
echo Gaah, should have conflicted
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo Ok, conflicted.
|
|
|
|
fi
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check merge result in index' '
|
|
|
|
|
|
|
|
git ls-files -u | grep binary &&
|
|
|
|
git ls-files -u | grep text &&
|
|
|
|
! (git ls-files -u | grep union)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check merge result in working tree' '
|
|
|
|
|
|
|
|
git cat-file -p HEAD:binary >binary-orig &&
|
|
|
|
grep "<<<<<<<" text &&
|
|
|
|
cmp binary-orig binary &&
|
|
|
|
! grep "<<<<<<<" union &&
|
2020-11-19 00:44:38 +01:00
|
|
|
grep Main union &&
|
2007-04-17 09:05:00 +02:00
|
|
|
grep Side union
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2010-01-21 08:49:27 +01:00
|
|
|
test_expect_success 'retry the merge with longer context' '
|
|
|
|
echo text conflict-marker-size=32 >>.gitattributes &&
|
|
|
|
git checkout -m text &&
|
|
|
|
sed -ne "/^\([<=>]\)\1\1\1*/{
|
|
|
|
s/ .*$//
|
|
|
|
p
|
|
|
|
}" >actual text &&
|
|
|
|
grep ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" actual &&
|
|
|
|
grep "================================" actual &&
|
|
|
|
grep "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" actual
|
|
|
|
'
|
|
|
|
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
test_expect_success 'custom merge backend' '
|
|
|
|
|
|
|
|
echo "* merge=union" >.gitattributes &&
|
|
|
|
echo "text merge=custom" >>.gitattributes &&
|
|
|
|
|
|
|
|
git reset --hard anchor &&
|
|
|
|
git config --replace-all \
|
2015-06-05 00:10:29 +02:00
|
|
|
merge.custom.driver "./custom-merge %O %A %B 0 %P" &&
|
2007-04-18 20:27:32 +02:00
|
|
|
git config --replace-all \
|
|
|
|
merge.custom.name "custom merge driver for testing" &&
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
|
2020-11-19 00:44:38 +01:00
|
|
|
git merge main &&
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
|
|
|
|
cmp binary union &&
|
|
|
|
sed -e 1,3d text >check-1 &&
|
2020-11-19 00:44:38 +01:00
|
|
|
o=$(git unpack-file main^:text) &&
|
2008-09-03 10:59:29 +02:00
|
|
|
a=$(git unpack-file side^:text) &&
|
2020-11-19 00:44:38 +01:00
|
|
|
b=$(git unpack-file main:text) &&
|
t: don't spuriously close and reopen quotes
In the test scripts, the recommended style is, e.g.:
test_expect_success 'name' '
do-something somehow &&
do-some-more testing
'
When using this style, any single quote in the multi-line test section
is actually closing the lone single quotes that surround it.
It can be a non-issue in practice:
test_expect_success 'sed a little' '
sed -e 's/hi/lo/' in >out # "ok": no whitespace in s/hi/lo/
'
Or it can be a bug in the test, e.g., because variable interpolation
happens before the test even begins executing:
v=abc
test_expect_success 'variable interpolation' '
v=def &&
echo '"$v"' # abc
'
Change several such in-test single quotes to use double quotes instead
or, in a few cases, drop them altogether. These were identified using
some crude grepping. We're not fixing any test bugs here, but we're
hopefully making these tests slightly easier to grok and to maintain.
There are legitimate use cases for closing a quote and opening a new
one, e.g., both '\'' and '"'"' can be used to produce a literal single
quote. I'm not touching any of those here.
In t9401, tuck the redirecting ">" to the filename while we're touching
those lines.
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-06 22:08:53 +02:00
|
|
|
sh -c "./custom-merge $o $a $b 0 text" &&
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
sed -e 1,3d $a >check-2 &&
|
|
|
|
cmp check-1 check-2 &&
|
|
|
|
rm -f $o $a $b
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'custom merge backend' '
|
|
|
|
|
|
|
|
git reset --hard anchor &&
|
|
|
|
git config --replace-all \
|
2015-06-05 00:10:29 +02:00
|
|
|
merge.custom.driver "./custom-merge %O %A %B 1 %P" &&
|
2007-04-18 20:27:32 +02:00
|
|
|
git config --replace-all \
|
|
|
|
merge.custom.name "custom merge driver for testing" &&
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
|
2020-11-19 00:44:38 +01:00
|
|
|
if git merge main
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
then
|
|
|
|
echo "Eh? should have conflicted"
|
|
|
|
false
|
|
|
|
else
|
|
|
|
echo "Ok, conflicted"
|
|
|
|
fi &&
|
|
|
|
|
|
|
|
cmp binary union &&
|
|
|
|
sed -e 1,3d text >check-1 &&
|
2020-11-19 00:44:38 +01:00
|
|
|
o=$(git unpack-file main^:text) &&
|
2008-09-03 10:59:29 +02:00
|
|
|
a=$(git unpack-file anchor:text) &&
|
2020-11-19 00:44:38 +01:00
|
|
|
b=$(git unpack-file main:text) &&
|
t: don't spuriously close and reopen quotes
In the test scripts, the recommended style is, e.g.:
test_expect_success 'name' '
do-something somehow &&
do-some-more testing
'
When using this style, any single quote in the multi-line test section
is actually closing the lone single quotes that surround it.
It can be a non-issue in practice:
test_expect_success 'sed a little' '
sed -e 's/hi/lo/' in >out # "ok": no whitespace in s/hi/lo/
'
Or it can be a bug in the test, e.g., because variable interpolation
happens before the test even begins executing:
v=abc
test_expect_success 'variable interpolation' '
v=def &&
echo '"$v"' # abc
'
Change several such in-test single quotes to use double quotes instead
or, in a few cases, drop them altogether. These were identified using
some crude grepping. We're not fixing any test bugs here, but we're
hopefully making these tests slightly easier to grok and to maintain.
There are legitimate use cases for closing a quote and opening a new
one, e.g., both '\'' and '"'"' can be used to produce a literal single
quote. I'm not touching any of those here.
In t9401, tuck the redirecting ">" to the filename while we're touching
those lines.
Signed-off-by: Martin Ågren <martin.agren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-08-06 22:08:53 +02:00
|
|
|
sh -c "./custom-merge $o $a $b 0 text" &&
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
sed -e 1,3d $a >check-2 &&
|
|
|
|
cmp check-1 check-2 &&
|
2015-06-05 00:10:29 +02:00
|
|
|
sed -e 1,3d -e 4q $a >check-3 &&
|
|
|
|
echo "path is text" >expect &&
|
|
|
|
cmp expect check-3 &&
|
Custom low-level merge driver support.
This allows users to specify custom low-level merge driver per
path, using the attributes mechanism. Just like you can specify
one of built-in "text", "binary", "union" low-level merge
drivers by saying:
* merge=text
.gitignore merge=union
*.jpg merge=binary
pick a name of your favorite merge driver, and assign it as the
value of the 'merge' attribute.
A custom low-level merge driver is defined via the config
mechanism. This patch introduces 'merge.driver', a multi-valued
configuration. Its value is the name (i.e. the one you use as
the value of 'merge' attribute) followed by a command line
specification. The command line can contain %O, %A, and %B to
be interpolated with the names of temporary files that hold the
common ancestor version, the version from your branch, and the
version from the other branch, and the resulting command is
spawned.
The low-level merge driver is expected to update the temporary
file for your branch (i.e. %A) with the result and exit with
status 0 for a clean merge, and non-zero status for a conflicted
merge.
A new test in t6026 demonstrates a sample usage.
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 07:51:45 +02:00
|
|
|
rm -f $o $a $b
|
|
|
|
'
|
|
|
|
|
2008-09-06 18:29:49 +02:00
|
|
|
test_expect_success 'up-to-date merge without common ancestor' '
|
2022-08-26 05:49:19 +02:00
|
|
|
git init repo1 &&
|
|
|
|
git init repo2 &&
|
2008-09-06 18:29:49 +02:00
|
|
|
test_tick &&
|
|
|
|
(
|
|
|
|
cd repo1 &&
|
|
|
|
>a &&
|
|
|
|
git add a &&
|
|
|
|
git commit -m initial
|
|
|
|
) &&
|
|
|
|
test_tick &&
|
|
|
|
(
|
|
|
|
cd repo2 &&
|
|
|
|
git commit --allow-empty -m initial
|
|
|
|
) &&
|
|
|
|
test_tick &&
|
|
|
|
(
|
|
|
|
cd repo1 &&
|
2020-11-19 00:44:38 +01:00
|
|
|
git fetch ../repo2 main &&
|
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 FETCH_HEAD
|
2008-09-06 18:29:49 +02:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2016-08-22 14:47:55 +02:00
|
|
|
test_expect_success 'custom merge does not lock index' '
|
2016-08-18 16:51:12 +02:00
|
|
|
git reset --hard anchor &&
|
2016-11-09 14:51:22 +01:00
|
|
|
write_script sleep-an-hour.sh <<-\EOF &&
|
|
|
|
sleep 3600 &
|
2016-09-07 08:10:41 +02:00
|
|
|
echo $! >sleep.pid
|
2016-08-18 16:51:12 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
test_write_lines >.gitattributes \
|
2016-11-09 14:51:22 +01:00
|
|
|
"* merge=ours" "text merge=sleep-an-hour" &&
|
2016-08-18 16:51:12 +02:00
|
|
|
test_config merge.ours.driver true &&
|
2016-11-09 14:51:22 +01:00
|
|
|
test_config merge.sleep-an-hour.driver ./sleep-an-hour.sh &&
|
2016-11-11 21:24:44 +01:00
|
|
|
|
|
|
|
# We are testing that the custom merge driver does not block
|
|
|
|
# index.lock on Windows due to an inherited file handle.
|
|
|
|
# To ensure that the backgrounded process ran sufficiently
|
|
|
|
# long (and has been started in the first place), we do not
|
|
|
|
# ignore the result of the kill command.
|
|
|
|
# By packaging the command in test_when_finished, we get both
|
|
|
|
# the correctness check and the clean-up.
|
|
|
|
test_when_finished "kill \$(cat sleep.pid)" &&
|
2020-11-19 00:44:38 +01:00
|
|
|
git merge main
|
2016-08-18 16:51:12 +02:00
|
|
|
'
|
|
|
|
|
2021-06-10 14:57:05 +02:00
|
|
|
test_expect_success 'binary files with union attribute' '
|
|
|
|
git checkout -b bin-main &&
|
|
|
|
printf "base\0" >bin.txt &&
|
|
|
|
echo "bin.txt merge=union" >.gitattributes &&
|
|
|
|
git add bin.txt .gitattributes &&
|
|
|
|
git commit -m base &&
|
|
|
|
|
|
|
|
printf "one\0" >bin.txt &&
|
|
|
|
git commit -am one &&
|
|
|
|
|
|
|
|
git checkout -b bin-side HEAD^ &&
|
|
|
|
printf "two\0" >bin.txt &&
|
|
|
|
git commit -am two &&
|
|
|
|
|
2022-02-02 03:37:31 +01:00
|
|
|
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
|
|
|
|
then
|
|
|
|
test_must_fail git merge bin-main >output
|
|
|
|
else
|
|
|
|
test_must_fail git merge bin-main 2>output
|
|
|
|
fi &&
|
|
|
|
grep -i "warning.*cannot merge.*HEAD vs. bin-main" output
|
2021-06-10 14:57:05 +02:00
|
|
|
'
|
|
|
|
|
2007-04-17 09:05:00 +02:00
|
|
|
test_done
|