-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmeta.go
53 lines (41 loc) · 904 Bytes
/
meta.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
53
package semv
import (
"bytes"
)
// UsernameCmd for git
var UsernameCmd = []string{"config", "user.name"}
// LatestCommitCmd for git
var LatestCommitCmd = []string{"describe", "--always"}
var usernameCmder Cmder
var latestCommitCmder Cmder
func username() ([]byte, error) {
if usernameCmder == nil {
usernameCmder = Cmd{}
}
b, err := usernameCmder.Do(git, UsernameCmd...)
if err != nil {
return nil, err
}
return bytes.TrimSpace(b), nil
}
func latestCommit() ([]byte, error) {
if latestCommitCmder == nil {
latestCommitCmder = Cmd{}
}
b, err := latestCommitCmder.Do(git, LatestCommitCmd...)
if err != nil {
return nil, err
}
return bytes.TrimSpace(b), nil
}
func meta() ([]string, error) {
user, err := username()
if err != nil {
return nil, err
}
hash, err := latestCommit()
if err != nil {
return nil, err
}
return []string{string(hash), string(user)}, nil
}