3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git apply boundary tests'
10 L
="c d e f g h i j k l m n o p q r s t u v w x"
12 test_expect_success setup
'
13 test_write_lines b $L y >victim &&
14 cat victim >original &&
15 git update-index --add victim &&
18 test_write_lines a b $L y >victim &&
19 cat victim >add-a-expect &&
20 git diff victim >add-a-patch.with &&
21 git diff --unified=0 >add-a-patch.without &&
24 test_write_lines b a $L y >victim &&
25 cat victim >insert-a-expect &&
26 git diff victim >insert-a-patch.with &&
27 git diff --unified=0 >insert-a-patch.without &&
30 test_write_lines a $L y >victim &&
31 cat victim >mod-a-expect &&
32 git diff victim >mod-a-patch.with &&
33 git diff --unified=0 >mod-a-patch.without &&
35 # remove from the head
36 test_write_lines $L y >victim &&
37 cat victim >del-a-expect &&
38 git diff victim >del-a-patch.with &&
39 git diff --unified=0 >del-a-patch.without &&
42 test_write_lines b $L y z >victim &&
43 cat victim >add-z-expect &&
44 git diff victim >add-z-patch.with &&
45 git diff --unified=0 >add-z-patch.without &&
48 test_write_lines b $L z >victim &&
49 cat victim >mod-z-expect &&
50 git diff victim >mod-z-patch.with &&
51 git diff --unified=0 >mod-z-patch.without &&
53 # remove from the tail
54 test_write_lines b $L >victim &&
55 cat victim >del-z-expect &&
56 git diff victim >del-z-patch.with &&
57 git diff --unified=0 >del-z-patch.without
62 for with
in with without
66 without
) u
=--unidiff-zero ;;
68 for kind
in add-a add-z insert-a mod-a mod-z del-a del-z
70 test_expect_success
"apply $kind-patch $with context" '
71 cat original >victim &&
72 git update-index victim &&
73 git apply --index $u "$kind-patch.$with" &&
74 test_cmp "$kind-expect" victim
79 for kind
in add-a add-z insert-a mod-a mod-z del-a del-z
81 rm -f $kind-ng.without
82 sed -e "s/^diff --git /diff /" \
84 <$kind-patch.without
>$kind-ng.without
85 test_expect_success
"apply non-git $kind-patch without context" '
86 cat original >victim &&
87 git update-index victim &&
88 git apply --unidiff-zero --index "$kind-ng.without" &&
89 test_cmp "$kind-expect" victim
93 test_expect_success
'two lines' '
101 test_must_fail git apply --check patch
104 test_expect_success
'apply patch with 3 context lines matching at end' '
105 test_write_lines a b c d >file &&
110 test_must_fail git apply patch