]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4119-apply-config.sh
Merge branch 'tb/make-indent-conditional-with-non-spaces'
[thirdparty/git.git] / t / t4119-apply-config.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Junio C Hamano
4 #
5
6 test_description='git apply --whitespace=strip and configuration file.
7
8 '
9
10
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13
14 test_expect_success setup '
15 mkdir sub &&
16 echo A >sub/file1 &&
17 cp sub/file1 saved &&
18 git add sub/file1 &&
19 echo "B " >sub/file1 &&
20 git diff >patch.file
21 '
22
23 # Also handcraft GNU diff output; note this has trailing whitespace.
24 tr '_' ' ' >gpatch.file <<\EOF &&
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
29 +B_
30 EOF
31
32 sed -e 's|file1|sub/&|' gpatch.file >gpatch-sub.file &&
33 sed -e '
34 /^--- /s|file1|a/sub/&|
35 /^+++ /s|file1|b/sub/&|
36 ' gpatch.file >gpatch-ab-sub.file &&
37
38 check_result () {
39 if grep " " "$1"
40 then
41 echo "Eh?"
42 false
43 elif grep B "$1"
44 then
45 echo Happy
46 else
47 echo "Huh?"
48 false
49 fi
50 }
51
52 test_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
60 '
61
62 test_expect_success 'apply --whitespace=strip from config' '
63
64 rm -f sub/file1 &&
65 cp saved sub/file1 &&
66 git update-index --refresh &&
67
68 git config apply.whitespace strip &&
69 git apply patch.file &&
70 check_result sub/file1
71 '
72
73 D=$(pwd)
74
75 test_expect_success 'apply --whitespace=strip in subdir' '
76
77 cd "$D" &&
78 git config --unset-all apply.whitespace &&
79 rm -f sub/file1 &&
80 cp saved sub/file1 &&
81 git update-index --refresh &&
82
83 cd sub &&
84 git apply --whitespace=strip ../patch.file &&
85 check_result file1
86 '
87
88 test_expect_success 'apply --whitespace=strip from config in subdir' '
89
90 cd "$D" &&
91 git config apply.whitespace strip &&
92 rm -f sub/file1 &&
93 cp saved sub/file1 &&
94 git update-index --refresh &&
95
96 cd sub &&
97 git apply ../patch.file &&
98 check_result file1
99 '
100
101 test_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 &&
110 git apply ../gpatch.file &&
111 check_result file1
112 '
113
114 test_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 &&
124 check_result file1
125 '
126
127 test_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 &&
137 check_result file1
138 '
139
140 test_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
152 test_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
162 '
163
164 test_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
181 test_done