-
Notifications
You must be signed in to change notification settings - Fork 25
/
global-gitconfig.go
45 lines (37 loc) · 1002 Bytes
/
global-gitconfig.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
package main
import (
"fmt"
"gopkg.in/libgit2/git2go.v24"
"os/exec"
"strings"
)
func ConfigForCurrentDir() (GitConfig, error) {
path, e := exec.Command("git", "rev-parse", "--show-toplevel").Output()
p := strings.TrimRight(string(path), "\n")
if len(p) < 1 {
// here is not git directory
return NewGlobalGitConfig(), e
}
return NewLocalGitConfig()
}
type GlobalGitConfig struct{}
func NewGlobalGitConfig() *GlobalGitConfig {
config := new(GlobalGitConfig)
return config
}
func (this *GlobalGitConfig) Host() (string, error) {
path, e := git.ConfigFindGlobal()
global, e := git.OpenOndisk(nil, path)
host, e := global.LookupString("gitlab.host")
return host, e
}
func (this *GlobalGitConfig) Token() (string, error) {
path, e := git.ConfigFindGlobal()
global, e := git.OpenOndisk(nil, path)
token, e := global.LookupString("gitlab.token")
return token, e
}
func (this *GlobalGitConfig) ApiPath() (string, error) {
apiPath := fmt.Sprintf("/api/v3")
return apiPath, nil
}