// 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}) } // 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) }