1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-12 04:23:03 +02:00
lazygit/pkg/commands/remotes.go

42 lines
1.4 KiB
Go
Raw Normal View History

2020-09-29 12:03:39 +02:00
package commands
import (
"fmt"
2020-09-29 12:03:39 +02:00
)
func (c *GitCommand) AddRemote(name string, url string) error {
2021-10-06 16:20:19 +02:00
return c.RunCommand("git remote add %s %s", c.OSCommand.Quote(name), c.OSCommand.Quote(url))
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) RemoveRemote(name string) error {
2021-10-06 16:20:19 +02:00
return c.RunCommand("git remote remove %s", c.OSCommand.Quote(name))
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) error {
2021-10-06 16:20:19 +02:00
return c.RunCommand("git remote rename %s %s", c.OSCommand.Quote(oldRemoteName), c.OSCommand.Quote(newRemoteName))
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error {
2021-10-06 16:20:19 +02:00
return c.RunCommand("git remote set-url %s %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(updatedUrl))
2020-09-29 12:03:39 +02:00
}
func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string, promptUserForCredential func(string) string) error {
2021-10-06 16:20:19 +02:00
command := fmt.Sprintf("git push %s --delete %s", c.OSCommand.Quote(remoteName), c.OSCommand.Quote(branchName))
return c.OSCommand.DetectUnamePass(command, promptUserForCredential)
2020-09-29 12:03:39 +02:00
}
// CheckRemoteBranchExists Returns remote branch
2021-07-27 12:02:52 +02:00
func (c *GitCommand) CheckRemoteBranchExists(branchName string) bool {
2020-09-29 12:03:39 +02:00
_, err := c.OSCommand.RunCommandWithOutput(
"git show-ref --verify -- refs/remotes/origin/%s",
2021-10-06 16:26:25 +02:00
c.OSCommand.Quote(branchName),
2020-09-29 12:03:39 +02:00
)
return err == nil
}
// GetRemoteURL returns current repo remote url
func (c *GitCommand) GetRemoteURL() string {
return c.GetConfigValue("remote.origin.url")
}