add wrapper for git_config_open_default (#758)

This commit is contained in:
Vladimir Buzuev 2021-04-03 18:45:55 -07:00 committed by GitHub
parent 0d7c8dadb4
commit 1e2cb92b48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 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) 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()
}