diff options
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/git.go | 8 | ||||
-rw-r--r-- | modules/git/git_test.go | 24 |
2 files changed, 26 insertions, 6 deletions
diff --git a/modules/git/git.go b/modules/git/git.go index a31afc077a..2e0a16fb5c 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -224,6 +224,14 @@ func syncGitConfig() (err error) { return fmt.Errorf("unable to prepare git home directory %s, err: %w", 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(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. diff --git a/modules/git/git_test.go b/modules/git/git_test.go index 25eb308531..37ab669ea4 100644 --- a/modules/git/git_test.go +++ b/modules/git/git_test.go @@ -42,14 +42,14 @@ func TestMain(m *testing.M) { } } -func TestGitConfig(t *testing.T) { - gitConfigContains := func(sub string) bool { - if b, err := os.ReadFile(HomeDir() + "/.gitconfig"); err == nil { - return strings.Contains(string(b), sub) - } - return false +func gitConfigContains(sub string) bool { + if b, err := os.ReadFile(HomeDir() + "/.gitconfig"); err == nil { + return strings.Contains(string(b), sub) } + return false +} +func TestGitConfig(t *testing.T) { assert.False(t, gitConfigContains("key-a")) assert.NoError(t, configSetNonExist("test.key-a", "val-a")) @@ -81,3 +81,15 @@ func TestGitConfig(t *testing.T) { assert.NoError(t, configUnsetAll("test.key-x", "*")) assert.False(t, gitConfigContains("key-x = *")) } + +func TestSyncConfig(t *testing.T) { + oldGitConfig := setting.GitConfig + defer func() { + setting.GitConfig = oldGitConfig + }() + + setting.GitConfig.Options["sync-test.cfg-key-a"] = "CfgValA" + assert.NoError(t, syncGitConfig()) + assert.True(t, gitConfigContains("[sync-test]")) + assert.True(t, gitConfigContains("cfg-key-a = CfgValA")) +} |