1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +02:00

Add ammend commit action.

This commit is contained in:
Kristijan Husak 2018-09-12 15:20:35 +02:00
parent 7fb2cafd0c
commit 61f0801bd3
7 changed files with 51 additions and 3 deletions

View File

@ -299,8 +299,12 @@ func (c *GitCommand) usingGpg() bool {
} }
// Commit commits to git // Commit commits to git
func (c *GitCommand) Commit(message string) (*exec.Cmd, error) { func (c *GitCommand) Commit(message string, amend bool) (*exec.Cmd, error) {
command := fmt.Sprintf("git commit -m %s", c.OSCommand.Quote(message)) amendParam := ""
if amend {
amendParam = "--amend "
}
command := fmt.Sprintf("git commit %s-m %s", amendParam, c.OSCommand.Quote(message))
if c.usingGpg() { if c.usingGpg() {
return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command), nil return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command), nil
} }

View File

@ -12,7 +12,8 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
if message == "" { if message == "" {
return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr")) return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr"))
} }
sub, err := gui.GitCommand.Commit(message) amendCommit := v.Title == gui.Tr.SLocalize("AmendLastCommit")
sub, err := gui.GitCommand.Commit(message, amendCommit)
if err != nil { if err != nil {
// TODO need to find a way to send through this error // TODO need to find a way to send through this error
if err != gui.Errors.ErrSubProcess { if err != gui.Errors.ErrSubProcess {

View File

@ -198,7 +198,14 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts { if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts {
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit")) return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit"))
} }
commitMessageView := gui.getCommitMessageView(g) commitMessageView := gui.getCommitMessageView(g)
if commitMessageView.Title == gui.Tr.SLocalize("AmendLastCommit") {
commitMessageView.Clear()
commitMessageView.SetCursor(0, 0)
}
commitMessageView.Title = gui.Tr.SLocalize("CommitMessage")
g.Update(func(g *gocui.Gui) error { g.Update(func(g *gocui.Gui) error {
g.SetViewOnTop("commitMessage") g.SetViewOnTop("commitMessage")
gui.switchFocus(g, filesView, commitMessageView) gui.switchFocus(g, filesView, commitMessageView)
@ -208,6 +215,26 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
return nil return nil
} }
func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) error {
if len(gui.stagedFiles()) == 0 && !gui.State.HasMergeConflicts {
return gui.createErrorPanel(g, gui.Tr.SLocalize("NoStagedFilesToCommit"))
}
commitMessageView := gui.getCommitMessageView(g)
commitMessageView.Clear()
commitMessageView.Title = gui.Tr.SLocalize("AmendLastCommit")
g.Update(func(g *gocui.Gui) error {
g.SetViewOnTop("commitMessage")
gui.switchFocus(g, filesView, commitMessageView)
lastCommitName := gui.State.Commits[0].Name
commitMessageView.Write([]byte(lastCommitName))
commitMessageView.SetCursor(len(lastCommitName), 0)
gui.RenderCommitLength()
return nil
})
return nil
}
// handleCommitEditorPress - handle when the user wants to commit changes via // handleCommitEditorPress - handle when the user wants to commit changes via
// their editor rather than via the popup panel // their editor rather than via the popup panel
func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error { func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error {

View File

@ -1,6 +1,7 @@
package gui package gui
import "github.com/jesseduffield/gocui" import "github.com/jesseduffield/gocui"
import "strings"
// Binding - a keybinding mapping a key and modifier to a handler. The keypress // Binding - a keybinding mapping a key and modifier to a handler. The keypress
// is only handled if the given view has focus, or handled globally if the view // is only handled if the given view has focus, or handled globally if the view
@ -98,6 +99,12 @@ func (gui *Gui) GetKeybindings() []Binding {
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleCommitPress, Handler: gui.handleCommitPress,
Description: gui.Tr.SLocalize("CommitChanges"), Description: gui.Tr.SLocalize("CommitChanges"),
}, {
ViewName: "files",
Key: 'M',
Modifier: gocui.ModNone,
Handler: gui.handleAmendCommitPress,
Description: strings.ToLower(gui.Tr.SLocalize("AmendLastCommit")),
}, { }, {
ViewName: "files", ViewName: "files",
Key: 'C', Key: 'C',

View File

@ -34,6 +34,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
}, &i18n.Message{ }, &i18n.Message{
ID: "CommitChanges", ID: "CommitChanges",
Other: "Commit Veranderingen", Other: "Commit Veranderingen",
}, &i18n.Message{
ID: "AmendLastCommit",
Other: "Wijzig laatste commit",
}, &i18n.Message{ }, &i18n.Message{
ID: "CommitChangesWithEditor", ID: "CommitChangesWithEditor",
Other: "commit Veranderingen met de git editor", Other: "commit Veranderingen met de git editor",

View File

@ -42,6 +42,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{ }, &i18n.Message{
ID: "CommitChanges", ID: "CommitChanges",
Other: "commit changes", Other: "commit changes",
}, &i18n.Message{
ID: "AmendLastCommit",
Other: "Amend last commit",
}, &i18n.Message{ }, &i18n.Message{
ID: "CommitChangesWithEditor", ID: "CommitChangesWithEditor",
Other: "commit changes using git editor", Other: "commit changes using git editor",

View File

@ -32,6 +32,9 @@ func addPolish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{ }, &i18n.Message{
ID: "CommitChanges", ID: "CommitChanges",
Other: "commituj zmiany", Other: "commituj zmiany",
}, &i18n.Message{
ID: "AmendLastCommit",
Other: "Zmień ostatnie zatwierdzenie",
}, &i18n.Message{ }, &i18n.Message{
ID: "CommitChangesWithEditor", ID: "CommitChangesWithEditor",
Other: "commituj zmiany używając edytora z gita", Other: "commituj zmiany używając edytora z gita",