add wrapper for git_config_open_default (#758) #766

Merged
github-actions[bot] merged 1 commits from cherry-pick-715596110-release-1.0 into release-1.0 2021-04-04 10:29:36 -05:00
2 changed files with 24 additions and 0 deletions

View File

@ -450,3 +450,17 @@ func ConfigFindProgramdata() (string, error) {
return C.GoString(buf.ptr), nil
}
// OpenDefault opens the default config according to git rules
func OpenDefault() (*Config, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
config := new(Config)
if ret := C.git_config_open_default(&config.ptr); ret < 0 {
return nil, MakeGitError(ret)
}
return config, nil
}

View File

@ -107,3 +107,13 @@ func TestConfigLookups(t *testing.T) {
test(c, t)
}
}
func TestOpenDefault(t *testing.T) {
c, err := OpenDefault()
if err != nil {
t.Errorf("OpenDefault error: '%v'. Expected none\n", err)
return
}
defer c.Free()
}