diff options
-rw-r--r-- | pkg/gui/commits_panel.go | 9 | ||||
-rw-r--r-- | pkg/gui/reset_menu_panel.go (renamed from pkg/gui/commit_reset_menu_panel.go) | 18 |
2 files changed, 15 insertions, 12 deletions
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 43b3cb802..150a7ae16 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -652,3 +652,12 @@ func (gui *Gui) handlePrevCommitsTab(g *gocui.Gui, v *gocui.View) error { utils.ModuloWithWrap(v.TabIndex-1, len(v.Tabs)), ) } + +func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error { + commit := gui.getSelectedCommit(g) + if commit == nil { + return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoCommitsThisBranch")) + } + + return gui.createResetMenu(commit.Sha) +} diff --git a/pkg/gui/commit_reset_menu_panel.go b/pkg/gui/reset_menu_panel.go index 8e9da1aad..10f2705dc 100644 --- a/pkg/gui/commit_reset_menu_panel.go +++ b/pkg/gui/reset_menu_panel.go @@ -4,15 +4,9 @@ import ( "fmt" "github.com/fatih/color" - "github.com/jesseduffield/gocui" ) -func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error { - commit := gui.getSelectedCommit(g) - if commit == nil { - return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("NoCommitsThisBranch")) - } - +func (gui *Gui) createResetMenu(ref string) error { strengths := []string{"soft", "mixed", "hard"} menuItems := make([]*menuItem, len(strengths)) for i, strength := range strengths { @@ -21,15 +15,15 @@ func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error { displayStrings: []string{ fmt.Sprintf("%s reset", strength), color.New(color.FgRed).Sprint( - fmt.Sprintf("reset --%s %s", strength, commit.Sha), + fmt.Sprintf("reset --%s %s", strength, ref), ), }, onPress: func() error { - if err := gui.GitCommand.ResetToCommit(commit.Sha, innerStrength); err != nil { + if err := gui.GitCommand.ResetToCommit(ref, innerStrength); err != nil { return err } - if err := gui.refreshCommits(g); err != nil { + if err := gui.refreshCommits(gui.g); err != nil { return err } if err := gui.refreshFiles(); err != nil { @@ -40,10 +34,10 @@ func (gui *Gui) handleCreateCommitResetMenu(g *gocui.Gui, v *gocui.View) error { } gui.State.Panels.Commits.SelectedLine = 0 - return gui.handleCommitSelect(g, gui.getCommitsView()) + return gui.handleCommitSelect(gui.g, gui.getCommitsView()) }, } } - return gui.createMenu(fmt.Sprintf("%s %s", gui.Tr.SLocalize("resetTo"), commit.Sha), menuItems, createMenuOptions{showCancel: true}) + return gui.createMenu(fmt.Sprintf("%s %s", gui.Tr.SLocalize("resetTo"), ref), menuItems, createMenuOptions{showCancel: true}) } |