Skip to content

Commit e1238b5

Browse files
author
Axel Wagner
committed
Implement git_repository_discover
1 parent c9adbf0 commit e1238b5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

git.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "C"
99
import (
1010
"bytes"
1111
"unsafe"
12+
"strings"
1213
)
1314

1415
const (
@@ -122,3 +123,29 @@ func ucbool(b bool) C.uint {
122123
}
123124
return C.uint(0)
124125
}
126+
127+
func Discover(start string, across_fs bool, ceiling_dirs []string) (string, error) {
128+
ceildirs := C.CString(strings.Join(ceiling_dirs, string(C.GIT_PATH_LIST_SEPARATOR)))
129+
defer C.free(unsafe.Pointer(ceildirs))
130+
131+
cstart := C.CString(start)
132+
defer C.free(unsafe.Pointer(cstart))
133+
134+
retpath := (*C.char)(C.malloc(C.GIT_PATH_MAX))
135+
defer C.free(unsafe.Pointer(retpath))
136+
137+
var acrfs C.int
138+
if across_fs {
139+
acrfs = 1
140+
} else {
141+
acrfs = 0
142+
}
143+
144+
r := C.git_repository_discover(retpath, C.GIT_PATH_MAX, cstart, acrfs, ceildirs)
145+
146+
if r == 0 {
147+
return C.GoString(retpath), nil
148+
}
149+
150+
return "", LastError()
151+
}

0 commit comments

Comments
 (0)