增加获取git配置的用户名+邮箱

This commit is contained in:
白茶清欢 2023-01-12 15:08:05 +08:00
parent 903d1d9553
commit f7309c25b6

31
git.go
View File

@ -176,6 +176,37 @@ func (g *git) ConfigAuthor(name string, email string) *define.Result {
return nil
}
// GetAuthor ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:59 2023/1/12
func (g *git) GetAuthor(useGlobal bool) (string, string, error) {
var (
username string
email string
)
// git config [--global] user.name 白茶清欢
param := []string{"config"}
if useGlobal {
param = append(param, "--global")
}
nameParam := append(param, "user.name")
if r := Execute(g.workDir, g.gitCmdPath, nameParam); nil != r.Error {
return "", "", r.Error
} else {
username = string(r.Output)
}
mailParam := append(param, "user.email")
if r := Execute(g.workDir, g.gitCmdPath, mailParam); nil != r.Error {
return "", "", r.Error
} else {
email = string(r.Output)
}
return username, email, nil
}
// Clone 拉取 git 仓库代码
//
// Author : go_developer@163.com<白茶清欢>