mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-17 14:11:02 +02:00
support merging remote branches into checked out branch
This commit is contained in:
parent
55ff0c0dee
commit
2afbd7ba7f
@ -1080,3 +1080,8 @@ func (c *GitCommand) AddRemote(name string, url string) error {
|
||||
func (c *GitCommand) RemoveRemote(name string) error {
|
||||
return c.OSCommand.RunCommand(fmt.Sprintf("git remote remove %s", name))
|
||||
}
|
||||
|
||||
func (c *GitCommand) IsHeadDetached() bool {
|
||||
err := c.OSCommand.RunCommand("git symbolic-ref -q HEAD")
|
||||
return err != nil
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1065,6 +1065,14 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||
Handler: gui.handleCheckoutRemoteBranch,
|
||||
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,
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user