forked from shibukawa/git4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.go
52 lines (44 loc) · 1022 Bytes
/
git.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package git4go
type ErrorCode int
const (
// Signals end of iteration with iterator
ErrNotFound ErrorCode = -3
ErrIterOver ErrorCode = -31
)
type GitError struct {
Message string
Code ErrorCode
}
func (e GitError) Error() string {
return e.Message
}
func IsErrorCode(err error, c ErrorCode) bool {
if err == nil {
return false
}
if gitError, ok := err.(*GitError); ok {
return gitError.Code == c
}
return false
}
func MakeGitError(message string, errorCode ErrorCode) error {
return &GitError{
Message: message,
Code: errorCode,
}
}
const (
GitOidRawSize = 20
GitOidHexSize = 40
GitOidMinimumPrefixLength = 4
GitObjectDirMode uint32 = 0777
GitObjectFileMode uint32 = 0444
)
func Discover(start string, acrossFs bool, ceilingDirs []string) (string, error) {
var flags uint32 = 0
if acrossFs {
flags = GIT_REPOSITORY_OPEN_CROSS_FS
}
repoPath, _, _, err := findRepo(start, flags, ceilingDirs)
return repoPath, err
}