3 test_description
='Test git config-set API in different settings'
7 # 'check_config get_* section.key value' verifies that the entry for
8 # section.key is 'value'
10 if test "$1" = expect_code
12 expect_code
="$2" && shift && shift
16 op
=$1 key
=$2 && shift && shift &&
21 test_expect_code
$expect_code test-config
"$op" "$key" >actual
&&
22 test_cmp expect actual
25 test_expect_success
'setup default config' '
26 cat >.git/config <<-\EOF
63 test_expect_success
'get value for a simple key' '
64 check_config get_value case.penguin "very blue"
67 test_expect_success
'get value for a key with value as an empty string' '
68 check_config get_value case.my ""
71 test_expect_success
'get value for a key with value as NULL' '
72 check_config get_value case.foo "(NULL)"
75 test_expect_success
'upper case key' '
76 check_config get_value case.UPPERCASE "true" &&
77 check_config get_value case.uppercase "true"
80 test_expect_success
'mixed case key' '
81 check_config get_value case.MixedCase "true" &&
82 check_config get_value case.MIXEDCASE "true" &&
83 check_config get_value case.mixedcase "true"
86 test_expect_success
'key and value with mixed case' '
87 check_config get_value case.Movie "BadPhysics"
90 test_expect_success
'key with case sensitive subsection' '
91 check_config get_value "my.Foo bAr.hi" "mixed-case" &&
92 check_config get_value "my.FOO BAR.hi" "upper-case" &&
93 check_config get_value "my.foo bar.hi" "lower-case"
96 test_expect_success
'key with case insensitive section header' '
97 check_config get_value cores.baz "ball" &&
98 check_config get_value Cores.baz "ball" &&
99 check_config get_value CORES.baz "ball" &&
100 check_config get_value coreS.baz "ball"
103 test_expect_success
'key with case insensitive section header & variable' '
104 check_config get_value CORES.BAZ "ball" &&
105 check_config get_value cores.baz "ball" &&
106 check_config get_value cores.BaZ "ball" &&
107 check_config get_value cOreS.bAz "ball"
110 test_expect_success
'find value with misspelled key' '
111 check_config expect_code 1 get_value "my.fOo Bar.hi" "Value not found for \"my.fOo Bar.hi\""
114 test_expect_success
'find value with the highest priority' '
115 check_config get_value case.baz "hask"
118 test_expect_success
'find integer value for a key' '
119 check_config get_int lamb.chop 65
122 test_expect_success
'find string value for a key' '
123 check_config get_string case.baz hask &&
124 check_config expect_code 1 get_string case.ba "Value not found for \"case.ba\""
127 test_expect_success
'check line error when NULL string is queried' '
128 test_expect_code 128 test-config get_string case.foo 2>result &&
129 test_i18ngrep "fatal: .*case\.foo.*\.git/config.*line 7" result
132 test_expect_success
'find integer if value is non parse-able' '
133 check_config expect_code 128 get_int lamb.head
136 test_expect_success
'find bool value for the entered key' '
137 check_config get_bool goat.head 1 &&
138 check_config get_bool goat.skin 0 &&
139 check_config get_bool goat.nose 1 &&
140 check_config get_bool goat.horns 1 &&
141 check_config get_bool goat.legs 1
144 test_expect_success
'find multiple values' '
145 check_config get_value_multi case.baz sam bat hask
148 test_expect_success
'find value from a configset' '
149 cat >config2 <<-\EOF &&
158 test-config configset_get_value my.new config2 .git/config >actual &&
159 test_cmp expect actual
162 test_expect_success
'find value with highest priority from a configset' '
164 test-config configset_get_value case.baz config2 .git/config >actual &&
165 test_cmp expect actual
168 test_expect_success
'find value_list for a key from a configset' '
169 cat >except <<-\EOF &&
176 test-config configset_get_value case.baz config2 .git/config >actual &&
177 test_cmp expect actual
180 test_expect_success
'proper error on non-existent files' '
181 echo "Error (-1) reading configuration file non-existent-file." >expect &&
182 test_expect_code 2 test-config configset_get_value foo.bar non-existent-file 2>actual &&
183 test_cmp expect actual
186 test_expect_success
'proper error on directory "files"' '
187 echo "Error (-1) reading configuration file a-directory." >expect &&
189 test_expect_code 2 test-config configset_get_value foo.bar a-directory 2>output &&
190 grep "^warning:" output &&
191 grep "^Error" output >actual &&
192 test_cmp expect actual
195 test_expect_success POSIXPERM
,SANITY
'proper error on non-accessible files' '
196 chmod -r .git/config &&
197 test_when_finished "chmod +r .git/config" &&
198 echo "Error (-1) reading configuration file .git/config." >expect &&
199 test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>output &&
200 grep "^warning:" output &&
201 grep "^Error" output >actual &&
202 test_cmp expect actual
205 test_expect_success
'proper error on error in default config files' '
206 cp .git/config .git/config.old &&
207 test_when_finished "mv .git/config.old .git/config" &&
208 echo "[" >>.git/config &&
209 echo "fatal: bad config line 34 in file .git/config" >expect &&
210 test_expect_code 128 test-config get_value foo.bar 2>actual &&
211 test_i18ncmp expect actual
214 test_expect_success
'proper error on error in custom config files' '
215 echo "[" >>syntax-error &&
216 echo "fatal: bad config line 1 in file syntax-error" >expect &&
217 test_expect_code 128 test-config configset_get_value foo.bar syntax-error 2>actual &&
218 test_i18ncmp expect actual
221 test_expect_success
'check line errors for malformed values' '
222 mv .git/config .git/config.old &&
223 test_when_finished "mv .git/config.old .git/config" &&
224 cat >.git/config <<-\EOF &&
228 test_expect_code 128 git br 2>result &&
229 test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result
232 test_expect_success
'error on modifying repo config without repo' '
233 nongit test_must_fail git config a.b c 2>err &&
234 grep "not in a git directory" err
237 cmdline_config
="'foo.bar=from-cmdline'"
238 test_expect_success
'iteration shows correct origins' '
239 echo "[foo]bar = from-repo" >.git/config &&
240 echo "[foo]bar = from-home" >.gitconfig &&
241 if test_have_prereq MINGW
243 # Use Windows path (i.e. *not* $HOME)
244 HOME_GITCONFIG=$(pwd)/.gitconfig
246 # Do not get fooled by symbolic links, i.e. $HOME != $(pwd)
247 HOME_GITCONFIG=$HOME/.gitconfig
249 cat >expect <<-EOF &&
268 GIT_CONFIG_PARAMETERS=$cmdline_config test-config iterate >actual &&
269 test_cmp expect actual