# git config oddity

5 messages from 2008-07-15 to 2008-07-15. Participants: Sverre Rabbelier, Johannes Schindelin.
Thread: https://gitlist.dev/t/14466

## Sverre Rabbelier, 2008-07-15 14:44

Subject: git config oddity
Message-ID: <bd6139dc0807150744l78eb8d54ld167d3a9a5a600f@mail.gmail.com>
URL: https://gitlist.dev/e/bd6139dc0807150744l78eb8d54ld167d3a9a5a600f%40mail.gmail.com

```
Heya,

I noticed today that when unsetting the last value in a group git
config leaves the empty group header. I was somewhat surprised here,
but I am guessing it has a purpose? Anyway, I also noticed (and this
threw my manual config parser off) that when later on an option is set
to that empty group, a new group is created with the same name. Is
this something I have to deal with in my parser (e.g., should I keep
scanning the file for occurrences of my header and allow for empty
groups, or is this a bug in git config? Either is fine with me, was
just wondering :).

-----------------
sverre@Laptop-Sverre:~/code$ mkdir config-oddity
sverre@Laptop-Sverre:~/code$ cd config-oddity/
sverre@Laptop-Sverre:~/code/config-oddity$ git init
Initialized empty Git repository in /home/sverre/code/config-oddity/.git/
sverre@Laptop-Sverre:~/code/config-oddity$ cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
sverre@Laptop-Sverre:~/code/config-oddity$ git config foo.bar spam
sverre@Laptop-Sverre:~/code/config-oddity$ cat .git/config # as expected
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[foo]
	bar = spam
sverre@Laptop-Sverre:~/code/config-oddity$ git config --unset foo.bar
sverre@Laptop-Sverre:~/code/config-oddity$ cat .git/config # dubious,
but acceptable
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[foo]
sverre@Laptop-Sverre:~/code/config-oddity$ git config foo.bar eggs
sverre@Laptop-Sverre:~/code/config-oddity$ cat .git/config # errr? two
[foo] headers?
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[foo]
[foo]
	bar = eggs
sverre@Laptop-Sverre:~/code/config-oddity$
-----------------

-- 
Cheers,

Sverre Rabbelier

```

## Johannes Schindelin, 2008-07-15 15:02

Subject: Re: git config oddity
Message-ID: <alpine.DEB.1.00.0807151600170.8950@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807151600170.8950%40racer
In-Reply-To: <bd6139dc0807150744l78eb8d54ld167d3a9a5a600f@mail.gmail.com>

```
Hi,

On Tue, 15 Jul 2008, Sverre Rabbelier wrote:

> I noticed today that when unsetting the last value in a group git
> config leaves the empty group header.

That is on purpose.  As .git/config was always meant as a user-editable 
file, you can put comments into that section.  Or comment out some values.

So "git config" does not remove the section, even if no variable is there 
at the moment.

It is somewhat unfortunate that setting a variable does not find the 
section; the reason is that it sees sections only when a variable is set 
(to avoid having to do the parsing itself).

Hth,
Dscho

```

## Sverre Rabbelier, 2008-07-15 15:29

Subject: Re: git config oddity
Message-ID: <bd6139dc0807150829n2b3c88d7p18c203e93cd4e0c1@mail.gmail.com>
URL: https://gitlist.dev/e/bd6139dc0807150829n2b3c88d7p18c203e93cd4e0c1%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0807151600170.8950@racer>

```
On Tue, Jul 15, 2008 at 5:02 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>> I noticed today that when unsetting the last value in a group git
>> config leaves the empty group header.
>
> That is on purpose.  As .git/config was always meant as a user-editable
> file, you can put comments into that section.  Or comment out some values.

Ok, this makes sense :). I agree that I would be unhappily surprised
if I found that git removed a section that I had put some comments in
when I unset a variable.

> It is somewhat unfortunate that setting a variable does not find the
> section; the reason is that it sees sections only when a variable is set
> (to avoid having to do the parsing itself).

Ah, unfortunate indeed. I'm not sure I understand why it does not see
the existing header? I had a look at config.c but I couldn't really
make out why it doesn't. Would it be difficult to add that?

-- 
Cheers,

Sverre Rabbelier

```

## Johannes Schindelin, 2008-07-15 15:33

Subject: Re: git config oddity
Message-ID: <alpine.DEB.1.00.0807151631520.8950@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807151631520.8950%40racer
In-Reply-To: <bd6139dc0807150829n2b3c88d7p18c203e93cd4e0c1@mail.gmail.com>

```
Hi,

On Tue, 15 Jul 2008, Sverre Rabbelier wrote:

> On Tue, Jul 15, 2008 at 5:02 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> 
> > It is somewhat unfortunate that setting a variable does not find the 
> > section; the reason is that it sees sections only when a variable is 
> > set (to avoid having to do the parsing itself).
> 
> Ah, unfortunate indeed. I'm not sure I understand why it does not see 
> the existing header? I had a look at config.c but I couldn't really make 
> out why it doesn't.

The config writing uses the config parser to determine where the locations 
of the config variables (and therefore, sections) are by using the parser, 
and remembering the position in the file.

> Would it be difficult to add that?

Yes.

Ciao,
Dscho

```

## Sverre Rabbelier, 2008-07-15 15:35

Subject: Re: git config oddity
Message-ID: <bd6139dc0807150835p1da70becj7fe28f6fa7d79ed5@mail.gmail.com>
URL: https://gitlist.dev/e/bd6139dc0807150835p1da70becj7fe28f6fa7d79ed5%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0807151631520.8950@racer>

```
On Tue, Jul 15, 2008 at 5:33 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> The config writing uses the config parser to determine where the locations
> of the config variables (and therefore, sections) are by using the parser,
> and remembering the position in the file.

Ok, thanks for the explanation, I'll add a workaround in my code.

-- 
Cheers,

Sverre Rabbelier

```
