Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description=gitattributes |
| 4 | |
Ævar Arnfjörð Bjarmason | c150064 | 2021-10-12 15:56:37 +0200 | [diff] [blame] | 5 | TEST_PASSES_SANITIZE_LEAK=true |
Ævar Arnfjörð Bjarmason | 8da0b02 | 2022-06-03 13:15:06 +0200 | [diff] [blame] | 6 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
Jeff King | 2ef579e2 | 2021-02-16 09:44:32 -0500 | [diff] [blame] | 9 | attr_check_basic () { |
Denton Liu | 3738439 | 2019-12-20 10:15:50 -0800 | [diff] [blame] | 10 | path="$1" expect="$2" git_opts="$3" && |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 11 | |
Denton Liu | 3738439 | 2019-12-20 10:15:50 -0800 | [diff] [blame] | 12 | git $git_opts check-attr test -- "$path" >actual 2>err && |
| 13 | echo "$path: test: $expect" >expect && |
Jeff King | 2ef579e2 | 2021-02-16 09:44:32 -0500 | [diff] [blame] | 14 | test_cmp expect actual |
| 15 | } |
| 16 | |
| 17 | attr_check () { |
| 18 | attr_check_basic "$@" && |
Denton Liu | 99c049b | 2019-12-20 10:15:51 -0800 | [diff] [blame] | 19 | test_must_be_empty err |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 20 | } |
| 21 | |
Nguyễn Thái Ngọc Duy | 860a74d | 2017-01-27 18:01:50 -0800 | [diff] [blame] | 22 | attr_check_quote () { |
Denton Liu | 3738439 | 2019-12-20 10:15:50 -0800 | [diff] [blame] | 23 | path="$1" quoted_path="$2" expect="$3" && |
Nguyễn Thái Ngọc Duy | 860a74d | 2017-01-27 18:01:50 -0800 | [diff] [blame] | 24 | |
| 25 | git check-attr test -- "$path" >actual && |
| 26 | echo "\"$quoted_path\": test: $expect" >expect && |
| 27 | test_cmp expect actual |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 28 | } |
Nguyễn Thái Ngọc Duy | 860a74d | 2017-01-27 18:01:50 -0800 | [diff] [blame] | 29 | |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 30 | attr_check_source () { |
| 31 | path="$1" expect="$2" source="$3" git_opts="$4" && |
| 32 | |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 33 | echo "$path: test: $expect" >expect && |
John Cai | 44451a2 | 2023-05-06 04:15:29 +0000 | [diff] [blame] | 34 | |
| 35 | git $git_opts check-attr --source $source test -- "$path" >actual 2>err && |
| 36 | test_cmp expect actual && |
| 37 | test_must_be_empty err && |
| 38 | |
| 39 | git $git_opts --attr-source="$source" check-attr test -- "$path" >actual 2>err && |
| 40 | test_cmp expect actual && |
| 41 | test_must_be_empty err |
| 42 | |
John Cai | 9f9c40c | 2023-10-13 17:39:30 +0000 | [diff] [blame^] | 43 | git $git_opts -c "attr.tree=$source" check-attr test -- "$path" >actual 2>err && |
| 44 | test_cmp expect actual && |
| 45 | test_must_be_empty err |
| 46 | |
John Cai | 44451a2 | 2023-05-06 04:15:29 +0000 | [diff] [blame] | 47 | GIT_ATTR_SOURCE="$source" git $git_opts check-attr test -- "$path" >actual 2>err && |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 48 | test_cmp expect actual && |
| 49 | test_must_be_empty err |
Nguyễn Thái Ngọc Duy | 860a74d | 2017-01-27 18:01:50 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | test_expect_success 'open-quoted pathname' ' |
| 53 | echo "\"a test=a" >.gitattributes && |
Denton Liu | f46c243 | 2019-12-20 10:15:52 -0800 | [diff] [blame] | 54 | attr_check a unspecified |
Nguyễn Thái Ngọc Duy | 860a74d | 2017-01-27 18:01:50 -0800 | [diff] [blame] | 55 | ' |
| 56 | |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 57 | test_expect_success 'setup' ' |
Michael Haggerty | 0216af8 | 2011-08-04 06:47:45 +0200 | [diff] [blame] | 58 | mkdir -p a/b/d a/c b && |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 59 | ( |
Eric Sunshine | 75651fd | 2018-07-01 20:23:55 -0400 | [diff] [blame] | 60 | echo "[attr]notest !test" && |
| 61 | echo "\" d \" test=d" && |
| 62 | echo " e test=e" && |
| 63 | echo " e\" test=e" && |
| 64 | echo "f test=f" && |
| 65 | echo "a/i test=a/i" && |
| 66 | echo "onoff test -test" && |
| 67 | echo "offon -test test" && |
| 68 | echo "no notest" && |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 69 | echo "A/e/F test=A/e/F" |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 70 | ) >.gitattributes && |
| 71 | ( |
| 72 | echo "g test=a/g" && |
| 73 | echo "b/g test=a/b/g" |
| 74 | ) >a/.gitattributes && |
| 75 | ( |
| 76 | echo "h test=a/b/h" && |
Eric Sunshine | 75651fd | 2018-07-01 20:23:55 -0400 | [diff] [blame] | 77 | echo "d/* test=a/b/d/*" && |
Henrik Grubbström | ec775c4 | 2010-04-06 14:46:44 +0200 | [diff] [blame] | 78 | echo "d/yes notest" |
Michael Haggerty | dcc0436 | 2011-08-04 06:36:15 +0200 | [diff] [blame] | 79 | ) >a/b/.gitattributes && |
Petr Onderka | 6df42ab | 2010-09-01 00:42:43 +0200 | [diff] [blame] | 80 | ( |
| 81 | echo "global test=global" |
Michael Haggerty | c9d8f0a | 2011-08-04 06:36:31 +0200 | [diff] [blame] | 82 | ) >"$HOME"/global-gitattributes && |
Junio C Hamano | 78cec75 | 2011-09-22 16:34:05 -0700 | [diff] [blame] | 83 | cat <<-EOF >expect-all |
| 84 | f: test: f |
| 85 | a/f: test: f |
| 86 | a/c/f: test: f |
| 87 | a/g: test: a/g |
| 88 | a/b/g: test: a/b/g |
| 89 | b/g: test: unspecified |
| 90 | a/b/h: test: a/b/h |
| 91 | a/b/d/g: test: a/b/d/* |
| 92 | onoff: test: unset |
| 93 | offon: test: set |
| 94 | no: notest: set |
| 95 | no: test: unspecified |
| 96 | a/b/d/no: notest: set |
| 97 | a/b/d/no: test: a/b/d/* |
| 98 | a/b/d/yes: notest: set |
| 99 | a/b/d/yes: test: unspecified |
| 100 | EOF |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 101 | ' |
| 102 | |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 103 | test_expect_success 'setup branches' ' |
| 104 | mkdir -p foo/bar && |
| 105 | test_commit --printf "add .gitattributes" foo/bar/.gitattributes \ |
| 106 | "f test=f\na/i test=n\n" tag-1 && |
| 107 | test_commit --printf "add .gitattributes" foo/bar/.gitattributes \ |
| 108 | "g test=g\na/i test=m\n" tag-2 && |
| 109 | rm foo/bar/.gitattributes |
| 110 | ' |
| 111 | |
Michael Haggerty | c0b13b2 | 2011-08-04 06:36:14 +0200 | [diff] [blame] | 112 | test_expect_success 'command line checks' ' |
Michael Haggerty | 09d7dd7 | 2011-08-04 06:36:16 +0200 | [diff] [blame] | 113 | test_must_fail git check-attr && |
| 114 | test_must_fail git check-attr -- && |
Michael Haggerty | fdf6be8 | 2011-08-04 06:36:29 +0200 | [diff] [blame] | 115 | test_must_fail git check-attr test && |
| 116 | test_must_fail git check-attr test -- && |
Michael Haggerty | 09d7dd7 | 2011-08-04 06:36:16 +0200 | [diff] [blame] | 117 | test_must_fail git check-attr -- f && |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 118 | test_must_fail git check-attr --source && |
| 119 | test_must_fail git check-attr --source not-a-valid-ref && |
Michael Haggerty | 09d7dd7 | 2011-08-04 06:36:16 +0200 | [diff] [blame] | 120 | echo "f" | test_must_fail git check-attr --stdin && |
| 121 | echo "f" | test_must_fail git check-attr --stdin -- f && |
| 122 | echo "f" | test_must_fail git check-attr --stdin test -- f && |
Michael Haggerty | c0b13b2 | 2011-08-04 06:36:14 +0200 | [diff] [blame] | 123 | test_must_fail git check-attr "" -- f |
Michael Haggerty | c0b13b2 | 2011-08-04 06:36:14 +0200 | [diff] [blame] | 124 | ' |
| 125 | |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 126 | test_expect_success 'attribute test' ' |
Nguyễn Thái Ngọc Duy | 860a74d | 2017-01-27 18:01:50 -0800 | [diff] [blame] | 127 | |
| 128 | attr_check " d " d && |
| 129 | attr_check e e && |
| 130 | attr_check_quote e\" e\\\" e && |
| 131 | |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 132 | attr_check f f && |
| 133 | attr_check a/f f && |
| 134 | attr_check a/c/f f && |
| 135 | attr_check a/g a/g && |
| 136 | attr_check a/b/g a/b/g && |
| 137 | attr_check b/g unspecified && |
| 138 | attr_check a/b/h a/b/h && |
Matthieu Moy | 520ea85 | 2010-08-28 20:18:36 +0200 | [diff] [blame] | 139 | attr_check a/b/d/g "a/b/d/*" && |
| 140 | attr_check onoff unset && |
| 141 | attr_check offon set && |
| 142 | attr_check no unspecified && |
| 143 | attr_check a/b/d/no "a/b/d/*" && |
Henrik Grubbström | ec775c4 | 2010-04-06 14:46:44 +0200 | [diff] [blame] | 144 | attr_check a/b/d/yes unspecified |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 145 | ' |
| 146 | |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 147 | test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' ' |
| 148 | |
Denton Liu | f46c243 | 2019-12-20 10:15:52 -0800 | [diff] [blame] | 149 | attr_check F unspecified "-c core.ignorecase=0" && |
| 150 | attr_check a/F unspecified "-c core.ignorecase=0" && |
| 151 | attr_check a/c/F unspecified "-c core.ignorecase=0" && |
| 152 | attr_check a/G unspecified "-c core.ignorecase=0" && |
| 153 | attr_check a/B/g a/g "-c core.ignorecase=0" && |
| 154 | attr_check a/b/G unspecified "-c core.ignorecase=0" && |
| 155 | attr_check a/b/H unspecified "-c core.ignorecase=0" && |
| 156 | attr_check a/b/D/g a/g "-c core.ignorecase=0" && |
| 157 | attr_check oNoFf unspecified "-c core.ignorecase=0" && |
| 158 | attr_check oFfOn unspecified "-c core.ignorecase=0" && |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 159 | attr_check NO unspecified "-c core.ignorecase=0" && |
Denton Liu | f46c243 | 2019-12-20 10:15:52 -0800 | [diff] [blame] | 160 | attr_check a/b/D/NO unspecified "-c core.ignorecase=0" && |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 161 | attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" && |
Denton Liu | f46c243 | 2019-12-20 10:15:52 -0800 | [diff] [blame] | 162 | attr_check a/E/f f "-c core.ignorecase=0" |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 163 | |
| 164 | ' |
| 165 | |
| 166 | test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' ' |
| 167 | |
| 168 | attr_check F f "-c core.ignorecase=1" && |
| 169 | attr_check a/F f "-c core.ignorecase=1" && |
| 170 | attr_check a/c/F f "-c core.ignorecase=1" && |
| 171 | attr_check a/G a/g "-c core.ignorecase=1" && |
| 172 | attr_check a/B/g a/b/g "-c core.ignorecase=1" && |
| 173 | attr_check a/b/G a/b/g "-c core.ignorecase=1" && |
| 174 | attr_check a/b/H a/b/h "-c core.ignorecase=1" && |
| 175 | attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" && |
| 176 | attr_check oNoFf unset "-c core.ignorecase=1" && |
| 177 | attr_check oFfOn set "-c core.ignorecase=1" && |
| 178 | attr_check NO unspecified "-c core.ignorecase=1" && |
| 179 | attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" && |
| 180 | attr_check a/b/d/YES unspecified "-c core.ignorecase=1" && |
| 181 | attr_check a/E/f "A/e/F" "-c core.ignorecase=1" |
| 182 | |
| 183 | ' |
| 184 | |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 185 | test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' |
Denton Liu | f46c243 | 2019-12-20 10:15:52 -0800 | [diff] [blame] | 186 | attr_check a/B/D/g a/g "-c core.ignorecase=0" && |
| 187 | attr_check A/B/D/NO unspecified "-c core.ignorecase=0" && |
Brandon Casey | 6eba621 | 2011-10-11 10:53:31 -0500 | [diff] [blame] | 188 | attr_check A/b/h a/b/h "-c core.ignorecase=1" && |
| 189 | attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" && |
| 190 | attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1" |
| 191 | ' |
| 192 | |
Michael Haggerty | f5114a4 | 2011-08-04 06:47:46 +0200 | [diff] [blame] | 193 | test_expect_success 'unnormalized paths' ' |
Michael Haggerty | d4d4f8d | 2011-08-04 06:47:44 +0200 | [diff] [blame] | 194 | attr_check ./f f && |
| 195 | attr_check ./a/g a/g && |
| 196 | attr_check a/./g a/g && |
| 197 | attr_check a/c/../b/g a/b/g |
Michael Haggerty | d4d4f8d | 2011-08-04 06:47:44 +0200 | [diff] [blame] | 198 | ' |
| 199 | |
Michael Haggerty | f5114a4 | 2011-08-04 06:47:46 +0200 | [diff] [blame] | 200 | test_expect_success 'relative paths' ' |
Michael Haggerty | 0216af8 | 2011-08-04 06:47:45 +0200 | [diff] [blame] | 201 | (cd a && attr_check ../f f) && |
| 202 | (cd a && attr_check f f) && |
| 203 | (cd a && attr_check i a/i) && |
| 204 | (cd a && attr_check g a/g) && |
| 205 | (cd a && attr_check b/g a/b/g) && |
| 206 | (cd b && attr_check ../a/f f) && |
| 207 | (cd b && attr_check ../a/g a/g) && |
| 208 | (cd b && attr_check ../a/b/g a/b/g) |
Michael Haggerty | 0216af8 | 2011-08-04 06:47:45 +0200 | [diff] [blame] | 209 | ' |
| 210 | |
Jeff King | 1afca44 | 2012-01-10 13:08:21 -0500 | [diff] [blame] | 211 | test_expect_success 'prefixes are not confused with leading directories' ' |
| 212 | attr_check a_plus/g unspecified && |
| 213 | cat >expect <<-\EOF && |
| 214 | a/g: test: a/g |
| 215 | a_plus/g: test: unspecified |
| 216 | EOF |
| 217 | git check-attr test a/g a_plus/g >actual && |
| 218 | test_cmp expect actual |
| 219 | ' |
| 220 | |
Petr Onderka | 6df42ab | 2010-09-01 00:42:43 +0200 | [diff] [blame] | 221 | test_expect_success 'core.attributesfile' ' |
| 222 | attr_check global unspecified && |
| 223 | git config core.attributesfile "$HOME/global-gitattributes" && |
| 224 | attr_check global global && |
| 225 | git config core.attributesfile "~/global-gitattributes" && |
| 226 | attr_check global global && |
Junio C Hamano | 78cec75 | 2011-09-22 16:34:05 -0700 | [diff] [blame] | 227 | echo "global test=precedence" >>.gitattributes && |
Petr Onderka | 6df42ab | 2010-09-01 00:42:43 +0200 | [diff] [blame] | 228 | attr_check global precedence |
| 229 | ' |
| 230 | |
Dmitry Potapov | b466685 | 2008-10-07 04:16:52 +0400 | [diff] [blame] | 231 | test_expect_success 'attribute test: read paths from stdin' ' |
Junio C Hamano | 78cec75 | 2011-09-22 16:34:05 -0700 | [diff] [blame] | 232 | grep -v notest <expect-all >expect && |
| 233 | sed -e "s/:.*//" <expect | git check-attr --stdin test >actual && |
Dmitry Potapov | b466685 | 2008-10-07 04:16:52 +0400 | [diff] [blame] | 234 | test_cmp expect actual |
| 235 | ' |
| 236 | |
Karthik Nayak | c847e8c | 2023-01-14 09:30:37 +0100 | [diff] [blame] | 237 | test_expect_success 'setup --all option' ' |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 238 | grep -v unspecified <expect-all | sort >specified-all && |
Karthik Nayak | c847e8c | 2023-01-14 09:30:37 +0100 | [diff] [blame] | 239 | sed -e "s/:.*//" <expect-all | uniq >stdin-all |
| 240 | ' |
| 241 | |
| 242 | test_expect_success 'attribute test: --all option' ' |
Shubham Mishra | ae5d569 | 2022-02-23 17:23:47 +0530 | [diff] [blame] | 243 | git check-attr --stdin --all <stdin-all >tmp && |
| 244 | sort tmp >actual && |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 245 | test_cmp specified-all actual |
| 246 | ' |
| 247 | |
| 248 | test_expect_success 'attribute test: --cached option' ' |
Shubham Mishra | ae5d569 | 2022-02-23 17:23:47 +0530 | [diff] [blame] | 249 | git check-attr --cached --stdin --all <stdin-all >tmp && |
| 250 | sort tmp >actual && |
SZEDER Gábor | 1c5e94f | 2018-08-19 23:57:25 +0200 | [diff] [blame] | 251 | test_must_be_empty actual && |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 252 | git add .gitattributes a/.gitattributes a/b/.gitattributes && |
Shubham Mishra | ae5d569 | 2022-02-23 17:23:47 +0530 | [diff] [blame] | 253 | git check-attr --cached --stdin --all <stdin-all >tmp && |
| 254 | sort tmp >actual && |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 255 | test_cmp specified-all actual |
Michael Haggerty | 4ca0f18 | 2011-08-04 06:36:30 +0200 | [diff] [blame] | 256 | ' |
| 257 | |
Matthew Ogilvie | 82881b3 | 2008-04-22 12:19:12 -0600 | [diff] [blame] | 258 | test_expect_success 'root subdir attribute test' ' |
Matthew Ogilvie | 82881b3 | 2008-04-22 12:19:12 -0600 | [diff] [blame] | 259 | attr_check a/i a/i && |
| 260 | attr_check subdir/a/i unspecified |
Matthew Ogilvie | 82881b3 | 2008-04-22 12:19:12 -0600 | [diff] [blame] | 261 | ' |
| 262 | |
Nguyễn Thái Ngọc Duy | 82dce99 | 2012-10-15 13:24:39 +0700 | [diff] [blame] | 263 | test_expect_success 'negative patterns' ' |
| 264 | echo "!f test=bar" >.gitattributes && |
Thomas Rast | 8b1bd02 | 2013-03-01 21:06:17 +0100 | [diff] [blame] | 265 | git check-attr test -- '"'"'!f'"'"' 2>errors && |
| 266 | test_i18ngrep "Negative patterns are ignored" errors |
Nguyễn Thái Ngọc Duy | 82dce99 | 2012-10-15 13:24:39 +0700 | [diff] [blame] | 267 | ' |
| 268 | |
| 269 | test_expect_success 'patterns starting with exclamation' ' |
| 270 | echo "\!f test=foo" >.gitattributes && |
| 271 | attr_check "!f" foo |
| 272 | ' |
| 273 | |
Nguyễn Thái Ngọc Duy | 237ec6e | 2012-10-15 13:26:02 +0700 | [diff] [blame] | 274 | test_expect_success '"**" test' ' |
| 275 | echo "**/f foo=bar" >.gitattributes && |
| 276 | cat <<\EOF >expect && |
| 277 | f: foo: bar |
| 278 | a/f: foo: bar |
| 279 | a/b/f: foo: bar |
| 280 | a/b/c/f: foo: bar |
| 281 | EOF |
| 282 | git check-attr foo -- "f" >actual 2>err && |
| 283 | git check-attr foo -- "a/f" >>actual 2>>err && |
| 284 | git check-attr foo -- "a/b/f" >>actual 2>>err && |
| 285 | git check-attr foo -- "a/b/c/f" >>actual 2>>err && |
| 286 | test_cmp expect actual && |
Denton Liu | 99c049b | 2019-12-20 10:15:51 -0800 | [diff] [blame] | 287 | test_must_be_empty err |
Nguyễn Thái Ngọc Duy | 237ec6e | 2012-10-15 13:26:02 +0700 | [diff] [blame] | 288 | ' |
| 289 | |
| 290 | test_expect_success '"**" with no slashes test' ' |
| 291 | echo "a**f foo=bar" >.gitattributes && |
| 292 | git check-attr foo -- "f" >actual && |
| 293 | cat <<\EOF >expect && |
| 294 | f: foo: unspecified |
| 295 | af: foo: bar |
| 296 | axf: foo: bar |
| 297 | a/f: foo: unspecified |
| 298 | a/b/f: foo: unspecified |
| 299 | a/b/c/f: foo: unspecified |
| 300 | EOF |
| 301 | git check-attr foo -- "f" >actual 2>err && |
| 302 | git check-attr foo -- "af" >>actual 2>err && |
| 303 | git check-attr foo -- "axf" >>actual 2>err && |
| 304 | git check-attr foo -- "a/f" >>actual 2>>err && |
| 305 | git check-attr foo -- "a/b/f" >>actual 2>>err && |
| 306 | git check-attr foo -- "a/b/c/f" >>actual 2>>err && |
| 307 | test_cmp expect actual && |
Denton Liu | 99c049b | 2019-12-20 10:15:51 -0800 | [diff] [blame] | 308 | test_must_be_empty err |
Nguyễn Thái Ngọc Duy | 237ec6e | 2012-10-15 13:26:02 +0700 | [diff] [blame] | 309 | ' |
| 310 | |
Junio C Hamano | cdbf623 | 2014-02-06 10:19:33 -0800 | [diff] [blame] | 311 | test_expect_success 'using --git-dir and --work-tree' ' |
| 312 | mkdir unreal real && |
| 313 | git init real && |
| 314 | echo "file test=in-real" >real/.gitattributes && |
| 315 | ( |
| 316 | cd unreal && |
| 317 | attr_check file in-real "--git-dir ../real/.git --work-tree ../real" |
| 318 | ) |
| 319 | ' |
| 320 | |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 321 | test_expect_success 'using --source' ' |
| 322 | attr_check_source foo/bar/f f tag-1 && |
| 323 | attr_check_source foo/bar/a/i n tag-1 && |
| 324 | attr_check_source foo/bar/f unspecified tag-2 && |
| 325 | attr_check_source foo/bar/a/i m tag-2 && |
| 326 | attr_check_source foo/bar/g g tag-2 && |
| 327 | attr_check_source foo/bar/g unspecified tag-1 |
| 328 | ' |
| 329 | |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 330 | test_expect_success 'setup bare' ' |
Ævar Arnfjörð Bjarmason | 8da0b02 | 2022-06-03 13:15:06 +0200 | [diff] [blame] | 331 | git clone --template= --bare . bare.git |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 332 | ' |
| 333 | |
| 334 | test_expect_success 'bare repository: check that .gitattribute is ignored' ' |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 335 | ( |
Junio C Hamano | c4a7bce | 2014-02-06 10:16:27 -0800 | [diff] [blame] | 336 | cd bare.git && |
| 337 | ( |
Eric Sunshine | 75651fd | 2018-07-01 20:23:55 -0400 | [diff] [blame] | 338 | echo "f test=f" && |
Junio C Hamano | c4a7bce | 2014-02-06 10:16:27 -0800 | [diff] [blame] | 339 | echo "a/i test=a/i" |
| 340 | ) >.gitattributes && |
| 341 | attr_check f unspecified && |
| 342 | attr_check a/f unspecified && |
| 343 | attr_check a/c/f unspecified && |
| 344 | attr_check a/i unspecified && |
| 345 | attr_check subdir/a/i unspecified |
| 346 | ) |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 347 | ' |
| 348 | |
John Cai | 9f9c40c | 2023-10-13 17:39:30 +0000 | [diff] [blame^] | 349 | bad_attr_source_err="fatal: bad --attr-source or GIT_ATTR_SOURCE" |
| 350 | |
| 351 | test_expect_success '--attr-source is bad' ' |
| 352 | test_when_finished rm -rf empty && |
| 353 | git init empty && |
| 354 | ( |
| 355 | cd empty && |
| 356 | echo "$bad_attr_source_err" >expect_err && |
| 357 | test_must_fail git --attr-source=HEAD check-attr test -- f/path 2>err && |
| 358 | test_cmp expect_err err |
| 359 | ) |
| 360 | ' |
| 361 | |
| 362 | test_expect_success 'attr.tree when HEAD is unborn' ' |
| 363 | test_when_finished rm -rf empty && |
| 364 | git init empty && |
| 365 | ( |
| 366 | cd empty && |
| 367 | echo "f/path: test: unspecified" >expect && |
| 368 | git -c attr.tree=HEAD check-attr test -- f/path >actual 2>err && |
| 369 | test_must_be_empty err && |
| 370 | test_cmp expect actual |
| 371 | ) |
| 372 | ' |
| 373 | |
| 374 | test_expect_success 'bad attr source defaults to reading .gitattributes file' ' |
| 375 | test_when_finished rm -rf empty && |
| 376 | git init empty && |
| 377 | ( |
| 378 | cd empty && |
| 379 | echo "f/path test=val" >.gitattributes && |
| 380 | echo "f/path: test: val" >expect && |
| 381 | git -c attr.tree=HEAD check-attr test -- f/path >actual 2>err && |
| 382 | test_must_be_empty err && |
| 383 | test_cmp expect actual |
| 384 | ) |
| 385 | ' |
John Cai | 2386535 | 2023-10-13 17:39:29 +0000 | [diff] [blame] | 386 | |
| 387 | test_expect_success 'bare repo defaults to reading .gitattributes from HEAD' ' |
| 388 | test_when_finished rm -rf test bare_with_gitattribute && |
| 389 | git init test && |
| 390 | test_commit -C test gitattributes .gitattributes "f/path test=val" && |
| 391 | git clone --bare test bare_with_gitattribute && |
| 392 | echo "f/path: test: val" >expect && |
| 393 | git -C bare_with_gitattribute check-attr test -- f/path >actual && |
| 394 | test_cmp expect actual |
| 395 | ' |
| 396 | |
John Cai | 9f9c40c | 2023-10-13 17:39:30 +0000 | [diff] [blame^] | 397 | test_expect_success 'precedence of --attr-source, GIT_ATTR_SOURCE, then attr.tree' ' |
| 398 | test_when_finished rm -rf empty && |
| 399 | git init empty && |
| 400 | ( |
| 401 | cd empty && |
| 402 | git checkout -b attr-source && |
| 403 | test_commit "val1" .gitattributes "f/path test=val1" && |
| 404 | git checkout -b attr-tree && |
| 405 | test_commit "val2" .gitattributes "f/path test=val2" && |
| 406 | git checkout attr-source && |
| 407 | echo "f/path: test: val1" >expect && |
| 408 | GIT_ATTR_SOURCE=attr-source git -c attr.tree=attr-tree --attr-source=attr-source \ |
| 409 | check-attr test -- f/path >actual && |
| 410 | test_cmp expect actual && |
| 411 | GIT_ATTR_SOURCE=attr-source git -c attr.tree=attr-tree \ |
| 412 | check-attr test -- f/path >actual && |
| 413 | test_cmp expect actual |
| 414 | ) |
| 415 | ' |
| 416 | |
Karthik Nayak | 47cfc9b | 2023-01-14 09:30:38 +0100 | [diff] [blame] | 417 | test_expect_success 'bare repository: with --source' ' |
| 418 | ( |
| 419 | cd bare.git && |
| 420 | attr_check_source foo/bar/f f tag-1 && |
| 421 | attr_check_source foo/bar/a/i n tag-1 && |
| 422 | attr_check_source foo/bar/f unspecified tag-2 && |
| 423 | attr_check_source foo/bar/a/i m tag-2 && |
| 424 | attr_check_source foo/bar/g g tag-2 && |
| 425 | attr_check_source foo/bar/g unspecified tag-1 |
| 426 | ) |
| 427 | ' |
| 428 | |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 429 | test_expect_success 'bare repository: check that --cached honors index' ' |
Junio C Hamano | c4a7bce | 2014-02-06 10:16:27 -0800 | [diff] [blame] | 430 | ( |
| 431 | cd bare.git && |
| 432 | GIT_INDEX_FILE=../.git/index \ |
| 433 | git check-attr --cached --stdin --all <../stdin-all | |
| 434 | sort >actual && |
| 435 | test_cmp ../specified-all actual |
| 436 | ) |
Jay Soffian | b2b3e9c | 2011-09-22 17:44:20 -0400 | [diff] [blame] | 437 | ' |
| 438 | |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 439 | test_expect_success 'bare repository: test info/attributes' ' |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 440 | ( |
Junio C Hamano | c4a7bce | 2014-02-06 10:16:27 -0800 | [diff] [blame] | 441 | cd bare.git && |
Ævar Arnfjörð Bjarmason | 8da0b02 | 2022-06-03 13:15:06 +0200 | [diff] [blame] | 442 | mkdir info && |
Junio C Hamano | c4a7bce | 2014-02-06 10:16:27 -0800 | [diff] [blame] | 443 | ( |
Eric Sunshine | 75651fd | 2018-07-01 20:23:55 -0400 | [diff] [blame] | 444 | echo "f test=f" && |
Junio C Hamano | c4a7bce | 2014-02-06 10:16:27 -0800 | [diff] [blame] | 445 | echo "a/i test=a/i" |
| 446 | ) >info/attributes && |
| 447 | attr_check f f && |
| 448 | attr_check a/f f && |
| 449 | attr_check a/c/f f && |
| 450 | attr_check a/i a/i && |
| 451 | attr_check subdir/a/i unspecified |
| 452 | ) |
René Scharfe | 2d35d55 | 2008-06-08 17:16:11 +0200 | [diff] [blame] | 453 | ' |
| 454 | |
Jeff King | 7b95849 | 2019-01-18 16:34:58 -0500 | [diff] [blame] | 455 | test_expect_success 'binary macro expanded by -a' ' |
| 456 | echo "file binary" >.gitattributes && |
| 457 | cat >expect <<-\EOF && |
| 458 | file: binary: set |
| 459 | file: diff: unset |
| 460 | file: merge: unset |
| 461 | file: text: unset |
| 462 | EOF |
| 463 | git check-attr -a file >actual && |
| 464 | test_cmp expect actual |
| 465 | ' |
| 466 | |
Jeff King | 7b95849 | 2019-01-18 16:34:58 -0500 | [diff] [blame] | 467 | test_expect_success 'query binary macro directly' ' |
| 468 | echo "file binary" >.gitattributes && |
| 469 | echo file: binary: set >expect && |
| 470 | git check-attr binary file >actual && |
| 471 | test_cmp expect actual |
| 472 | ' |
| 473 | |
Jeff King | 2ef579e2 | 2021-02-16 09:44:32 -0500 | [diff] [blame] | 474 | test_expect_success SYMLINKS 'set up symlink tests' ' |
| 475 | echo "* test" >attr && |
| 476 | rm -f .gitattributes |
| 477 | ' |
| 478 | |
| 479 | test_expect_success SYMLINKS 'symlinks respected in core.attributesFile' ' |
| 480 | test_when_finished "rm symlink" && |
| 481 | ln -s attr symlink && |
| 482 | test_config core.attributesFile "$(pwd)/symlink" && |
| 483 | attr_check file set |
| 484 | ' |
| 485 | |
| 486 | test_expect_success SYMLINKS 'symlinks respected in info/attributes' ' |
| 487 | test_when_finished "rm .git/info/attributes" && |
Ævar Arnfjörð Bjarmason | 8da0b02 | 2022-06-03 13:15:06 +0200 | [diff] [blame] | 488 | mkdir .git/info && |
Jeff King | 2ef579e2 | 2021-02-16 09:44:32 -0500 | [diff] [blame] | 489 | ln -s ../../attr .git/info/attributes && |
| 490 | attr_check file set |
| 491 | ' |
| 492 | |
| 493 | test_expect_success SYMLINKS 'symlinks not respected in-tree' ' |
| 494 | test_when_finished "rm -rf .gitattributes subdir" && |
| 495 | ln -s attr .gitattributes && |
| 496 | mkdir subdir && |
| 497 | ln -s ../attr subdir/.gitattributes && |
| 498 | attr_check_basic subdir/file unspecified && |
| 499 | test_i18ngrep "unable to access.*gitattributes" err |
| 500 | ' |
| 501 | |
Patrick Steinhardt | dfa6b32 | 2022-12-01 15:45:48 +0100 | [diff] [blame] | 502 | test_expect_success 'large attributes line ignored in tree' ' |
| 503 | test_when_finished "rm .gitattributes" && |
| 504 | printf "path %02043d" 1 >.gitattributes && |
| 505 | git check-attr --all path >actual 2>err && |
| 506 | echo "warning: ignoring overly long attributes line 1" >expect && |
| 507 | test_cmp expect err && |
| 508 | test_must_be_empty actual |
| 509 | ' |
| 510 | |
Patrick Steinhardt | d74b1fd | 2022-12-01 15:45:44 +0100 | [diff] [blame] | 511 | test_expect_success 'large attributes line ignores trailing content in tree' ' |
| 512 | test_when_finished "rm .gitattributes" && |
| 513 | # older versions of Git broke lines at 2048 bytes; the 2045 bytes |
| 514 | # of 0-padding here is accounting for the three bytes of "a 1", which |
| 515 | # would knock "trailing" to the "next" line, where it would be |
| 516 | # erroneously parsed. |
| 517 | printf "a %02045dtrailing attribute\n" 1 >.gitattributes && |
| 518 | git check-attr --all trailing >actual 2>err && |
Patrick Steinhardt | dfa6b32 | 2022-12-01 15:45:48 +0100 | [diff] [blame] | 519 | echo "warning: ignoring overly long attributes line 1" >expect && |
| 520 | test_cmp expect err && |
| 521 | test_must_be_empty actual |
| 522 | ' |
| 523 | |
Patrick Steinhardt | 3c50032 | 2022-12-01 15:45:53 +0100 | [diff] [blame] | 524 | test_expect_success EXPENSIVE 'large attributes file ignored in tree' ' |
| 525 | test_when_finished "rm .gitattributes" && |
Torsten Bögershausen | 5458ba0 | 2023-01-22 07:28:39 +0100 | [diff] [blame] | 526 | dd if=/dev/zero of=.gitattributes bs=1048576 count=101 2>/dev/null && |
Patrick Steinhardt | 3c50032 | 2022-12-01 15:45:53 +0100 | [diff] [blame] | 527 | git check-attr --all path >/dev/null 2>err && |
| 528 | echo "warning: ignoring overly large gitattributes file ${SQ}.gitattributes${SQ}" >expect && |
| 529 | test_cmp expect err |
| 530 | ' |
| 531 | |
Patrick Steinhardt | dfa6b32 | 2022-12-01 15:45:48 +0100 | [diff] [blame] | 532 | test_expect_success 'large attributes line ignored in index' ' |
| 533 | test_when_finished "git update-index --remove .gitattributes" && |
| 534 | blob=$(printf "path %02043d" 1 | git hash-object -w --stdin) && |
| 535 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && |
| 536 | git check-attr --cached --all path >actual 2>err && |
| 537 | echo "warning: ignoring overly long attributes line 1" >expect && |
| 538 | test_cmp expect err && |
Patrick Steinhardt | d74b1fd | 2022-12-01 15:45:44 +0100 | [diff] [blame] | 539 | test_must_be_empty actual |
| 540 | ' |
| 541 | |
| 542 | test_expect_success 'large attributes line ignores trailing content in index' ' |
| 543 | test_when_finished "git update-index --remove .gitattributes" && |
| 544 | blob=$(printf "a %02045dtrailing attribute\n" 1 | git hash-object -w --stdin) && |
| 545 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && |
| 546 | git check-attr --cached --all trailing >actual 2>err && |
Patrick Steinhardt | dfa6b32 | 2022-12-01 15:45:48 +0100 | [diff] [blame] | 547 | echo "warning: ignoring overly long attributes line 1" >expect && |
| 548 | test_cmp expect err && |
Patrick Steinhardt | d74b1fd | 2022-12-01 15:45:44 +0100 | [diff] [blame] | 549 | test_must_be_empty actual |
| 550 | ' |
| 551 | |
Patrick Steinhardt | 3c50032 | 2022-12-01 15:45:53 +0100 | [diff] [blame] | 552 | test_expect_success EXPENSIVE 'large attributes file ignored in index' ' |
| 553 | test_when_finished "git update-index --remove .gitattributes" && |
Torsten Bögershausen | 5458ba0 | 2023-01-22 07:28:39 +0100 | [diff] [blame] | 554 | blob=$(dd if=/dev/zero bs=1048576 count=101 2>/dev/null | git hash-object -w --stdin) && |
Patrick Steinhardt | 3c50032 | 2022-12-01 15:45:53 +0100 | [diff] [blame] | 555 | git update-index --add --cacheinfo 100644,$blob,.gitattributes && |
| 556 | git check-attr --cached --all path >/dev/null 2>err && |
| 557 | echo "warning: ignoring overly large gitattributes blob ${SQ}.gitattributes${SQ}" >expect && |
| 558 | test_cmp expect err |
| 559 | ' |
| 560 | |
Junio C Hamano | cf94ccd | 2008-02-07 00:02:08 -0800 | [diff] [blame] | 561 | test_done |