2020-01-08 13:19:13 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2020-09-29 10:16:40 +02:00
|
|
|
"fmt"
|
|
|
|
|
2021-07-27 15:00:37 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
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 {
|
2020-10-04 02:00:48 +02:00
|
|
|
nukeStr = fmt.Sprintf("%s (%s)", nukeStr, gui.Tr.LcAndResetSubmodules)
|
2020-09-29 10:16:40 +02:00
|
|
|
}
|
|
|
|
|
2020-02-14 14:13:37 +02:00
|
|
|
menuItems := []*menuItem{
|
2020-01-08 13:19:13 +02:00
|
|
|
{
|
2020-02-14 14:13:37 +02:00
|
|
|
displayStrings: []string{
|
2020-10-04 02:00:48 +02:00
|
|
|
gui.Tr.LcDiscardAllChangesToAllFiles,
|
2020-09-29 10:16:40 +02:00
|
|
|
red.Sprint(nukeStr),
|
2020-02-14 14:13:37 +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 {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
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 {
|
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 {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
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 {
|
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 {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
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 {
|
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 {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-02-14 14:13:37 +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
|
|
|
},
|
|
|
|
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 {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2020-02-14 14:13:37 +02:00
|
|
|
displayStrings: []string{
|
2020-10-04 02:00:48 +02:00
|
|
|
gui.Tr.LcHardReset,
|
2020-02-16 00:19:08 +02:00
|
|
|
red.Sprint("git reset --hard HEAD"),
|
2020-02-14 14:13:37 +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 {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|
|
|
|
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{FILES}})
|
2020-01-08 13:19:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-02-14 14:39:02 +02:00
|
|
|
return gui.createMenu("", menuItems, createMenuOptions{showCancel: true})
|
2020-01-08 13:19:13 +02:00
|
|
|
}
|