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
config: read from config sequence for global scope
The output of `git config list --global` should include both
`$HOME/.gitconfig` and `$XDG_CONFIG_HOME/git/config`, but it only reads
from the former.
We've assumed each config scope corresponds to a single config file
location. Because of this assumption, `git config list --global` reads
the global config by calling
`git_config_from_file_with_options(..., "~/.gitconfig", ...)`. This
function usage restricts us to a single config file. Since the global
scope includes more than one file, we should use another method to read
the global config.
The output of `git config list --show-scope --show-origin` correctly
includes both the home and XDG config files. So there's existing code
that respects both locations, namely the `do_git_config_sequence()`
function which reads from all scopes. Introduce flags that make it
possible to ignore all but the global scope (i.e. ignore system, local,
worktree, and cmdline). Then, reuse this function for reading only the
global scope. This was the suggested solution in the original bug report
thread [1].
However, this change introduces a regression. If the global config file
does not exist or is unreadable, `git config list --global` should fail.
Since `do_git_config_sequence()` reads from all scopes, it will still
succeed when the global config file is missing. This regression will be
addressed in the next patch.
Modify the tests as follows:
A. Assert that the output of `git config list --global` now includes
both the home and XDG config.
B. Expect success even when the global config file is missing or
unreadable, marking them as a "TODO known breakage".
Note 1: The `ignore_global` flag is not set anywhere, so the
`if (!opts->ignore_global)` condition is always met. We can remove this
flag if desired.
Note 2: It's assumed that `config_source->scope == CONFIG_SCOPE_GLOBAL`
iff `--global` is specified. This comparison determines whether to call
`do_git_config_sequence()` for the global scope, or to keep calling
`git_config_from_file_with_options()` for other scopes.
Note 3: Keep populating `opts->source.file` in `builtin/config.c`
because it is used as the destination 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 help clarify this. Please let me know if it's unclear.
[1]: https://lore.kernel.org/git/[email protected].
Reported-by: Jade Lovelace <[email protected]>
Helped-by: Derrick Stolee <[email protected]>
Suggested-by: Glen Choo <[email protected]>
Signed-off-by: Delilah Ashley Wu <[email protected]>
0 commit comments