summaryrefslogtreecommitdiffstats
path: root/pkg/gui/files_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-03-18 21:19:07 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-03-23 13:26:17 +1100
commitf502f75e1f56bf8f34d3fdf42e934919cd045d85 (patch)
tree27236dda4b1bd011d43e0bc1efb2e642371c6c6d /pkg/gui/files_panel.go
parentff97ef7b94b5ccfda1d8b98b0a7e21a779309fcc (diff)
add more options for resetting files in the working tree
Diffstat (limited to 'pkg/gui/files_panel.go')
-rw-r--r--pkg/gui/files_panel.go88
1 files changed, 67 insertions, 21 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index deaffb83b..2f91df519 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -10,6 +10,7 @@ import (
"fmt"
"strings"
+ "github.com/fatih/color"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -455,15 +456,6 @@ func (gui *Gui) handleAbortMerge(g *gocui.Gui, v *gocui.View) error {
return gui.refreshFiles()
}
-func (gui *Gui) handleResetAndClean(g *gocui.Gui, v *gocui.View) error {
- return gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("ClearFilePanel"), gui.Tr.SLocalize("SureResetHardHead"), func(g *gocui.Gui, v *gocui.View) error {
- if err := gui.GitCommand.ResetAndClean(); err != nil {
- gui.createErrorPanel(g, err.Error())
- }
- return gui.refreshFiles()
- }, nil)
-}
-
func (gui *Gui) openFile(filename string) error {
if err := gui.OSCommand.OpenFile(filename); err != nil {
return gui.createErrorPanel(gui.g, err.Error())
@@ -498,13 +490,22 @@ type discardOption struct {
description string
}
-type discardOptionValue int
+type discardAllOption struct {
+ handler func() error
+ description string
+ command string
+}
// GetDisplayStrings is a function.
func (r *discardOption) GetDisplayStrings(isFocused bool) []string {
return []string{r.description}
}
+// GetDisplayStrings is a function.
+func (r *discardAllOption) GetDisplayStrings(isFocused bool) []string {
+ return []string{r.description, color.New(color.FgRed).Sprint(r.command)}
+}
+
func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
file, err := gui.getSelectedFile(g)
if err != nil {
@@ -518,11 +519,7 @@ func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
{
description: gui.Tr.SLocalize("discardAllChanges"),
handler: func(file *commands.File) error {
- if err := gui.GitCommand.DiscardAllFileChanges(file); err != nil {
- return err
- }
-
- return gui.refreshFiles()
+ return gui.GitCommand.DiscardAllFileChanges(file)
},
},
{
@@ -537,11 +534,7 @@ func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
discardUnstagedChanges := &discardOption{
description: gui.Tr.SLocalize("discardUnstagedChanges"),
handler: func(file *commands.File) error {
- if err := gui.GitCommand.DiscardUnstagedFileChanges(file); err != nil {
- return err
- }
-
- return gui.refreshFiles()
+ return gui.GitCommand.DiscardUnstagedFileChanges(file)
},
}
@@ -549,8 +542,61 @@ func (gui *Gui) handleCreateDiscardMenu(g *gocui.Gui, v *gocui.View) error {
}
handleMenuPress := func(index int) error {
- return options[index].handler(file)
+ if err := options[index].handler(file); err != nil {
+ return err
+ }
+
+ return gui.refreshFiles()
}
return gui.createMenu(file.Name, options, handleMenuPress)
}
+
+func (gui *Gui) handleResetAndClean(g *gocui.Gui, v *gocui.View) error {
+ options := []*discardAllOption{
+ {
+ description: gui.Tr.SLocalize("discardAllChangesToAllFiles"),
+ command: "reset --hard HEAD && git clean -fd",
+ handler: func() error {
+ return gui.GitCommand.ResetAndClean()
+ },
+ },
+ {
+ description: gui.Tr.SLocalize("discardAnyUnstagedChanges"),
+ command: "git checkout -- .",
+ handler: func() error {
+ return gui.GitCommand.DiscardAnyUnstagedFileChanges()
+ },
+ },
+ {
+ description: gui.Tr.SLocalize("discardUntrackedFiles"),
+ command: "git clean -fd",
+ handler: func() error {
+ return gui.GitCommand.RemoveUntrackedFiles()
+ },
+ },
+ {
+ description: gui.Tr.SLocalize("hardReset"),
+ command: "git reset --hard HEAD",
+ handler: func() error {
+ return gui.GitCommand.ResetHardHead()
+ },
+ },
+ {
+ description: gui.Tr.SLocalize("cancel"),
+ handler: func() error {
+ return nil
+ },
+ },
+ }
+
+ handleMenuPress := func(index int) error {
+ if err := options[index].handler(); err != nil {
+ return err
+ }
+
+ return gui.refreshFiles()
+ }
+
+ return gui.createMenu("", options, handleMenuPress)
+}