diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-17 18:15:32 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 22:07:14 +1100 |
commit | cea24c2cf98c48e187900041d9e3bbeb93596019 (patch) | |
tree | 2390449a308f689470f6e944c2a317b89718ee9f /pkg | |
parent | 64017cf8745258cc6d4838a602295b8281585b9f (diff) |
allow editing remotes
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/git.go | 8 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 8 | ||||
-rw-r--r-- | pkg/gui/remotes_panel.go | 40 | ||||
-rw-r--r-- | pkg/i18n/english.go | 9 |
4 files changed, 65 insertions, 0 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 9dda1b2d2..76c753940 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -1091,3 +1091,11 @@ func (c *GitCommand) DeleteRemoteBranch(remoteName string, branchName string) er func (c *GitCommand) SetBranchUpstream(remoteName string, remoteBranchName string, branchName string) error { return c.OSCommand.RunCommand(fmt.Sprintf("git branch --set-upstream-to=%s/%s %s", remoteName, remoteBranchName, branchName)) } + +func (c *GitCommand) RenameRemote(oldRemoteName string, newRemoteName string) error { + return c.OSCommand.RunCommand(fmt.Sprintf("git remote rename %s %s", oldRemoteName, newRemoteName)) +} + +func (c *GitCommand) UpdateRemoteUrl(remoteName string, updatedUrl string) error { + return c.OSCommand.RunCommand(fmt.Sprintf("git remote set-url %s %s", remoteName, updatedUrl)) +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 79972837b..a64bb2965 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1032,6 +1032,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { }, { ViewName: "branches", + Contexts: []string{"remotes"}, + Key: 'e', + Modifier: gocui.ModNone, + Handler: gui.handleEditRemote, + Description: gui.Tr.SLocalize("editRemote"), + }, + { + ViewName: "branches", Contexts: []string{"remote-branches"}, Key: gocui.KeySpace, Modifier: gocui.ModNone, diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 76b174e89..bf9f8e110 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -132,3 +132,43 @@ func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error { }, nil) } + +func (gui *Gui) handleEditRemote(g *gocui.Gui, v *gocui.View) error { + branchesView := gui.getBranchesView() + remote := gui.getSelectedRemote() + if remote == nil { + return nil + } + + editNameMessage := gui.Tr.TemplateLocalize( + "editRemoteName", + Teml{ + "remoteName": remote.Name, + }, + ) + + return gui.createPromptPanel(g, branchesView, editNameMessage, "", func(g *gocui.Gui, v *gocui.View) error { + updatedRemoteName := gui.trimmedContent(v) + + if updatedRemoteName != remote.Name { + if err := gui.GitCommand.RenameRemote(remote.Name, updatedRemoteName); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + } + + editUrlMessage := gui.Tr.TemplateLocalize( + "editRemoteUrl", + Teml{ + "remoteName": updatedRemoteName, + }, + ) + + return gui.createPromptPanel(g, branchesView, editUrlMessage, "", func(g *gocui.Gui, v *gocui.View) error { + updatedRemoteUrl := gui.trimmedContent(v) + if err := gui.GitCommand.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + return gui.refreshRemotes() + }) + }) +} diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 5a5622f6c..3dae1106b 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -856,6 +856,12 @@ func addEnglish(i18nObject *i18n.Bundle) error { ID: "newRemoteUrl", Other: `New remote url:`, }, &i18n.Message{ + ID: "editRemoteName", + Other: `Enter updated remote name for {{ .remoteName }}:`, + }, &i18n.Message{ + ID: "editRemoteUrl", + Other: `Enter updated remote url for {{ .remoteName }}:`, + }, &i18n.Message{ ID: "removeRemote", Other: `remove remote`, }, &i18n.Message{ @@ -876,6 +882,9 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "SetUpstreamMessage", Other: "Are you sure you want to set the upstream branch of '{{.checkedOut}}' to '{{.selected}}'", + }, &i18n.Message{ + ID: "editRemote", + Other: "edit remote", }, ) } |