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
|
|
|
)
|
|
|
|
|
2021-12-07 12:59:36 +02:00
|
|
|
func (gui *Gui) resetToRef(ref string, strength string, span string, envVars []string) error {
|
|
|
|
if err := gui.GitCommand.WithSpan(span).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 {
|
2021-12-07 12:59:36 +02:00
|
|
|
return gui.resetToRef(ref, strength, "Reset", []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
|
|
|
}
|