3 test_description
=gitattributes
10 git
$3 check-attr
test -- "$path" >actual
2>err
&&
11 echo "$path: test: $2" >expect
&&
12 test_cmp expect actual
&&
13 test_line_count
= 0 err
17 test_expect_success
'setup' '
18 mkdir -p a/b/d a/c b &&
20 echo "[attr]notest !test"
23 echo "onoff test -test"
24 echo "offon -test test"
26 echo "A/e/F test=A/e/F"
31 ) >a/.gitattributes &&
33 echo "h test=a/b/h" &&
34 echo "d/* test=a/b/d/*"
36 ) >a/b/.gitattributes &&
38 echo "global test=global"
39 ) >"$HOME"/global-gitattributes &&
40 cat <<-EOF >expect-all
46 b/g: test: unspecified
48 a/b/d/g: test: a/b/d/*
54 a/b/d/no: test: a/b/d/*
55 a/b/d/yes: notest: set
56 a/b/d/yes: test: unspecified
60 test_expect_success
'command line checks' '
61 test_must_fail git check-attr &&
62 test_must_fail git check-attr -- &&
63 test_must_fail git check-attr test &&
64 test_must_fail git check-attr test -- &&
65 test_must_fail git check-attr -- f &&
66 echo "f" | test_must_fail git check-attr --stdin &&
67 echo "f" | test_must_fail git check-attr --stdin -- f &&
68 echo "f" | test_must_fail git check-attr --stdin test -- f &&
69 test_must_fail git check-attr "" -- f
72 test_expect_success
'attribute test' '
77 attr_check a/b/g a/b/g &&
78 attr_check b/g unspecified &&
79 attr_check a/b/h a/b/h &&
80 attr_check a/b/d/g "a/b/d/*" &&
81 attr_check onoff unset &&
82 attr_check offon set &&
83 attr_check no unspecified &&
84 attr_check a/b/d/no "a/b/d/*" &&
85 attr_check a/b/d/yes unspecified
88 test_expect_success
'attribute matching is case sensitive when core.ignorecase=0' '
90 test_must_fail attr_check F f "-c core.ignorecase=0" &&
91 test_must_fail attr_check a/F f "-c core.ignorecase=0" &&
92 test_must_fail attr_check a/c/F f "-c core.ignorecase=0" &&
93 test_must_fail attr_check a/G a/g "-c core.ignorecase=0" &&
94 test_must_fail attr_check a/B/g a/b/g "-c core.ignorecase=0" &&
95 test_must_fail attr_check a/b/G a/b/g "-c core.ignorecase=0" &&
96 test_must_fail attr_check a/b/H a/b/h "-c core.ignorecase=0" &&
97 test_must_fail attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=0" &&
98 test_must_fail attr_check oNoFf unset "-c core.ignorecase=0" &&
99 test_must_fail attr_check oFfOn set "-c core.ignorecase=0" &&
100 attr_check NO unspecified "-c core.ignorecase=0" &&
101 test_must_fail attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
102 attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" &&
103 test_must_fail attr_check a/E/f "A/e/F" "-c core.ignorecase=0"
107 test_expect_success
'attribute matching is case insensitive when core.ignorecase=1' '
109 attr_check F f "-c core.ignorecase=1" &&
110 attr_check a/F f "-c core.ignorecase=1" &&
111 attr_check a/c/F f "-c core.ignorecase=1" &&
112 attr_check a/G a/g "-c core.ignorecase=1" &&
113 attr_check a/B/g a/b/g "-c core.ignorecase=1" &&
114 attr_check a/b/G a/b/g "-c core.ignorecase=1" &&
115 attr_check a/b/H a/b/h "-c core.ignorecase=1" &&
116 attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" &&
117 attr_check oNoFf unset "-c core.ignorecase=1" &&
118 attr_check oFfOn set "-c core.ignorecase=1" &&
119 attr_check NO unspecified "-c core.ignorecase=1" &&
120 attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" &&
121 attr_check a/b/d/YES unspecified "-c core.ignorecase=1" &&
122 attr_check a/E/f "A/e/F" "-c core.ignorecase=1"
126 test_expect_success CASE_INSENSITIVE_FS
'additional case insensitivity tests' '
127 test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" &&
128 test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" &&
129 attr_check A/b/h a/b/h "-c core.ignorecase=1" &&
130 attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" &&
131 attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1"
134 test_expect_success
'unnormalized paths' '
136 attr_check ./a/g a/g &&
137 attr_check a/./g a/g &&
138 attr_check a/c/../b/g a/b/g
141 test_expect_success
'relative paths' '
142 (cd a && attr_check ../f f) &&
143 (cd a && attr_check f f) &&
144 (cd a && attr_check i a/i) &&
145 (cd a && attr_check g a/g) &&
146 (cd a && attr_check b/g a/b/g) &&
147 (cd b && attr_check ../a/f f) &&
148 (cd b && attr_check ../a/g a/g) &&
149 (cd b && attr_check ../a/b/g a/b/g)
152 test_expect_success
'prefixes are not confused with leading directories' '
153 attr_check a_plus/g unspecified &&
154 cat >expect <<-\EOF &&
156 a_plus/g: test: unspecified
158 git check-attr test a/g a_plus/g >actual &&
159 test_cmp expect actual
162 test_expect_success
'core.attributesfile' '
163 attr_check global unspecified &&
164 git config core.attributesfile "$HOME/global-gitattributes" &&
165 attr_check global global &&
166 git config core.attributesfile "~/global-gitattributes" &&
167 attr_check global global &&
168 echo "global test=precedence" >>.gitattributes &&
169 attr_check global precedence
172 test_expect_success
'attribute test: read paths from stdin' '
173 grep -v notest <expect-all >expect &&
174 sed -e "s/:.*//" <expect | git check-attr --stdin test >actual &&
175 test_cmp expect actual
178 test_expect_success
'attribute test: --all option' '
179 grep -v unspecified <expect-all | sort >specified-all &&
180 sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
181 git check-attr --stdin --all <stdin-all | sort >actual &&
182 test_cmp specified-all actual
185 test_expect_success
'attribute test: --cached option' '
187 git check-attr --cached --stdin --all <stdin-all | sort >actual &&
188 test_cmp empty actual &&
189 git add .gitattributes a/.gitattributes a/b/.gitattributes &&
190 git check-attr --cached --stdin --all <stdin-all | sort >actual &&
191 test_cmp specified-all actual
194 test_expect_success
'root subdir attribute test' '
195 attr_check a/i a/i &&
196 attr_check subdir/a/i unspecified
199 test_expect_success
'negative patterns' '
200 echo "!f test=bar" >.gitattributes &&
201 git check-attr test -- '"'"'!f'"'"' 2>errors &&
202 test_i18ngrep "Negative patterns are ignored" errors
205 test_expect_success
'patterns starting with exclamation' '
206 echo "\!f test=foo" >.gitattributes &&
210 test_expect_success
'setup bare' '
211 git clone --bare . bare.git &&
215 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
227 test_expect_success
'bare repository: check that --cached honors index' '
228 GIT_INDEX_FILE=../.git/index \
229 git check-attr --cached --stdin --all <../stdin-all |
231 test_cmp ../specified-all actual
234 test_expect_success
'bare repository: test info/attributes' '
238 ) >info/attributes &&
241 attr_check a/c/f f &&
242 attr_check a/i a/i &&
243 attr_check subdir/a/i unspecified