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/gui | |
parent | 64017cf8745258cc6d4838a602295b8281585b9f (diff) |
allow editing remotes
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/keybindings.go | 8 | ||||
-rw-r--r-- | pkg/gui/remotes_panel.go | 40 |
2 files changed, 48 insertions, 0 deletions
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() + }) + }) +} |