mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-04 10:34:55 +02:00
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
)
|
|
|
|
func (gui *Gui) resetToRef(ref string, strength string, options commands.RunCommandOptions) error {
|
|
if err := gui.GitCommand.ResetToCommit(ref, strength, options); err != nil {
|
|
return gui.surfaceError(err)
|
|
}
|
|
|
|
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
|
|
|
|
if err := gui.switchContext(gui.Contexts.BranchCommits.Context); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := gui.refreshSidePanels(refreshOptions{scope: []int{FILES, BRANCHES, REFLOG, COMMITS}}); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (gui *Gui) createResetMenu(ref string) error {
|
|
strengths := []string{"soft", "mixed", "hard"}
|
|
menuItems := make([]*menuItem, len(strengths))
|
|
for i, strength := range strengths {
|
|
strength := strength
|
|
menuItems[i] = &menuItem{
|
|
displayStrings: []string{
|
|
fmt.Sprintf("%s reset", strength),
|
|
color.New(color.FgRed).Sprint(
|
|
fmt.Sprintf("reset --%s %s", strength, ref),
|
|
),
|
|
},
|
|
onPress: func() error {
|
|
return gui.resetToRef(ref, strength, commands.RunCommandOptions{})
|
|
},
|
|
}
|
|
}
|
|
|
|
return gui.createMenu(fmt.Sprintf("%s %s", gui.Tr.SLocalize("resetTo"), ref), menuItems, createMenuOptions{showCancel: true})
|
|
}
|