]>
Commit | Line | Data |
---|---|---|
4be60962 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
289218de | 6 | test_description='git apply boundary tests' |
4be60962 | 7 | |
71c79160 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
4be60962 JH |
9 | . ./test-lib.sh |
10 | ||
11 | L="c d e f g h i j k l m n o p q r s t u v w x" | |
12 | ||
13 | test_expect_success setup ' | |
289218de | 14 | test_write_lines b $L y >victim && |
4be60962 JH |
15 | cat victim >original && |
16 | git update-index --add victim && | |
17 | ||
53350a35 | 18 | # add to the head |
289218de | 19 | test_write_lines a b $L y >victim && |
4be60962 JH |
20 | cat victim >add-a-expect && |
21 | git diff victim >add-a-patch.with && | |
22 | git diff --unified=0 >add-a-patch.without && | |
23 | ||
53350a35 | 24 | # insert at line two |
289218de | 25 | test_write_lines b a $L y >victim && |
ed0f47a8 JH |
26 | cat victim >insert-a-expect && |
27 | git diff victim >insert-a-patch.with && | |
28 | git diff --unified=0 >insert-a-patch.without && | |
29 | ||
53350a35 | 30 | # modify at the head |
289218de | 31 | test_write_lines a $L y >victim && |
4be60962 JH |
32 | cat victim >mod-a-expect && |
33 | git diff victim >mod-a-patch.with && | |
34 | git diff --unified=0 >mod-a-patch.without && | |
35 | ||
53350a35 | 36 | # remove from the head |
289218de | 37 | test_write_lines $L y >victim && |
4be60962 | 38 | cat victim >del-a-expect && |
53350a35 | 39 | git diff victim >del-a-patch.with && |
4be60962 JH |
40 | git diff --unified=0 >del-a-patch.without && |
41 | ||
53350a35 | 42 | # add to the tail |
289218de | 43 | test_write_lines b $L y z >victim && |
4be60962 JH |
44 | cat victim >add-z-expect && |
45 | git diff victim >add-z-patch.with && | |
46 | git diff --unified=0 >add-z-patch.without && | |
47 | ||
53350a35 | 48 | # modify at the tail |
289218de | 49 | test_write_lines b $L z >victim && |
4be60962 JH |
50 | cat victim >mod-z-expect && |
51 | git diff victim >mod-z-patch.with && | |
52 | git diff --unified=0 >mod-z-patch.without && | |
53 | ||
53350a35 | 54 | # remove from the tail |
289218de | 55 | test_write_lines b $L >victim && |
4be60962 | 56 | cat victim >del-z-expect && |
8fb26872 JK |
57 | git diff victim >del-z-patch.with && |
58 | git diff --unified=0 >del-z-patch.without | |
4be60962 | 59 | |
53350a35 | 60 | # done |
4be60962 JH |
61 | ' |
62 | ||
63 | for with in with without | |
64 | do | |
65 | case "$with" in | |
66 | with) u= ;; | |
289218de | 67 | without) u=--unidiff-zero ;; |
4be60962 | 68 | esac |
ed0f47a8 | 69 | for kind in add-a add-z insert-a mod-a mod-z del-a del-z |
4be60962 JH |
70 | do |
71 | test_expect_success "apply $kind-patch $with context" ' | |
72 | cat original >victim && | |
73 | git update-index victim && | |
289218de MÅ |
74 | git apply --index $u "$kind-patch.$with" && |
75 | test_cmp "$kind-expect" victim | |
4be60962 JH |
76 | ' |
77 | done | |
78 | done | |
79 | ||
ed0f47a8 | 80 | for kind in add-a add-z insert-a mod-a mod-z del-a del-z |
4be60962 JH |
81 | do |
82 | rm -f $kind-ng.without | |
83 | sed -e "s/^diff --git /diff /" \ | |
84 | -e '/^index /d' \ | |
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 && | |
289218de MÅ |
89 | git apply --unidiff-zero --index "$kind-ng.without" && |
90 | test_cmp "$kind-expect" victim | |
4be60962 JH |
91 | ' |
92 | done | |
93 | ||
ee5a317e | 94 | test_expect_success 'two lines' ' |
ee5a317e JH |
95 | >file && |
96 | git add file && | |
97 | echo aaa >file && | |
98 | git diff >patch && | |
99 | git add file && | |
100 | echo bbb >file && | |
101 | git add file && | |
102 | test_must_fail git apply --check patch | |
ee5a317e JH |
103 | ' |
104 | ||
24ff4d56 | 105 | test_expect_success 'apply patch with 3 context lines matching at end' ' |
289218de | 106 | test_write_lines a b c d >file && |
24ff4d56 BG |
107 | git add file && |
108 | echo e >>file && | |
109 | git diff >patch && | |
110 | >file && | |
111 | test_must_fail git apply patch | |
112 | ' | |
113 | ||
4be60962 | 114 | test_done |