]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4119-apply-config.sh
The twentieth batch
[thirdparty/git.git] / t / t4119-apply-config.sh
CommitLineData
dc7b2436
JH
1#!/bin/sh
2#
3# Copyright (c) 2007 Junio C Hamano
4#
5
5be60078 6test_description='git apply --whitespace=strip and configuration file.
dc7b2436
JH
7
8'
9
f54f48fc
ÆAB
10
11TEST_PASSES_SANITIZE_LEAK=true
dc7b2436
JH
12. ./test-lib.sh
13
14test_expect_success setup '
56185f49
JH
15 mkdir sub &&
16 echo A >sub/file1 &&
17 cp sub/file1 saved &&
18 git add sub/file1 &&
19 echo "B " >sub/file1 &&
dc7b2436
JH
20 git diff >patch.file
21'
22
c24e9757 23# Also handcraft GNU diff output; note this has trailing whitespace.
74f16b0c 24tr '_' ' ' >gpatch.file <<\EOF &&
c24e9757
JH
25--- file1 2007-02-21 01:04:24.000000000 -0800
26+++ file1+ 2007-02-21 01:07:44.000000000 -0800
27@@ -1 +1 @@
28-A
74f16b0c 29+B_
c24e9757
JH
30EOF
31
3e8a5db9
JH
32sed -e 's|file1|sub/&|' gpatch.file >gpatch-sub.file &&
33sed -e '
34 /^--- /s|file1|a/sub/&|
35 /^+++ /s|file1|b/sub/&|
36' gpatch.file >gpatch-ab-sub.file &&
37
fe6e0eec
JH
38check_result () {
39 if grep " " "$1"
dc7b2436
JH
40 then
41 echo "Eh?"
42 false
fe6e0eec 43 elif grep B "$1"
c24e9757 44 then
dc7b2436 45 echo Happy
c24e9757
JH
46 else
47 echo "Huh?"
48 false
dc7b2436 49 fi
fe6e0eec
JH
50}
51
52test_expect_success 'apply --whitespace=strip' '
53
54 rm -f sub/file1 &&
55 cp saved sub/file1 &&
56 git update-index --refresh &&
57
58 git apply --whitespace=strip patch.file &&
59 check_result sub/file1
dc7b2436
JH
60'
61
62test_expect_success 'apply --whitespace=strip from config' '
63
56185f49
JH
64 rm -f sub/file1 &&
65 cp saved sub/file1 &&
dc7b2436
JH
66 git update-index --refresh &&
67
68 git config apply.whitespace strip &&
69 git apply patch.file &&
fe6e0eec 70 check_result sub/file1
dc7b2436
JH
71'
72
6003eb13 73D=$(pwd)
dc7b2436
JH
74
75test_expect_success 'apply --whitespace=strip in subdir' '
76
77 cd "$D" &&
a48fcd83 78 git config --unset-all apply.whitespace &&
56185f49
JH
79 rm -f sub/file1 &&
80 cp saved sub/file1 &&
dc7b2436
JH
81 git update-index --refresh &&
82
83 cd sub &&
9987d7c5 84 git apply --whitespace=strip ../patch.file &&
fe6e0eec 85 check_result file1
dc7b2436
JH
86'
87
88test_expect_success 'apply --whitespace=strip from config in subdir' '
89
90 cd "$D" &&
91 git config apply.whitespace strip &&
56185f49
JH
92 rm -f sub/file1 &&
93 cp saved sub/file1 &&
dc7b2436
JH
94 git update-index --refresh &&
95
96 cd sub &&
9987d7c5 97 git apply ../patch.file &&
fe6e0eec 98 check_result file1
c24e9757
JH
99'
100
101test_expect_success 'same in subdir but with traditional patch input' '
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 &&
3e8a5db9 110 git apply ../gpatch.file &&
fe6e0eec 111 check_result file1
3e8a5db9
JH
112'
113
114test_expect_success 'same but with traditional patch input of depth 1' '
115
116 cd "$D" &&
117 git config apply.whitespace strip &&
118 rm -f sub/file1 &&
119 cp saved sub/file1 &&
120 git update-index --refresh &&
121
122 cd sub &&
123 git apply ../gpatch-sub.file &&
fe6e0eec 124 check_result file1
3e8a5db9
JH
125'
126
127test_expect_success 'same but with traditional patch input of depth 2' '
128
129 cd "$D" &&
130 git config apply.whitespace strip &&
131 rm -f sub/file1 &&
132 cp saved sub/file1 &&
133 git update-index --refresh &&
134
135 cd sub &&
136 git apply ../gpatch-ab-sub.file &&
fe6e0eec
JH
137 check_result file1
138'
139
140test_expect_success 'same but with traditional patch input of depth 1' '
141
142 cd "$D" &&
143 git config apply.whitespace strip &&
144 rm -f sub/file1 &&
145 cp saved sub/file1 &&
146 git update-index --refresh &&
147
148 git apply -p0 gpatch-sub.file &&
149 check_result sub/file1
150'
151
152test_expect_success 'same but with traditional patch input of depth 2' '
153
154 cd "$D" &&
155 git config apply.whitespace strip &&
156 rm -f sub/file1 &&
157 cp saved sub/file1 &&
158 git update-index --refresh &&
159
160 git apply gpatch-ab-sub.file &&
161 check_result sub/file1
dc7b2436
JH
162'
163
d487b0ba
JH
164test_expect_success 'in subdir with traditional patch input' '
165 cd "$D" &&
166 git config apply.whitespace strip &&
167 cat >.gitattributes <<-EOF &&
168 /* whitespace=blank-at-eol
169 sub/* whitespace=-blank-at-eol
170 EOF
171 rm -f sub/file1 &&
172 cp saved sub/file1 &&
173 git update-index --refresh &&
174
175 cd sub &&
176 git apply ../gpatch.file &&
177 echo "B " >expect &&
178 test_cmp expect file1
179'
180
dc7b2436 181test_done