git/t/t4108-apply-threeway.sh
Junio C Hamano 4f4a6cb988 apply: register conflicted stages to the index
Now we have all the necessary logic to fall back on three-way merge when
the patch does not cleanly apply, insert the conflicted entries to the
index as appropriate.  This obviously triggers only when the "--index"
option is used.

When we fall back to three-way merge and some of the merges fail, just
like the case where the "--reject" option was specified and we had to
write some "*.rej" files out for unapplicable patches, exit the command
with non-zero status without showing the diffstat and summary.  Otherwise
they would make the list of problematic paths scroll off the display.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-09 14:40:03 -07:00

78 lines
1.6 KiB
Bash
Executable file

#!/bin/sh
test_description='git apply --3way'
. ./test-lib.sh
create_file () {
for i
do
echo "$i"
done
}
sanitize_conflicted_diff () {
sed -e '
/^index /d
s/^\(+[<>][<>][<>][<>]*\) .*/\1/
'
}
test_expect_success setup '
test_tick &&
create_file >one 1 2 3 4 5 6 7 &&
cat one >two &&
git add one two &&
git commit -m initial &&
git branch side &&
test_tick &&
create_file >one 1 two 3 4 5 six 7 &&
create_file >two 1 two 3 4 5 6 7 &&
git commit -a -m master &&
git checkout side &&
create_file >one 1 2 3 4 five 6 7 &&
create_file >two 1 2 3 4 five 6 7 &&
git commit -a -m side &&
git checkout master
'
test_expect_success 'apply without --3way' '
git diff side^ side >P.diff &&
# should fail to apply
git reset --hard &&
git checkout master^0 &&
test_must_fail git apply --index P.diff &&
# should leave things intact
git diff-files --exit-code &&
git diff-index --exit-code --cached HEAD
'
test_expect_success 'apply with --3way' '
# Merging side should be similar to applying this patch
git diff ...side >P.diff &&
# The corresponding conflicted merge
git reset --hard &&
git checkout master^0 &&
test_must_fail git merge --no-commit side &&
git ls-files -s >expect.ls &&
git diff HEAD | sanitize_conflicted_diff >expect.diff &&
# should fail to apply
git reset --hard &&
git checkout master^0 &&
test_must_fail git apply --index --3way P.diff &&
git ls-files -s >actual.ls &&
git diff HEAD | sanitize_conflicted_diff >actual.diff &&
# The result should resemble the corresponding merge
test_cmp expect.ls actual.ls &&
test_cmp expect.diff actual.diff
'
test_done