2020-02-14 14:08:27 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
2020-09-29 11:10:57 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
2020-02-14 14:08:27 +02:00
|
|
|
)
|
|
|
|
|
2021-04-10 08:25:45 +02:00
|
|
|
func (gui *Gui) resetToRef(ref string, strength string, span string, options oscommands.RunCommandOptions) error {
|
|
|
|
if err := gui.GitCommand.WithSpan(span).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
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
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 {
|
2021-04-10 08:25:45 +02:00
|
|
|
return gui.resetToRef(ref, strength, "Reset", oscommands.RunCommandOptions{})
|
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
|
|
|
}
|