git/t/t6432-merge-recursive-space-options.sh

211 lines
6.2 KiB
Bash
Raw Normal View History

#!/bin/sh
test_description='merge-recursive space options
* [main] Clarify
! [remote] Remove cruft
--
+ [remote] Remove cruft
* [main] Clarify
*+ [remote^] Initial revision
* ok 1: setup
'
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-18 23:44:19 +00:00
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh
test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b
if test_have_prereq GREP_STRIPS_CR
then
GREP_OPTIONS=-U
export GREP_OPTIONS
fi
test_expect_success 'setup' '
conflict_hunks () {
sed $SED_OPTIONS -n -e "
/^<<<</ b conflict
b
: conflict
p
/^>>>>/ b
n
b conflict
" "$@"
} &&
cat <<-\EOF >text.txt &&
Hope, he says, cherishes the soul of him who lives in
justice and holiness and is the nurse of his age and the
companion of his journey;--hope which is mightiest to sway
the restless soul of man.
How admirable are his words! And the great blessing of riches, I do
not say to every man, but to a good man, is, that he has had no
occasion to deceive or to defraud others, either intentionally or
unintentionally; and when he departs to the world below he is not in
any apprehension about offerings due to the gods or debts which he owes
to men. Now to this peace of mind the possession of wealth greatly
contributes; and therefore I say, that, setting one thing against
another, of the many advantages which wealth has to give, to a man of
sense this is in my opinion the greatest.
Well said, Cephalus, I replied; but as concerning justice, what is
it?--to speak the truth and to pay your debts--no more than this? And
even to this are there not exceptions? Suppose that a friend when in
his right mind has deposited arms with me and he asks for them when he
is not in his right mind, ought I to give them back to him? No one
would say that I ought or that I should be right in doing so, any more
than they would say that I ought always to speak the truth to one who
is in his condition.
You are quite right, he replied.
But then, I said, speaking the truth and paying your debts is not a
correct definition of justice.
CEPHALUS - SOCRATES - POLEMARCHUS
Quite correct, Socrates, if Simonides is to be believed, said
Polemarchus interposing.
I fear, said Cephalus, that I must go now, for I have to look after the
sacrifices, and I hand over the argument to Polemarchus and the company.
EOF
git add text.txt &&
test_tick &&
git commit -m "Initial revision" &&
git checkout -b remote &&
sed -e "
s/\. /\. /g
s/[?] /? /g
s/ / /g
s/--/---/g
s/but as concerning/but as con cerning/
/CEPHALUS - SOCRATES - POLEMARCHUS/ d
" text.txt >text.txt+ &&
mv text.txt+ text.txt &&
git commit -a -m "Remove cruft" &&
git checkout main &&
sed -e "
s/\(not in his right mind\),\(.*\)/\1;\2Q/
s/Quite correct\(.*\)/It is too correct\1Q/
s/unintentionally/un intentionally/
/un intentionally/ s/$/Q/
s/Polemarchus interposing./Polemarchus, interposing.Q/
/justice and holiness/ s/$/Q/
/pay your debts/ s/$/Q/
" text.txt | q_to_cr >text.txt+ &&
mv text.txt+ text.txt &&
git commit -a -m "Clarify" &&
git show-branch --all
'
test_expect_success 'naive merge fails' '
git read-tree --reset -u HEAD &&
test_must_fail git merge-recursive HEAD^ -- HEAD remote &&
test_must_fail git update-index --refresh &&
grep "<<<<<<" text.txt
'
test_expect_success '--ignore-space-change makes merge succeed' '
git read-tree --reset -u HEAD &&
git merge-recursive --ignore-space-change HEAD^ -- HEAD remote
'
test_expect_success 'naive cherry-pick fails' '
git read-tree --reset -u HEAD &&
test_must_fail git cherry-pick --no-commit remote &&
git read-tree --reset -u HEAD &&
test_must_fail git cherry-pick remote &&
test_must_fail git update-index --refresh &&
grep "<<<<<<" text.txt
'
test_expect_success '-Xignore-space-change makes cherry-pick succeed' '
git read-tree --reset -u HEAD &&
git cherry-pick --no-commit -Xignore-space-change remote
'
test_expect_success '--ignore-space-change: our w/s-only change wins' '
q_to_cr <<-\EOF >expected &&
justice and holiness and is the nurse of his age and theQ
EOF
git read-tree --reset -u HEAD &&
git merge-recursive --ignore-space-change HEAD^ -- HEAD remote &&
grep "justice and holiness" text.txt >actual &&
test_cmp expected actual
'
test_expect_success '--ignore-space-change: their real change wins over w/s' '
cat <<-\EOF >expected &&
it?---to speak the truth and to pay your debts---no more than this? And
EOF
git read-tree --reset -u HEAD &&
git merge-recursive --ignore-space-change HEAD^ -- HEAD remote &&
grep "pay your debts" text.txt >actual &&
test_cmp expected actual
'
test_expect_success '--ignore-space-change: does not ignore new spaces' '
cat <<-\EOF >expected1 &&
Well said, Cephalus, I replied; but as con cerning justice, what is
EOF
q_to_cr <<-\EOF >expected2 &&
un intentionally; and when he departs to the world below he is not inQ
EOF
git read-tree --reset -u HEAD &&
git merge-recursive --ignore-space-change HEAD^ -- HEAD remote &&
grep "Well said" text.txt >actual1 &&
grep "when he departs" text.txt >actual2 &&
test_cmp expected1 actual1 &&
test_cmp expected2 actual2
'
test_expect_success '--ignore-all-space drops their new spaces' '
cat <<-\EOF >expected &&
Well said, Cephalus, I replied; but as concerning justice, what is
EOF
git read-tree --reset -u HEAD &&
git merge-recursive --ignore-all-space HEAD^ -- HEAD remote &&
grep "Well said" text.txt >actual &&
test_cmp expected actual
'
test_expect_success '--ignore-all-space keeps our new spaces' '
q_to_cr <<-\EOF >expected &&
un intentionally; and when he departs to the world below he is not inQ
EOF
git read-tree --reset -u HEAD &&
git merge-recursive --ignore-all-space HEAD^ -- HEAD remote &&
grep "when he departs" text.txt >actual &&
test_cmp expected actual
'
test_expect_success '--ignore-space-at-eol' '
q_to_cr <<-\EOF >expected &&
<<<<<<< HEAD
is not in his right mind; ought I to give them back to him? No oneQ
=======
is not in his right mind, ought I to give them back to him? No one
>>>>>>> remote
EOF
git read-tree --reset -u HEAD &&
test_must_fail git merge-recursive --ignore-space-at-eol \
HEAD^ -- HEAD remote &&
conflict_hunks text.txt >actual &&
test_cmp expected actual
'
test_done