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

Re: BUG: git config --global --get ITEM ignores ~/.config/git/config when ~/.gitconfig is present

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 11, 2023, 03:10 UTC
Message-ID
<xmqqzg9kew1q.fsf@gitster.g>
In-Reply-To
<xmqqmt5lezi3.fsf@gitster.g>
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.

Previous: Junio C HamanoNext: Glen Choo
Message 5 of 7 in “BUG: git config --global --get ITEM ignores ~/.config/git/config when ~/.gitconfig is present”
  1. Jade LovelaceFeb 11, 2023
  2. Junio C HamanoFeb 11, 2023
  3. Jade LovelaceFeb 11, 2023
  4. Junio C HamanoFeb 11, 2023
  5. Junio C HamanoFeb 11, 2023
  6. Glen ChooFeb 15, 2023
  7. Junio C HamanoFeb 15, 2023

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.