diff --git a/files_panel.go b/files_panel.go index 0987dfbe0..22b88f6ab 100644 --- a/files_panel.go +++ b/files_panel.go @@ -354,3 +354,12 @@ func handleAbortMerge(g *gocui.Gui, v *gocui.View) error { refreshStatus(g) return refreshFiles(g) } + +func handleResetHard(g *gocui.Gui, v *gocui.View) error { + return createConfirmationPanel(g, v, "Clear file panel", "Are you sure you want `reset --hard HEAD`? You may lose changes", func(g *gocui.Gui, v *gocui.View) error { + if err := gitResetHard(); err != nil { + createErrorPanel(g, err.Error()) + } + return refreshFiles(g) + }, nil) +} diff --git a/gitcommands.go b/gitcommands.go index 08a2ec411..fbe8ddae5 100644 --- a/gitcommands.go +++ b/gitcommands.go @@ -652,3 +652,7 @@ func getAndMergeFetchedBranches(branches []Branch) []Branch { } return branches } + +func gitResetHard() error { + return w.Reset(&git.ResetOptions{Mode: git.HardReset}) +} diff --git a/keybindings.go b/keybindings.go index 6448a6be0..5ab572d81 100644 --- a/keybindings.go +++ b/keybindings.go @@ -39,6 +39,7 @@ func keybindings(g *gocui.Gui) error { Binding{ViewName: "files", Key: 'S', Modifier: gocui.ModNone, Handler: handleStashSave}, Binding{ViewName: "files", Key: 'a', Modifier: gocui.ModNone, Handler: handleAbortMerge}, Binding{ViewName: "files", Key: 't', Modifier: gocui.ModNone, Handler: handleAddPatch}, + Binding{ViewName: "files", Key: 'D', Modifier: gocui.ModNone, Handler: handleResetHard}, Binding{ViewName: "main", Key: gocui.KeyArrowUp, Modifier: gocui.ModNone, Handler: handleSelectTop}, Binding{ViewName: "main", Key: gocui.KeyArrowDown, Modifier: gocui.ModNone, Handler: handleSelectBottom}, Binding{ViewName: "main", Key: gocui.KeyEsc, Modifier: gocui.ModNone, Handler: handleEscapeMerge},