55f46737c6f1ba3983be10fb6ab86d0c5d3af69a
1#!/bin/sh
2#
3# Copyright (c) 2007 Junio C Hamano
4#
5
6test_description='git-apply --whitespace=strip and configuration file.
7
8'
9
10. ./test-lib.sh
11
12test_expect_success setup '
13 mkdir sub &&
14 echo A >sub/file1 &&
15 cp sub/file1 saved &&
16 git add sub/file1 &&
17 echo "B " >sub/file1 &&
18 git diff >patch.file
19'
20
21# Also handcraft GNU diff output; note this has trailing whitespace.
22cat >gpatch.file <<\EOF &&
23--- file1 2007-02-21 01:04:24.000000000 -0800
24+++ file1+ 2007-02-21 01:07:44.000000000 -0800
25@@ -1 +1 @@
26-A
27+B
28EOF
29
30sed -e 's|file1|sub/&|' gpatch.file >gpatch-sub.file &&
31sed -e '
32 /^--- /s|file1|a/sub/&|
33 /^+++ /s|file1|b/sub/&|
34' gpatch.file >gpatch-ab-sub.file &&
35
36test_expect_success 'apply --whitespace=strip' '
37
38 rm -f sub/file1 &&
39 cp saved sub/file1 &&
40 git update-index --refresh &&
41
42 git apply --whitespace=strip patch.file &&
43 if grep " " sub/file1
44 then
45 echo "Eh?"
46 false
47 elif grep B sub/file1
48 then
49 echo Happy
50 else
51 echo "Huh?"
52 false
53 fi
54'
55
56test_expect_success 'apply --whitespace=strip from config' '
57
58 rm -f sub/file1 &&
59 cp saved sub/file1 &&
60 git update-index --refresh &&
61
62 git config apply.whitespace strip &&
63 git apply patch.file &&
64 if grep " " sub/file1
65 then
66 echo "Eh?"
67 false
68 elif grep B sub/file1
69 then
70 echo Happy
71 else
72 echo Happy
73 fi
74'
75
76D=`pwd`
77
78test_expect_success 'apply --whitespace=strip in subdir' '
79
80 cd "$D" &&
81 git config --unset-all apply.whitespace
82 rm -f sub/file1 &&
83 cp saved sub/file1 &&
84 git update-index --refresh &&
85
86 cd sub &&
87 git apply --whitespace=strip ../patch.file &&
88 if grep " " file1
89 then
90 echo "Eh?"
91 false
92 elif grep B file1
93 then
94 echo Happy
95 else
96 echo "Huh?"
97 false
98 fi
99'
100
101test_expect_success 'apply --whitespace=strip from config in subdir' '
102
103 cd "$D" &&
104 git config apply.whitespace strip &&
105 rm -f sub/file1 &&
106 cp saved sub/file1 &&
107 git update-index --refresh &&
108
109 cd sub &&
110 git apply ../patch.file &&
111 if grep " " file1
112 then
113 echo "Eh?"
114 false
115 elif grep B file1
116 then
117 echo Happy
118 else
119 echo "Huh?"
120 false
121 fi
122'
123
124test_expect_success 'same in subdir but with traditional patch input' '
125
126 cd "$D" &&
127 git config apply.whitespace strip &&
128 rm -f sub/file1 &&
129 cp saved sub/file1 &&
130 git update-index --refresh &&
131
132 cd sub &&
133 git apply ../gpatch.file &&
134 if grep " " file1
135 then
136 echo "Eh?"
137 false
138 elif grep B file1
139 then
140 echo Happy
141 else
142 echo "Huh?"
143 false
144 fi
145'
146
147test_expect_success 'same but with traditional patch input of depth 1' '
148
149 cd "$D" &&
150 git config apply.whitespace strip &&
151 rm -f sub/file1 &&
152 cp saved sub/file1 &&
153 git update-index --refresh &&
154
155 cd sub &&
156 git apply ../gpatch-sub.file &&
157 if grep " " file1
158 then
159 echo "Eh?"
160 false
161 elif grep B file1
162 then
163 echo Happy
164 else
165 echo "Huh?"
166 false
167 fi
168'
169
170test_expect_success 'same but with traditional patch input of depth 2' '
171
172 cd "$D" &&
173 git config apply.whitespace strip &&
174 rm -f sub/file1 &&
175 cp saved sub/file1 &&
176 git update-index --refresh &&
177
178 cd sub &&
179 git apply ../gpatch-ab-sub.file &&
180 if grep " " file1
181 then
182 echo "Eh?"
183 false
184 elif grep B file1
185 then
186 echo Happy
187 else
188 echo "Huh?"
189 false
190 fi
191'
192
193test_done