mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-17 01:42:45 +02:00
refactor commit reset menu
This commit is contained in:
49
pkg/gui/commit_reset_menu_panel.go
Normal file
49
pkg/gui/commit_reset_menu_panel.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package gui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
commit := gui.getSelectedCommit(g)
|
||||||
|
if commit == nil {
|
||||||
|
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoCommitsThisBranch"))
|
||||||
|
}
|
||||||
|
|
||||||
|
strengths := []string{"soft", "mixed", "hard"}
|
||||||
|
menuItems := make([]*menuItem, len(strengths))
|
||||||
|
for i, strength := range strengths {
|
||||||
|
innerStrength := strength
|
||||||
|
menuItems[i] = &menuItem{
|
||||||
|
displayStrings: []string{
|
||||||
|
fmt.Sprintf("%s reset", strength),
|
||||||
|
color.New(color.FgRed).Sprint(
|
||||||
|
fmt.Sprintf("reset --%s %s", strength, commit.Sha),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
onPress: func() error {
|
||||||
|
if err := gui.GitCommand.ResetToCommit(commit.Sha, innerStrength); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := gui.refreshCommits(g); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := gui.refreshFiles(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := gui.resetOrigin(gui.getCommitsView()); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.Panels.Commits.SelectedLine = 0
|
||||||
|
return gui.handleCommitSelect(g, gui.getCommitsView())
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.createMenuNew(fmt.Sprintf("%s %s", gui.Tr.SLocalize("resetTo"), commit.Sha), menuItems, createMenuOptions{showCancel: true})
|
||||||
|
}
|
@ -1,10 +1,8 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
@ -560,53 +558,6 @@ func (gui *Gui) handleSquashAllAboveFixupCommits(g *gocui.Gui, v *gocui.View) er
|
|||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
type resetOption struct {
|
|
||||||
description string
|
|
||||||
command string
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDisplayStrings is a function.
|
|
||||||
func (r *resetOption) GetDisplayStrings(isFocused bool) []string {
|
|
||||||
return []string{r.description, color.New(color.FgRed).Sprint(r.command)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error {
|
|
||||||
commit := gui.getSelectedCommit(g)
|
|
||||||
if commit == nil {
|
|
||||||
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoCommitsThisBranch"))
|
|
||||||
}
|
|
||||||
|
|
||||||
strengths := []string{"soft", "mixed", "hard"}
|
|
||||||
options := make([]*resetOption, len(strengths))
|
|
||||||
for i, strength := range strengths {
|
|
||||||
options[i] = &resetOption{
|
|
||||||
description: fmt.Sprintf("%s reset", strength),
|
|
||||||
command: fmt.Sprintf("reset --%s %s", strength, commit.Sha),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleMenuPress := func(index int) error {
|
|
||||||
if err := gui.GitCommand.ResetToCommit(commit.Sha, strengths[index]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := gui.refreshCommits(g); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := gui.refreshFiles(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := gui.resetOrigin(gui.getCommitsView()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.State.Panels.Commits.SelectedLine = 0
|
|
||||||
return gui.handleCommitSelect(g, gui.getCommitsView())
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.createMenu(fmt.Sprintf("%s %s", gui.Tr.SLocalize("resetTo"), commit.Sha), options, len(options), handleMenuPress)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gui *Gui) handleTagCommit(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleTagCommit(g *gocui.Gui, v *gocui.View) error {
|
||||||
// TODO: bring up menu asking if you want to make a lightweight or annotated tag
|
// TODO: bring up menu asking if you want to make a lightweight or annotated tag
|
||||||
// if annotated, switch to a subprocess to create the message
|
// if annotated, switch to a subprocess to create the message
|
||||||
|
Reference in New Issue
Block a user