Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description=gitattributes |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | attr_check () { |
Junio C Hamano | 78cec75 | 2011-09-22 16:34:05 -0700 | [diff] [blame] | 8 | path="$1" expect="$2" |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 9 | |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 10 | git $3 check-attr test -- "$path" >actual 2>err && |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 11 | echo "$path: test: $2" >expect && |
Michael Haggerty | fa92f32 | 2011-08-04 06:47:43 +0200 | [diff] [blame] | 12 | test_cmp expect actual && |
| 13 | test_line_count = 0 err |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | |
| 17 | test_expect_success 'setup' ' |
Michael Haggerty | 0216af8 | 2011-08-04 06:47:45 +0200 | [diff] [blame] | 18 | mkdir -p a/b/d a/c b && |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 19 | ( |
Henrik Grubbström | ec775c4 | 2010-04-06 14:46:44 +0200 | [diff] [blame] | 20 | echo "[attr]notest !test" |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 21 | echo "f test=f" |
Matthew Ogilvie | 82881b3 | 2008-04-22 12:19:12 -0600 | [diff] [blame] | 22 | echo "a/i test=a/i" |
Henrik Grubbström | 969f9d7 | 2010-04-06 14:46:43 +0200 | [diff] [blame] | 23 | echo "onoff test -test" |
| 24 | echo "offon -test test" |
Henrik Grubbström | ec775c4 | 2010-04-06 14:46:44 +0200 | [diff] [blame] | 25 | echo "no notest" |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 26 | echo "A/e/F test=A/e/F" |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 27 | ) >.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öm | ec775c4 | 2010-04-06 14:46:44 +0200 | [diff] [blame] | 35 | echo "d/yes notest" |
Michael Haggerty | dcc0436 | 2011-08-04 06:36:15 +0200 | [diff] [blame] | 36 | ) >a/b/.gitattributes && |
Petr Onderka | 6df42ab | 2010-09-01 00:42:43 +0200 | [diff] [blame] | 37 | ( |
| 38 | echo "global test=global" |
Michael Haggerty | c9d8f0a | 2011-08-04 06:36:31 +0200 | [diff] [blame] | 39 | ) >"$HOME"/global-gitattributes && |
Junio C Hamano | 78cec75 | 2011-09-22 16:34:05 -0700 | [diff] [blame] | 40 | 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 Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 58 | ' |
| 59 | |
Michael Haggerty | c0b13b2 | 2011-08-04 06:36:14 +0200 | [diff] [blame] | 60 | test_expect_success 'command line checks' ' |
Michael Haggerty | 09d7dd7 | 2011-08-04 06:36:16 +0200 | [diff] [blame] | 61 | test_must_fail git check-attr && |
| 62 | test_must_fail git check-attr -- && |
Michael Haggerty | fdf6be8 | 2011-08-04 06:36:29 +0200 | [diff] [blame] | 63 | test_must_fail git check-attr test && |
| 64 | test_must_fail git check-attr test -- && |
Michael Haggerty | 09d7dd7 | 2011-08-04 06:36:16 +0200 | [diff] [blame] | 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 && |
Michael Haggerty | c0b13b2 | 2011-08-04 06:36:14 +0200 | [diff] [blame] | 69 | test_must_fail git check-attr "" -- f |
Michael Haggerty | c0b13b2 | 2011-08-04 06:36:14 +0200 | [diff] [blame] | 70 | ' |
| 71 | |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 72 | test_expect_success 'attribute test' ' |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 73 | 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 Moy | 520ea85 | 2010-08-28 20:18:36 +0200 | [diff] [blame] | 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/*" && |
Henrik Grubbström | ec775c4 | 2010-04-06 14:46:44 +0200 | [diff] [blame] | 85 | attr_check a/b/d/yes unspecified |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 86 | ' |
| 87 | |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 88 | test_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 | |
| 107 | test_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 | |
| 126 | test_expect_success 'check whether FS is case-insensitive' ' |
| 127 | mkdir junk && |
| 128 | echo good >junk/CamelCase && |
| 129 | echo bad >junk/camelcase && |
| 130 | if test "$(cat junk/CamelCase)" != good |
| 131 | then |
| 132 | test_set_prereq CASE_INSENSITIVE_FS |
| 133 | fi |
| 134 | ' |
| 135 | |
| 136 | test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' |
| 137 | test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" && |
| 138 | test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" && |
| 139 | attr_check A/b/h a/b/h "-c core.ignorecase=1" && |
| 140 | attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" && |
| 141 | attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1" |
| 142 | ' |
| 143 | |
Michael Haggerty | f5114a4 | 2011-08-04 06:47:46 +0200 | [diff] [blame] | 144 | test_expect_success 'unnormalized paths' ' |
Michael Haggerty | d4d4f8d | 2011-08-04 06:47:44 +0200 | [diff] [blame] | 145 | attr_check ./f f && |
| 146 | attr_check ./a/g a/g && |
| 147 | attr_check a/./g a/g && |
| 148 | attr_check a/c/../b/g a/b/g |
Michael Haggerty | d4d4f8d | 2011-08-04 06:47:44 +0200 | [diff] [blame] | 149 | ' |
| 150 | |
Michael Haggerty | f5114a4 | 2011-08-04 06:47:46 +0200 | [diff] [blame] | 151 | test_expect_success 'relative paths' ' |
Michael Haggerty | 0216af8 | 2011-08-04 06:47:45 +0200 | [diff] [blame] | 152 | (cd a && attr_check ../f f) && |
| 153 | (cd a && attr_check f f) && |
| 154 | (cd a && attr_check i a/i) && |
| 155 | (cd a && attr_check g a/g) && |
| 156 | (cd a && attr_check b/g a/b/g) && |
| 157 | (cd b && attr_check ../a/f f) && |
| 158 | (cd b && attr_check ../a/g a/g) && |
| 159 | (cd b && attr_check ../a/b/g a/b/g) |
Michael Haggerty | 0216af8 | 2011-08-04 06:47:45 +0200 | [diff] [blame] | 160 | ' |
| 161 | |
Jeff King | 1afca44 | 2012-01-10 13:08:21 -0500 | [diff] [blame] | 162 | test_expect_success 'prefixes are not confused with leading directories' ' |
| 163 | attr_check a_plus/g unspecified && |
| 164 | cat >expect <<-\EOF && |
| 165 | a/g: test: a/g |
| 166 | a_plus/g: test: unspecified |
| 167 | EOF |
| 168 | git check-attr test a/g a_plus/g >actual && |
| 169 | test_cmp expect actual |
| 170 | ' |
| 171 | |
Petr Onderka | 6df42ab | 2010-09-01 00:42:43 +0200 | [diff] [blame] | 172 | test_expect_success 'core.attributesfile' ' |
| 173 | attr_check global unspecified && |
| 174 | git config core.attributesfile "$HOME/global-gitattributes" && |
| 175 | attr_check global global && |
| 176 | git config core.attributesfile "~/global-gitattributes" && |
| 177 | attr_check global global && |
Junio C Hamano | 78cec75 | 2011-09-22 16:34:05 -0700 | [diff] [blame] | 178 | echo "global test=precedence" >>.gitattributes && |
Petr Onderka | 6df42ab | 2010-09-01 00:42:43 +0200 | [diff] [blame] | 179 | attr_check global precedence |
| 180 | ' |
| 181 | |
Dmitry Potapov | b466685 | 2008-10-07 04:16:52 +0400 | [diff] [blame] | 182 | test_expect_success 'attribute test: read paths from stdin' ' |
Junio C Hamano | 78cec75 | 2011-09-22 16:34:05 -0700 | [diff] [blame] | 183 | grep -v notest <expect-all >expect && |
| 184 | sed -e "s/:.*//" <expect | git check-attr --stdin test >actual && |
Dmitry Potapov | b466685 | 2008-10-07 04:16:52 +0400 | [diff] [blame] | 185 | test_cmp expect actual |
| 186 | ' |
| 187 | |
Michael Haggerty | 4ca0f18 | 2011-08-04 06:36:30 +0200 | [diff] [blame] | 188 | test_expect_success 'attribute test: --all option' ' |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 189 | grep -v unspecified <expect-all | sort >specified-all && |
| 190 | sed -e "s/:.*//" <expect-all | uniq >stdin-all && |
| 191 | git check-attr --stdin --all <stdin-all | sort >actual && |
| 192 | test_cmp specified-all actual |
| 193 | ' |
| 194 | |
| 195 | test_expect_success 'attribute test: --cached option' ' |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 196 | : >empty && |
| 197 | git check-attr --cached --stdin --all <stdin-all | sort >actual && |
| 198 | test_cmp empty actual && |
| 199 | git add .gitattributes a/.gitattributes a/b/.gitattributes && |
| 200 | git check-attr --cached --stdin --all <stdin-all | sort >actual && |
| 201 | test_cmp specified-all actual |
Michael Haggerty | 4ca0f18 | 2011-08-04 06:36:30 +0200 | [diff] [blame] | 202 | ' |
| 203 | |
Matthew Ogilvie | 82881b3 | 2008-04-22 12:19:12 -0600 | [diff] [blame] | 204 | test_expect_success 'root subdir attribute test' ' |
Matthew Ogilvie | 82881b3 | 2008-04-22 12:19:12 -0600 | [diff] [blame] | 205 | attr_check a/i a/i && |
| 206 | attr_check subdir/a/i unspecified |
Matthew Ogilvie | 82881b3 | 2008-04-22 12:19:12 -0600 | [diff] [blame] | 207 | ' |
| 208 | |
Nguyễn Thái Ngọc Duy | 82dce99 | 2012-10-15 13:24:39 +0700 | [diff] [blame^] | 209 | test_expect_success 'negative patterns' ' |
| 210 | echo "!f test=bar" >.gitattributes && |
| 211 | test_must_fail git check-attr test -- f |
| 212 | ' |
| 213 | |
| 214 | test_expect_success 'patterns starting with exclamation' ' |
| 215 | echo "\!f test=foo" >.gitattributes && |
| 216 | attr_check "!f" foo |
| 217 | ' |
| 218 | |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 219 | test_expect_success 'setup bare' ' |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 220 | git clone --bare . bare.git && |
| 221 | cd bare.git |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 222 | ' |
| 223 | |
| 224 | test_expect_success 'bare repository: check that .gitattribute is ignored' ' |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 225 | ( |
| 226 | echo "f test=f" |
| 227 | echo "a/i test=a/i" |
| 228 | ) >.gitattributes && |
| 229 | attr_check f unspecified && |
| 230 | attr_check a/f unspecified && |
| 231 | attr_check a/c/f unspecified && |
| 232 | attr_check a/i unspecified && |
| 233 | attr_check subdir/a/i unspecified |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 234 | ' |
| 235 | |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 236 | test_expect_success 'bare repository: check that --cached honors index' ' |
| 237 | GIT_INDEX_FILE=../.git/index \ |
| 238 | git check-attr --cached --stdin --all <../stdin-all | |
| 239 | sort >actual && |
| 240 | test_cmp ../specified-all actual |
| 241 | ' |
| 242 | |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 243 | test_expect_success 'bare repository: test info/attributes' ' |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 244 | ( |
| 245 | echo "f test=f" |
| 246 | echo "a/i test=a/i" |
| 247 | ) >info/attributes && |
| 248 | attr_check f f && |
| 249 | attr_check a/f f && |
| 250 | attr_check a/c/f f && |
| 251 | attr_check a/i a/i && |
| 252 | attr_check subdir/a/i unspecified |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 253 | ' |
| 254 | |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 255 | test_done |