From b237251b38a50ab83aa33109d0f31375f0410795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 14 Jun 2022 20:30:14 +0800 Subject: [PATCH] =?UTF-8?q?git=20=E6=94=AF=E6=8C=81=20add=20comment=20push?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/git.go b/git.go index d3cba39..1478c9c 100644 --- a/git.go +++ b/git.go @@ -57,3 +57,46 @@ func (g *git) RemoteAddOrigin(gitRepoAddress string) *define.Result { func (g *git) SetUpstreamOrigin(origin string) *define.Result { return Execute(g.workDir, g.gitCmdPath, []string{"push", "--set-upstream ", "origin", origin}) } + +// Add 对应 git add xxx 命令 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:24 2022/6/14 +func (g *git) Add(fileList ...string) *define.Result { + if len(fileList) == 0 { + fileList = []string{"*"} + } + param := []string{"add"} + for _, item := range fileList { + param = append(param, item) + } + return Execute(g.workDir, g.gitCmdPath, param) +} + +// Commit 对应 git commit -m 'xxxx' +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:26 2022/6/14 +func (g *git) Commit(comment string) *define.Result { + if len(comment) == 0 { + comment = "add some code" + } + return Execute(g.workDir, g.gitCmdPath, []string{"commit", "-m", comment}) +} + +// Push 对应 git push +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:28 2022/6/14 +func (g *git) Push(force bool) *define.Result { + param := []string{ + "push", + } + if force { + param = append(param, "-f") + } + return Execute(g.workDir, g.gitCmdPath, param) +}