mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
Merge branch 'sb/config-write-fix'
Recent update to "git config" broke updating variable in a subsection, which has been corrected. * sb/config-write-fix: git-config: document accidental multi-line setting in deprecated syntax config: fix case sensitive subsection names on writing t1300: document current behavior of setting options
This commit is contained in:
commit
2a2c18f1c3
|
@ -453,6 +453,27 @@ http.sslverify false
|
||||||
|
|
||||||
include::config.txt[]
|
include::config.txt[]
|
||||||
|
|
||||||
|
BUGS
|
||||||
|
----
|
||||||
|
When using the deprecated `[section.subsection]` syntax, changing a value
|
||||||
|
will result in adding a multi-line key instead of a change, if the subsection
|
||||||
|
is given with at least one uppercase character. For example when the config
|
||||||
|
looks like
|
||||||
|
|
||||||
|
--------
|
||||||
|
[section.subsection]
|
||||||
|
key = value1
|
||||||
|
--------
|
||||||
|
|
||||||
|
and running `git config section.Subsection.key value2` will result in
|
||||||
|
|
||||||
|
--------
|
||||||
|
[section.subsection]
|
||||||
|
key = value1
|
||||||
|
key = value2
|
||||||
|
--------
|
||||||
|
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
---
|
---
|
||||||
Part of the linkgit:git[1] suite
|
Part of the linkgit:git[1] suite
|
||||||
|
|
12
config.c
12
config.c
|
@ -38,6 +38,7 @@ struct config_source {
|
||||||
int eof;
|
int eof;
|
||||||
struct strbuf value;
|
struct strbuf value;
|
||||||
struct strbuf var;
|
struct strbuf var;
|
||||||
|
unsigned subsection_case_sensitive : 1;
|
||||||
|
|
||||||
int (*do_fgetc)(struct config_source *c);
|
int (*do_fgetc)(struct config_source *c);
|
||||||
int (*do_ungetc)(int c, struct config_source *conf);
|
int (*do_ungetc)(int c, struct config_source *conf);
|
||||||
|
@ -606,6 +607,7 @@ static int get_value(config_fn_t fn, void *data, struct strbuf *name)
|
||||||
|
|
||||||
static int get_extended_base_var(struct strbuf *name, int c)
|
static int get_extended_base_var(struct strbuf *name, int c)
|
||||||
{
|
{
|
||||||
|
cf->subsection_case_sensitive = 0;
|
||||||
do {
|
do {
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
goto error_incomplete_line;
|
goto error_incomplete_line;
|
||||||
|
@ -642,6 +644,7 @@ static int get_extended_base_var(struct strbuf *name, int c)
|
||||||
|
|
||||||
static int get_base_var(struct strbuf *name)
|
static int get_base_var(struct strbuf *name)
|
||||||
{
|
{
|
||||||
|
cf->subsection_case_sensitive = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = get_next_char();
|
int c = get_next_char();
|
||||||
if (cf->eof)
|
if (cf->eof)
|
||||||
|
@ -2370,14 +2373,21 @@ static int store_aux_event(enum config_event_t type,
|
||||||
store->parsed[store->parsed_nr].type = type;
|
store->parsed[store->parsed_nr].type = type;
|
||||||
|
|
||||||
if (type == CONFIG_EVENT_SECTION) {
|
if (type == CONFIG_EVENT_SECTION) {
|
||||||
|
int (*cmpfn)(const char *, const char *, size_t);
|
||||||
|
|
||||||
if (cf->var.len < 2 || cf->var.buf[cf->var.len - 1] != '.')
|
if (cf->var.len < 2 || cf->var.buf[cf->var.len - 1] != '.')
|
||||||
return error(_("invalid section name '%s'"), cf->var.buf);
|
return error(_("invalid section name '%s'"), cf->var.buf);
|
||||||
|
|
||||||
|
if (cf->subsection_case_sensitive)
|
||||||
|
cmpfn = strncasecmp;
|
||||||
|
else
|
||||||
|
cmpfn = strncmp;
|
||||||
|
|
||||||
/* Is this the section we were looking for? */
|
/* Is this the section we were looking for? */
|
||||||
store->is_keys_section =
|
store->is_keys_section =
|
||||||
store->parsed[store->parsed_nr].is_keys_section =
|
store->parsed[store->parsed_nr].is_keys_section =
|
||||||
cf->var.len - 1 == store->baselen &&
|
cf->var.len - 1 == store->baselen &&
|
||||||
!strncasecmp(cf->var.buf, store->key, store->baselen);
|
!cmpfn(cf->var.buf, store->key, store->baselen);
|
||||||
if (store->is_keys_section) {
|
if (store->is_keys_section) {
|
||||||
store->section_seen = 1;
|
store->section_seen = 1;
|
||||||
ALLOC_GROW(store->seen, store->seen_nr + 1,
|
ALLOC_GROW(store->seen, store->seen_nr + 1,
|
||||||
|
|
|
@ -1218,6 +1218,93 @@ test_expect_success 'last one wins: three level vars' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'old-fashioned settings are case insensitive' '
|
||||||
|
test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
|
||||||
|
|
||||||
|
cat >testConfig_actual <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
r = value1
|
||||||
|
EOF
|
||||||
|
q_to_tab >testConfig_expect <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
Qr = value2
|
||||||
|
EOF
|
||||||
|
git config -f testConfig_actual "v.a.r" value2 &&
|
||||||
|
test_cmp testConfig_expect testConfig_actual &&
|
||||||
|
|
||||||
|
cat >testConfig_actual <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
r = value1
|
||||||
|
EOF
|
||||||
|
q_to_tab >testConfig_expect <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
QR = value2
|
||||||
|
EOF
|
||||||
|
git config -f testConfig_actual "V.a.R" value2 &&
|
||||||
|
test_cmp testConfig_expect testConfig_actual &&
|
||||||
|
|
||||||
|
cat >testConfig_actual <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
r = value1
|
||||||
|
EOF
|
||||||
|
q_to_tab >testConfig_expect <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
r = value1
|
||||||
|
Qr = value2
|
||||||
|
EOF
|
||||||
|
git config -f testConfig_actual "V.A.r" value2 &&
|
||||||
|
test_cmp testConfig_expect testConfig_actual &&
|
||||||
|
|
||||||
|
cat >testConfig_actual <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
r = value1
|
||||||
|
EOF
|
||||||
|
q_to_tab >testConfig_expect <<-EOF &&
|
||||||
|
[V.A]
|
||||||
|
r = value1
|
||||||
|
Qr = value2
|
||||||
|
EOF
|
||||||
|
git config -f testConfig_actual "v.A.r" value2 &&
|
||||||
|
test_cmp testConfig_expect testConfig_actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'setting different case sensitive subsections ' '
|
||||||
|
test_when_finished "rm -f testConfig testConfig_expect testConfig_actual" &&
|
||||||
|
|
||||||
|
cat >testConfig_actual <<-EOF &&
|
||||||
|
[V "A"]
|
||||||
|
R = v1
|
||||||
|
[K "E"]
|
||||||
|
Y = v1
|
||||||
|
[a "b"]
|
||||||
|
c = v1
|
||||||
|
[d "e"]
|
||||||
|
f = v1
|
||||||
|
EOF
|
||||||
|
q_to_tab >testConfig_expect <<-EOF &&
|
||||||
|
[V "A"]
|
||||||
|
Qr = v2
|
||||||
|
[K "E"]
|
||||||
|
Qy = v2
|
||||||
|
[a "b"]
|
||||||
|
Qc = v2
|
||||||
|
[d "e"]
|
||||||
|
f = v1
|
||||||
|
[d "E"]
|
||||||
|
Qf = v2
|
||||||
|
EOF
|
||||||
|
# exact match
|
||||||
|
git config -f testConfig_actual a.b.c v2 &&
|
||||||
|
# match section and subsection, key is cased differently.
|
||||||
|
git config -f testConfig_actual K.E.y v2 &&
|
||||||
|
# section and key are matched case insensitive, but subsection needs
|
||||||
|
# to match; When writing out new values only the key is adjusted
|
||||||
|
git config -f testConfig_actual v.A.r v2 &&
|
||||||
|
# subsection is not matched:
|
||||||
|
git config -f testConfig_actual d.E.f v2 &&
|
||||||
|
test_cmp testConfig_expect testConfig_actual
|
||||||
|
'
|
||||||
|
|
||||||
for VAR in a .a a. a.0b a."b c". a."b c".0d
|
for VAR in a .a a. a.0b a."b c". a."b c".0d
|
||||||
do
|
do
|
||||||
test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
|
test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" '
|
||||||
|
|
Loading…
Reference in a new issue