1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-29 22:48:24 +02:00

Use confirmation popup for amending last commit.

This commit is contained in:
Kristijan Husak
2018-09-25 22:11:51 +02:00
parent b6b21bc98e
commit 28fe3d6cf9
6 changed files with 24 additions and 27 deletions

View File

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

View File

@@ -201,14 +201,7 @@ 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)
@@ -222,20 +215,17 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro
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")
title := strings.Title(gui.Tr.SLocalize("AmendLastCommit"))
question := gui.Tr.SLocalize("SureToAmend")
return gui.createConfirmationPanel(g, filesView, title, question, func(g *gocui.Gui, v *gocui.View) error {
lastCommitMsg := gui.State.Commits[0].Name
_, err := gui.GitCommand.Commit(lastCommitMsg, true)
if err != nil {
gui.createErrorPanel(g, err.Error())
}
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
return gui.refreshFiles(g)
}, nil)
}
// handleCommitEditorPress - handle when the user wants to commit changes via

View File

@@ -2,7 +2,6 @@ package gui
import (
"github.com/jesseduffield/gocui"
"strings"
)
// Binding - a keybinding mapping a key and modifier to a handler. The keypress
@@ -131,7 +130,7 @@ func (gui *Gui) GetKeybindings() []*Binding {
Key: 'M',
Modifier: gocui.ModNone,
Handler: gui.handleAmendCommitPress,
Description: strings.ToLower(gui.Tr.SLocalize("AmendLastCommit")),
Description: gui.Tr.SLocalize("AmendLastCommit"),
}, {
ViewName: "files",
Key: 'C',