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