diff --git a/git.go b/git.go index 12196d7..3e9952d 100644 --- a/git.go +++ b/git.go @@ -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<白茶清欢>