Skip to content

Implement ConfigLoader plugins that aligns with upstream behaviour#1924

Merged
pjbgf merged 4 commits into
go-git:mainfrom
pjbgf:config-plugin
Apr 15, 2026
Merged

Implement ConfigLoader plugins that aligns with upstream behaviour#1924
pjbgf merged 4 commits into
go-git:mainfrom
pjbgf:config-plugin

Conversation

@pjbgf
Copy link
Copy Markdown
Member

@pjbgf pjbgf commented Mar 25, 2026

Summary

  • Deprecate config.LoadConfig and the config.Paths helper in favour of the ConfigLoader plugin, centralising all scoped config resolution through ConfigSource.
  • Add Auto ConfigSource implementation to match Git behaviour - considering both files in disk and environment vars.
  • Update EXTENDING.md with ConfigLoader plugin documentation.
  • Make Auto the default ConfigLoader implementation.

Parts of go-git that depend on system or global configuration began using the ConfigLoader plugin with the introduction of #1860. By default, config.Configs for both System and Global will 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:

import (
	"github.com/go-git/go-git/v6/x/plugin"
	xconfig "github.com/go-git/go-git/v6/x/plugin/config"
)
...

func init() {
    plugin.Register(plugin.ConfigLoader(), func() plugin.ConfigSource {
        return xconfig.NewEmpty()
    })
}

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.

@pjbgf pjbgf force-pushed the config-plugin branch 4 times, most recently from 949b9bb to 6e7b60c Compare March 30, 2026 11:34
@pjbgf pjbgf marked this pull request as ready for review March 30, 2026 11:36
Copilot AI review requested due to automatic review settings March 30, 2026 11:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ConfigLoader with a default Auto implementation to align System/Global config resolution with upstream Git (disk + env var overrides).
  • Add x/plugin/config implementations (Auto, Static, Empty) plus comprehensive hermetic tests for Git path/env precedence.
  • Deprecate config.LoadConfig and config.Paths, and document ConfigLoader usage in EXTENDING.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.

Comment thread x/plugin/config/static.go Outdated
Comment thread x/plugin/config/empty.go Outdated
Comment thread x/plugin/config/auto.go
Comment thread x/plugin/config/auto_git_test.go
Copy link
Copy Markdown
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pjbgf pjbgf force-pushed the config-plugin branch 2 times, most recently from 72fa013 to ab6a2ef Compare April 13, 2026 15:19
Comment thread x/plugin/config/auto_git_test.go Outdated
pjbgf added 4 commits April 15, 2026 12:22
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
@pjbgf pjbgf merged commit 71c0311 into go-git:main Apr 15, 2026
16 checks passed
@pjbgf pjbgf deleted the config-plugin branch April 15, 2026 11:31
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.

support global config (i.e. $HOME/.gitconfig)

3 participants