add wrapper for git_config_open_default (#758) (#767)

(cherry picked from commit 1e2cb92b48)

Co-authored-by: Vladimir Buzuev <44682889+vladimir-buzuev@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2021-04-04 08:29:44 -07:00 committed by GitHub
parent 77a92cd976
commit 0bfc9d1536
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
}
// 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()
}