Skip to content

Implement ConfigLoader plugins that aligns with upstream behaviour#1924

Draft
pjbgf wants to merge 3 commits intogo-git:mainfrom
pjbgf:config-plugin
Draft

Implement ConfigLoader plugins that aligns with upstream behaviour#1924
pjbgf wants to merge 3 commits intogo-git:mainfrom
pjbgf:config-plugin

Conversation

@pjbgf
Copy link
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 three ConfigSource implementations: Disk (host filesystem only), Environment (respects GIT_CONFIG_* and XDG_CONFIG_HOME), and Auto (merges both, matching default Git behaviour).
  • Update EXTENDING.md with ConfigLoader plugin documentation.

Opt-in to Git's behaviour when using go-git

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 are initialized as empty. This behaviour is intentional, as it prevents unintended side effects in applications that use go-git to automate operations outside of a user-specific context.

For applications that need go-git to mimic the behavior of the standard git CLI, this can be enabled by registering the Auto ConfigSource:

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

Fixes #395 #1701 #1849.
Supersedes #1702.
Follows-up from #1860.

pjbgf added 3 commits March 25, 2026 05:28
Signed-off-by: Paulo Gomes <paulo@entire.io>
…tations

Disk reads configuration solely from standard Git file locations on the
host filesystem without consulting environment variables. It supports
both Unix (/etc/gitconfig, ~/.gitconfig, ~/.config/git/config) and
Windows (%PROGRAMFILES%\Git\etc\gitconfig, %USERPROFILE%\.gitconfig).

Environment honours GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM,
GIT_CONFIG_NOSYSTEM, XDG_CONFIG_HOME, and %APPDATA% (Windows) for
locating configuration files.

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 <paulo@entire.io>
Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Paulo Gomes <paulo@entire.io>
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)

1 participant