From 745a03198eee628e54ed7e00dce842eae4143918 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:23:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0git=20init=20remote=20?= =?UTF-8?q?=E7=AD=89=E5=9F=BA=E7=A1=80=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 git.go diff --git a/git.go b/git.go new file mode 100644 index 0000000..d3cba39 --- /dev/null +++ b/git.go @@ -0,0 +1,59 @@ +// Package command ... +// +// Description : command ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2022-06-14 20:02 +package command + +import "git.zhangdeman.cn/zhangdeman/command/define" + +// Git ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:09 2022/6/14 +func Git(workDir string, gitCmdPath string) *git { + if len(gitCmdPath) == 0 { + gitCmdPath = "git" + } + return &git{ + workDir: workDir, + gitCmdPath: gitCmdPath, + } +} + +type git struct { + workDir string + gitCmdPath string +} + +// Init 对应 git init 命令 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:10 2022/6/14 +func (g *git) Init() *define.Result { + // 删除已有git信息 + _ = Dir(g.workDir).Delete(".git") + return Execute(g.workDir, g.gitCmdPath, []string{"init"}) +} + +// RemoteAddOrigin 对应 git remote add origin xxxx 命令 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:20 2022/6/14 +func (g *git) RemoteAddOrigin(gitRepoAddress string) *define.Result { + return Execute(g.workDir, g.gitCmdPath, []string{"remote", "add", "origin", gitRepoAddress}) +} + +// SetUpstreamOrigin 对应 git push --set-upstream origin xxx 命令 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:22 2022/6/14 +func (g *git) SetUpstreamOrigin(origin string) *define.Result { + return Execute(g.workDir, g.gitCmdPath, []string{"push", "--set-upstream ", "origin", origin}) +}