diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-05-19 20:18:02 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-05-20 20:54:24 +1000 |
commit | 25f8b0337e1e023fd9575ecd46467810c9f49824 (patch) | |
tree | da4937d66b110d6f69621c79d98c3d9ce9384b41 /pkg/commands/git_commands/remote.go | |
parent | 63ddc52a6b0b69b656b106ee5ae74dd736ac6317 (diff) |
Add convenience builder for git commands
Diffstat (limited to 'pkg/commands/git_commands/remote.go')
-rw-r--r-- | pkg/commands/git_commands/remote.go | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/pkg/commands/git_commands/remote.go b/pkg/commands/git_commands/remote.go index 1245a8cf0..4be4350ef 100644 --- a/pkg/commands/git_commands/remote.go +++ b/pkg/commands/git_commands/remote.go @@ -15,44 +15,52 @@ func NewRemoteCommands(gitCommon *GitCommon) *RemoteCommands { } func (self *RemoteCommands) AddRemote(name string, url string) error { - return self.cmd. - New(fmt.Sprintf("git remote add %s %s", self.cmd.Quote(name), self.cmd.Quote(url))). - Run() + cmdStr := NewGitCmd("remote"). + Arg("add", self.cmd.Quote(name), self.cmd.Quote(url)). + ToString() + + return self.cmd.New(cmdStr).Run() } func (self *RemoteCommands) RemoveRemote(name string) error { - return self.cmd. - New(fmt.Sprintf("git remote remove %s", self.cmd.Quote(name))). - Run() + cmdStr := NewGitCmd("remote"). + Arg("remove", self.cmd.Quote(name)). + ToString() + + return self.cmd.New(cmdStr).Run() } func (self *RemoteCommands) RenameRemote(oldRemoteName string, newRemoteName string) error { - return self.cmd. - New(fmt.Sprintf("git remote rename %s %s", self.cmd.Quote(oldRemoteName), self.cmd.Quote(newRemoteName))). - Run() + cmdStr := NewGitCmd("remote"). + Arg("rename", self.cmd.Quote(oldRemoteName), self.cmd.Quote(newRemoteName)). + ToString() + + return self.cmd.New(cmdStr).Run() } func (self *RemoteCommands) UpdateRemoteUrl(remoteName string, updatedUrl string) error { - return self.cmd. - New(fmt.Sprintf("git remote set-url %s %s", self.cmd.Quote(remoteName), self.cmd.Quote(updatedUrl))). - Run() + cmdStr := NewGitCmd("remote"). + Arg("set-url", self.cmd.Quote(remoteName), self.cmd.Quote(updatedUrl)). + ToString() + + return self.cmd.New(cmdStr).Run() } func (self *RemoteCommands) DeleteRemoteBranch(remoteName string, branchName string) error { - command := fmt.Sprintf("git push %s --delete %s", self.cmd.Quote(remoteName), self.cmd.Quote(branchName)) - return self.cmd.New(command).PromptOnCredentialRequest().WithMutex(self.syncMutex).Run() + cmdStr := NewGitCmd("push"). + Arg(self.cmd.Quote(remoteName), "--delete", self.cmd.Quote(branchName)). + ToString() + + return self.cmd.New(cmdStr).PromptOnCredentialRequest().WithMutex(self.syncMutex).Run() } // CheckRemoteBranchExists Returns remote branch func (self *RemoteCommands) CheckRemoteBranchExists(branchName string) bool { - _, err := self.cmd. - New( - fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s", - self.cmd.Quote(branchName), - ), - ). - DontLog(). - RunWithOutput() + cmdStr := NewGitCmd("show-ref"). + Arg("--verify", "--", fmt.Sprintf("refs/remotes/origin/%s", self.cmd.Quote(branchName))). + ToString() + + _, err := self.cmd.New(cmdStr).DontLog().RunWithOutput() return err == nil } |