blob: 6e6aef598836b6405006390aac5c5f11901de54d [file] [log] [blame]
Junio C Hamanocf94ccd2008-02-07 00:02:08 -08001#!/bin/sh
2
3test_description=gitattributes
4
5. ./test-lib.sh
6
7attr_check () {
Junio C Hamano78cec752011-09-22 16:34:05 -07008 path="$1" expect="$2"
Junio C Hamanocf94ccd2008-02-07 00:02:08 -08009
Brandon Casey6eba6212011-10-11 10:53:31 -050010 git $3 check-attr test -- "$path" >actual 2>err &&
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080011 echo "$path: test: $2" >expect &&
Michael Haggertyfa92f322011-08-04 06:47:43 +020012 test_cmp expect actual &&
13 test_line_count = 0 err
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080014}
15
16
17test_expect_success 'setup' '
Michael Haggerty0216af82011-08-04 06:47:45 +020018 mkdir -p a/b/d a/c b &&
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080019 (
Henrik Grubbströmec775c42010-04-06 14:46:44 +020020 echo "[attr]notest !test"
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080021 echo "f test=f"
Matthew Ogilvie82881b32008-04-22 12:19:12 -060022 echo "a/i test=a/i"
Henrik Grubbström969f9d72010-04-06 14:46:43 +020023 echo "onoff test -test"
24 echo "offon -test test"
Henrik Grubbströmec775c42010-04-06 14:46:44 +020025 echo "no notest"
Brandon Casey6eba6212011-10-11 10:53:31 -050026 echo "A/e/F test=A/e/F"
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080027 ) >.gitattributes &&
28 (
29 echo "g test=a/g" &&
30 echo "b/g test=a/b/g"
31 ) >a/.gitattributes &&
32 (
33 echo "h test=a/b/h" &&
34 echo "d/* test=a/b/d/*"
Henrik Grubbströmec775c42010-04-06 14:46:44 +020035 echo "d/yes notest"
Michael Haggertydcc04362011-08-04 06:36:15 +020036 ) >a/b/.gitattributes &&
Petr Onderka6df42ab2010-09-01 00:42:43 +020037 (
38 echo "global test=global"
Michael Haggertyc9d8f0a2011-08-04 06:36:31 +020039 ) >"$HOME"/global-gitattributes &&
Junio C Hamano78cec752011-09-22 16:34:05 -070040 cat <<-EOF >expect-all
41 f: test: f
42 a/f: test: f
43 a/c/f: test: f
44 a/g: test: a/g
45 a/b/g: test: a/b/g
46 b/g: test: unspecified
47 a/b/h: test: a/b/h
48 a/b/d/g: test: a/b/d/*
49 onoff: test: unset
50 offon: test: set
51 no: notest: set
52 no: test: unspecified
53 a/b/d/no: notest: set
54 a/b/d/no: test: a/b/d/*
55 a/b/d/yes: notest: set
56 a/b/d/yes: test: unspecified
57 EOF
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080058'
59
Michael Haggertyc0b13b22011-08-04 06:36:14 +020060test_expect_success 'command line checks' '
Michael Haggerty09d7dd72011-08-04 06:36:16 +020061 test_must_fail git check-attr &&
62 test_must_fail git check-attr -- &&
Michael Haggertyfdf6be82011-08-04 06:36:29 +020063 test_must_fail git check-attr test &&
64 test_must_fail git check-attr test -- &&
Michael Haggerty09d7dd72011-08-04 06:36:16 +020065 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 &&
Michael Haggertyc0b13b22011-08-04 06:36:14 +020069 test_must_fail git check-attr "" -- f
Michael Haggertyc0b13b22011-08-04 06:36:14 +020070'
71
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080072test_expect_success 'attribute test' '
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080073 attr_check f f &&
74 attr_check a/f f &&
75 attr_check a/c/f f &&
76 attr_check a/g a/g &&
77 attr_check a/b/g a/b/g &&
78 attr_check b/g unspecified &&
79 attr_check a/b/h a/b/h &&
Matthieu Moy520ea852010-08-28 20:18:36 +020080 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/*" &&
Henrik Grubbströmec775c42010-04-06 14:46:44 +020085 attr_check a/b/d/yes unspecified
Junio C Hamanocf94ccd2008-02-07 00:02:08 -080086'
87
Brandon Casey6eba6212011-10-11 10:53:31 -050088test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' '
89
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"
104
105'
106
107test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' '
108
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"
123
124'
125
Brandon Casey6eba6212011-10-11 10:53:31 -0500126test_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"
132'
133
Michael Haggertyf5114a42011-08-04 06:47:46 +0200134test_expect_success 'unnormalized paths' '
Michael Haggertyd4d4f8d2011-08-04 06:47:44 +0200135 attr_check ./f f &&
136 attr_check ./a/g a/g &&
137 attr_check a/./g a/g &&
138 attr_check a/c/../b/g a/b/g
Michael Haggertyd4d4f8d2011-08-04 06:47:44 +0200139'
140
Michael Haggertyf5114a42011-08-04 06:47:46 +0200141test_expect_success 'relative paths' '
Michael Haggerty0216af82011-08-04 06:47:45 +0200142 (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)
Michael Haggerty0216af82011-08-04 06:47:45 +0200150'
151
Jeff King1afca442012-01-10 13:08:21 -0500152test_expect_success 'prefixes are not confused with leading directories' '
153 attr_check a_plus/g unspecified &&
154 cat >expect <<-\EOF &&
155 a/g: test: a/g
156 a_plus/g: test: unspecified
157 EOF
158 git check-attr test a/g a_plus/g >actual &&
159 test_cmp expect actual
160'
161
Petr Onderka6df42ab2010-09-01 00:42:43 +0200162test_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 &&
Junio C Hamano78cec752011-09-22 16:34:05 -0700168 echo "global test=precedence" >>.gitattributes &&
Petr Onderka6df42ab2010-09-01 00:42:43 +0200169 attr_check global precedence
170'
171
Dmitry Potapovb4666852008-10-07 04:16:52 +0400172test_expect_success 'attribute test: read paths from stdin' '
Junio C Hamano78cec752011-09-22 16:34:05 -0700173 grep -v notest <expect-all >expect &&
174 sed -e "s/:.*//" <expect | git check-attr --stdin test >actual &&
Dmitry Potapovb4666852008-10-07 04:16:52 +0400175 test_cmp expect actual
176'
177
Michael Haggerty4ca0f182011-08-04 06:36:30 +0200178test_expect_success 'attribute test: --all option' '
Jay Soffianb2b3e9c2011-09-22 17:44:20 -0400179 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
183'
184
185test_expect_success 'attribute test: --cached option' '
Jay Soffianb2b3e9c2011-09-22 17:44:20 -0400186 : >empty &&
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
Michael Haggerty4ca0f182011-08-04 06:36:30 +0200192'
193
Matthew Ogilvie82881b32008-04-22 12:19:12 -0600194test_expect_success 'root subdir attribute test' '
Matthew Ogilvie82881b32008-04-22 12:19:12 -0600195 attr_check a/i a/i &&
196 attr_check subdir/a/i unspecified
Matthew Ogilvie82881b32008-04-22 12:19:12 -0600197'
198
Junio C Hamanocdbf6232014-02-06 10:19:33 -0800199test_expect_success 'using --git-dir and --work-tree' '
200 mkdir unreal real &&
201 git init real &&
202 echo "file test=in-real" >real/.gitattributes &&
203 (
204 cd unreal &&
205 attr_check file in-real "--git-dir ../real/.git --work-tree ../real"
206 )
207'
208
René Scharfe2d35d552008-06-08 17:16:11 +0200209test_expect_success 'setup bare' '
Junio C Hamanoc4a7bce2014-02-06 10:16:27 -0800210 git clone --bare . bare.git
René Scharfe2d35d552008-06-08 17:16:11 +0200211'
212
213test_expect_success 'bare repository: check that .gitattribute is ignored' '
René Scharfe2d35d552008-06-08 17:16:11 +0200214 (
Junio C Hamanoc4a7bce2014-02-06 10:16:27 -0800215 cd bare.git &&
216 (
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
225 )
René Scharfe2d35d552008-06-08 17:16:11 +0200226'
227
Jay Soffianb2b3e9c2011-09-22 17:44:20 -0400228test_expect_success 'bare repository: check that --cached honors index' '
Junio C Hamanoc4a7bce2014-02-06 10:16:27 -0800229 (
230 cd bare.git &&
231 GIT_INDEX_FILE=../.git/index \
232 git check-attr --cached --stdin --all <../stdin-all |
233 sort >actual &&
234 test_cmp ../specified-all actual
235 )
Jay Soffianb2b3e9c2011-09-22 17:44:20 -0400236'
237
René Scharfe2d35d552008-06-08 17:16:11 +0200238test_expect_success 'bare repository: test info/attributes' '
René Scharfe2d35d552008-06-08 17:16:11 +0200239 (
Junio C Hamanoc4a7bce2014-02-06 10:16:27 -0800240 cd bare.git &&
241 (
242 echo "f test=f"
243 echo "a/i test=a/i"
244 ) >info/attributes &&
245 attr_check f f &&
246 attr_check a/f f &&
247 attr_check a/c/f f &&
248 attr_check a/i a/i &&
249 attr_check subdir/a/i unspecified
250 )
René Scharfe2d35d552008-06-08 17:16:11 +0200251'
252
Junio C Hamanocf94ccd2008-02-07 00:02:08 -0800253test_done