1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-03 13:21:56 +02:00
lazygit/pkg/commands/remotes.go

49 lines
1.8 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"
2020-09-29 20:03:39 +10:00
)
func (c *GitCommand) AddRemote(name string, url string) error {
2021-12-29 14:33:38 +11:00
return c.Cmd.New(fmt.Sprintf("git remote add %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(url))).Run()
2020-09-29 20:03:39 +10:00
}
func (c *GitCommand) RemoveRemote(name string) error {
2021-12-29 14:33:38 +11:00
return c.Cmd.New(fmt.Sprintf("git remote remove %s", c.OSCommand.Quote(name))).Run()
2020-09-29 20:03:39 +10:00
}
func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) error {
2021-12-29 14:33:38 +11:00
return c.Cmd.New(fmt.Sprintf("git remote rename %s %s", c.OSCommand.Quote(oldRemoteName), c.OSCommand.Quote(newRemoteName))).Run()
2020-09-29 20:03:39 +10:00
}
func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error {
2021-12-29 14:33:38 +11:00
return c.Cmd.New(fmt.Sprintf("git remote set-url %s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(updatedUrl))).Run()
2020-09-29 20:03:39 +10:00
}
func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string, promptUserForCredential func(string) string) error {
2021-10-06 23:20:19 +09:00
command := fmt.Sprintf("git push %s --delete %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(branchName))
2021-12-29 14:33:38 +11:00
cmdObj := c.Cmd.New(command)
return c.DetectUnamePass(cmdObj, promptUserForCredential)
}
func (c *GitCommand) DetectUnamePass(cmdObj oscommands.ICmdObj, promptUserForCredential func(string) string) error {
return c.OSCommand.DetectUnamePass(cmdObj, c.GetCmdWriter(), promptUserForCredential)
2020-09-29 20:03:39 +10:00
}
// CheckRemoteBranchExists Returns remote branch
2021-07-27 20:02:52 +10:00
func (c *GitCommand) CheckRemoteBranchExists(branchName string) bool {
2021-12-29 14:33:38 +11:00
_, err := c.Cmd.New(
2021-12-07 21:59:36 +11:00
fmt.Sprintf("git show-ref --verify -- refs/remotes/origin/%s",
c.OSCommand.Quote(branchName),
2021-12-29 14:33:38 +11:00
)).RunWithOutput()
2020-09-29 20:03:39 +10:00
return err == nil
}
// GetRemoteURL returns current repo remote url
func (c *GitCommand) GetRemoteURL() string {
2021-10-23 09:52:19 +11:00
return c.GitConfig.Get("remote.origin.url")
2020-09-29 20:03:39 +10:00
}