diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-05-18 21:04:50 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-05-19 09:57:37 +1000 |
commit | 003e45d2f5447d1f88e59e2f1edd85effeaae3ae (patch) | |
tree | 0c3072806664617f9e094c71e7b73193014d608b | |
parent | 04e93317b86f8ed3347e05ba5be30c7f39281682 (diff) |
allow creating branches off of remote branches
-rw-r--r-- | pkg/gui/keybindings.go | 8 | ||||
-rw-r--r-- | pkg/gui/remote_branches_panel.go | 23 |
2 files changed, 31 insertions, 0 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 01447a67b..8248e5e99 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1290,6 +1290,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { { ViewName: "branches", Contexts: []string{"remote-branches"}, + Key: gui.getKey("universal.new"), + Handler: gui.handleNewBranchOffRemote, + Description: gui.Tr.SLocalize("newBranch"), + }, + + { + ViewName: "branches", + Contexts: []string{"remote-branches"}, Key: gui.getKey("branches.mergeIntoCurrentBranch"), Handler: gui.handleMergeRemoteBranch, Description: gui.Tr.SLocalize("mergeIntoCurrentBranch"), diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 0b0349da0..b5cc102b9 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -139,3 +139,26 @@ func (gui *Gui) handleCreateResetToRemoteBranchMenu(g *gocui.Gui, v *gocui.View) return gui.createResetMenu(fmt.Sprintf("%s/%s", selectedBranch.RemoteName, selectedBranch.Name)) } + +func (gui *Gui) handleNewBranchOffRemote(g *gocui.Gui, v *gocui.View) error { + branch := gui.getSelectedRemoteBranch() + if branch == nil { + return nil + } + message := gui.Tr.TemplateLocalize( + "NewBranchNameBranchOff", + Teml{ + "branchName": branch.FullName(), + }, + ) + return gui.createPromptPanel(g, v, message, branch.FullName(), func(g *gocui.Gui, v *gocui.View) error { + if err := gui.GitCommand.NewBranch(gui.trimmedContent(v), branch.FullName()); err != nil { + return gui.surfaceError(err) + } + gui.State.Panels.Branches.SelectedLine = 0 + if err := gui.switchBranchesPanelContext("local-branches"); err != nil { + return err + } + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + }) +} |