diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 20:03:39 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-09-29 20:48:49 +1000 |
commit | 72af7e41778bca93d82fa668641f515fba1d92bc (patch) | |
tree | 7e755e857be72205ee99641d5eb5d4556151ad8f /pkg/commands/remotes.go | |
parent | 1767f91047a35318f6b1e469199c8a7f547f2afc (diff) |
factor out code from git.go
Diffstat (limited to 'pkg/commands/remotes.go')
-rw-r--r-- | pkg/commands/remotes.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/commands/remotes.go b/pkg/commands/remotes.go new file mode 100644 index 000000000..59793a155 --- /dev/null +++ b/pkg/commands/remotes.go @@ -0,0 +1,40 @@ +package commands + +import ( + "github.com/jesseduffield/lazygit/pkg/models" +) + +func (c *GitCommand) AddRemote(name string, url string) error { + return c.OSCommand.RunCommand("git remote add %s %s", name, url) +} + +func (c *GitCommand) RemoveRemote(name string) error { + return c.OSCommand.RunCommand("git remote remove %s", name) +} + +func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) error { + return c.OSCommand.RunCommand("git remote rename %s %s", oldRemoteName, newRemoteName) +} + +func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error { + return c.OSCommand.RunCommand("git remote set-url %s %s", remoteName, updatedUrl) +} + +func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string) error { + return c.OSCommand.RunCommand("git push %s --delete %s", remoteName, branchName) +} + +// 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") +} |