2020-02-14 14:08:27 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2021-07-27 15:00:37 +02:00
|
|
|
"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
|
2020-03-26 12:12:12 +02:00
|
|
|
// 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
|
|
|
|
2021-03-31 14:55:06 +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),
|
2021-07-27 15:00:37 +02:00
|
|
|
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
|
|
|
}
|