From f7309c25b647c697f08ef6bde3fa7b20ce2d37e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 12 Jan 2023 15:08:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96git?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84=E7=94=A8=E6=88=B7=E5=90=8D+?= =?UTF-8?q?=E9=82=AE=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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<白茶清欢>