3 test_description=gitattributes
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"
27 echo "onoff test -test"
28 echo "offon -test test"
30 echo "A/e/F test=A/e/F"
35 ) >a/.gitattributes &&
37 echo "h test=a/b/h" &&
38 echo "d/* test=a/b/d/*"
40 ) >a/b/.gitattributes &&
42 echo "global test=global"
43 ) >"$HOME"/global-gitattributes &&
50 b/g: test: unspecified
52 a/b/d/g: test: a/b/d/*
58 a/b/d/no: test: a/b/d/*
59 a/b/d/yes: notest: set
60 a/b/d/yes: test: unspecified
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' '
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' '
137 echo good >junk/CamelCase &&
138 echo bad >junk/camelcase &&
139 if test "$(cat junk/CamelCase)" != good
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' '
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 &&
214 test_expect_success 'bare repository: check that .gitattribute is ignored' '
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' '
233 ) >info/attributes &&
236 attr_check a/c/f f &&
237 attr_check a/i a/i &&
238 attr_check subdir/a/i unspecified