Merge branch 'jk/command-line-config-empty-string' into maint
* jk/command-line-config-empty-string: config: teach "git -c" to recognize an empty string Conflicts: config.cmaint
commit
04cd47f553
|
@ -452,6 +452,11 @@ example the following invocations are equivalent:
|
||||||
given will override values from configuration files.
|
given will override values from configuration files.
|
||||||
The <name> is expected in the same format as listed by
|
The <name> is expected in the same format as listed by
|
||||||
'git config' (subkeys separated by dots).
|
'git config' (subkeys separated by dots).
|
||||||
|
+
|
||||||
|
Note that omitting the `=` in `git -c foo.bar ...` is allowed and sets
|
||||||
|
`foo.bar` to the boolean true value (just like `[foo]bar` would in a
|
||||||
|
config file). Including the equals but with an empty value (like `git -c
|
||||||
|
foo.bar= ...`) sets `foo.bar` to the empty string.
|
||||||
|
|
||||||
--exec-path[=<path>]::
|
--exec-path[=<path>]::
|
||||||
Path to wherever your core Git programs are installed.
|
Path to wherever your core Git programs are installed.
|
||||||
|
|
12
config.c
12
config.c
|
@ -162,19 +162,27 @@ void git_config_push_parameter(const char *text)
|
||||||
int git_config_parse_parameter(const char *text,
|
int git_config_parse_parameter(const char *text,
|
||||||
config_fn_t fn, void *data)
|
config_fn_t fn, void *data)
|
||||||
{
|
{
|
||||||
|
const char *value;
|
||||||
struct strbuf **pair;
|
struct strbuf **pair;
|
||||||
|
|
||||||
pair = strbuf_split_str(text, '=', 2);
|
pair = strbuf_split_str(text, '=', 2);
|
||||||
if (!pair[0])
|
if (!pair[0])
|
||||||
return error("bogus config parameter: %s", text);
|
return error("bogus config parameter: %s", text);
|
||||||
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
|
|
||||||
|
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') {
|
||||||
strbuf_setlen(pair[0], pair[0]->len - 1);
|
strbuf_setlen(pair[0], pair[0]->len - 1);
|
||||||
|
value = pair[1] ? pair[1]->buf : "";
|
||||||
|
} else {
|
||||||
|
value = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
strbuf_trim(pair[0]);
|
strbuf_trim(pair[0]);
|
||||||
if (!pair[0]->len) {
|
if (!pair[0]->len) {
|
||||||
strbuf_list_free(pair);
|
strbuf_list_free(pair);
|
||||||
return error("bogus config parameter: %s", text);
|
return error("bogus config parameter: %s", text);
|
||||||
}
|
}
|
||||||
strbuf_tolower(pair[0]);
|
strbuf_tolower(pair[0]);
|
||||||
if (fn(pair[0]->buf, pair[1] ? pair[1]->buf : NULL, data) < 0) {
|
if (fn(pair[0]->buf, value, data) < 0) {
|
||||||
strbuf_list_free(pair);
|
strbuf_list_free(pair);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1010,6 +1010,17 @@ test_expect_success 'git -c "key=value" support' '
|
||||||
test_must_fail git -c name=value config core.name
|
test_must_fail git -c name=value config core.name
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# We just need a type-specifier here that cares about the
|
||||||
|
# distinction internally between a NULL boolean and a real
|
||||||
|
# string (because most of git's internal parsers do care).
|
||||||
|
# Using "--path" works, but we do not otherwise care about
|
||||||
|
# its semantics.
|
||||||
|
test_expect_success 'git -c can represent empty string' '
|
||||||
|
echo >expect &&
|
||||||
|
git -c foo.empty= config --path foo.empty >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'key sanity-checking' '
|
test_expect_success 'key sanity-checking' '
|
||||||
test_must_fail git config foo=bar &&
|
test_must_fail git config foo=bar &&
|
||||||
test_must_fail git config foo=.bar &&
|
test_must_fail git config foo=.bar &&
|
||||||
|
|
Loading…
Reference in New Issue