2020-02-14 14:08:27 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/fatih/color"
|
|
|
|
)
|
|
|
|
|
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 {
|
|
|
|
innerStrength := strength
|
|
|
|
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-02-15 23:59:48 +02:00
|
|
|
if err := gui.GitCommand.ResetToCommit(ref, innerStrength); err != nil {
|
2020-02-16 00:32:51 +02:00
|
|
|
return gui.createErrorPanel(gui.g, err.Error())
|
2020-02-14 14:08:27 +02:00
|
|
|
}
|
|
|
|
|
2020-03-09 02:34:10 +02:00
|
|
|
if err := gui.switchCommitsPanelContext("branch-commits"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-16 00:32:51 +02:00
|
|
|
gui.State.Panels.Commits.SelectedLine = 0
|
|
|
|
gui.State.Panels.ReflogCommits.SelectedLine = 0
|
|
|
|
|
2020-02-15 23:59:48 +02:00
|
|
|
if err := gui.refreshCommits(gui.g); err != nil {
|
2020-02-14 14:08:27 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := gui.refreshFiles(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := gui.resetOrigin(gui.getCommitsView()); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-15 23:59:48 +02:00
|
|
|
return gui.handleCommitSelect(gui.g, gui.getCommitsView())
|
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
|
|
|
}
|