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_expect_success
'find value from a configset' '
150 cat >config2 <<-\EOF &&
159 test-tool config configset_get_value my.new config2 .git/config >actual &&
160 test_cmp expect actual
163 test_expect_success
'find value with highest priority from a configset' '
165 test-tool config configset_get_value case.baz config2 .git/config >actual &&
166 test_cmp expect actual
169 test_expect_success
'find value_list for a key from a configset' '
170 cat >expect <<-\EOF &&
177 test-tool config configset_get_value_multi case.baz config2 .git/config >actual &&
178 test_cmp expect actual
181 test_expect_success
'proper error on non-existent files' '
182 echo "Error (-1) reading configuration file non-existent-file." >expect &&
183 test_expect_code 2 test-tool config configset_get_value foo.bar non-existent-file 2>actual &&
184 test_cmp expect actual
187 test_expect_success
'proper error on directory "files"' '
188 echo "Error (-1) reading configuration file a-directory." >expect &&
190 test_expect_code 2 test-tool config configset_get_value foo.bar a-directory 2>output &&
191 grep "^warning:" output &&
192 grep "^Error" output >actual &&
193 test_cmp expect actual
196 test_expect_success POSIXPERM
,SANITY
'proper error on non-accessible files' '
197 chmod -r .git/config &&
198 test_when_finished "chmod +r .git/config" &&
199 echo "Error (-1) reading configuration file .git/config." >expect &&
200 test_expect_code 2 test-tool config configset_get_value foo.bar .git/config 2>output &&
201 grep "^warning:" output &&
202 grep "^Error" output >actual &&
203 test_cmp expect actual
206 test_expect_success
'proper error on error in default config files' '
207 cp .git/config .git/config.old &&
208 test_when_finished "mv .git/config.old .git/config" &&
209 echo "[" >>.git/config &&
210 echo "fatal: bad config line 34 in file .git/config" >expect &&
211 test_expect_code 128 test-tool config get_value foo.bar 2>actual &&
212 test_cmp expect actual
215 test_expect_success
'proper error on error in custom config files' '
216 echo "[" >>syntax-error &&
217 echo "fatal: bad config line 1 in file syntax-error" >expect &&
218 test_expect_code 128 test-tool config configset_get_value foo.bar syntax-error 2>actual &&
219 test_cmp expect actual
222 test_expect_success
'check line errors for malformed values' '
223 mv .git/config .git/config.old &&
224 test_when_finished "mv .git/config.old .git/config" &&
225 cat >.git/config <<-\EOF &&
229 test_expect_code 128 git br 2>result &&
230 test_i18ngrep "missing value for .alias\.br" result &&
231 test_i18ngrep "fatal: .*\.git/config" result &&
232 test_i18ngrep "fatal: .*line 2" result
235 test_expect_success
'error on modifying repo config without repo' '
236 nongit test_must_fail git config a.b c 2>err &&
237 test_i18ngrep "not in a git directory" err
240 cmdline_config
="'foo.bar=from-cmdline'"
241 test_expect_success
'iteration shows correct origins' '
242 printf "[ignore]\n\tthis = please\n[foo]bar = from-repo\n" >.git/config &&
243 printf "[foo]\n\tbar = from-home\n" >.gitconfig &&
244 if test_have_prereq MINGW
246 # Use Windows path (i.e. *not* $HOME)
247 HOME_GITCONFIG=$(pwd)/.gitconfig
249 # Do not get fooled by symbolic links, i.e. $HOME != $(pwd)
250 HOME_GITCONFIG=$HOME/.gitconfig
252 cat >expect <<-EOF &&
281 GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config iterate >actual &&
282 test_cmp expect actual