2012-05-10 03:50:58 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git apply --3way'
|
|
|
|
|
2020-11-19 02:44:27 +03: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 02:44:19 +03:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2012-05-10 03:50:58 +04:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2019-10-24 02:32:31 +03:00
|
|
|
print_sanitized_conflicted_diff () {
|
|
|
|
git diff HEAD >diff.raw &&
|
2012-05-10 03:50:58 +04:00
|
|
|
sed -e '
|
|
|
|
/^index /d
|
2019-10-24 02:32:36 +03:00
|
|
|
s/^\(+[<>|][<>|][<>|][<>|]*\) .*/\1/
|
2019-10-24 02:32:31 +03:00
|
|
|
' diff.raw
|
2012-05-10 03:50:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
test_tick &&
|
2019-10-24 02:32:28 +03:00
|
|
|
test_write_lines 1 2 3 4 5 6 7 >one &&
|
2012-05-10 03:50:58 +04:00
|
|
|
cat one >two &&
|
|
|
|
git add one two &&
|
|
|
|
git commit -m initial &&
|
|
|
|
|
|
|
|
git branch side &&
|
|
|
|
|
|
|
|
test_tick &&
|
2019-10-24 02:32:28 +03:00
|
|
|
test_write_lines 1 two 3 4 5 six 7 >one &&
|
|
|
|
test_write_lines 1 two 3 4 5 6 7 >two &&
|
2020-11-19 02:44:27 +03:00
|
|
|
git commit -a -m main &&
|
2012-05-10 03:50:58 +04:00
|
|
|
|
|
|
|
git checkout side &&
|
2019-10-24 02:32:28 +03:00
|
|
|
test_write_lines 1 2 3 4 five 6 7 >one &&
|
|
|
|
test_write_lines 1 2 3 4 five 6 7 >two &&
|
2012-05-10 03:50:58 +04:00
|
|
|
git commit -a -m side &&
|
|
|
|
|
2020-11-19 02:44:27 +03:00
|
|
|
git checkout main
|
2012-05-10 03:50:58 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply without --3way' '
|
|
|
|
git diff side^ side >P.diff &&
|
|
|
|
|
|
|
|
# should fail to apply
|
|
|
|
git reset --hard &&
|
2020-11-19 02:44:27 +03:00
|
|
|
git checkout main^0 &&
|
2012-05-10 03:50:58 +04:00
|
|
|
test_must_fail git apply --index P.diff &&
|
|
|
|
# should leave things intact
|
|
|
|
git diff-files --exit-code &&
|
|
|
|
git diff-index --exit-code --cached HEAD
|
|
|
|
'
|
|
|
|
|
2019-10-24 02:32:36 +03:00
|
|
|
test_apply_with_3way () {
|
2012-05-10 03:50:58 +04:00
|
|
|
# Merging side should be similar to applying this patch
|
|
|
|
git diff ...side >P.diff &&
|
|
|
|
|
|
|
|
# The corresponding conflicted merge
|
|
|
|
git reset --hard &&
|
2020-11-19 02:44:27 +03:00
|
|
|
git checkout main^0 &&
|
2012-05-10 03:50:58 +04:00
|
|
|
test_must_fail git merge --no-commit side &&
|
|
|
|
git ls-files -s >expect.ls &&
|
2019-10-24 02:32:31 +03:00
|
|
|
print_sanitized_conflicted_diff >expect.diff &&
|
2012-05-10 03:50:58 +04:00
|
|
|
|
|
|
|
# should fail to apply
|
|
|
|
git reset --hard &&
|
2020-11-19 02:44:27 +03:00
|
|
|
git checkout main^0 &&
|
2012-05-10 03:50:58 +04:00
|
|
|
test_must_fail git apply --index --3way P.diff &&
|
|
|
|
git ls-files -s >actual.ls &&
|
2019-10-24 02:32:31 +03:00
|
|
|
print_sanitized_conflicted_diff >actual.diff &&
|
2012-05-10 03:50:58 +04:00
|
|
|
|
|
|
|
# The result should resemble the corresponding merge
|
|
|
|
test_cmp expect.ls actual.ls &&
|
|
|
|
test_cmp expect.diff actual.diff
|
2019-10-24 02:32:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'apply with --3way' '
|
|
|
|
test_apply_with_3way
|
|
|
|
'
|
|
|
|
|
2019-10-24 02:32:38 +03:00
|
|
|
test_expect_success 'apply with --3way with merge.conflictStyle = diff3' '
|
2019-10-24 02:32:36 +03:00
|
|
|
test_config merge.conflictStyle diff3 &&
|
|
|
|
test_apply_with_3way
|
2012-05-10 03:50:58 +04:00
|
|
|
'
|
|
|
|
|
2012-05-11 00:56:49 +04:00
|
|
|
test_expect_success 'apply with --3way with rerere enabled' '
|
2019-10-24 02:32:33 +03:00
|
|
|
test_config rerere.enabled true &&
|
2012-05-11 00:56:49 +04:00
|
|
|
|
|
|
|
# Merging side should be similar to applying this patch
|
|
|
|
git diff ...side >P.diff &&
|
|
|
|
|
|
|
|
# The corresponding conflicted merge
|
|
|
|
git reset --hard &&
|
2020-11-19 02:44:27 +03:00
|
|
|
git checkout main^0 &&
|
2012-05-11 00:56:49 +04:00
|
|
|
test_must_fail git merge --no-commit side &&
|
|
|
|
|
|
|
|
# Manually resolve and record the resolution
|
2019-10-24 02:32:28 +03:00
|
|
|
test_write_lines 1 two 3 4 five six 7 >one &&
|
2012-05-11 00:56:49 +04:00
|
|
|
git rerere &&
|
|
|
|
cat one >expect &&
|
|
|
|
|
|
|
|
# should fail to apply
|
|
|
|
git reset --hard &&
|
2020-11-19 02:44:27 +03:00
|
|
|
git checkout main^0 &&
|
2012-05-11 00:56:49 +04:00
|
|
|
test_must_fail git apply --index --3way P.diff &&
|
|
|
|
|
|
|
|
# but rerere should have replayed the recorded resolution
|
|
|
|
test_cmp expect one
|
|
|
|
'
|
|
|
|
|
2012-06-13 09:57:57 +04:00
|
|
|
test_expect_success 'apply -3 with add/add conflict setup' '
|
|
|
|
git reset --hard &&
|
|
|
|
|
|
|
|
git checkout -b adder &&
|
2019-10-24 02:32:28 +03:00
|
|
|
test_write_lines 1 2 3 4 5 6 7 >three &&
|
|
|
|
test_write_lines 1 2 3 4 5 6 7 >four &&
|
2012-06-13 09:57:57 +04:00
|
|
|
git add three four &&
|
|
|
|
git commit -m "add three and four" &&
|
|
|
|
|
|
|
|
git checkout -b another adder^ &&
|
2019-10-24 02:32:28 +03:00
|
|
|
test_write_lines 1 2 3 4 5 6 7 >three &&
|
|
|
|
test_write_lines 1 2 3 four 5 6 7 >four &&
|
2012-06-13 09:57:57 +04:00
|
|
|
git add three four &&
|
|
|
|
git commit -m "add three and four" &&
|
|
|
|
|
|
|
|
# Merging another should be similar to applying this patch
|
|
|
|
git diff adder...another >P.diff &&
|
|
|
|
|
|
|
|
git checkout adder^0 &&
|
|
|
|
test_must_fail git merge --no-commit another &&
|
|
|
|
git ls-files -s >expect.ls &&
|
2019-10-24 02:32:31 +03:00
|
|
|
print_sanitized_conflicted_diff >expect.diff
|
2012-06-13 09:57:57 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply -3 with add/add conflict' '
|
|
|
|
# should fail to apply ...
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout adder^0 &&
|
|
|
|
test_must_fail git apply --index --3way P.diff &&
|
|
|
|
# ... and leave conflicts in the index and in the working tree
|
|
|
|
git ls-files -s >actual.ls &&
|
2019-10-24 02:32:31 +03:00
|
|
|
print_sanitized_conflicted_diff >actual.diff &&
|
2012-06-13 09:57:57 +04:00
|
|
|
|
|
|
|
# The result should resemble the corresponding merge
|
|
|
|
test_cmp expect.ls actual.ls &&
|
|
|
|
test_cmp expect.diff actual.diff
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply -3 with add/add conflict (dirty working tree)' '
|
|
|
|
# should fail to apply ...
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout adder^0 &&
|
|
|
|
echo >>four &&
|
|
|
|
cat four >four.save &&
|
|
|
|
cat three >three.save &&
|
|
|
|
git ls-files -s >expect.ls &&
|
|
|
|
test_must_fail git apply --index --3way P.diff &&
|
|
|
|
# ... and should not touch anything
|
|
|
|
git ls-files -s >actual.ls &&
|
|
|
|
test_cmp expect.ls actual.ls &&
|
|
|
|
test_cmp four.save four &&
|
|
|
|
test_cmp three.save three
|
|
|
|
'
|
|
|
|
|
2021-04-07 02:25:32 +03:00
|
|
|
test_expect_success 'apply -3 with ambiguous repeating file' '
|
|
|
|
git reset --hard &&
|
|
|
|
test_write_lines 1 2 1 2 1 2 1 2 1 2 1 >one_two_repeat &&
|
|
|
|
git add one_two_repeat &&
|
|
|
|
git commit -m "init one" &&
|
|
|
|
test_write_lines 1 2 1 2 1 2 1 2 one 2 1 >one_two_repeat &&
|
|
|
|
git commit -a -m "change one" &&
|
|
|
|
|
|
|
|
git diff HEAD~ >Repeat.diff &&
|
|
|
|
git reset --hard HEAD~ &&
|
|
|
|
|
|
|
|
test_write_lines 1 2 1 2 1 2 one 2 1 2 one >one_two_repeat &&
|
|
|
|
git commit -a -m "change surrounding one" &&
|
|
|
|
|
|
|
|
git apply --index --3way Repeat.diff &&
|
|
|
|
test_write_lines 1 2 1 2 1 2 one 2 one 2 one >expect &&
|
|
|
|
|
|
|
|
test_cmp expect one_two_repeat
|
|
|
|
'
|
|
|
|
|
2021-04-08 05:13:44 +03:00
|
|
|
test_expect_success 'apply with --3way --cached clean apply' '
|
|
|
|
# Merging side should be similar to applying this patch
|
|
|
|
git diff ...side >P.diff &&
|
|
|
|
|
|
|
|
# The corresponding cleanly applied merge
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout main~ &&
|
|
|
|
git merge --no-commit side &&
|
|
|
|
git ls-files -s >expect.ls &&
|
|
|
|
|
|
|
|
# should succeed
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout main~ &&
|
|
|
|
git apply --cached --3way P.diff &&
|
|
|
|
git ls-files -s >actual.ls &&
|
|
|
|
print_sanitized_conflicted_diff >actual.diff &&
|
|
|
|
|
|
|
|
# The cache should resemble the corresponding merge
|
|
|
|
# (both files at stage #0)
|
|
|
|
test_cmp expect.ls actual.ls &&
|
|
|
|
# However the working directory should not change
|
|
|
|
>expect.diff &&
|
|
|
|
test_cmp expect.diff actual.diff
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'apply with --3way --cached and conflicts' '
|
|
|
|
# Merging side should be similar to applying this patch
|
|
|
|
git diff ...side >P.diff &&
|
|
|
|
|
|
|
|
# The corresponding conflicted merge
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout main^0 &&
|
|
|
|
test_must_fail git merge --no-commit side &&
|
|
|
|
git ls-files -s >expect.ls &&
|
|
|
|
|
|
|
|
# should fail to apply
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout main^0 &&
|
|
|
|
test_must_fail git apply --cached --3way P.diff &&
|
|
|
|
git ls-files -s >actual.ls &&
|
|
|
|
print_sanitized_conflicted_diff >actual.diff &&
|
|
|
|
|
|
|
|
# The cache should resemble the corresponding merge
|
|
|
|
# (one file at stage #0, one file at stages #1 #2 #3)
|
|
|
|
test_cmp expect.ls actual.ls &&
|
|
|
|
# However the working directory should not change
|
|
|
|
>expect.diff &&
|
|
|
|
test_cmp expect.diff actual.diff
|
|
|
|
'
|
|
|
|
|
2012-05-10 03:50:58 +04:00
|
|
|
test_done
|