All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Jade Lovelace <lists@jade.fyi>
Subject: Re: BUG: git config --global --get ITEM ignores ~/.config/git/config when ~/.gitconfig is present
Date: Fri, 10 Feb 2023 19:10:57 -0800	[thread overview]
Message-ID: <xmqqzg9kew1q.fsf@gitster.g> (raw)
In-Reply-To: <xmqqmt5lezi3.fsf@gitster.g> (Junio C. Hamano's message of "Fri, 10 Feb 2023 17:56:20 -0800")

Junio C Hamano <gitster@pobox.com> writes:

> My gut feeling is that this is merely a bug that we can fix without
> worrying too much about users screaming at us complaining that they
> relied on the current behaviour.  Without --global we do read from
> both, so with with "--global" the behaviour is inconsistent.

So, here is what I think happens, if anybody wants to get their
hands dirty.

builtin/config.c::cmd_config() notices "--global", and
tries to choose between user_config and xdg_config and
picks one.

The choice is stored in given_config_source.file

Eventually, "--get", "--get-all", etc. are handled by calling
builtin/config.c::get_value() and that function eventually calls
config.c::config_with_options().

config.c::config_with_options(), when config_source.file exists,
uses only that file.  There is no facility to say "read from this
one, and also that one".

When the command is called without "--global",
given_config_source.file is not set and in that case,
config.c::config_with_options() does the "config sequence".
This is implemented in config.c::do_git_config_sequence().

What is disturbing about this function is that it knows about two
global configuration files, and finds out about these two files by
calling the same git_global_config() helper function
builtin/config.c::cmd_config() uses.  However, the logic used to
decide if the file(s) are actually attempted to be read (e.g.  it is
not a configuration error to lack ~/.gitconfig) is slightly
different.  Ideally, it would be very nice if the high level caller
in cmd_config() loses the duplicated logic and instead just sets a
single "we are dealing with --global" bit in given_config_source
structure, and config_with_options() is taught to reuse the "we need
to read both of them" logic in do_git_config_sequence() when the bit
is set.



  reply	other threads:[~2023-02-11  3:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-11  0:39 BUG: git config --global --get ITEM ignores ~/.config/git/config when ~/.gitconfig is present Jade Lovelace
2023-02-11  1:33 ` Junio C Hamano
2023-02-11  1:44   ` Jade Lovelace
2023-02-11  1:56   ` Junio C Hamano
2023-02-11  3:10     ` Junio C Hamano [this message]
2023-02-15  6:53       ` Glen Choo
2023-02-15 16:19         ` 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=xmqqzg9kew1q.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=lists@jade.fyi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.