2022-02-26 10:26:39 +02:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// this is in its own file given that the workspace controller file is already quite long
|
|
|
|
|
|
|
|
func (self *FilesController) createResetMenu() error {
|
|
|
|
red := style.FgRed
|
|
|
|
|
2022-05-08 13:30:43 +02:00
|
|
|
nukeStr := "git reset --hard HEAD && git clean -fd"
|
2023-03-23 04:04:57 +02:00
|
|
|
if len(self.c.Model().Submodules) > 0 {
|
2023-05-25 13:11:51 +02:00
|
|
|
nukeStr = fmt.Sprintf("%s (%s)", nukeStr, self.c.Tr.AndResetSubmodules)
|
2022-02-26 10:26:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
menuItems := []*types.MenuItem{
|
|
|
|
{
|
2022-05-08 06:23:32 +02:00
|
|
|
LabelColumns: []string{
|
2023-05-25 13:11:51 +02:00
|
|
|
self.c.Tr.DiscardAllChangesToAllFiles,
|
2022-02-26 10:26:39 +02:00
|
|
|
red.Sprint(nukeStr),
|
|
|
|
},
|
|
|
|
OnPress: func() error {
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.NukeWorkingTree)
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().WorkingTree.ResetAndClean(); err != nil {
|
2022-02-26 10:26:39 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
|
|
},
|
2023-02-02 09:13:12 +02:00
|
|
|
Key: 'x',
|
2022-05-08 04:46:48 +02:00
|
|
|
Tooltip: self.c.Tr.NukeDescription,
|
2022-02-26 10:26:39 +02:00
|
|
|
},
|
|
|
|
{
|
2022-05-08 06:23:32 +02:00
|
|
|
LabelColumns: []string{
|
2023-05-25 13:11:51 +02:00
|
|
|
self.c.Tr.DiscardAnyUnstagedChanges,
|
2022-02-26 10:26:39 +02:00
|
|
|
red.Sprint("git checkout -- ."),
|
|
|
|
},
|
|
|
|
OnPress: func() error {
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.DiscardUnstagedFileChanges)
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().WorkingTree.DiscardAnyUnstagedFileChanges(); err != nil {
|
2022-02-26 10:26:39 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
|
|
},
|
2022-03-27 08:19:31 +02:00
|
|
|
Key: 'u',
|
2022-02-26 10:26:39 +02:00
|
|
|
},
|
|
|
|
{
|
2022-05-08 06:23:32 +02:00
|
|
|
LabelColumns: []string{
|
2023-05-25 13:11:51 +02:00
|
|
|
self.c.Tr.DiscardUntrackedFiles,
|
2022-02-26 10:26:39 +02:00
|
|
|
red.Sprint("git clean -fd"),
|
|
|
|
},
|
|
|
|
OnPress: func() error {
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.RemoveUntrackedFiles)
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().WorkingTree.RemoveUntrackedFiles(); err != nil {
|
2022-02-26 10:26:39 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
|
|
},
|
2022-03-27 08:19:31 +02:00
|
|
|
Key: 'c',
|
2022-02-26 10:26:39 +02:00
|
|
|
},
|
2022-05-08 13:30:43 +02:00
|
|
|
{
|
|
|
|
LabelColumns: []string{
|
2023-05-25 13:11:51 +02:00
|
|
|
self.c.Tr.DiscardStagedChanges,
|
2022-05-08 13:30:43 +02:00
|
|
|
red.Sprint("stash staged and drop stash"),
|
|
|
|
},
|
2022-05-15 12:16:20 +02:00
|
|
|
Tooltip: self.c.Tr.DiscardStagedChangesDescription,
|
2022-05-08 13:30:43 +02:00
|
|
|
OnPress: func() error {
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.RemoveStagedFiles)
|
2023-03-23 09:47:29 +02:00
|
|
|
if !self.c.Helpers().WorkingTree.IsWorkingTreeDirty() {
|
2022-05-08 13:30:43 +02:00
|
|
|
return self.c.ErrorMsg(self.c.Tr.NoTrackedStagedFilesStash)
|
|
|
|
}
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().Stash.SaveStagedChanges("[lazygit] tmp stash"); err != nil {
|
2022-05-08 13:30:43 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().Stash.DropNewest(); err != nil {
|
2022-05-08 13:30:43 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
|
|
},
|
|
|
|
Key: 'S',
|
|
|
|
},
|
2022-02-26 10:26:39 +02:00
|
|
|
{
|
2022-05-08 06:23:32 +02:00
|
|
|
LabelColumns: []string{
|
2023-05-25 13:11:51 +02:00
|
|
|
self.c.Tr.SoftReset,
|
2022-02-26 10:26:39 +02:00
|
|
|
red.Sprint("git reset --soft HEAD"),
|
|
|
|
},
|
|
|
|
OnPress: func() error {
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.SoftReset)
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().WorkingTree.ResetSoft("HEAD"); err != nil {
|
2022-02-26 10:26:39 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
|
|
},
|
2022-03-27 08:19:31 +02:00
|
|
|
Key: 's',
|
2022-02-26 10:26:39 +02:00
|
|
|
},
|
|
|
|
{
|
2022-05-08 06:23:32 +02:00
|
|
|
LabelColumns: []string{
|
2022-02-26 10:26:39 +02:00
|
|
|
"mixed reset",
|
|
|
|
red.Sprint("git reset --mixed HEAD"),
|
|
|
|
},
|
|
|
|
OnPress: func() error {
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.MixedReset)
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().WorkingTree.ResetMixed("HEAD"); err != nil {
|
2022-02-26 10:26:39 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
|
|
},
|
2022-03-27 08:19:31 +02:00
|
|
|
Key: 'm',
|
2022-02-26 10:26:39 +02:00
|
|
|
},
|
|
|
|
{
|
2022-05-08 06:23:32 +02:00
|
|
|
LabelColumns: []string{
|
2023-05-25 13:11:51 +02:00
|
|
|
self.c.Tr.HardReset,
|
2022-02-26 10:26:39 +02:00
|
|
|
red.Sprint("git reset --hard HEAD"),
|
|
|
|
},
|
|
|
|
OnPress: func() error {
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.HardReset)
|
2023-03-23 04:04:57 +02:00
|
|
|
if err := self.c.Git().WorkingTree.ResetHard("HEAD"); err != nil {
|
2022-02-26 10:26:39 +02:00
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES}})
|
|
|
|
},
|
2022-03-27 08:19:31 +02:00
|
|
|
Key: 'h',
|
2022-02-26 10:26:39 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return self.c.Menu(types.CreateMenuOptions{Title: "", Items: menuItems})
|
|
|
|
}
|