git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG?] "git config --replace-all key value value_regex" ignores value_regex?

From
Derrick Stolee <stolee@gmail.com>
Date
Nov 18, 2020, 19:42 UTC
Message-ID
<c7dfbd1b-44bc-d074-5ec9-1011738c1522@gmail.com>
In-Reply-To
<xmqqo8ju1ooc.fsf@gitster.c.googlers.com>
On 11/18/2020 1:54 PM, Junio C Hamano wrote:
Show 52 quoted lines
> Derrick Stolee <stolee@gmail.com> writes:
> 
>> --replace-all::
>> 	Default behavior is to replace at most one line. This replaces
>> 	all lines matching the key (and optionally the value_regex).
>>
>> However, this test fails:
>>
>> test_expect_success '--replace-all and value_regex' '
>> 	q_to_tab >.git/config <<-\EOF &&
>> 	[abc]
>> 	Qkey = one
>> 	Qkey = two
>> 	Qkey = three
>> 	EOF
>> 	q_to_tab >expect <<-\EOF &&
>> 	[abc]
>> 	Qkey = four
>> 	Qkey = two
>> 	Qkey = three
>> 	EOF
>> 	git config --replace-all abc.key four "o*" &&
>> 	test_cmp expect .git/config
>> '
> 
> I do not know or try to guess the original intention (I thought this
> is Dscho's thing, no?), but if there are one/two/three and I were
> asked to replace all of those that have zero or more 'o' in it with
> 'four' I would expect that
> 
>  (1) all three be removed, because they all have zero or more 'o',
>      and then
> 
>  (2) one instance of 'four' be added,
> 
> resulting in a single 'four' left.
>
> If the value_regex were "o+" (since it takes ERE) to mean one or
> more, then my expectation would be
> 
>  (1) one and two be removed, because 'three' does not match, and
>      then
> 
>  (2) one instance of 'four' be added,
> 
> resulting in two items, 'three' and 'four'.
> 
> An alternative interpretation would be that each of the removed
> entries is replaced with a new one, resulting in three entries
> (i.e. with "o*", it would leave three identical entries 'four',
> with "o+", it would leave 'four', 'four' and 'three'), but that
> may be less useful in practice.

Thank you. Naturally, PEBKAC and my lack of understanding the regex I was using in my own test. Clearly this is behaving correctly. Modifying as suggested shows this works properly.

Thanks, -Stolee

 
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 4 in “[BUG?] "git config --replace-all key value value_regex" ignores value_regex?”
  1. Derrick StoleeNov 18, 2020
  2. Junio C HamanoNov 18, 2020
  3. Derrick StoleeNov 18, 2020
  4. Junio C HamanoNov 18, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.