Minor bug: git config ignores empty sections

2 messages, 2 authors, 2016-08-15 · open the first message on its own page

Minor bug: git config ignores empty sections

From: Eli Barzilay <hidden>
Date: 2016-08-15 01:29:35

Looks like there's a problem with setting a config with an empty
section, making it create a new section.  The result is:

    $ git --version
    git version 2.9.2
    $ git init
    Initialized empty Git repository in /home/eli/t/.git/
    $ t() { git config x.y x; git config --unset x.y; }
    $ t;t;t
    $ grep -c '\[x\]' .git/config
    3
    $ git config x.z x
    $ t;t;t
    $ git config x.z x     # adds another [x], but leaves it populated
    $ t;t;t;t;t;t;t;t
    $ grep -c '\[x\]' .git/config
    4

-- 
                   ((x=>x(x))(x=>x(x)))                  Eli Barzilay:
                   http://barzilay.org/                  Maze is Life!

Re: Minor bug: git config ignores empty sections

From: Jeff King <hidden>
Date: 2016-08-15 12:09:23

On Sun, Aug 14, 2016 at 09:29:27PM -0400, Eli Barzilay wrote:
Looks like there's a problem with setting a config with an empty
section, making it create a new section.  The result is:

    $ git --version
    git version 2.9.2
    $ git init
    Initialized empty Git repository in /home/eli/t/.git/
    $ t() { git config x.y x; git config --unset x.y; }
    $ t;t;t
    $ grep -c '\[x\]' .git/config
    3
    $ git config x.z x
    $ t;t;t
    $ git config x.z x     # adds another [x], but leaves it populated
    $ t;t;t;t;t;t;t;t
    $ grep -c '\[x\]' .git/config
    4
Yep. This is a very old and well-known bug. IIRC, the problem is that
config updates use the regular callback-parser, so they see only the
config keys themselves. Empty section headers never trigger them.
Fixing it would require rewriting the config-update code.

And implicit in your test is the other bug, which is that deleting the
last key in a section leaves the empty header. I think it's related to
the same issue.

Patches welcome, of course.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help