Merge the attributes fix in from maint-1.6.6 branch
[git/mingw.git] / t / t0003-attributes.sh
blob19265c77cf0b1df828eea188d5f880cbb7497c63
1 #!/bin/sh
3 test_description=gitattributes
5 . ./test-lib.sh
7 attr_check () {
9 path="$1"
10 expect="$2"
12 git $3 check-attr test -- "$path" >actual 2>err &&
13 echo "$path: test: $2" >expect &&
14 test_cmp expect actual &&
15 test_line_count = 0 err
20 test_expect_success 'setup' '
22 mkdir -p a/b/d a/c b &&
24 echo "[attr]notest !test"
25 echo "f test=f"
26 echo "a/i test=a/i"
27 echo "onoff test -test"
28 echo "offon -test test"
29 echo "no notest"
30 echo "A/e/F test=A/e/F"
31 ) >.gitattributes &&
33 echo "g test=a/g" &&
34 echo "b/g test=a/b/g"
35 ) >a/.gitattributes &&
37 echo "h test=a/b/h" &&
38 echo "d/* test=a/b/d/*"
39 echo "d/yes notest"
40 ) >a/b/.gitattributes &&
42 echo "global test=global"
43 ) >"$HOME"/global-gitattributes &&
44 cat <<EOF >expect-all
45 f: test: f
46 a/f: test: f
47 a/c/f: test: f
48 a/g: test: a/g
49 a/b/g: test: a/b/g
50 b/g: test: unspecified
51 a/b/h: test: a/b/h
52 a/b/d/g: test: a/b/d/*
53 onoff: test: unset
54 offon: test: set
55 no: notest: set
56 no: test: unspecified
57 a/b/d/no: notest: set
58 a/b/d/no: test: a/b/d/*
59 a/b/d/yes: notest: set
60 a/b/d/yes: test: unspecified
61 EOF
65 test_expect_success 'command line checks' '
67 test_must_fail git check-attr &&
68 test_must_fail git check-attr -- &&
69 test_must_fail git check-attr test &&
70 test_must_fail git check-attr test -- &&
71 test_must_fail git check-attr -- f &&
72 echo "f" | test_must_fail git check-attr --stdin &&
73 echo "f" | test_must_fail git check-attr --stdin -- f &&
74 echo "f" | test_must_fail git check-attr --stdin test -- f &&
75 test_must_fail git check-attr "" -- f
79 test_expect_success 'attribute test' '
81 attr_check f f &&
82 attr_check a/f f &&
83 attr_check a/c/f f &&
84 attr_check a/g a/g &&
85 attr_check a/b/g a/b/g &&
86 attr_check b/g unspecified &&
87 attr_check a/b/h a/b/h &&
88 attr_check a/b/d/g "a/b/d/*" &&
89 attr_check onoff unset &&
90 attr_check offon set &&
91 attr_check no unspecified &&
92 attr_check a/b/d/no "a/b/d/*" &&
93 attr_check a/b/d/yes unspecified
97 test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '
99 test_must_fail attr_check F f "-c core.ignorecase=0" &&
100 test_must_fail attr_check a/F f "-c core.ignorecase=0" &&
101 test_must_fail attr_check a/c/F f "-c core.ignorecase=0" &&
102 test_must_fail attr_check a/G a/g "-c core.ignorecase=0" &&
103 test_must_fail attr_check a/B/g a/b/g "-c core.ignorecase=0" &&
104 test_must_fail attr_check a/b/G a/b/g "-c core.ignorecase=0" &&
105 test_must_fail attr_check a/b/H a/b/h "-c core.ignorecase=0" &&
106 test_must_fail attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=0" &&
107 test_must_fail attr_check oNoFf unset "-c core.ignorecase=0" &&
108 test_must_fail attr_check oFfOn set "-c core.ignorecase=0" &&
109 attr_check NO unspecified "-c core.ignorecase=0" &&
110 test_must_fail attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
111 attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" &&
112 test_must_fail attr_check a/E/f "A/e/F" "-c core.ignorecase=0"
116 test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' '
118 attr_check F f "-c core.ignorecase=1" &&
119 attr_check a/F f "-c core.ignorecase=1" &&
120 attr_check a/c/F f "-c core.ignorecase=1" &&
121 attr_check a/G a/g "-c core.ignorecase=1" &&
122 attr_check a/B/g a/b/g "-c core.ignorecase=1" &&
123 attr_check a/b/G a/b/g "-c core.ignorecase=1" &&
124 attr_check a/b/H a/b/h "-c core.ignorecase=1" &&
125 attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" &&
126 attr_check oNoFf unset "-c core.ignorecase=1" &&
127 attr_check oFfOn set "-c core.ignorecase=1" &&
128 attr_check NO unspecified "-c core.ignorecase=1" &&
129 attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" &&
130 attr_check a/b/d/YES unspecified "-c core.ignorecase=1" &&
131 attr_check a/E/f "A/e/F" "-c core.ignorecase=1"
135 test_expect_success 'check whether FS is case-insensitive' '
136 mkdir junk &&
137 echo good >junk/CamelCase &&
138 echo bad >junk/camelcase &&
139 if test "$(cat junk/CamelCase)" != good
140 then
141 test_set_prereq CASE_INSENSITIVE_FS
145 test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' '
146 test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" &&
147 test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
148 attr_check A/b/h a/b/h "-c core.ignorecase=1" &&
149 attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" &&
150 attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1"
153 test_expect_success 'unnormalized paths' '
155 attr_check ./f f &&
156 attr_check ./a/g a/g &&
157 attr_check a/./g a/g &&
158 attr_check a/c/../b/g a/b/g
162 test_expect_success 'relative paths' '
164 (cd a && attr_check ../f f) &&
165 (cd a && attr_check f f) &&
166 (cd a && attr_check i a/i) &&
167 (cd a && attr_check g a/g) &&
168 (cd a && attr_check b/g a/b/g) &&
169 (cd b && attr_check ../a/f f) &&
170 (cd b && attr_check ../a/g a/g) &&
171 (cd b && attr_check ../a/b/g a/b/g)
175 test_expect_success 'prefixes are not confused with leading directories' '
176 attr_check a_plus/g unspecified &&
177 cat >expect <<-\EOF &&
178 a/g: test: a/g
179 a_plus/g: test: unspecified
181 git check-attr test a/g a_plus/g >actual &&
182 test_cmp expect actual
185 test_expect_success 'core.attributesfile' '
186 attr_check global unspecified &&
187 git config core.attributesfile "$HOME/global-gitattributes" &&
188 attr_check global global &&
189 git config core.attributesfile "~/global-gitattributes" &&
190 attr_check global global &&
191 echo "global test=precedence" >> .gitattributes &&
192 attr_check global precedence
195 test_expect_success 'attribute test: read paths from stdin' '
197 grep -v notest < expect-all > expect &&
198 sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
199 test_cmp expect actual
202 test_expect_success 'attribute test: --all option' '
204 grep -v unspecified < expect-all | sort > expect &&
205 sed -e "s/:.*//" < expect-all | uniq |
206 git check-attr --stdin --all | sort > actual &&
207 test_cmp expect actual
210 test_expect_success 'root subdir attribute test' '
212 attr_check a/i a/i &&
213 attr_check subdir/a/i unspecified
217 test_expect_success 'setup bare' '
219 git clone --bare . bare.git &&
220 cd bare.git
224 test_expect_success 'bare repository: check that .gitattribute is ignored' '
227 echo "f test=f"
228 echo "a/i test=a/i"
229 ) >.gitattributes &&
230 attr_check f unspecified &&
231 attr_check a/f unspecified &&
232 attr_check a/c/f unspecified &&
233 attr_check a/i unspecified &&
234 attr_check subdir/a/i unspecified
238 test_expect_success 'bare repository: test info/attributes' '
241 echo "f test=f"
242 echo "a/i test=a/i"
243 ) >info/attributes &&
244 attr_check f f &&
245 attr_check a/f f &&
246 attr_check a/c/f f &&
247 attr_check a/i a/i &&
248 attr_check subdir/a/i unspecified
252 test_done