3 test_description
='Test git config-set API in different settings'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 # 'check_config get_* section.key value' verifies that the entry for
9 # section.key is 'value'
11 if test "$1" = expect_code
13 expect_code
="$2" && shift && shift
17 op
=$1 key
=$2 && shift && shift &&
22 test_expect_code
$expect_code test-tool config
"$op" "$key" >actual
&&
23 test_cmp expect actual
26 test_expect_success
'setup default config' '
27 cat >.git/config <<-\EOF
64 test_expect_success
'get value for a simple key' '
65 check_config get_value case.penguin "very blue"
68 test_expect_success
'get value for a key with value as an empty string' '
69 check_config get_value case.my ""
72 test_expect_success
'get value for a key with value as NULL' '
73 check_config get_value case.foo "(NULL)"
76 test_expect_success
'upper case key' '
77 check_config get_value case.UPPERCASE "true" &&
78 check_config get_value case.uppercase "true"
81 test_expect_success
'mixed case key' '
82 check_config get_value case.MixedCase "true" &&
83 check_config get_value case.MIXEDCASE "true" &&
84 check_config get_value case.mixedcase "true"
87 test_expect_success
'key and value with mixed case' '
88 check_config get_value case.Movie "BadPhysics"
91 test_expect_success
'key with case sensitive subsection' '
92 check_config get_value "my.Foo bAr.hi" "mixed-case" &&
93 check_config get_value "my.FOO BAR.hi" "upper-case" &&
94 check_config get_value "my.foo bar.hi" "lower-case"
97 test_expect_success
'key with case insensitive section header' '
98 check_config get_value cores.baz "ball" &&
99 check_config get_value Cores.baz "ball" &&
100 check_config get_value CORES.baz "ball" &&
101 check_config get_value coreS.baz "ball"
104 test_expect_success
'key with case insensitive section header & variable' '
105 check_config get_value CORES.BAZ "ball" &&
106 check_config get_value cores.baz "ball" &&
107 check_config get_value cores.BaZ "ball" &&
108 check_config get_value cOreS.bAz "ball"
111 test_expect_success
'find value with misspelled key' '
112 check_config expect_code 1 get_value "my.fOo Bar.hi" "Value not found for \"my.fOo Bar.hi\""
115 test_expect_success
'find value with the highest priority' '
116 check_config get_value case.baz "hask"
119 test_expect_success
'find integer value for a key' '
120 check_config get_int lamb.chop 65
123 test_expect_success
'find string value for a key' '
124 check_config get_string case.baz hask &&
125 check_config expect_code 1 get_string case.ba "Value not found for \"case.ba\""
128 test_expect_success
'check line error when NULL string is queried' '
129 test_expect_code 128 test-tool config get_string case.foo 2>result &&
130 test_i18ngrep "fatal: .*case\.foo.*\.git/config.*line 7" result
133 test_expect_success
'find integer if value is non parse-able' '
134 check_config expect_code 128 get_int lamb.head
137 test_expect_success
'find bool value for the entered key' '
138 check_config get_bool goat.head 1 &&
139 check_config get_bool goat.skin 0 &&
140 check_config get_bool goat.nose 1 &&
141 check_config get_bool goat.horns 1 &&
142 check_config get_bool goat.legs 1
145 test_expect_success
'find multiple values' '
146 check_config get_value_multi case.baz sam bat hask
149 test_NULL_in_multi
() {
153 test_expect_success
"$op: NULL value in config${file:+ in $file}" '
157 config=.git/config &&
158 test_when_finished "mv $config.old $config" &&
159 mv "$config" "$config".old
162 # Value-less in the middle of a list
163 cat >"$config" <<-\EOF &&
182 test-tool config "$op" a.key $file >actual &&
183 test_cmp expect actual &&
185 # Value-less at the end of a least
186 cat >"$config" <<-\EOF &&
205 test-tool config "$op" a.key $file >actual &&
206 test_cmp expect actual
210 test_NULL_in_multi
"get_value_multi"
211 test_NULL_in_multi
"configset_get_value" "my.config"
212 test_NULL_in_multi
"configset_get_value_multi" "my.config"
214 test_expect_success
'find value from a configset' '
215 cat >config2 <<-\EOF &&
224 test-tool config configset_get_value my.new config2 .git/config >actual &&
225 test_cmp expect actual
228 test_expect_success
'find value with highest priority from a configset' '
230 test-tool config configset_get_value case.baz config2 .git/config >actual &&
231 test_cmp expect actual
234 test_expect_success
'find value_list for a key from a configset' '
235 cat >expect <<-\EOF &&
242 test-tool config configset_get_value_multi case.baz config2 .git/config >actual &&
243 test_cmp expect actual
246 test_expect_success
'proper error on non-existent files' '
247 echo "Error (-1) reading configuration file non-existent-file." >expect &&
248 test_expect_code 2 test-tool config configset_get_value foo.bar non-existent-file 2>actual &&
249 test_cmp expect actual
252 test_expect_success
'proper error on directory "files"' '
253 echo "Error (-1) reading configuration file a-directory." >expect &&
255 test_expect_code 2 test-tool config configset_get_value foo.bar a-directory 2>output &&
256 grep "^warning:" output &&
257 grep "^Error" output >actual &&
258 test_cmp expect actual
261 test_expect_success POSIXPERM
,SANITY
'proper error on non-accessible files' '
262 chmod -r .git/config &&
263 test_when_finished "chmod +r .git/config" &&
264 echo "Error (-1) reading configuration file .git/config." >expect &&
265 test_expect_code 2 test-tool config configset_get_value foo.bar .git/config 2>output &&
266 grep "^warning:" output &&
267 grep "^Error" output >actual &&
268 test_cmp expect actual
271 test_expect_success
'proper error on error in default config files' '
272 cp .git/config .git/config.old &&
273 test_when_finished "mv .git/config.old .git/config" &&
274 echo "[" >>.git/config &&
275 echo "fatal: bad config line 34 in file .git/config" >expect &&
276 test_expect_code 128 test-tool config get_value foo.bar 2>actual &&
277 test_cmp expect actual
280 test_expect_success
'proper error on error in custom config files' '
281 echo "[" >>syntax-error &&
282 echo "fatal: bad config line 1 in file syntax-error" >expect &&
283 test_expect_code 128 test-tool config configset_get_value foo.bar syntax-error 2>actual &&
284 test_cmp expect actual
287 test_expect_success
'check line errors for malformed values' '
288 mv .git/config .git/config.old &&
289 test_when_finished "mv .git/config.old .git/config" &&
290 cat >.git/config <<-\EOF &&
294 test_expect_code 128 git br 2>result &&
295 test_i18ngrep "missing value for .alias\.br" result &&
296 test_i18ngrep "fatal: .*\.git/config" result &&
297 test_i18ngrep "fatal: .*line 2" result
300 test_expect_success
'error on modifying repo config without repo' '
301 nongit test_must_fail git config a.b c 2>err &&
302 test_i18ngrep "not in a git directory" err
305 cmdline_config
="'foo.bar=from-cmdline'"
306 test_expect_success
'iteration shows correct origins' '
307 printf "[ignore]\n\tthis = please\n[foo]bar = from-repo\n" >.git/config &&
308 printf "[foo]\n\tbar = from-home\n" >.gitconfig &&
309 if test_have_prereq MINGW
311 # Use Windows path (i.e. *not* $HOME)
312 HOME_GITCONFIG=$(pwd)/.gitconfig
314 # Do not get fooled by symbolic links, i.e. $HOME != $(pwd)
315 HOME_GITCONFIG=$HOME/.gitconfig
317 cat >expect <<-EOF &&
346 GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config iterate >actual &&
347 test_cmp expect actual