2006-12-13 01:36:16 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='Test merge without common ancestors'
|
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
|
|
|
|
|
2006-12-13 01:36:16 +01:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
# This scenario is based on a real-world repository of Shawn Pearce.
|
|
|
|
|
|
|
|
# 1 - A - D - F
|
|
|
|
# \ X /
|
|
|
|
# B X
|
|
|
|
# X \
|
|
|
|
# 2 - C - E - G
|
|
|
|
|
2006-12-28 10:10:50 +01:00
|
|
|
GIT_COMMITTER_DATE="2006-12-12 23:28:00 +0100"
|
|
|
|
export GIT_COMMITTER_DATE
|
|
|
|
|
2019-11-06 02:34:09 +01:00
|
|
|
test_expect_success 'setup tests' '
|
|
|
|
echo 1 >a1 &&
|
|
|
|
git add a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:00" git commit -m 1 a1 &&
|
|
|
|
|
2020-11-19 00:44:38 +01:00
|
|
|
git checkout -b A main &&
|
2019-11-06 02:34:09 +01:00
|
|
|
echo A >a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:01" git commit -m A a1 &&
|
|
|
|
|
2020-11-19 00:44:38 +01:00
|
|
|
git checkout -b B main &&
|
2019-11-06 02:34:09 +01:00
|
|
|
echo B >a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:02" git commit -m B a1 &&
|
|
|
|
|
|
|
|
git checkout -b D A &&
|
|
|
|
git rev-parse B >.git/MERGE_HEAD &&
|
|
|
|
echo D >a1 &&
|
|
|
|
git update-index a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:03" git commit -m D &&
|
|
|
|
|
|
|
|
git symbolic-ref HEAD refs/heads/other &&
|
|
|
|
echo 2 >a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:04" git commit -m 2 a1 &&
|
|
|
|
|
|
|
|
git checkout -b C &&
|
|
|
|
echo C >a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:05" git commit -m C a1 &&
|
|
|
|
|
|
|
|
git checkout -b E C &&
|
|
|
|
git rev-parse B >.git/MERGE_HEAD &&
|
|
|
|
echo E >a1 &&
|
|
|
|
git update-index a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:06" git commit -m E &&
|
|
|
|
|
|
|
|
git checkout -b G E &&
|
|
|
|
git rev-parse A >.git/MERGE_HEAD &&
|
|
|
|
echo G >a1 &&
|
|
|
|
git update-index a1 &&
|
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:07" git commit -m G &&
|
|
|
|
|
|
|
|
git checkout -b F D &&
|
|
|
|
git rev-parse C >.git/MERGE_HEAD &&
|
|
|
|
echo F >a1 &&
|
|
|
|
git update-index a1 &&
|
2020-02-07 01:52:54 +01:00
|
|
|
GIT_AUTHOR_DATE="2006-12-12 23:00:08" git commit -m F &&
|
|
|
|
|
|
|
|
test_oid_cache <<-EOF
|
|
|
|
idxstage1 sha1:ec3fe2a791706733f2d8fa7ad45d9a9672031f5e
|
|
|
|
idxstage1 sha256:b3c8488929903aaebdeb22270cb6d36e5b8724b01ae0d4da24632f158c99676f
|
|
|
|
EOF
|
2006-12-28 10:10:50 +01:00
|
|
|
'
|
2006-12-13 01:36:16 +01:00
|
|
|
|
2018-08-29 14:49:04 +02:00
|
|
|
test_expect_success 'combined merge conflicts' '
|
|
|
|
test_must_fail env GIT_TEST_COMMIT_GRAPH=0 git merge -m final G
|
|
|
|
'
|
2006-12-13 01:36:16 +01:00
|
|
|
|
2019-11-06 02:34:09 +01:00
|
|
|
test_expect_success 'result contains a conflict' '
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
<<<<<<< HEAD
|
|
|
|
F
|
|
|
|
=======
|
|
|
|
G
|
|
|
|
>>>>>>> G
|
|
|
|
EOF
|
2006-12-13 04:05:39 +01:00
|
|
|
|
2019-11-06 02:34:09 +01:00
|
|
|
test_cmp expect a1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'virtual trees were processed' '
|
|
|
|
git ls-files --stage >out &&
|
2006-12-13 04:05:39 +01:00
|
|
|
|
2020-02-07 01:52:54 +01:00
|
|
|
cat >expect <<-EOF &&
|
|
|
|
100644 $(test_oid idxstage1) 1 a1
|
|
|
|
100644 $(git rev-parse F:a1) 2 a1
|
|
|
|
100644 $(git rev-parse G:a1) 3 a1
|
2019-11-06 02:34:09 +01:00
|
|
|
EOF
|
2006-12-13 01:36:16 +01:00
|
|
|
|
2019-11-06 02:34:09 +01:00
|
|
|
test_cmp expect out
|
|
|
|
'
|
2006-12-13 01:36:16 +01:00
|
|
|
|
2007-06-05 04:36:49 +02:00
|
|
|
test_expect_success 'refuse to merge binary files' '
|
2008-03-01 10:10:12 +01:00
|
|
|
git reset --hard &&
|
2019-11-06 02:34:09 +01:00
|
|
|
printf "\0" >binary-file &&
|
2007-06-05 04:36:49 +02:00
|
|
|
git add binary-file &&
|
|
|
|
git commit -m binary &&
|
|
|
|
git checkout G &&
|
2019-11-06 02:34:09 +01:00
|
|
|
printf "\0\0" >binary-file &&
|
2007-06-05 04:36:49 +02:00
|
|
|
git add binary-file &&
|
|
|
|
git commit -m binary2 &&
|
2019-11-06 02:34:09 +01:00
|
|
|
test_must_fail git merge F >merge.out 2>merge.err &&
|
2009-07-01 22:18:04 +02:00
|
|
|
grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge.err
|
2007-06-05 04:36:49 +02:00
|
|
|
'
|
|
|
|
|
2008-12-22 23:10:20 +01:00
|
|
|
test_expect_success 'mark rename/delete as unmerged' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout -b delete &&
|
|
|
|
git rm a1 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m delete &&
|
|
|
|
git checkout -b rename HEAD^ &&
|
2010-10-31 02:46:54 +01:00
|
|
|
git mv a1 a2 &&
|
2008-12-22 23:10:20 +01:00
|
|
|
test_tick &&
|
|
|
|
git commit -m rename &&
|
|
|
|
test_must_fail git merge delete &&
|
2020-10-26 18:01:39 +01:00
|
|
|
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
|
|
|
|
then
|
|
|
|
test 2 = $(git ls-files --unmerged | wc -l)
|
|
|
|
else
|
|
|
|
test 1 = $(git ls-files --unmerged | wc -l)
|
|
|
|
fi &&
|
2008-12-22 23:10:20 +01:00
|
|
|
git rev-parse --verify :2:a2 &&
|
|
|
|
test_must_fail git rev-parse --verify :3:a2 &&
|
|
|
|
git checkout -f delete &&
|
|
|
|
test_must_fail git merge rename &&
|
2020-10-26 18:01:39 +01:00
|
|
|
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
|
|
|
|
then
|
|
|
|
test 2 = $(git ls-files --unmerged | wc -l)
|
|
|
|
else
|
|
|
|
test 1 = $(git ls-files --unmerged | wc -l)
|
|
|
|
fi &&
|
2008-12-22 23:10:20 +01:00
|
|
|
test_must_fail git rev-parse --verify :2:a2 &&
|
|
|
|
git rev-parse --verify :3:a2
|
|
|
|
'
|
|
|
|
|
2006-12-13 01:36:16 +01:00
|
|
|
test_done
|