threads / discuss / 46925

Git config multiple values

Subject: Git config multiple values

## tl;dr

6 messages between Oct 6, 2017 and Oct 6, 2017.

replies: 5people: 4as markdown or json

aleksander.baranowski· Oct 6, 2017, 11:10 UTC · lore
Hi,

I'm currently using git version 2.14.2. There is possible to put multiple values into same variable with git config.

Case 1: # git config --global user.name Foo - returns 0 # git config --global user.name Bar - returns 0 and replace Foo to Bar # git config --global user.name Foo - returns 0 and replace Bar to Foo

Case 2:
# git config --global user.name Foo - returns 0
# git config --global user.name Foo2 Bar - returns 0 and put second name
# cat ~/.gitconfig
[user]
	email = aleksander.baranowski@yahoo.pl
	name = Foo
	name = Foo2
# git config --global user.name Foo - return 5 and message
"warning: user.name has multiple values
error: cannot overwrite multiple values with a single value
       Use a regexp, --add or --replace-all to change user.name."
It's just an opinion, but this behaviour is no consistent for me.
If it's not the bug it's a feature just let me know.

Bests, Alex

Jeff King· Oct 6, 2017, 14:32 UTC · re: aleksander.baranowski · lore

Re: Git config multiple values

On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
> I'm currently using git version 2.14.2. There is possible to put
> multiple values into same variable with git config.
Yep, your examples should behave the same even with older versions.
> Case 1:
> # git config --global user.name Foo - returns 0
> # git config --global user.name Bar - returns 0 and replace Foo to Bar
> # git config --global user.name Foo - returns 0 and replace Bar to Foo

This is all as expected. You're hitting the first case in the manpage synopsis here (I snipped the uninteresting options):

  git config name [value [value_regex]]
So you're doing:
  git config name value
which replaces any existing key by default. You could also do:
  git config --add name value

to add without replacing (if you had a config key that takes multiple values).

> Case 2:
> # git config --global user.name Foo - returns 0
> # git config --global user.name Foo2 Bar - returns 0 and put second name
Here you're doing:
  git config name value value_regex

So we're replacing any values which match the regex "Bar" (and there are none), and leaving others intact. Hence after this you will have two user.name values.

If you wanted a name with two strings, you'd have to quote the string from the shell to leave it as a single argument:

  git config user.name "Foo2 Bar"
Show 5 quoted lines
> # cat ~/.gitconfig
> [user]
> 	email = aleksander.baranowski@yahoo.pl
> 	name = Foo
> 	name = Foo2
Right, this is what I'd expect.
> # git config --global user.name Foo - return 5 and message
> "warning: user.name has multiple values
> error: cannot overwrite multiple values with a single value
>        Use a regexp, --add or --replace-all to change user.name."
And this, too (though I forgot we had such a safety check).
> It's just an opinion, but this behaviour is no consistent for me.
> 
> If it's not the bug it's a feature just let me know.

It's a feature, though I agree that git-config is rather baroque. We're mostly stuck with it for reasons of backwards compatibility, though.

-Peff
aleksander.baranowski· Oct 6, 2017, 16:57 UTC · re: Jeff King · lore

Re: Git config multiple values

Hi!,
Thank you very much for descriptive answer.

You are absolutely right. I should read manual more carefully! Still it's quite odd interface. Thank you for your time.

Bests, Alex

On 10/06/2017 04:32 PM, Jeff King wrote:
Show 69 quoted lines
> On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
> 
>> I'm currently using git version 2.14.2. There is possible to put
>> multiple values into same variable with git config.
> 
> Yep, your examples should behave the same even with older versions.
> 
>> Case 1:
>> # git config --global user.name Foo - returns 0
>> # git config --global user.name Bar - returns 0 and replace Foo to Bar
>> # git config --global user.name Foo - returns 0 and replace Bar to Foo
> 
> This is all as expected. You're hitting the first case in the manpage
> synopsis here (I snipped the uninteresting options):
> 
>   git config name [value [value_regex]]
> 
> So you're doing:
> 
>   git config name value
> 
> which replaces any existing key by default. You could also do:
> 
>   git config --add name value
> 
> to add without replacing (if you had a config key that takes multiple
> values).
> 
>> Case 2:
>> # git config --global user.name Foo - returns 0
>> # git config --global user.name Foo2 Bar - returns 0 and put second name
> 
> Here you're doing:
> 
>   git config name value value_regex
> 
> So we're replacing any values which match the regex "Bar" (and there are
> none), and leaving others intact. Hence after this you will have two
> user.name values.
> 
> If you wanted a name with two strings, you'd have to quote the string
> from the shell to leave it as a single argument:
> 
>   git config user.name "Foo2 Bar"
> 
>> # cat ~/.gitconfig
>> [user]
>> 	email = aleksander.baranowski@yahoo.pl
>> 	name = Foo
>> 	name = Foo2
> 
> Right, this is what I'd expect.
> 
>> # git config --global user.name Foo - return 5 and message
>> "warning: user.name has multiple values
>> error: cannot overwrite multiple values with a single value
>>        Use a regexp, --add or --replace-all to change user.name."
> 
> And this, too (though I forgot we had such a safety check).
> 
>> It's just an opinion, but this behaviour is no consistent for me.
>>
>> If it's not the bug it's a feature just let me know.
> 
> It's a feature, though I agree that git-config is rather baroque. We're
> mostly stuck with it for reasons of backwards compatibility, though.
> 
> -Peff
> 
Jonathan Nieder· Oct 6, 2017, 17:25 UTC · re: Jeff King · lore

Re: Git config multiple values

Hi,
Jeff King wrote:
> On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
Show 6 quoted lines
>> It's just an opinion, but this behaviour is no consistent for me.
>>
>> If it's not the bug it's a feature just let me know.
>
> It's a feature, though I agree that git-config is rather baroque. We're
> mostly stuck with it for reasons of backwards compatibility, though.

This feels like a dodge. Can we make a list of what is baroque here, with an eye to fixing it? E.g. if we introduce a new --set option, then what should its semantics be, to be more intuitive?

Thanks, Jonathan

Jeff King· Oct 6, 2017, 17:28 UTC · re: Jonathan Nieder · lore

Re: Git config multiple values

On Fri, Oct 06, 2017 at 10:25:30AM -0700, Jonathan Nieder wrote:
Show 13 quoted lines
> Jeff King wrote:
> > On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
> 
> >> It's just an opinion, but this behaviour is no consistent for me.
> >>
> >> If it's not the bug it's a feature just let me know.
> >
> > It's a feature, though I agree that git-config is rather baroque. We're
> > mostly stuck with it for reasons of backwards compatibility, though.
> 
> This feels like a dodge.  Can we make a list of what is baroque here,
> with an eye to fixing it?  E.g. if we introduce a new --set option,
> then what should its semantics be, to be more intuitive?

Maybe baroque isn't the right word. But changing the function of a command drastically based on the number of arguments seems like a source of confusion.

I'm fine if somebody wants to champion a new "--set" option, but frankly I'm not sure it's worth the pain at this point.

-Peff
Andreas Heiduk· Oct 6, 2017, 18:58 UTC · re: Jonathan Nieder · lore

Re: Git config multiple values

Hi,
Am 06.10.2017 um 19:25 schrieb Jonathan Nieder:
Show 15 quoted lines
> Hi,
> 
> Jeff King wrote:
>> On Fri, Oct 06, 2017 at 01:10:17PM +0200, aleksander.baranowski wrote:
> 
>>> It's just an opinion, but this behaviour is no consistent for me.
>>>
>>> If it's not the bug it's a feature just let me know.
>>
>> It's a feature, though I agree that git-config is rather baroque. We're
>> mostly stuck with it for reasons of backwards compatibility, though.
> 
> This feels like a dodge.  Can we make a list of what is baroque here,
> with an eye to fixing it?  E.g. if we introduce a new --set option,
> then what should its semantics be, to be more intuitive?
My reading of the manual for 
	git config --global user.name Foo2 Bar
is this:
       Multiple lines can be added to an option by using the --add option.
Does not apply here - no `--add` option, so no new value should be added.
       If you want to update or unset an option which can occur on multiple
       lines, a POSIX regexp value_regex needs to be given. 
does not apply: First: no "--unset" variant is used here leaving only "update".
Second: before that command there is only one value.
       Only the existing values that match the regexp are updated or unset.

Since "Two" does not match the previous value and `update` is the only described case left I'd expect that the command changes nothing.I don't understand how the description allows `git config` to add a new value, because the manual talks about "update" twice, nothing about adding.

Confused --Andreas

← back to recent threads