1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/reset_menu_panel.go

54 lines
1.5 KiB
Go
Raw Normal View History

2020-02-14 14:08:27 +02:00
package gui
import (
"fmt"
"github.com/fatih/color"
2020-03-21 09:27:20 +02:00
"github.com/jesseduffield/lazygit/pkg/commands"
2020-02-14 14:08:27 +02:00
)
2020-03-21 09:27:20 +02:00
func (gui *Gui) resetToRef(ref string, strength string, options commands.RunCommandOptions) error {
if err := gui.GitCommand.ResetToCommit(ref, strength, options); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
2020-03-19 13:22:00 +02:00
}
if err := gui.switchCommitsPanelContext("branch-commits"); err != nil {
return err
}
gui.State.Panels.Commits.SelectedLine = 0
gui.State.Panels.ReflogCommits.SelectedLine = 0
// loading a heap of commits is slow so we limit them whenever doing a reset
gui.State.Panels.Commits.LimitCommits = true
2020-03-19 13:22:00 +02:00
if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES, BRANCHES, REFLOG, COMMITS}}); err != nil {
2020-03-19 13:22:00 +02:00
return err
}
if err := gui.resetOrigin(gui.getCommitsView()); err != nil {
return err
}
2020-08-15 09:01:43 +02:00
return gui.handleCommitSelect()
2020-03-19 13:22:00 +02:00
}
2020-02-15 23:59:48 +02:00
func (gui *Gui) createResetMenu(ref string) error {
2020-02-14 14:08:27 +02:00
strengths := []string{"soft", "mixed", "hard"}
menuItems := make([]*menuItem, len(strengths))
for i, strength := range strengths {
2020-03-19 13:22:00 +02:00
strength := strength
2020-02-14 14:08:27 +02:00
menuItems[i] = &menuItem{
displayStrings: []string{
fmt.Sprintf("%s reset", strength),
color.New(color.FgRed).Sprint(
2020-02-15 23:59:48 +02:00
fmt.Sprintf("reset --%s %s", strength, ref),
2020-02-14 14:08:27 +02:00
),
},
onPress: func() error {
2020-03-21 09:27:20 +02:00
return gui.resetToRef(ref, strength, commands.RunCommandOptions{})
2020-02-14 14:08:27 +02:00
},
}
}
2020-02-15 23:59:48 +02:00
return gui.createMenu(fmt.Sprintf("%s %s", gui.Tr.SLocalize("resetTo"), ref), menuItems, createMenuOptions{showCancel: true})
2020-02-14 14:08:27 +02:00
}