-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.go
More file actions
46 lines (40 loc) · 808 Bytes
/
commit.go
File metadata and controls
46 lines (40 loc) · 808 Bytes
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
package gitwrapper
import (
"strings"
)
func (rc RepoConfig) Commit(add bool, msg string) error {
// step 1
_, err := runGitCmd(true, "git status")
if err != nil {
return err
}
// step 2
if add {
_, err = runGitCmd(true, "git add -A")
if err != nil {
return err
}
}
// step 3
if len(msg) == 0 {
msg = rc.getDefaultCommitMessage()
}
_, err = runGitCmd(true, "git commit -am '"+msg+"'")
if err != nil {
return err
}
return nil
}
func (rc RepoConfig) getDefaultCommitMessage() string {
var m string
ss := strings.SplitN(rc.CurrentBranch, "/", 2)
if len(ss) > 1 {
m = "[" + strings.Title(ss[0]) + "] "
ss = ss[1:]
}
if len(ss[0]) == 0 {
return m
}
m += strings.Replace(strings.Title(ss[0][0:1])+ss[0][1:], "-", " ", -1)
return strings.Replace(m, "_", " ", -1)
}