Implement ConfigLoader plugins that aligns with upstream behaviour#1924
Merged
Conversation
949b9bb to
6e7b60c
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR completes the move to plugin-based scoped config resolution by implementing a Git-compatible ConfigLoader (Auto) and making it the default, while deprecating legacy helpers.
Changes:
- Register
ConfigLoaderwith a defaultAutoimplementation to align System/Global config resolution with upstream Git (disk + env var overrides). - Add
x/plugin/configimplementations (Auto,Static,Empty) plus comprehensive hermetic tests for Git path/env precedence. - Deprecate
config.LoadConfigandconfig.Paths, and documentConfigLoaderusage inEXTENDING.md.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| x/plugin/plugin_config.go | Registers a default ConfigLoader implementation (Auto) at init time. |
| x/plugin/config/auto.go | Implements Git-like System/Global config path/env resolution with size limits and read-only storers. |
| x/plugin/config/auto_git_test.go | Adds hermetic tests asserting precedence matches git-config(1) scenarios. |
| x/plugin/config/static.go | Updates static config source implementation and constructor signature. |
| x/plugin/config/empty.go | Updates empty config source constructor signature. |
| config/config.go | Deprecates legacy LoadConfig and Paths in favor of the plugin mechanism. |
| EXTENDING.md | Documents the new ConfigLoader plugin and built-in sources. |
Comments suppressed due to low confidence (1)
config/config.go:338
- The error message has a grammatical issue: "read from the a ConfigStorer". Consider changing it to something like "read from a ConfigStorer" to improve clarity for callers.
if scope == LocalScope {
return nil, fmt.Errorf("LocalScope should be read from the a ConfigStorer")
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
72fa013 to
ab6a2ef
Compare
aymanbagabas
approved these changes
Apr 13, 2026
Signed-off-by: Paulo Gomes <[email protected]>
Auto mimics default Git behaviour by merging all candidate config files in precedence order, with environment variable overrides replacing the default disk paths when set. Signed-off-by: Paulo Gomes <[email protected]> Assisted-by: Claude Opus 4.6 <[email protected]>
By default go-git will source System and Global configs the same way
as Git does. Server-side applications that wan't to opt-out from that
behaviour will need to register an empty/static (or custom) ConfigLoader
instead. Example:
err := plugin.Register(plugin.ConfigLoader(), func() plugin.ConfigSource {
return config.NewEmpty()
})
Signed-off-by: Paulo Gomes <[email protected]>
- Use billy.Basic for the fs field and osfs.Default instead of
osfs.New("/"), which broke absolute paths on Windows.
- Use os.LookupEnv for GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM so
that setting them to "" explicitly disables the scope (matching git).
- Centralise all Auto tests in auto_git_test.go backed by memfs;
config_test.go now only covers Static/Empty/ReadOnly.
- Set USERPROFILE alongside HOME in tests so os.UserHomeDir works
on Windows.
- Use filepath.Join and xdgConfigPath/systemPaths to derive
platform-correct paths in tests.
Signed-off-by: Paulo Gomes <[email protected]>
Assisted-by: Assisted-by: Claude Opus 4.6 <[email protected]>
Entire-Checkpoint: 3b696b8dea5e
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.
Summary
config.LoadConfigand theconfig.Pathshelper in favour of theConfigLoaderplugin, centralising all scoped config resolution throughConfigSource.ConfigSourceimplementation to match Git behaviour - considering both files in disk and environment vars.ConfigLoaderplugin documentation.Autothe defaultConfigLoaderimplementation.Parts of
go-gitthat depend on system or global configuration began using theConfigLoaderplugin with the introduction of #1860. By default,config.Configsfor bothSystemandGlobalwill be looked at locations in disk (and environment variable paths) that Git uses in order to load their contents.For applications that want to opt-out from the behaviour, and either ignore the contents from the System/Global configs:
Alternatively, it is also possible to set arbitrary configs for both contexts from a go-git perspective, by using
xconfig.NewStatic(cfg1, cfg2).Fixes #395 #1701 #1849 #401.
Supersedes #1702.
Follows-up from #1860.