1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-06 03:53:59 +02:00
lazygit/pkg/gui/workspace_reset_options_panel.go

100 lines
2.7 KiB
Go
Raw Normal View History

package gui
import (
"fmt"
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
func (gui *Gui) handleCreateResetMenu() error {
red := style.FgRed
2020-02-14 14:13:37 +02:00
nukeStr := "reset --hard HEAD && git clean -fd"
2020-09-30 00:27:23 +02:00
if len(gui.State.Submodules) > 0 {
2020-10-04 02:00:48 +02:00
nukeStr = fmt.Sprintf("%s (%s)", nukeStr, gui.Tr.LcAndResetSubmodules)
}
2020-02-14 14:13:37 +02:00
menuItems := []*menuItem{
{
2020-02-14 14:13:37 +02:00
displayStrings: []string{
2020-10-04 02:00:48 +02:00
gui.Tr.LcDiscardAllChangesToAllFiles,
red.Sprint(nukeStr),
2020-02-14 14:13:37 +02:00
},
onPress: func() error {
2021-04-11 11:35:42 +02:00
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.NukeWorkingTree).ResetAndClean(); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
},
},
{
2020-02-14 14:13:37 +02:00
displayStrings: []string{
2020-10-04 02:00:48 +02:00
gui.Tr.LcDiscardAnyUnstagedChanges,
2020-02-14 14:13:37 +02:00
red.Sprint("git checkout -- ."),
},
onPress: func() error {
2021-04-11 11:35:42 +02:00
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.DiscardUnstagedFileChanges).DiscardAnyUnstagedFileChanges(); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
},
},
{
2020-02-14 14:13:37 +02:00
displayStrings: []string{
2020-10-04 02:00:48 +02:00
gui.Tr.LcDiscardUntrackedFiles,
2020-02-14 14:13:37 +02:00
red.Sprint("git clean -fd"),
},
onPress: func() error {
2021-04-11 11:35:42 +02:00
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.RemoveUntrackedFiles).RemoveUntrackedFiles(); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
},
},
{
2020-02-14 14:13:37 +02:00
displayStrings: []string{
2020-10-04 02:00:48 +02:00
gui.Tr.LcSoftReset,
2020-02-14 14:13:37 +02:00
red.Sprint("git reset --soft HEAD"),
},
onPress: func() error {
2021-04-11 11:35:42 +02:00
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.SoftReset).ResetSoft("HEAD"); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
},
},
{
2020-02-14 14:13:37 +02:00
displayStrings: []string{
"mixed reset",
red.Sprint("git reset --mixed HEAD"),
2020-02-14 14:13:37 +02:00
},
onPress: func() error {
2021-04-11 11:35:42 +02:00
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.MixedReset).ResetMixed("HEAD"); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
},
},
{
2020-02-14 14:13:37 +02:00
displayStrings: []string{
2020-10-04 02:00:48 +02:00
gui.Tr.LcHardReset,
red.Sprint("git reset --hard HEAD"),
2020-02-14 14:13:37 +02:00
},
onPress: func() error {
2021-04-11 11:35:42 +02:00
if err := gui.GitCommand.WithSpan(gui.Tr.Spans.HardReset).ResetHard("HEAD"); err != nil {
2020-03-28 02:47:54 +02:00
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
},
},
}
2020-02-14 14:39:02 +02:00
return gui.createMenu("", menuItems, createMenuOptions{showCancel: true})
}