public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Tim Landscheidt <tim@tim-landscheidt•de>
To: Junio C Hamano <gitster@pobox•com>
Cc: git@vger•kernel.org
Subject: Re: Inconsistent/buggy behaviour of "git config --add"
Date: Sun, 24 Mar 2024 18:57:21 +0000	[thread overview]
Message-ID: <87o7b3xxta.fsf@vagabond.tim-landscheidt.de> (raw)
In-Reply-To: <xmqq8r28ygwi.fsf@gitster.g> (Junio C. Hamano's message of "Sat, 23 Mar 2024 10:52:45 -0700")

Junio C Hamano <gitster@pobox•com> wrote:

> […]

>> So on one hand, "--add" must be given before the key to add
>> a line, but if on the other hand one passes the option after
>> the key and before the value, it is literally taken as the
>> value and the value does not seem to be interpreted as a
>> value-pattern, either.  However, if the value is missing,
>> Git correctly recognizes that this does not make sense.

> Not really.  I agree that the "git config" syntax is messy, but I
> followed your example with "git config --help" (especially its
> SYNOPSIS section) in hand, and reached the above explanation, which
> your conjecutre does not quite match.

I respectfully disagree (somewhat).  git-config(1) reads:

| […]

|        Multiple lines can be added to an option by using
|        the --add option. If you want to update or unset an
|        option which can occur on multiple lines, a
|        value-pattern (which is an extended regular
|        expression, unless the --fixed-value option is
|        given) needs to be given. Only the existing values
|        that match the pattern are updated or unset. If you
|        want to handle the lines that do not match the
|        pattern, just prepend a single exclamation mark in
|        front (see also the section called “EXAMPLES”), but
|        note that this only works when the --fixed-value
|        option is not in use.

| […]

|        --replace-all
|            Default behavior is to replace at most one
|            line. This replaces all lines matching the key
|            (and optionally the value-pattern).

This says quite clearly if one wants to /add/ a value,
"--add" must be given; the default is to /replace/ an
existing value.

The only indication that this might be false is the
description of "--add" itself which gives another and
different explanation for the behaviour of "--replace-all":

|        --add
|            Adds a new line to the option without altering
|            any existing values. This is the same as
|            providing ^$ as the value-pattern in
|            --replace-all.

| […]

So the first section states that "only the existing values
that match the pattern are updated or unset", and here it
says that if there are no matches, a new line is added.

>> My expectation of least surprise is that "git config
>> section.key --add value" should be equivalent to "git config
>> --add section.key value".

> You cannot have "--add" as a value by doing so.

> […]

The standard way to achieve this would be to use "--",
i. e. "git config section.key --add -- --add" (apparently
even part of POSIX as "Utility Syntax Guidelines", but also
commonly used elsewhere in Git).

Tim

  reply	other threads:[~2024-03-24 18:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-23 16:07 Inconsistent/buggy behaviour of "git config --add" Tim Landscheidt
2024-03-23 17:52 ` Junio C Hamano
2024-03-24 18:57   ` Tim Landscheidt [this message]
2024-03-25  0:31     ` brian m. carlson
2024-03-25  7:28     ` Patrick Steinhardt
2024-03-25 18:56       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o7b3xxta.fsf@vagabond.tim-landscheidt.de \
    --to=tim@tim-landscheidt$(echo .)de \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox