1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00

add reset to reflog commit menu

This commit is contained in:
Jesse Duffield 2020-02-16 09:32:51 +11:00
parent feaf98bd01
commit 0a69c1a02d
4 changed files with 11 additions and 67 deletions

View File

@ -6,16 +6,6 @@ import (
"github.com/jesseduffield/gocui"
)
type patchMenuOption struct {
displayName string
function func() error
}
// GetDisplayStrings is a function.
func (o *patchMenuOption) GetDisplayStrings(isFocused bool) []string {
return []string{o.displayName}
}
func (gui *Gui) handleCreatePatchOptionsMenu(g *gocui.Gui, v *gocui.View) error {
if !gui.GitCommand.PatchManager.CommitSelected() {
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoPatchError"))

View File

@ -95,3 +95,9 @@ func (gui *Gui) handleCheckoutReflogCommit(g *gocui.Gui, v *gocui.View) error {
return nil
}
func (gui *Gui) handleCreateReflogResetMenu(g *gocui.Gui, v *gocui.View) error {
commit := gui.getSelectedReflogCommit()
return gui.createResetMenu(commit.Sha)
}

View File

@ -1,55 +0,0 @@
package gui
import (
"fmt"
"github.com/fatih/color"
"github.com/jesseduffield/gocui"
)
type reflogResetOption struct {
handler func() error
description string
command string
}
// GetDisplayStrings is a function.
func (r *reflogResetOption) GetDisplayStrings(isFocused bool) []string {
return []string{r.description, color.New(color.FgRed).Sprint(r.command)}
}
func (gui *Gui) handleCreateReflogResetMenu(g *gocui.Gui, v *gocui.View) error {
commit := gui.getSelectedReflogCommit()
red := color.New(color.FgRed)
resetFunction := func(reset func(string) error) func() error {
return func() error {
if err := reset(commit.Sha); err != nil {
return gui.createErrorPanel(gui.g, err.Error())
}
gui.State.Panels.ReflogCommits.SelectedLine = 0
return gui.refreshSidePanels(gui.g)
}
}
menuItems := []*menuItem{
{
displayStrings: []string{
gui.Tr.SLocalize("hardReset"),
red.Sprint(fmt.Sprintf("reset --hard %s", commit.Sha)),
},
onPress: resetFunction(gui.GitCommand.ResetHard),
},
{
displayStrings: []string{
gui.Tr.SLocalize("softReset"),
red.Sprint(fmt.Sprintf("reset --soft %s", commit.Sha)),
},
onPress: resetFunction(gui.GitCommand.ResetSoft),
},
}
return gui.createMenu("", menuItems, createMenuOptions{showCancel: true})
}

View File

@ -20,9 +20,13 @@ func (gui *Gui) createResetMenu(ref string) error {
},
onPress: func() error {
if err := gui.GitCommand.ResetToCommit(ref, innerStrength); err != nil {
return err
return gui.createErrorPanel(gui.g, err.Error())
}
gui.switchCommitsPanelContext("branch-commits")
gui.State.Panels.Commits.SelectedLine = 0
gui.State.Panels.ReflogCommits.SelectedLine = 0
if err := gui.refreshCommits(gui.g); err != nil {
return err
}
@ -33,7 +37,6 @@ func (gui *Gui) createResetMenu(ref string) error {
return err
}
gui.State.Panels.Commits.SelectedLine = 0
return gui.handleCommitSelect(gui.g, gui.getCommitsView())
},
}