File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -452,6 +452,11 @@ example the following invocations are equivalent:
452
452
given will override values from configuration files.
453
453
The <name> is expected in the same format as listed by
454
454
'git config' (subkeys separated by dots).
455
+ +
456
+ Note that omitting the `=` in `git -c foo.bar ...` is allowed and sets
457
+ `foo.bar` to the boolean true value (just like `[foo]bar` would in a
458
+ config file). Including the equals but with an empty value (like `git -c
459
+ foo.bar= ...`) sets `foo.bar` to the empty string.
455
460
456
461
--exec-path[=<path>]::
457
462
Path to wherever your core Git programs are installed.
Original file line number Diff line number Diff line change @@ -162,19 +162,27 @@ void git_config_push_parameter(const char *text)
162
162
int git_config_parse_parameter (const char * text ,
163
163
config_fn_t fn , void * data )
164
164
{
165
+ const char * value ;
165
166
struct strbuf * * pair ;
167
+
166
168
pair = strbuf_split_str (text , '=' , 2 );
167
169
if (!pair [0 ])
168
170
return error ("bogus config parameter: %s" , text );
169
- if (pair [0 ]-> len && pair [0 ]-> buf [pair [0 ]-> len - 1 ] == '=' )
171
+
172
+ if (pair [0 ]-> len && pair [0 ]-> buf [pair [0 ]-> len - 1 ] == '=' ) {
170
173
strbuf_setlen (pair [0 ], pair [0 ]-> len - 1 );
174
+ value = pair [1 ] ? pair [1 ]-> buf : "" ;
175
+ } else {
176
+ value = NULL ;
177
+ }
178
+
171
179
strbuf_trim (pair [0 ]);
172
180
if (!pair [0 ]-> len ) {
173
181
strbuf_list_free (pair );
174
182
return error ("bogus config parameter: %s" , text );
175
183
}
176
184
strbuf_tolower (pair [0 ]);
177
- if (fn (pair [0 ]-> buf , pair [ 1 ] ? pair [ 1 ] -> buf : NULL , data ) < 0 ) {
185
+ if (fn (pair [0 ]-> buf , value , data ) < 0 ) {
178
186
strbuf_list_free (pair );
179
187
return -1 ;
180
188
}
Original file line number Diff line number Diff line change @@ -1010,6 +1010,17 @@ test_expect_success 'git -c "key=value" support' '
1010
1010
test_must_fail git -c name=value config core.name
1011
1011
'
1012
1012
1013
+ # We just need a type-specifier here that cares about the
1014
+ # distinction internally between a NULL boolean and a real
1015
+ # string (because most of git's internal parsers do care).
1016
+ # Using "--path" works, but we do not otherwise care about
1017
+ # its semantics.
1018
+ test_expect_success ' git -c can represent empty string' '
1019
+ echo >expect &&
1020
+ git -c foo.empty= config --path foo.empty >actual &&
1021
+ test_cmp expect actual
1022
+ '
1023
+
1013
1024
test_expect_success ' key sanity-checking' '
1014
1025
test_must_fail git config foo=bar &&
1015
1026
test_must_fail git config foo=.bar &&
You can’t perform that action at this time.
0 commit comments