1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-27 23:08:02 +02:00

prompt to commit all files if committing with no staged files

This commit is contained in:
Jesse Duffield 2020-07-17 08:39:45 +10:00
parent 96f821b841
commit 6349214f00
4 changed files with 48 additions and 15 deletions

View File

@ -284,9 +284,12 @@ func (gui *Gui) handleWIPCommitPress(g *gocui.Gui, filesView *gocui.View) error
}
func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
if len(gui.stagedFiles()) == 0 && gui.GitCommand.WorkingTreeState() == "normal" {
return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit"))
if len(gui.stagedFiles()) == 0 {
return gui.promptToStageAllAndRetry(func() error {
return gui.handleCommitPress(gui.g, filesView)
})
}
commitMessageView := gui.getCommitMessageView()
prefixPattern := gui.Config.GetUserConfig().GetString("git.commitPrefixes." + utils.GetCurrentRepoName() + ".pattern")
prefixReplace := gui.Config.GetUserConfig().GetString("git.commitPrefixes." + utils.GetCurrentRepoName() + ".replace")
@ -317,10 +320,28 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
return nil
}
func (gui *Gui) promptToStageAllAndRetry(retry func() error) error {
return gui.createConfirmationPanel(
gui.g, gui.getFilesView(), true, gui.Tr.SLocalize("NoFilesStagedTitle"), gui.Tr.SLocalize("NoFilesStagedPrompt"),
func(*gocui.Gui, *gocui.View) error {
if err := gui.GitCommand.StageAll(); err != nil {
return gui.surfaceError(err)
}
if err := gui.refreshFiles(); err != nil {
return gui.surfaceError(err)
}
return retry()
}, nil)
}
func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) error {
if len(gui.stagedFiles()) == 0 && gui.GitCommand.WorkingTreeState() == "normal" {
return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit"))
if len(gui.stagedFiles()) == 0 {
return gui.promptToStageAllAndRetry(func() error {
return gui.handleAmendCommitPress(gui.g, filesView)
})
}
if len(gui.State.Commits) == 0 {
return gui.createErrorPanel(gui.Tr.SLocalize("NoCommitToAmend"))
}
@ -344,9 +365,12 @@ func (gui *Gui) handleAmendCommitPress(g *gocui.Gui, filesView *gocui.View) erro
// 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 {
if len(gui.stagedFiles()) == 0 && gui.GitCommand.WorkingTreeState() == "normal" {
return gui.createErrorPanel(gui.Tr.SLocalize("NoStagedFilesToCommit"))
if len(gui.stagedFiles()) == 0 {
return gui.promptToStageAllAndRetry(func() error {
return gui.handleCommitEditorPress(gui.g, filesView)
})
}
gui.PrepareSubProcess(g, "git", "commit")
return nil
}

View File

@ -136,9 +136,6 @@ func addDutch(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "CannotGitAdd",
Other: "Kan commando niet uitvoeren git add --path untracked files",
}, &i18n.Message{
ID: "NoStagedFilesToCommit",
Other: "Er zijn geen staged bestanden om te commiten",
}, &i18n.Message{
ID: "NoFilesDisplay",
Other: "Geen bestanden om te laten zien",
@ -766,6 +763,12 @@ func addDutch(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "commitPrefixPatternError",
Other: "Error in commitPrefix pattern",
}, &i18n.Message{
ID: "NoFilesStagedTitle",
Other: "No files staged",
}, &i18n.Message{
ID: "NoFilesStagedPrompt",
Other: "You have not staged any files. Commit all files?",
},
)
}

View File

@ -156,9 +156,6 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "CannotGitAdd",
Other: "Cannot git add --patch untracked files",
}, &i18n.Message{
ID: "NoStagedFilesToCommit",
Other: "There are no staged files to commit",
}, &i18n.Message{
ID: "NoFilesDisplay",
Other: "No file to display",
@ -1152,6 +1149,12 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "commitPrefixPatternError",
Other: "Error in commitPrefix pattern",
}, &i18n.Message{
ID: "NoFilesStagedTitle",
Other: "No files staged",
}, &i18n.Message{
ID: "NoFilesStagedPrompt",
Other: "You have not staged any files. Commit all files?",
},
)
}

View File

@ -128,9 +128,6 @@ func addPolish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "CannotGitAdd",
Other: "Nie można git add --patch nieśledzonych plików",
}, &i18n.Message{
ID: "NoStagedFilesToCommit",
Other: "Brak zatwierdzonych plików do commita",
}, &i18n.Message{
ID: "NoFilesDisplay",
Other: "Brak pliku do wyświetlenia",
@ -749,6 +746,12 @@ func addPolish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "commitPrefixPatternError",
Other: "Error in commitPrefix pattern",
}, &i18n.Message{
ID: "NoFilesStagedTitle",
Other: "No files staged",
}, &i18n.Message{
ID: "NoFilesStagedPrompt",
Other: "You have not staged any files. Commit all files?",
},
)
}