Skip to content

Commit 1e2cb92

Browse files
add wrapper for git_config_open_default (#758)
1 parent 0d7c8da commit 1e2cb92

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

config.go

+14
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,17 @@ func ConfigFindProgramdata() (string, error) {
450450

451451
return C.GoString(buf.ptr), nil
452452
}
453+
454+
// OpenDefault opens the default config according to git rules
455+
func OpenDefault() (*Config, error) {
456+
runtime.LockOSThread()
457+
defer runtime.UnlockOSThread()
458+
459+
config := new(Config)
460+
461+
if ret := C.git_config_open_default(&config.ptr); ret < 0 {
462+
return nil, MakeGitError(ret)
463+
}
464+
465+
return config, nil
466+
}

config_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,13 @@ func TestConfigLookups(t *testing.T) {
107107
test(c, t)
108108
}
109109
}
110+
111+
func TestOpenDefault(t *testing.T) {
112+
113+
c, err := OpenDefault()
114+
if err != nil {
115+
t.Errorf("OpenDefault error: '%v'. Expected none\n", err)
116+
return
117+
}
118+
defer c.Free()
119+
}

0 commit comments

Comments
 (0)