attr.c: respect core.ignorecase when matching attribute patterns
[git/mingw/j6t.git] / t / t0003-attributes.sh
blob6946c4b82f9291f6618d49de2e3892a2c203d337
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 'core.attributesfile' '
176 attr_check global unspecified &&
177 git config core.attributesfile "$HOME/global-gitattributes" &&
178 attr_check global global &&
179 git config core.attributesfile "~/global-gitattributes" &&
180 attr_check global global &&
181 echo "global test=precedence" >> .gitattributes &&
182 attr_check global precedence
185 test_expect_success 'attribute test: read paths from stdin' '
187 grep -v notest < expect-all > expect &&
188 sed -e "s/:.*//" < expect | git check-attr --stdin test > actual &&
189 test_cmp expect actual
192 test_expect_success 'attribute test: --all option' '
194 grep -v unspecified < expect-all | sort > expect &&
195 sed -e "s/:.*//" < expect-all | uniq |
196 git check-attr --stdin --all | sort > actual &&
197 test_cmp expect actual
200 test_expect_success 'root subdir attribute test' '
202 attr_check a/i a/i &&
203 attr_check subdir/a/i unspecified
207 test_expect_success 'setup bare' '
209 git clone --bare . bare.git &&
210 cd bare.git
214 test_expect_success 'bare repository: check that .gitattribute is ignored' '
217 echo "f test=f"
218 echo "a/i test=a/i"
219 ) >.gitattributes &&
220 attr_check f unspecified &&
221 attr_check a/f unspecified &&
222 attr_check a/c/f unspecified &&
223 attr_check a/i unspecified &&
224 attr_check subdir/a/i unspecified
228 test_expect_success 'bare repository: test info/attributes' '
231 echo "f test=f"
232 echo "a/i test=a/i"
233 ) >info/attributes &&
234 attr_check f f &&
235 attr_check a/f f &&
236 attr_check a/c/f f &&
237 attr_check a/i a/i &&
238 attr_check subdir/a/i unspecified
242 test_done