You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 33d79b9
Browse filesBrowse the repository at this point in the historyBrowse files
When both `$HOME/.gitconfig` and `$XDG_CONFIG_HOME/git/config` exist,
`git config list --global` and `git config --get --global` read the home
configuration file but ignore the XDG file. Bug reporters expected these
commands to read both files and be consistent with the documentation and
the behaviour of the unscoped `git config list` and `git config --get`
commands [1][2], which read from both files (in addition to
system-wide and repository-specific entries, of course).
We assume each scope corresponds to a single configuration file. So,
during `--global` operations, Git selects a single path and passes it to
`git_config_from_file_with_options(path)`. Since global configuration
comes from two files, we should read the configuration files with
another method.
Running `git config list --show-scope --show-origin` (without
`--global`) reads both the home and XDG files. So there's existing code
that respects both locations, namely `do_git_config_sequence()` which
reads from all scopes. Introduce flags to ignore all but the global
scope (i.e. ignore system, local, worktree, and cmdline). Then, reuse
the function to read only the global scope when `--global` is specified.
This was the suggested solution [3] in the original bug report.
Modify tests to check that both configuration files are respected during
`--global` read operations and add tests to ensure we do not introduce
regressions. Specifically:
- The home config should take precedence over the XDG config.
- `git config list` should not fail on non-existent global config.
- `git config list --global` should fail when both global config files
are non-existent. It should not fail if at least one of them exists.
Implementation notes:
- The `ignore_global` flag is not set anywhere, so the
`if (!opts->ignore_global)` condition is always met. Include the
flag for completeness.
- Keep populating `opts->source.file` in `builtin/config.c` because it
is used as the destination config file for write operations. The
proposed changes could convolute the code because there is no single
source of truth for the config file locations in the global scope.
Add a comment to clarify this.
[1] https://lore.kernel.org/git/CAFA9we-QLQRzJdGMMCPatmfrk1oHeiUu9msMRXXk1MLE5HRxBQ@mail.gmail.com/
[2] https://lore.kernel.org/git/CAAdFe9yhBk-WecVzCTsjQ-4Z3AZAbpP+w+B076ouM3qX6d1WAg@mail.gmail.com/
[3] https://lore.kernel.org/git/kl6ly1oze7wb.fsf@chooglen-macbookpro.roam.corp.google.com
Reported-by: Jade Lovelace <lists@jade.fyi>
Reported-by: Nils Fahldieck <nils@fahldieck.de>
Suggested-by: Glen Choo <glencbz@gmail.com>
Helped-by: Derrick Stolee <stolee@gmail.com>
Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Delilah Ashley Wu <delilahwu@microsoft.com>
0 commit comments