Merge branch 'wl/new-command-doc'
[git.git] / t / t4119-apply-config.sh
blob208c961d376b28035e3e7c9563199f9c5867cf11
1 #!/bin/sh
3 # Copyright (c) 2007 Junio C Hamano
6 test_description='git apply --whitespace=strip and configuration file.
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
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
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 @@
29 +B_
30 EOF
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 &&
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
52 test_expect_success 'apply --whitespace=strip' '
54 rm -f sub/file1 &&
55 cp saved sub/file1 &&
56 git update-index --refresh &&
58 git apply --whitespace=strip patch.file &&
59 check_result sub/file1
62 test_expect_success 'apply --whitespace=strip from config' '
64 rm -f sub/file1 &&
65 cp saved sub/file1 &&
66 git update-index --refresh &&
68 git config apply.whitespace strip &&
69 git apply patch.file &&
70 check_result sub/file1
73 D=$(pwd)
75 test_expect_success 'apply --whitespace=strip in subdir' '
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 &&
83 cd sub &&
84 git apply --whitespace=strip ../patch.file &&
85 check_result file1
88 test_expect_success 'apply --whitespace=strip from config in subdir' '
90 cd "$D" &&
91 git config apply.whitespace strip &&
92 rm -f sub/file1 &&
93 cp saved sub/file1 &&
94 git update-index --refresh &&
96 cd sub &&
97 git apply ../patch.file &&
98 check_result file1
101 test_expect_success 'same in subdir but with traditional patch input' '
103 cd "$D" &&
104 git config apply.whitespace strip &&
105 rm -f sub/file1 &&
106 cp saved sub/file1 &&
107 git update-index --refresh &&
109 cd sub &&
110 git apply ../gpatch.file &&
111 check_result file1
114 test_expect_success 'same but with traditional patch input of depth 1' '
116 cd "$D" &&
117 git config apply.whitespace strip &&
118 rm -f sub/file1 &&
119 cp saved sub/file1 &&
120 git update-index --refresh &&
122 cd sub &&
123 git apply ../gpatch-sub.file &&
124 check_result file1
127 test_expect_success 'same but with traditional patch input of depth 2' '
129 cd "$D" &&
130 git config apply.whitespace strip &&
131 rm -f sub/file1 &&
132 cp saved sub/file1 &&
133 git update-index --refresh &&
135 cd sub &&
136 git apply ../gpatch-ab-sub.file &&
137 check_result file1
140 test_expect_success 'same but with traditional patch input of depth 1' '
142 cd "$D" &&
143 git config apply.whitespace strip &&
144 rm -f sub/file1 &&
145 cp saved sub/file1 &&
146 git update-index --refresh &&
148 git apply -p0 gpatch-sub.file &&
149 check_result sub/file1
152 test_expect_success 'same but with traditional patch input of depth 2' '
154 cd "$D" &&
155 git config apply.whitespace strip &&
156 rm -f sub/file1 &&
157 cp saved sub/file1 &&
158 git update-index --refresh &&
160 git apply gpatch-ab-sub.file &&
161 check_result sub/file1
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
171 rm -f sub/file1 &&
172 cp saved sub/file1 &&
173 git update-index --refresh &&
175 cd sub &&
176 git apply ../gpatch.file &&
177 echo "B " >expect &&
178 test_cmp expect file1
181 test_done