config: honor environment variable config overrides in open_default#7204
Open
amaanq wants to merge 1 commit intolibgit2:mainfrom
Open
config: honor environment variable config overrides in open_default#7204amaanq wants to merge 1 commit intolibgit2:mainfrom
open_default#7204amaanq wants to merge 1 commit intolibgit2:mainfrom
Conversation
`git_config_open_default()` now checks `GIT_CONFIG_GLOBAL`, `GIT_CONFIG_SYSTEM`, and `GIT_CONFIG_NOSYSTEM` environment variables before falling back to standard config file locations. This matches the behavior already implemented for repository-based config loading, allowing tools that use libgit2's standalone config API (like delta, gitui, etc.) to respect the same environment variables that git honors since version 2.32.
Author
|
Friendly ping @ethomson if you have the time :) |
Member
|
Thanks for the ping - I want to ponder this a bit, since this is a behavioral change, I wonder if we should have a flag here to determine the behavior (or if using the environment variables is always the expected behavior). 🤔 |
Author
|
Hm, git itself honors these environment variables unconditionally, I don't think you can opt-in to this. Additionally, the repo-based config loading path already does this now (since #6544). I think it makes the most sense to do this unconditionally just like git, though I am not an expert :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
The following environment variables have been supported by git since version 2.32:
GIT_CONFIG_GLOBAL- which overrides the global config file locationGIT_CONFIG_SYSTEM- which overrides the system config file locationGIT_CONFIG_NOSYSTEM- which skips the system config entirely#6544 added support for these environment variables when loading the config through a repository, but
git_config_open_default()was not updated to use these. This function is used by tools that need to read the git configuration without an open repository (deltais one such program that does this, via the git2-rs bindings).Solution
In this PR, I've updated
git_config_open_default()such that it now respectsGIT_CONFIG_GLOBAL,GIT_CONFIG_SYSTEM, andGIT_CONFIG_NOSYSTEM, which matches the behavior already implemented for repository-based config loading. I also added a few tests to ensure it functions as expected, and all tests pass on my machine :)Thank you!