Merge branch 'mn/sideband-no-ansi' into maint
[git/gitweb.git] / t / t4104-apply-boundary.sh
blobc617c2a33d8e8ac1dc7e049f9056ca6025fbf852
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git apply boundary tests
9 . ./test-lib.sh
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 for i in b '"$L"' y
16 echo $i
17 done >victim &&
18 cat victim >original &&
19 git update-index --add victim &&
21 : add to the head
22 for i in a b '"$L"' y
24 echo $i
25 done >victim &&
26 cat victim >add-a-expect &&
27 git diff victim >add-a-patch.with &&
28 git diff --unified=0 >add-a-patch.without &&
30 : insert at line two
31 for i in b a '"$L"' y
33 echo $i
34 done >victim &&
35 cat victim >insert-a-expect &&
36 git diff victim >insert-a-patch.with &&
37 git diff --unified=0 >insert-a-patch.without &&
39 : modify at the head
40 for i in a '"$L"' y
42 echo $i
43 done >victim &&
44 cat victim >mod-a-expect &&
45 git diff victim >mod-a-patch.with &&
46 git diff --unified=0 >mod-a-patch.without &&
48 : remove from the head
49 for i in '"$L"' y
51 echo $i
52 done >victim &&
53 cat victim >del-a-expect &&
54 git diff victim >del-a-patch.with
55 git diff --unified=0 >del-a-patch.without &&
57 : add to the tail
58 for i in b '"$L"' y z
60 echo $i
61 done >victim &&
62 cat victim >add-z-expect &&
63 git diff victim >add-z-patch.with &&
64 git diff --unified=0 >add-z-patch.without &&
66 : modify at the tail
67 for i in b '"$L"' z
69 echo $i
70 done >victim &&
71 cat victim >mod-z-expect &&
72 git diff victim >mod-z-patch.with &&
73 git diff --unified=0 >mod-z-patch.without &&
75 : remove from the tail
76 for i in b '"$L"'
78 echo $i
79 done >victim &&
80 cat victim >del-z-expect &&
81 git diff victim >del-z-patch.with
82 git diff --unified=0 >del-z-patch.without &&
84 : done
87 for with in with without
89 case "$with" in
90 with) u= ;;
91 without) u='--unidiff-zero ' ;;
92 esac
93 for kind in add-a add-z insert-a mod-a mod-z del-a del-z
95 test_expect_success "apply $kind-patch $with context" '
96 cat original >victim &&
97 git update-index victim &&
98 git apply --index '"$u$kind-patch.$with"' || {
99 cat '"$kind-patch.$with"'
100 (exit 1)
101 } &&
102 test_cmp '"$kind"'-expect victim
104 done
105 done
107 for kind in add-a add-z insert-a mod-a mod-z del-a del-z
109 rm -f $kind-ng.without
110 sed -e "s/^diff --git /diff /" \
111 -e '/^index /d' \
112 <$kind-patch.without >$kind-ng.without
113 test_expect_success "apply non-git $kind-patch without context" '
114 cat original >victim &&
115 git update-index victim &&
116 git apply --unidiff-zero --index '"$kind-ng.without"' || {
117 cat '"$kind-ng.without"'
118 (exit 1)
119 } &&
120 test_cmp '"$kind"'-expect victim
122 done
124 test_expect_success 'two lines' '
126 >file &&
127 git add file &&
128 echo aaa >file &&
129 git diff >patch &&
130 git add file &&
131 echo bbb >file &&
132 git add file &&
133 test_must_fail git apply --check patch
137 test_expect_success 'apply patch with 3 context lines matching at end' '
138 { echo a; echo b; echo c; echo d; } >file &&
139 git add file &&
140 echo e >>file &&
141 git diff >patch &&
142 >file &&
143 test_must_fail git apply patch
146 test_done