enhance: allow builtin default git config options to be overridden (#38172)

This is really a follow-up to
[#38148](https://github.com/go-gitea/gitea/pull/35305) , instead of
having specific mappings of options for git configurations, just honor
any user-provided gitconfig. I include a test which points out the
specific config I have which was previously not honored, but more
generally this means that gitea now only *adds* new gitconfig and never
overwrites any config provided under `[git.config]`.

---------

Signed-off-by: Royce Remer <royceremer@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Royce Remer
2026-06-22 18:29:06 +00:00
committed by GitHub
co-authored by wxiaoguang
parent 08a18d36a6
commit 736ab982c8
3 changed files with 27 additions and 15 deletions
+11 -9
View File
@@ -21,14 +21,6 @@ func syncGitConfig(ctx context.Context) (err error) {
return fmt.Errorf("unable to prepare git home directory %s, err: %w", gitcmd.HomeDir(), err)
}
// first, write user's git config options to git config file
// user config options could be overwritten by builtin values later, because if a value is builtin, it must have some special purposes
for k, v := range setting.GitConfig.Options {
if err = configSet(ctx, strings.ToLower(k), v); err != nil {
return err
}
}
// Git requires setting user.name and user.email in order to commit changes - old comment: "if they're not set just add some defaults"
// TODO: need to confirm whether users really need to change these values manually. It seems that these values are dummy only and not really used.
// If these values are not really used, then they can be set (overwritten) directly without considering about existence.
@@ -111,8 +103,18 @@ func syncGitConfig(ctx context.Context) (err error) {
}
err = configUnsetAll(ctx, "uploadpack.allowAnySHA1InWant", "true")
}
if err != nil {
return err
}
return err
// Apply user's git config options last so they take precedence over builtin defaults
for k, v := range setting.GitConfig.Options {
if err = configSet(ctx, strings.ToLower(k), v); err != nil {
return err
}
}
return nil
}
func configSet(ctx context.Context, key, value string) error {