mirror of
https://github.com/git/git.git
synced 2024-11-05 08:47:56 +01:00
ed0f47a8c4
Even after a handfle attempts, match_beginning logic still has corner cases:1bf1a85
(apply: treat EOF as proper context., 2006-05-23)65aadb9
(apply: force matching at the beginning., 2006-05-24)4be6096
(apply --unidiff-zero: loosen sanity checks ..., 2006-09-17)ee5a317
(Fix "git apply" to correctly enforce "match ..., 2008-04-06) This is a tricky piece of code. We still incorrectly enforce "match_beginning" for -U0 matches. I noticed this while trying out an example sequence from Clemens Buchacher: $ echo a >victim $ git add victim $ echo b >>victim $ git diff -U0 >patch $ cat patch diff --git i/victim w/victim index 7898192..422c2b7 100644 --- i/victim +++ w/victim @@ -1,0 +2 @@ a +b $ git apply --cached --unidiff-zero <patch $ git show :victim b a The change inserts a new line before the second line, but we insist it to be applied at the beginning. As the result, the code refuses to apply it at the original offset, and we end up adding the line at the beginning. Updates to the test script are by Clemens Buchacher. Signed-off-by: Junio C Hamano <gitster@pobox.com>
137 lines
2.7 KiB
Bash
Executable file
137 lines
2.7 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2005 Junio C Hamano
|
|
#
|
|
|
|
test_description='git apply boundary tests
|
|
|
|
'
|
|
. ./test-lib.sh
|
|
|
|
L="c d e f g h i j k l m n o p q r s t u v w x"
|
|
|
|
test_expect_success setup '
|
|
for i in b '"$L"' y
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >original &&
|
|
git update-index --add victim &&
|
|
|
|
: add to the head
|
|
for i in a b '"$L"' y
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >add-a-expect &&
|
|
git diff victim >add-a-patch.with &&
|
|
git diff --unified=0 >add-a-patch.without &&
|
|
|
|
: insert at line two
|
|
for i in b a '"$L"' y
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >insert-a-expect &&
|
|
git diff victim >insert-a-patch.with &&
|
|
git diff --unified=0 >insert-a-patch.without &&
|
|
|
|
: modify at the head
|
|
for i in a '"$L"' y
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >mod-a-expect &&
|
|
git diff victim >mod-a-patch.with &&
|
|
git diff --unified=0 >mod-a-patch.without &&
|
|
|
|
: remove from the head
|
|
for i in '"$L"' y
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >del-a-expect &&
|
|
git diff victim >del-a-patch.with
|
|
git diff --unified=0 >del-a-patch.without &&
|
|
|
|
: add to the tail
|
|
for i in b '"$L"' y z
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >add-z-expect &&
|
|
git diff victim >add-z-patch.with &&
|
|
git diff --unified=0 >add-z-patch.without &&
|
|
|
|
: modify at the tail
|
|
for i in b '"$L"' z
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >mod-z-expect &&
|
|
git diff victim >mod-z-patch.with &&
|
|
git diff --unified=0 >mod-z-patch.without &&
|
|
|
|
: remove from the tail
|
|
for i in b '"$L"'
|
|
do
|
|
echo $i
|
|
done >victim &&
|
|
cat victim >del-z-expect &&
|
|
git diff victim >del-z-patch.with
|
|
git diff --unified=0 >del-z-patch.without &&
|
|
|
|
: done
|
|
'
|
|
|
|
for with in with without
|
|
do
|
|
case "$with" in
|
|
with) u= ;;
|
|
without) u='--unidiff-zero ' ;;
|
|
esac
|
|
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
|
|
do
|
|
test_expect_success "apply $kind-patch $with context" '
|
|
cat original >victim &&
|
|
git update-index victim &&
|
|
git apply --index '"$u$kind-patch.$with"' || {
|
|
cat '"$kind-patch.$with"'
|
|
(exit 1)
|
|
} &&
|
|
test_cmp '"$kind"'-expect victim
|
|
'
|
|
done
|
|
done
|
|
|
|
for kind in add-a add-z insert-a mod-a mod-z del-a del-z
|
|
do
|
|
rm -f $kind-ng.without
|
|
sed -e "s/^diff --git /diff /" \
|
|
-e '/^index /d' \
|
|
<$kind-patch.without >$kind-ng.without
|
|
test_expect_success "apply non-git $kind-patch without context" '
|
|
cat original >victim &&
|
|
git update-index victim &&
|
|
git apply --unidiff-zero --index '"$kind-ng.without"' || {
|
|
cat '"$kind-ng.without"'
|
|
(exit 1)
|
|
} &&
|
|
test_cmp '"$kind"'-expect victim
|
|
'
|
|
done
|
|
|
|
test_expect_success 'two lines' '
|
|
|
|
>file &&
|
|
git add file &&
|
|
echo aaa >file &&
|
|
git diff >patch &&
|
|
git add file &&
|
|
echo bbb >file &&
|
|
git add file &&
|
|
test_must_fail git apply --check patch
|
|
|
|
'
|
|
|
|
test_done
|