Skip to content

config: honor environment variable config overrides in open_default - #7204

Open
amaanq wants to merge 1 commit into
libgit2:mainfrom
amaanq:config-open-default-env-vars
Open

config: honor environment variable config overrides in open_default#7204
amaanq wants to merge 1 commit into
libgit2:mainfrom
amaanq:config-open-default-env-vars

Conversation

@amaanq

@amaanq amaanq commented Jan 26, 2026

Copy link
Copy Markdown

Background

The following environment variables have been supported by git since version 2.32:

  • GIT_CONFIG_GLOBAL - which overrides the global config file location
  • GIT_CONFIG_SYSTEM - which overrides the system config file location
  • GIT_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 (delta is 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 respects GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, and GIT_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!

`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.
@amaanq

amaanq commented Mar 9, 2026

Copy link
Copy Markdown
Author

Friendly ping @ethomson if you have the time :)

@ethomson

Copy link
Copy Markdown
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). 🤔

@amaanq

amaanq commented Mar 25, 2026

Copy link
Copy Markdown
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 :)

@amaanq

amaanq commented Jul 19, 2026

Copy link
Copy Markdown
Author

Bump @ethomson...is there any hopes of this PR being merged? Or if not, at least some kind of explanation/reason as to why not?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants