1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/commands/remotes.go

44 lines
1.3 KiB
Go
Raw Normal View History

2020-09-29 12:03:39 +02:00
package commands
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/commands/models"
2020-09-29 12:03:39 +02:00
)
func (c *GitCommand) AddRemote(name string, url string) error {
return c.RunCommand("git remote add %s %s", name, url)
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) RemoveRemote(name string) error {
return c.RunCommand("git remote remove %s", name)
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) error {
return c.RunCommand("git remote rename %s %s", oldRemoteName, newRemoteName)
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error {
return c.RunCommand("git remote set-url %s %s", remoteName, updatedUrl)
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string, promptUserForCredential func(string) string) error {
command := fmt.Sprintf("git push %s --delete %s", remoteName, branchName)
return c.OSCommand.DetectUnamePass(command, promptUserForCredential)
2020-09-29 12:03:39 +02:00
}
// CheckRemoteBranchExists Returns remote branch
func (c *GitCommand) CheckRemoteBranchExists(branch *models.Branch) bool {
_, err := c.OSCommand.RunCommandWithOutput(
"git show-ref --verify -- refs/remotes/origin/%s",
branch.Name,
)
return err == nil
}
// GetRemoteURL returns current repo remote url
func (c *GitCommand) GetRemoteURL() string {
return c.GetConfigValue("remote.origin.url")
}