1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-22 05:29:44 +02:00
lazygit/pkg/commands/remotes.go

68 lines
1.7 KiB
Go
Raw Normal View History

2020-09-29 20:03:39 +10:00
package commands
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
2022-01-02 10:34:33 +11:00
"github.com/jesseduffield/lazygit/pkg/common"
2020-09-29 20:03:39 +10:00
)
2022-01-02 10:34:33 +11:00
type RemoteCommands struct {
*common.Common
cmd oscommands.ICmdObjBuilder
}
func NewRemoteCommands(
common *common.Common,
cmd oscommands.ICmdObjBuilder,
) *RemoteCommands {
return &RemoteCommands{
Common: common,
cmd: cmd,
}
2020-09-29 20:03:39 +10:00
}
2022-01-02 10:34:33 +11: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 09:45:29 +11:00
Run()
2020-09-29 20:03:39 +10:00
}
2022-01-02 10:34:33 +11: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 09:45:29 +11:00
Run()
2020-09-29 20:03:39 +10:00
}
2022-01-02 10:34:33 +11: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 09:45:29 +11:00
Run()
2020-09-29 20:03:39 +10:00
}
2022-01-02 10:34:33 +11: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 10:34:33 +11: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().Run()
2020-09-29 20:03:39 +10:00
}
// CheckRemoteBranchExists Returns remote branch
2022-01-02 10:34:33 +11:00
func (self *RemoteCommands) CheckRemoteBranchExists(branchName string) bool {
_, err := self.cmd.
2021-12-31 09:45:29 +11:00
New(
fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s",
2022-01-02 10:34:33 +11:00
self.cmd.Quote(branchName),
2022-01-05 11:57:32 +11:00
),
).
DontLog().
2021-12-31 09:45:29 +11:00
RunWithOutput()
2020-09-29 20:03:39 +10:00
return err == nil
}