3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git apply boundary tests'
8 TEST_PASSES_SANITIZE_LEAK
=true
11 L
="c d e f g h i j k l m n o p q r s t u v w x"
13 test_expect_success setup
'
14 test_write_lines b $L y >victim &&
15 cat victim >original &&
16 git update-index --add victim &&
19 test_write_lines a b $L y >victim &&
20 cat victim >add-a-expect &&
21 git diff victim >add-a-patch.with &&
22 git diff --unified=0 >add-a-patch.without &&
25 test_write_lines b a $L y >victim &&
26 cat victim >insert-a-expect &&
27 git diff victim >insert-a-patch.with &&
28 git diff --unified=0 >insert-a-patch.without &&
31 test_write_lines a $L y >victim &&
32 cat victim >mod-a-expect &&
33 git diff victim >mod-a-patch.with &&
34 git diff --unified=0 >mod-a-patch.without &&
36 # remove from the head
37 test_write_lines $L y >victim &&
38 cat victim >del-a-expect &&
39 git diff victim >del-a-patch.with &&
40 git diff --unified=0 >del-a-patch.without &&
43 test_write_lines b $L y z >victim &&
44 cat victim >add-z-expect &&
45 git diff victim >add-z-patch.with &&
46 git diff --unified=0 >add-z-patch.without &&
49 test_write_lines b $L z >victim &&
50 cat victim >mod-z-expect &&
51 git diff victim >mod-z-patch.with &&
52 git diff --unified=0 >mod-z-patch.without &&
54 # remove from the tail
55 test_write_lines b $L >victim &&
56 cat victim >del-z-expect &&
57 git diff victim >del-z-patch.with &&
58 git diff --unified=0 >del-z-patch.without
63 for with
in with without
67 without
) u
=--unidiff-zero ;;
69 for kind
in add-a add-z insert-a mod-a mod-z del-a del-z
71 test_expect_success
"apply $kind-patch $with context" '
72 cat original >victim &&
73 git update-index victim &&
74 git apply --index $u "$kind-patch.$with" &&
75 test_cmp "$kind-expect" victim
80 for kind
in add-a add-z insert-a mod-a mod-z del-a del-z
82 rm -f $kind-ng.without
83 sed -e "s/^diff --git /diff /" \
85 <$kind-patch.without
>$kind-ng.without
86 test_expect_success
"apply non-git $kind-patch without context" '
87 cat original >victim &&
88 git update-index victim &&
89 git apply --unidiff-zero --index "$kind-ng.without" &&
90 test_cmp "$kind-expect" victim
94 test_expect_success
'two lines' '
102 test_must_fail git apply --check patch
105 test_expect_success
'apply patch with 3 context lines matching at end' '
106 test_write_lines a b c d >file &&
111 test_must_fail git apply patch