# builtin/config: --name-only doesn't imply --show-names in "git config get"

6 messages from 2024-08-21 to 2024-08-22. Participants: Yukai Chou, Junio C Hamano, Patrick Steinhardt.
Thread: https://gitlist.dev/t/61985

## Yukai Chou, 2024-08-21 08:10

Subject: builtin/config: --name-only doesn't imply --show-names in "git config get"
Message-ID: <CAEg0tHTWzgD5bw3oK7-Rtv9oTymqyhvZz3bcJ7yNRhF8wXMLGA@mail.gmail.com>
URL: https://gitlist.dev/e/CAEg0tHTWzgD5bw3oK7-Rtv9oTymqyhvZz3bcJ7yNRhF8wXMLGA%40mail.gmail.com

```
The v2.46.0 doc of git-config(1) says

> --name-only
> Output only the names of config variables for `list` or `get`.
https://git-scm.com/docs/git-config#Documentation/git-config.txt---name-only

But the behavior of --name-only is more like "disable non-name outputs
and leave the output state of names as-is". Thus using --name-only
alone, one gets totally empty lines (which might be weird); only using
--name-only and --show-names together, can one get output of just
names.

# get empty line(s)
git config get --all --name-only remote.origin.fetch
# get lines of name(s)
git config get --all --show-names --name-only remote.origin.fetch

Either the doc or the behavior of --name-only needs some adjustment.

Yukai Chou

```

## Junio C Hamano, 2024-08-21 16:06

Subject: Re: builtin/config: --name-only doesn't imply --show-names in "git config get"
Message-ID: <xmqqttfd2734.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqttfd2734.fsf%40gitster.g
In-Reply-To: <CAEg0tHTWzgD5bw3oK7-Rtv9oTymqyhvZz3bcJ7yNRhF8wXMLGA@mail.gmail.com>

```
Yukai Chou <muzimuzhi@gmail.com> writes:

> The v2.46.0 doc of git-config(1) says
>
>> --name-only
>> Output only the names of config variables for `list` or `get`.
> https://git-scm.com/docs/git-config#Documentation/git-config.txt---name-only
>
> But the behavior of --name-only is more like "disable non-name outputs
> and leave the output state of names as-is". Thus using --name-only
> alone, one gets totally empty lines (which might be weird); only using
> --name-only and --show-names together, can one get output of just
> names.
>
> # get empty line(s)
> git config get --all --name-only remote.origin.fetch
> # get lines of name(s)
> git config get --all --show-names --name-only remote.origin.fetch
>
> Either the doc or the behavior of --name-only needs some adjustment.

This argues for making "all" imply we need to show the name of the
configuration variable, and introducing an option "--hide-name" to
omit the name.  That way, you'd need to give clearly contradicting
"--hide-name" and "--name-only" together to get a nonsense output.

```

## Yukai Chou, 2024-08-21 20:28

Subject: Re: builtin/config: --name-only doesn't imply --show-names in "git config get"
Message-ID: <CAEg0tHQVK9hgcHTzn-ZPdwoFbbYFB2joeT0jLQgtD6yEH+1GiA@mail.gmail.com>
URL: https://gitlist.dev/e/CAEg0tHQVK9hgcHTzn-ZPdwoFbbYFB2joeT0jLQgtD6yEH%2B1GiA%40mail.gmail.com
In-Reply-To: <xmqqttfd2734.fsf@gitster.g>

```
Junio C Hamano <gitster@pobox.com> 于2024年8月22日周四 00:07写道：
>
> Yukai Chou <muzimuzhi@gmail.com> writes:
>
> > # get empty line(s)
> > git config get --all --name-only remote.origin.fetch
> > # get lines of name(s)
> > git config get --all --show-names --name-only remote.origin.fetch
> >
> > Either the doc or the behavior of --name-only needs some adjustment.
>
> This argues for making "all" imply we need to show the name of the
> configuration variable,

Sorry can you elaborate on what that "all" meant? A new option "--show-all"?

> and introducing an option "--hide-name" to
> omit the name.  That way, you'd need to give clearly contradicting
> "--hide-name" and "--name-only" together to get a nonsense output.

I have a feeling that finally a collection of options shared by "git
config list" and "git config get" will be introduced to fully control
what they output, and even make the form of output given by one of
"git config list" and "git config get" look exactly like the other.

An ideal design:

--show-all
--[no-]show-scope
--[no-]show-origin
--[no-]show-name
--[no-]show-value
--hide-all
--separator=<sep> # fuzzy name?

Initial options
- git config list: --hide-all --show-name --show-value --separator="="
- git config get: --hide-all --show-value --separator=" "

The drawback is, quite some combinations of such options are nonsense.

Yukai

```

## Junio C Hamano, 2024-08-21 20:59

Subject: Re: builtin/config: --name-only doesn't imply --show-names in "git config get"
Message-ID: <xmqqttfdwq0w.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqttfdwq0w.fsf%40gitster.g
In-Reply-To: <CAEg0tHQVK9hgcHTzn-ZPdwoFbbYFB2joeT0jLQgtD6yEH+1GiA@mail.gmail.com>

```
Yukai Chou <muzimuzhi@gmail.com> writes:

> Junio C Hamano <gitster@pobox.com> 于2024年8月22日周四 00:07写道：
>>
>> Yukai Chou <muzimuzhi@gmail.com> writes:
>>
>> > # get empty line(s)
>> > git config get --all --name-only remote.origin.fetch
>> > # get lines of name(s)
>> > git config get --all --show-names --name-only remote.origin.fetch
>> >
>> > Either the doc or the behavior of --name-only needs some adjustment.
>>
>> This argues for making "all" imply we need to show the name of the
>> configuration variable,
>
> Sorry can you elaborate on what that "all" meant? A new option "--show-all"?

Sorry, but "--all" is probably a red herring.

What I wanted to say was that we can 

 (1) get rid of "--show-name",

 (2) have the combination of options that can emit values for more
    than one key to automatically show both name and value, and

 (3) add "--hide-name" so that such command can still show only the
     value.

where I mixed up (2) and "all".  In fact, "--all" is not something
that gives values for more than one key (it is things like regexp
and urlmatch).

For example:

 $ git config --get-regexp 'sendemail\..*'

would show values for more than one variable, and depending on the 
variable, it may show the values for one variable more than once.
According to the documentation, this was replaced with

    --get-regexp <name-regexp>::
            Replaced by `git config get --all --show-names --regexp <name-regexp>`.

but it could have been

    git config get --all --regexp <name-regexp>

as it is clear --regexp could give results for more than one key.

This points at a bug in the documentation, by the way.  "git config --get-all"
is described like so:

    --get-all <name> [<value-pattern>]::
            Replaced by `git config get [--value=<pattern>] --all --show-names <name>`.

but this gives values for only one key, and the command does not
show key names.  It is replaced by

	git config get [--value=<pattern>] --all <name>

without "--show-names".


```

## Patrick Steinhardt, 2024-08-22 05:57

Subject: Re: builtin/config: --name-only doesn't imply --show-names in "git config get"
Message-ID: <ZsbTPeFIPcqnEd-n@tanuki>
URL: https://gitlist.dev/e/ZsbTPeFIPcqnEd-n%40tanuki
In-Reply-To: <xmqqttfdwq0w.fsf@gitster.g>

```
On Wed, Aug 21, 2024 at 01:59:43PM -0700, Junio C Hamano wrote:
> Yukai Chou <muzimuzhi@gmail.com> writes:
> 
> > Junio C Hamano <gitster@pobox.com> 于2024年8月22日周四 00:07写道：
> >>
> >> Yukai Chou <muzimuzhi@gmail.com> writes:
> >>
> >> > # get empty line(s)
> >> > git config get --all --name-only remote.origin.fetch
> >> > # get lines of name(s)
> >> > git config get --all --show-names --name-only remote.origin.fetch
> >> >
> >> > Either the doc or the behavior of --name-only needs some adjustment.
> >>
> >> This argues for making "all" imply we need to show the name of the
> >> configuration variable,
> >
> > Sorry can you elaborate on what that "all" meant? A new option "--show-all"?
> 
> Sorry, but "--all" is probably a red herring.
> 
> What I wanted to say was that we can 
> 
>  (1) get rid of "--show-name",
> 
>  (2) have the combination of options that can emit values for more
>     than one key to automatically show both name and value, and
> 
>  (3) add "--hide-name" so that such command can still show only the
>      value.
> 
> where I mixed up (2) and "all".  In fact, "--all" is not something
> that gives values for more than one key (it is things like regexp
> and urlmatch).

I wouldn't get rid of `--show-name`, as it also implicitly brings along
`--no-show-name`, basically checking the box for (3).

In any case, I agree that it probably makes sense to do (2). Unless I'm
mistaken, the only case we need to care about is `--regexp`, because
without all the emitted names would be the same anyway.

Patrick

```

## Junio C Hamano, 2024-08-22 14:54

Subject: Re: builtin/config: --name-only doesn't imply --show-names in "git config get"
Message-ID: <xmqqa5h4wqts.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqa5h4wqts.fsf%40gitster.g
In-Reply-To: <ZsbTPeFIPcqnEd-n@tanuki>

```
Patrick Steinhardt <ps@pks.im> writes:

> In any case, I agree that it probably makes sense to do (2). Unless I'm
> mistaken, the only case we need to care about is `--regexp`, because
> without all the emitted names would be the same anyway.

OK.  And we need to fix the "config --get-all" description, which
does not need --show-names there, I think.

Thanks.

```
