2020-01-08 13:19:13 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2020-09-29 10:16:40 +02:00
|
|
|
"fmt"
|
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/popup"
|
2021-07-27 15:00:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
2022-01-28 11:44:36 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2020-01-08 13:19:13 +02:00
|
|
|
)
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCreateResetMenu() error {
|
2021-07-27 15:00:37 +02:00
|
|
|
red := style.FgRed
|
2020-02-14 14:13:37 +02:00
|
|
|
|
2020-09-29 10:16:40 +02:00
|
|
|
nukeStr := "reset --hard HEAD && git clean -fd"
|
2020-09-30 00:27:23 +02:00
|
|
|
if len(gui.State.Submodules) > 0 {
|
2022-01-16 05:46:53 +02:00
|
|
|
nukeStr = fmt.Sprintf("%s (%s)", nukeStr, gui.c.Tr.LcAndResetSubmodules)
|
2020-09-29 10:16:40 +02:00
|
|
|
}
|
|
|
|
|
2022-01-28 11:44:36 +02:00
|
|
|
menuItems := []*popup.MenuItem{
|
2020-01-08 13:19:13 +02:00
|
|
|
{
|
2022-01-28 11:44:36 +02:00
|
|
|
DisplayStrings: []string{
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.Tr.LcDiscardAllChangesToAllFiles,
|
2020-09-29 10:16:40 +02:00
|
|
|
red.Sprint(nukeStr),
|
2020-02-14 14:13:37 +02:00
|
|
|
},
|
2022-01-28 11:44:36 +02:00
|
|
|
OnPress: func() error {
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.NukeWorkingTree)
|
|
|
|
if err := gui.git.WorkingTree.ResetAndClean(); err != nil {
|
|
|
|
return gui.c.Error(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-01-28 11:44:36 +02:00
|
|
|
DisplayStrings: []string{
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.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-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.DiscardUnstagedFileChanges)
|
|
|
|
if err := gui.git.WorkingTree.DiscardAnyUnstagedFileChanges(); err != nil {
|
|
|
|
return gui.c.Error(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-01-28 11:44:36 +02:00
|
|
|
DisplayStrings: []string{
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.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-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.RemoveUntrackedFiles)
|
|
|
|
if err := gui.git.WorkingTree.RemoveUntrackedFiles(); err != nil {
|
|
|
|
return gui.c.Error(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-01-28 11:44:36 +02:00
|
|
|
DisplayStrings: []string{
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.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-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.SoftReset)
|
|
|
|
if err := gui.git.WorkingTree.ResetSoft("HEAD"); err != nil {
|
|
|
|
return gui.c.Error(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-01-28 11:44:36 +02:00
|
|
|
DisplayStrings: []string{
|
2020-02-16 00:19:08 +02:00
|
|
|
"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-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.MixedReset)
|
|
|
|
if err := gui.git.WorkingTree.ResetMixed("HEAD"); err != nil {
|
|
|
|
return gui.c.Error(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-01-28 11:44:36 +02:00
|
|
|
DisplayStrings: []string{
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.Tr.LcHardReset,
|
2020-02-16 00:19:08 +02:00
|
|
|
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-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.HardReset)
|
|
|
|
if err := gui.git.WorkingTree.ResetHard("HEAD"); err != nil {
|
|
|
|
return gui.c.Error(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Menu(popup.CreateMenuOptions{Title: "", Items: menuItems})
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|