1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/commands/git_commands/remote.go

59 lines
1.6 KiB
Go
Raw Normal View History

2022-01-08 05:00:36 +02:00
package git_commands
2020-09-29 12:03:39 +02:00
import (
"fmt"
2020-09-29 12:03:39 +02:00
)
2022-01-02 01:34:33 +02:00
type RemoteCommands struct {
*GitCommon
2022-01-02 01:34:33 +02:00
}
func NewRemoteCommands(gitCommon *GitCommon) *RemoteCommands {
2022-01-02 01:34:33 +02:00
return &RemoteCommands{
GitCommon: gitCommon,
2022-01-02 01:34:33 +02:00
}
2020-09-29 12:03:39 +02:00
}
2022-01-02 01:34:33 +02:00
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))).
2021-12-31 00:45:29 +02:00
Run()
2020-09-29 12:03:39 +02:00
}
2022-01-02 01:34:33 +02:00
func (self *RemoteCommands) RemoveRemote(name string) error {
return self.cmd.
New(fmt.Sprintf("git remote remove %s", self.cmd.Quote(name))).
2021-12-31 00:45:29 +02:00
Run()
2020-09-29 12:03:39 +02:00
}
2022-01-02 01:34:33 +02:00
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))).
2021-12-31 00:45:29 +02:00
Run()
2020-09-29 12:03:39 +02:00
}
2022-01-02 01:34:33 +02:00
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()
}
2022-01-02 01:34:33 +02:00
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()
2020-09-29 12:03:39 +02:00
}
// CheckRemoteBranchExists Returns remote branch
2022-01-02 01:34:33 +02:00
func (self *RemoteCommands) CheckRemoteBranchExists(branchName string) bool {
_, err := self.cmd.
2021-12-31 00:45:29 +02:00
New(
fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s",
2022-01-02 01:34:33 +02:00
self.cmd.Quote(branchName),
2022-01-05 02:57:32 +02:00
),
).
DontLog().
2021-12-31 00:45:29 +02:00
RunWithOutput()
2020-09-29 12:03:39 +02:00
return err == nil
}