# Bug: Git Maintenance does not register multiple repos

4 messages from 2024-06-20 to 2024-06-21. Participants: Shubham Kanodia, Kristoffer Haugsbakk, Phillip Wood.
Thread: https://gitlist.dev/t/61656

## Shubham Kanodia, 2024-06-20 13:15

Subject: Bug: Git Maintenance does not register multiple repos
Message-ID: <CAG=Um+0LXVRHmvKdTB9WHJujjh9agK_ZHdv45ffzMsqX65NLVw@mail.gmail.com>
URL: https://gitlist.dev/e/CAG%3DUm%2B0LXVRHmvKdTB9WHJujjh9agK_ZHdv45ffzMsqX65NLVw%40mail.gmail.com

```
When I run — `git maintenance register` to register a particular
repository for maintenance,
it appends a new entry to `~/.gitconfig` with the repo name.

ˋˋˋ
[maintenance]
       repo = /path/to/repo-1
       repo = /path/to/repo-2
ˋˋˋ

Now, since git uses the INI format for these files, this would imply that
repo-2 actually overrides repo 1 for maintenance.

This implies that a user can only register a single repository on
their system for
maintenance.

What did you expect to happen? (Expected behavior)
I expected that multiple repositories on the system could be setup for
maintenance using this command.
Which would mean, the `repo` filed would be an array.

ˋˋˋ
[maintenance]
       repo[] = /path/to/repo-1
       repo[] = /path/to/repo-2
ˋˋˋ
What happened instead? (Actual behavior)
It appended an entry with the same key, which would mean only the last
key wins, and a user cannot have
multiple repos as a part of maintenance.

What's different between what you expected and what actually happened?
Mentioned earlier.

Anything else you want to add:
No.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.39.3 (Apple Git-146)
cpu: arm64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:12:58
PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000 arm64
compiler info: clang: 15.0.0 (clang-1500.3.9.4)
libc info: no libc information available
$SHELL (typically, interactive shell): /opt/homebrew/bin/fish


[Enabled Hooks]
post-checkout
post-commit
post-merge
pre-push

```

## Kristoffer Haugsbakk, 2024-06-20 13:54

Subject: Re: Bug: Git Maintenance does not register multiple repos
Message-ID: <665f77a0-f301-40ae-ab94-2920d15fcc8d@app.fastmail.com>
URL: https://gitlist.dev/e/665f77a0-f301-40ae-ab94-2920d15fcc8d%40app.fastmail.com
In-Reply-To: <CAG=Um+0LXVRHmvKdTB9WHJujjh9agK_ZHdv45ffzMsqX65NLVw@mail.gmail.com>

```
Hi

On Thu, Jun 20, 2024, at 15:15, Shubham Kanodia wrote:
> When I run — `git maintenance register` to register a particular
> repository for maintenance,
> it appends a new entry to `~/.gitconfig` with the repo name.
>
> ˋˋˋ
> [maintenance]
>        repo = /path/to/repo-1
>        repo = /path/to/repo-2
> ˋˋˋ
>
> Now, since git uses the INI format for these files, this would imply that
> repo-2 actually overrides repo 1 for maintenance.
>
> This implies that a user can only register a single repository on
> their system for
> maintenance.

Imply? Did you test this? From memory this is a multi-valued config, and
multi-valued configs are sometimes listed by using `=` multiple times
for the same config variable. That’s also what [this] email says:

  “ The 'git maintenance [un]register' commands set or unset the multi-
    valued maintenance.repo config key with the absolute path of the
    current repository. These are set in the global config file.

🔗 this: https://lore.kernel.org/git/5aa9cc1d6b93b5ad3d66ac01a4518a91ced39bcb.1664287021.git.gitgitgadget@gmail.com/

I’ve never seen that git config uses the INI format. I’ve had the
impression that it is a bespoke format that simply looks like the INI
format. (But is the INI format even standardized?)

I have two repositories registered. When I run this:

ˋˋˋ
git for-each-repo --config=maintenance.repo maintenance run
ˋˋˋ

Well, it doesn’t tell me what repositories are being manipulated, but I do get two of these lines:

ˋˋˋ
Enumerating objects: […]
ˋˋˋ

So I surmise that this command is being run twice.

-- 
Kristoffer Haugsbakk


```

## Kristoffer Haugsbakk, 2024-06-21 06:58

Subject: Re: Bug: Git Maintenance does not register multiple repos
Message-ID: <4480de3f-851f-4cf7-889f-b5ab7c4e0223@app.fastmail.com>
URL: https://gitlist.dev/e/4480de3f-851f-4cf7-889f-b5ab7c4e0223%40app.fastmail.com
In-Reply-To: <CAG=Um+1EyB08n7oH6rgqPmmn0OWndUdv4vEsY5Hcv3aaf-BHxg@mail.gmail.com>

```
On Thu, Jun 20, 2024, at 17:34, Shubham Kanodia wrote:
> I've seen libraries in a few language ecosystems use `ini` parsers for
> parsing the config file, and there's several blogs (that perhaps
> incorrectly?) state so, so
> I assumed that might be true. But you're right in that I don't see it
> be mentioned on git's official site.

I see no warrant for such an assumption.

In my experience, plenty of syntaxes are described as like-X”. Java and
C# are C-like. That doesn’t mean you can use a C parser on those other
languages. Config files are simpler but the same principle applies.

> 1. What spec does the config file follow?

Apparently there isn’t a spec because it is bespoke.

https://stackoverflow.com/a/68461700/1725151

> 2. What is the correct way then to get an "effective" git config
> value? Typically, I assumed that if a value appeared twice in the git
> config, the second would override the first (for say, `core.editor`).
>   How does git parse "overrides" vs "arrays" if they are defined using
> the same syntax?

There are two dimensions

1. How config variables are parsed
2. What is expected of the specific config variable

`core.editor` is a single value. You can test with

ˋˋˋ
[core]
	editor=vim
	editor=nano
ˋˋˋ

The last one wins here. `core.editor` expects a single value.

But you can define a multi-valued variable

ˋˋˋ
[customsection]
    mycustomvariable = value1
    mycustomvariable = value2
    mycustomvariable = value3
ˋˋˋ

ˋˋˋ
$ git config --global --get-all customsection.mycustomvariable
value1
value2
value3
ˋˋˋ

-- 
Kristoffer Haugsbakk

```

## Phillip Wood, 2024-06-21 10:10

Subject: Re: Bug: Git Maintenance does not register multiple repos
Message-ID: <d0deaa08-2894-4e89-ba51-7bed8e785ef3@gmail.com>
URL: https://gitlist.dev/e/d0deaa08-2894-4e89-ba51-7bed8e785ef3%40gmail.com
In-Reply-To: <4480de3f-851f-4cf7-889f-b5ab7c4e0223@app.fastmail.com>

```
On 21/06/2024 07:58, Kristoffer Haugsbakk wrote:
> On Thu, Jun 20, 2024, at 17:34, Shubham Kanodia wrote:
>> 1. What spec does the config file follow?
> 
> Apparently there isn’t a spec because it is bespoke.

The syntax is documented on the "git config" man page.

>> 2. What is the correct way then to get an "effective" git config
>> value? Typically, I assumed that if a value appeared twice in the git
>> config, the second would override the first (for say, `core.editor`).
>>    How does git parse "overrides" vs "arrays" if they are defined using
>> the same syntax?
> 
> There are two dimensions
> 
> 1. How config variables are parsed
> 2. What is expected of the specific config variable

To expand a little on what Kristoffer has said - this means that you 
need to know in advance what type of variable you are checking. You can 
do that by reading the documentation for that variable on the "git 
config" man page. "git config" also offers the --type=<type> option to 
normalize values to the expected type.

Best Wishes

Phillip

> `core.editor` is a single value. You can test with
> 
> ˋˋˋ
> [core]
> 	editor=vim
> 	editor=nano
> ˋˋˋ
> 
> The last one wins here. `core.editor` expects a single value.
> 
> But you can define a multi-valued variable
> 
> ˋˋˋ
> [customsection]
>      mycustomvariable = value1
>      mycustomvariable = value2
>      mycustomvariable = value3
> ˋˋˋ
> 
> ˋˋˋ
> $ git config --global --get-all customsection.mycustomvariable
> value1
> value2
> value3
> ˋˋˋ
> 


```
