diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-01-08 22:19:13 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-01-08 22:30:54 +1100 |
commit | e0015a52e567b58697851f616549c37213c621fe (patch) | |
tree | 85011eedc44acf236f13758e11e0a171e690f6c7 /pkg/gui/workspace_reset_options_panel.go | |
parent | aea4661be540f075e86f97b881ed125f0233866c (diff) |
refresh side panels when resetting to upstreamv0.12.1
Diffstat (limited to 'pkg/gui/workspace_reset_options_panel.go')
-rw-r--r-- | pkg/gui/workspace_reset_options_panel.go | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/pkg/gui/workspace_reset_options_panel.go b/pkg/gui/workspace_reset_options_panel.go new file mode 100644 index 000000000..0e3cd59c6 --- /dev/null +++ b/pkg/gui/workspace_reset_options_panel.go @@ -0,0 +1,100 @@ +package gui + +import ( + "github.com/fatih/color" + "github.com/jesseduffield/gocui" +) + +type workspaceResetOption struct { + handler func() error + description string + command string +} + +// GetDisplayStrings is a function. +func (r *workspaceResetOption) GetDisplayStrings(isFocused bool) []string { + return []string{r.description, color.New(color.FgRed).Sprint(r.command)} +} + +func (gui *Gui) handleCreateResetMenu(g *gocui.Gui, v *gocui.View) error { + options := []*workspaceResetOption{ + { + description: gui.Tr.SLocalize("discardAllChangesToAllFiles"), + command: "reset --hard HEAD && git clean -fd", + handler: func() error { + if err := gui.GitCommand.ResetAndClean(); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + return gui.refreshFiles() + }, + }, + { + description: gui.Tr.SLocalize("discardAnyUnstagedChanges"), + command: "git checkout -- .", + handler: func() error { + if err := gui.GitCommand.DiscardAnyUnstagedFileChanges(); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + return gui.refreshFiles() + }, + }, + { + description: gui.Tr.SLocalize("discardUntrackedFiles"), + command: "git clean -fd", + handler: func() error { + if err := gui.GitCommand.RemoveUntrackedFiles(); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + return gui.refreshFiles() + }, + }, + { + description: gui.Tr.SLocalize("softReset"), + command: "git reset --soft HEAD", + handler: func() error { + if err := gui.GitCommand.ResetSoft("HEAD"); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + return gui.refreshFiles() + }, + }, + { + description: gui.Tr.SLocalize("hardReset"), + command: "git reset --hard HEAD", + handler: func() error { + if err := gui.GitCommand.ResetHard("HEAD"); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + return gui.refreshFiles() + }, + }, + { + description: gui.Tr.SLocalize("hardResetUpstream"), + command: "git reset --hard @{upstream}", + handler: func() error { + if err := gui.GitCommand.ResetHard("@{upstream}"); err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + return gui.refreshSidePanels(gui.g) + }, + }, + { + description: gui.Tr.SLocalize("cancel"), + handler: func() error { + return nil + }, + }, + } + + handleMenuPress := func(index int) error { + return options[index].handler() + } + + return gui.createMenu("", options, len(options), handleMenuPress) +} |