Thread (17 messages) flat view 17 messages, 6 authors, 10d ago
COOLING10d

[PATCH v2 0/3] config: read both home and xdg files for --global

From: Delilah Ashley Wu <hidden>
Date: 2026-08-23 10:30:57

Hi all, thanks for your patience. Here's my reroll.

As reported in [1], `$HOME/.gitconfig` and `$XDG_CONFIG_HOME/git/config`
are both valid global configuration locations. However, when both files
exist, `git config list --global` only reads from the former location
whereas `git config list` (without `--global`) reads from both. The same
issue was reported for `git config get` in [2]. This inconsistency has
no good justification and contradicts the documented behaviour.

Suppose that `$HOME/.gitconfig` contains:
    [home]
        config = true

and `$XDG_CONFIG_HOME/git/config` contains:
    [xdg]
        config = true

Then, listing with `--global` shows only the home config:
    $ git config list --global --show-scope --show-origin
    global  file:/Users/delilah/.gitconfig    home.config=true

and getting the XDG configuration entry with `--global` will fail:
    $ git config get --global xdg.config; echo $?
    1

Git still reads the XDG config as part of its effective configuration,
as shown by listing the configuration without `--global`:
    $ git config list --show-scope --show-origin
    global  file:/Users/delilah/.config/git/config    xdg.config=true
    global  file:/Users/delilah/.gitconfig            home.config=true

The documentation, quoted in [1] and [2], states that `--global` should
read from both files, so its output should be the same as above. Here's
the relevant excerpt:
OPTIONS
    --global::
        For writing options: write to global `~/.gitconfig` file
        rather than the repository `.git/config`, write to
        `$XDG_CONFIG_HOME/git/config` file if this file exists and the
        `~/.gitconfig` file doesn't.

        For reading options: read only from global `~/.gitconfig` and from
        `$XDG_CONFIG_HOME/git/config` rather than from all available files.
To be consistent with the documentation and the behaviour without
`--global`, we should read both configuration files when `--global` is
passed. We do this in a few steps:

 - Patch 1 fixes slash normalisation on Windows paths. This is used for
   `--show-origin` assertions in patch 3 tests.
 - Patch 2 modifies error handling when reading configuration files.
   This is used to prevent a regression in patch 3.
 - Patch 3 reads both configuration files when `--global` is specified.

[1]: https://lore.kernel.org/git/CAFA9we-QLQRzJdGMMCPatmfrk1oHeiUu9msMRXXk1MLE5HRxBQ@mail.gmail.com/ (local)
[2]: https://lore.kernel.org/git/CAAdFe9yhBk-WecVzCTsjQ-4Z3AZAbpP+w+B076ouM3qX6d1WAg@mail.gmail.com/ (local)

Thanks again for your time!
Delilah

---
Changes in v2:
 - Squash test-only patches into their corresponding implementation
   patches.
 - Reorder patches to prevent a regression from being introduced and
   then fixed in a later patch.
 - Narrow the scope of slash conversion to `xdg_config_home_for()` and
   avoid modifying `cleanup_path()`, which could've broken callers that
   do not expect normalised slashes.
 - Clarify that some tests only check the return code of a `git config`
   command; we do not care about the output.
 - Link to v1: https://patch.msgid.link/pull.1938.git.1760058849.gitgitgadget@gmail.com/

---
Delilah Ashley Wu (3):
      path: use forward slashes in XDG config on Windows
      config: let sequence require a successful file
      config: read global scope via config_sequence

 builtin/config.c     |  11 +++++
 config.c             |  76 +++++++++++++++++++++++-----------
 config.h             |   2 +
 path.c               |  16 ++++---
 t/t1300-config.sh    | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++
 t/t1306-xdg-files.sh |   5 ++-
 6 files changed, 194 insertions(+), 31 deletions(-)

Range-diff versus v1:

1:  d9525d954e < -:  ---------- config: read both home and xdg files for --global
2:  c24ed49bac < -:  ---------- cleanup_path: force forward slashes on Windows
3:  51293ee827 < -:  ---------- config: test home and xdg files in `list --global`
4:  26f3c46598 < -:  ---------- config: read global scope via config_sequence
5:  b6ab7bfd67 < -:  ---------- config: keep bailing on unreadable global files
-:  ---------- > 1:  2fa37d8aa7 path: use forward slashes in XDG config on Windows
-:  ---------- > 2:  d90c9ae69f config: let sequence require a successful file
-:  ---------- > 3:  a3b5599c8d config: read global scope via config_sequence

---
base-commit: 2c78326f810173a4f3aefd8021f1e07575412481
change-id: 20260808-fix-config-list-global-home-and-xdg-9bcaac093a1b
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help