summaryrefslogtreecommitdiffstats
path: root/pkg/gui
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-17 13:21:38 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-21 22:07:14 +1100
commit2afbd7ba7fcd3668d7c70b831e525741e6214bd5 (patch)
treeba81a610920249818773befbfe0d051802244910 /pkg/gui
parent55ff0c0dee09b505ecd123f3f893e143651947bf (diff)
support merging remote branches into checked out branch
Diffstat (limited to 'pkg/gui')
-rw-r--r--pkg/gui/branches_panel.go25
-rw-r--r--pkg/gui/keybindings.go8
-rw-r--r--pkg/gui/remote_branches_panel.go5
3 files changed, 29 insertions, 9 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index c47138bd1..154149a33 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -276,27 +276,34 @@ func (gui *Gui) deleteNamedBranch(g *gocui.Gui, v *gocui.View, selectedBranch *c
}, nil)
}
-func (gui *Gui) handleMerge(g *gocui.Gui, v *gocui.View) error {
- checkedOutBranch := gui.State.Branches[0].Name
- selectedBranch := gui.getSelectedBranch().Name
- if checkedOutBranch == selectedBranch {
- return gui.createErrorPanel(g, gui.Tr.SLocalize("CantMergeBranchIntoItself"))
+func (gui *Gui) mergeBranchIntoCheckedOutBranch(branchName string) error {
+ if gui.GitCommand.IsHeadDetached() {
+ return gui.createErrorPanel(gui.g, "Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on")
+ }
+ checkedOutBranchName := gui.State.Branches[0].Name
+ if checkedOutBranchName == branchName {
+ return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantMergeBranchIntoItself"))
}
prompt := gui.Tr.TemplateLocalize(
"ConfirmMerge",
Teml{
- "checkedOutBranch": checkedOutBranch,
- "selectedBranch": selectedBranch,
+ "checkedOutBranch": checkedOutBranchName,
+ "selectedBranch": branchName,
},
)
- return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("MergingTitle"), prompt,
+ return gui.createConfirmationPanel(gui.g, gui.getBranchesView(), true, gui.Tr.SLocalize("MergingTitle"), prompt,
func(g *gocui.Gui, v *gocui.View) error {
- err := gui.GitCommand.Merge(selectedBranch)
+ err := gui.GitCommand.Merge(branchName)
return gui.handleGenericMergeCommandResult(err)
}, nil)
}
+func (gui *Gui) handleMerge(g *gocui.Gui, v *gocui.View) error {
+ selectedBranchName := gui.getSelectedBranch().Name
+ return gui.mergeBranchIntoCheckedOutBranch(selectedBranchName)
+}
+
func (gui *Gui) handleRebase(g *gocui.Gui, v *gocui.View) error {
checkedOutBranch := gui.State.Branches[0].Name
selectedBranch := gui.getSelectedBranch().Name
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index b74281df7..19d2191f5 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1066,6 +1066,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Description: gui.Tr.SLocalize("checkout"),
},
{
+ ViewName: "branches",
+ Contexts: []string{"remote-branches"},
+ Key: 'M',
+ Modifier: gocui.ModNone,
+ Handler: gui.handleMergeRemoteBranch,
+ Description: gui.Tr.SLocalize("mergeIntoCurrentBranch"),
+ },
+ {
ViewName: "commits",
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go
index 771a7a9ad..b8959e12f 100644
--- a/pkg/gui/remote_branches_panel.go
+++ b/pkg/gui/remote_branches_panel.go
@@ -92,3 +92,8 @@ func (gui *Gui) handleCheckoutRemoteBranch(g *gocui.Gui, v *gocui.View) error {
}
return gui.switchBranchesPanelContext("local-branches")
}
+
+func (gui *Gui) handleMergeRemoteBranch(g *gocui.Gui, v *gocui.View) error {
+ selectedBranchName := gui.getSelectedRemoteBranch().Name
+ return gui.mergeBranchIntoCheckedOutBranch(selectedBranchName)
+}