1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-24 05:36:19 +02:00

prefill commit reword editor

This commit is contained in:
Jesse Duffield 2020-08-16 19:31:55 +10:00
parent c8add47fe7
commit 53f06f6a4e
2 changed files with 19 additions and 1 deletions

View File

@ -501,6 +501,13 @@ func (c *GitCommand) GetHeadCommitMessage() (string, error) {
return strings.TrimSpace(message), err
}
func (c *GitCommand) GetCommitMessage(commitSha string) (string, error) {
cmdStr := "git rev-list --format=%B --max-count=1 " + commitSha
messageWithHeader, err := c.OSCommand.RunCommandWithOutput(cmdStr)
message := strings.Join(strings.SplitAfter(messageWithHeader, "\n")[1:], "\n")
return strings.TrimSpace(message), err
}
// AmendHead amends HEAD with whatever is staged in your working tree
func (c *GitCommand) AmendHead() (*exec.Cmd, error) {
command := "git commit --amend --no-edit --allow-empty"

View File

@ -216,7 +216,18 @@ func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error {
if gui.State.Panels.Commits.SelectedLine != 0 {
return gui.createErrorPanel(gui.Tr.SLocalize("OnlyRenameTopCommit"))
}
return gui.prompt(v, gui.Tr.SLocalize("renameCommit"), "", func(response string) error {
commit := gui.getSelectedCommit()
if commit == nil {
return nil
}
message, err := gui.GitCommand.GetCommitMessage(commit.Sha)
if err != nil {
return gui.surfaceError(err)
}
return gui.prompt(v, gui.Tr.SLocalize("renameCommit"), message, func(response string) error {
if err := gui.GitCommand.RenameCommit(response); err != nil {
return gui.surfaceError(err)
}