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

49 lines
1.3 KiB
Go
Raw Normal View History

2020-02-14 14:08:27 +02:00
package gui
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/gui/style"
2020-02-14 14:08:27 +02:00
)
2022-01-05 02:57:32 +02:00
func (gui *Gui) resetToRef(ref string, strength string, envVars []string) error {
2022-01-08 05:10:01 +02:00
if err := gui.Git.Commit.ResetToCommit(ref, strength, envVars); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
2020-03-19 13:22:00 +02:00
}
2020-08-20 00:53:10 +02:00
gui.State.Panels.Commits.SelectedLineIdx = 0
gui.State.Panels.ReflogCommits.SelectedLineIdx = 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
2021-04-03 06:56:11 +02:00
if err := gui.pushContext(gui.State.Contexts.BranchCommits); err != nil {
2020-03-19 13:22:00 +02:00
return err
}
2020-08-19 11:16:00 +02:00
if err := gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{FILES, BRANCHES, REFLOG, COMMITS}}); err != nil {
2020-03-19 13:22:00 +02:00
return err
}
2020-08-19 11:16:00 +02:00
return nil
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),
style.FgRed.Sprintf("reset --%s %s", strength, ref),
2020-02-14 14:08:27 +02:00
},
onPress: func() error {
2022-01-05 03:01:59 +02:00
gui.logAction("Reset")
2022-01-05 02:57:32 +02:00
return gui.resetToRef(ref, strength, []string{})
2020-02-14 14:08:27 +02:00
},
}
}
2020-10-04 02:00:48 +02:00
return gui.createMenu(fmt.Sprintf("%s %s", gui.Tr.LcResetTo, ref), menuItems, createMenuOptions{showCancel: true})
2020-02-14 14:08:27 +02:00
}