diff --git a/docs/Keybindings.md b/docs/Keybindings.md index 9160b9c2b..2f10a297c 100644 --- a/docs/Keybindings.md +++ b/docs/Keybindings.md @@ -54,6 +54,7 @@
s: squash down (only available for topmost commit) r: rename commit + shift+R: rename commit using git editor g: reset to this commitdiff --git a/pkg/commands/git.go b/pkg/commands/git.go index 619db05e7..704a45c73 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -422,6 +422,11 @@ func (c *GitCommand) PrepareCommitSubProcess() *exec.Cmd { return c.OSCommand.PrepareSubProcess("git", "commit") } +// PrepareCommitAmendSubProcess prepares a subprocess for `git commit --amend --allow-empty` +func (c *GitCommand) PrepareCommitAmendSubProcess() *exec.Cmd { + return c.OSCommand.PrepareSubProcess("git", "commit", "--amend", "--allow-empty") +} + // GetBranchGraph gets the color-formatted graph of the log for the given branch // Currently it limits the result to 100 commits, but when we get async stuff // working we can do lazy loading diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index c428e3b99..0969692b6 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -155,6 +155,19 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error { return nil } +func (gui *Gui) handleRenameCommitEditor(g *gocui.Gui, v *gocui.View) error { + if gui.getItemPosition(v) != 0 { + return gui.createErrorPanel(g, gui.Tr.SLocalize("OnlyRenameTopCommit")) + } + + gui.SubProcess = gui.GitCommand.PrepareCommitAmendSubProcess() + g.Update(func(g *gocui.Gui) error { + return gui.Errors.ErrSubProcess + }) + + return nil +} + func (gui *Gui) getSelectedCommit(g *gocui.Gui) (commands.Commit, error) { v, err := g.View("commits") if err != nil { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 52496b918..b09358fac 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -64,6 +64,7 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { {ViewName: "branches", Key: 'm', Modifier: gocui.ModNone, Handler: gui.handleMerge}, {ViewName: "commits", Key: 's', Modifier: gocui.ModNone, Handler: gui.handleCommitSquashDown}, {ViewName: "commits", Key: 'r', Modifier: gocui.ModNone, Handler: gui.handleRenameCommit}, + {ViewName: "commits", Key: 'R', Modifier: gocui.ModNone, Handler: gui.handleRenameCommitEditor}, {ViewName: "commits", Key: 'g', Modifier: gocui.ModNone, Handler: gui.handleResetToCommit}, {ViewName: "commits", Key: 'f', Modifier: gocui.ModNone, Handler: gui.handleCommitFixup}, {ViewName: "stash", Key: gocui.KeySpace, Modifier: gocui.ModNone, Handler: gui.handleStashApply},