diff options
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 } |