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:
parent
7fb2cafd0c
commit
61f0801bd3
@ -299,8 +299,12 @@ func (c *GitCommand) usingGpg() bool {
|
||||
}
|
||||
|
||||
// Commit commits to git
|
||||
func (c *GitCommand) Commit(message string) (*exec.Cmd, error) {
|
||||
command := fmt.Sprintf("git commit -m %s", c.OSCommand.Quote(message))
|
||||
func (c *GitCommand) Commit(message string, amend bool) (*exec.Cmd, error) {
|
||||
amendParam := ""
|
||||
if amend {
|
||||
amendParam = "--amend "
|
||||
}
|
||||
command := fmt.Sprintf("git commit %s-m %s", amendParam, c.OSCommand.Quote(message))
|
||||
if c.usingGpg() {
|
||||
return c.OSCommand.PrepareSubProcess(c.OSCommand.Platform.shell, c.OSCommand.Platform.shellArg, command), nil
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
|
||||
if message == "" {
|
||||
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 {
|
||||
// TODO need to find a way to send through this error
|
||||
if err != gui.Errors.ErrSubProcess {
|
||||
|
@ -198,7 +198,14 @@ func (gui *Gui) handleCommitPress(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)
|
||||
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.SetViewOnTop("commitMessage")
|
||||
gui.switchFocus(g, filesView, commitMessageView)
|
||||
@ -208,6 +215,26 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||
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
|
||||
// their editor rather than via the popup panel
|
||||
func (gui *Gui) handleCommitEditorPress(g *gocui.Gui, filesView *gocui.View) error {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gui
|
||||
|
||||
import "github.com/jesseduffield/gocui"
|
||||
import "strings"
|
||||
|
||||
// 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
|
||||
@ -98,6 +99,12 @@ func (gui *Gui) GetKeybindings() []Binding {
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleCommitPress,
|
||||
Description: gui.Tr.SLocalize("CommitChanges"),
|
||||
}, {
|
||||
ViewName: "files",
|
||||
Key: 'M',
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleAmendCommitPress,
|
||||
Description: strings.ToLower(gui.Tr.SLocalize("AmendLastCommit")),
|
||||
}, {
|
||||
ViewName: "files",
|
||||
Key: 'C',
|
||||
|
@ -34,6 +34,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
|
||||
}, &i18n.Message{
|
||||
ID: "CommitChanges",
|
||||
Other: "Commit Veranderingen",
|
||||
}, &i18n.Message{
|
||||
ID: "AmendLastCommit",
|
||||
Other: "Wijzig laatste commit",
|
||||
}, &i18n.Message{
|
||||
ID: "CommitChangesWithEditor",
|
||||
Other: "commit Veranderingen met de git editor",
|
||||
|
@ -42,6 +42,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
||||
}, &i18n.Message{
|
||||
ID: "CommitChanges",
|
||||
Other: "commit changes",
|
||||
}, &i18n.Message{
|
||||
ID: "AmendLastCommit",
|
||||
Other: "Amend last commit",
|
||||
}, &i18n.Message{
|
||||
ID: "CommitChangesWithEditor",
|
||||
Other: "commit changes using git editor",
|
||||
|
@ -32,6 +32,9 @@ func addPolish(i18nObject *i18n.Bundle) error {
|
||||
}, &i18n.Message{
|
||||
ID: "CommitChanges",
|
||||
Other: "commituj zmiany",
|
||||
}, &i18n.Message{
|
||||
ID: "AmendLastCommit",
|
||||
Other: "Zmień ostatnie zatwierdzenie",
|
||||
}, &i18n.Message{
|
||||
ID: "CommitChangesWithEditor",
|
||||
Other: "commituj zmiany używając edytora z gita",
|
||||
|
Loading…
x
Reference in New Issue
Block a user