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:
452452 given will override values from configuration files.
453453 The <name> is expected in the same format as listed by
454454 '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.
455460
456461--exec-path[=<path>]::
457462 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)
162162int git_config_parse_parameter (const char * text ,
163163 config_fn_t fn , void * data )
164164{
165+ const char * value ;
165166 struct strbuf * * pair ;
167+
166168 pair = strbuf_split_str (text , '=' , 2 );
167169 if (!pair [0 ])
168170 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 ] == '=' ) {
170173 strbuf_setlen (pair [0 ], pair [0 ]-> len - 1 );
174+ value = pair [1 ] ? pair [1 ]-> buf : "" ;
175+ } else {
176+ value = NULL ;
177+ }
178+
171179 strbuf_trim (pair [0 ]);
172180 if (!pair [0 ]-> len ) {
173181 strbuf_list_free (pair );
174182 return error ("bogus config parameter: %s" , text );
175183 }
176184 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 ) {
178186 strbuf_list_free (pair );
179187 return -1 ;
180188 }
Original file line number Diff line number Diff line change @@ -1010,6 +1010,17 @@ test_expect_success 'git -c "key=value" support' '
10101010 test_must_fail git -c name=value config core.name
10111011'
10121012
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+
10131024test_expect_success ' key sanity-checking' '
10141025 test_must_fail git config foo=bar &&
10151026 test_must_fail git config foo=.bar &&
You can’t perform that action at this time.
0 commit comments