1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/workspace_reset_options_panel.go

108 lines
3.0 KiB
Go
Raw Normal View History

package gui
import (
"fmt"
2022-01-28 11:44:36 +02:00
"github.com/jesseduffield/lazygit/pkg/gui/popup"
"github.com/jesseduffield/lazygit/pkg/gui/style"
2022-01-28 11:44:36 +02:00
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
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)
}
2022-01-28 11:44:36 +02:00
menuItems := []*popup.MenuItem{
{
2022-01-28 11:44:36 +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
},
2022-01-28 11:44:36 +02:00
OnPress: func() error {
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.NukeWorkingTree)
2022-01-08 05:10:01 +02:00
if err := gui.Git.WorkingTree.ResetAndClean(); err != nil {
2022-01-28 11:44:36 +02:00
return gui.PopupHandler.Error(err)
}
2022-01-28 11:44:36 +02:00
return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
},
},
{
2022-01-28 11:44:36 +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 -- ."),
},
2022-01-28 11:44:36 +02:00
OnPress: func() error {
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.DiscardUnstagedFileChanges)
2022-01-08 05:10:01 +02:00
if err := gui.Git.WorkingTree.DiscardAnyUnstagedFileChanges(); err != nil {
2022-01-28 11:44:36 +02:00
return gui.PopupHandler.Error(err)
}
2022-01-28 11:44:36 +02:00
return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
},
},
{
2022-01-28 11:44:36 +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"),
},
2022-01-28 11:44:36 +02:00
OnPress: func() error {
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.RemoveUntrackedFiles)
2022-01-08 05:10:01 +02:00
if err := gui.Git.WorkingTree.RemoveUntrackedFiles(); err != nil {
2022-01-28 11:44:36 +02:00
return gui.PopupHandler.Error(err)
}
2022-01-28 11:44:36 +02:00
return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
},
},
{
2022-01-28 11:44:36 +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"),
},
2022-01-28 11:44:36 +02:00
OnPress: func() error {
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.SoftReset)
2022-01-08 05:10:01 +02:00
if err := gui.Git.WorkingTree.ResetSoft("HEAD"); err != nil {
2022-01-28 11:44:36 +02:00
return gui.PopupHandler.Error(err)
}
2022-01-28 11:44:36 +02:00
return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
},
},
{
2022-01-28 11:44:36 +02:00
DisplayStrings: []string{
"mixed reset",
red.Sprint("git reset --mixed HEAD"),
2020-02-14 14:13:37 +02:00
},
2022-01-28 11:44:36 +02:00
OnPress: func() error {
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.MixedReset)
2022-01-08 05:10:01 +02:00
if err := gui.Git.WorkingTree.ResetMixed("HEAD"); err != nil {
2022-01-28 11:44:36 +02:00
return gui.PopupHandler.Error(err)
}
2022-01-28 11:44:36 +02:00
return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
},
},
{
2022-01-28 11:44:36 +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
},
2022-01-28 11:44:36 +02:00
OnPress: func() error {
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.HardReset)
2022-01-08 05:10:01 +02:00
if err := gui.Git.WorkingTree.ResetHard("HEAD"); err != nil {
2022-01-28 11:44:36 +02:00
return gui.PopupHandler.Error(err)
}
2022-01-28 11:44:36 +02:00
return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
},
},
}
2022-01-28 11:44:36 +02:00
return gui.PopupHandler.Menu(popup.CreateMenuOptions{Title: "", Items: menuItems})
}