summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-07-17 08:39:45 +1000
committerJesse Duffield <jessedduffield@gmail.com>2020-07-17 09:01:40 +1000
commit6349214f000fcece292fb7e1176fee833adcdf59 (patch)
treeadefb54b04f9a728d87698a280d0ffa005ea7fb9
parent96f821b84100a75852715d6e4975f3a62cad7fbb (diff)
prompt to commit all files if committing with no staged files
-rw-r--r--pkg/gui/files_panel.go36
-rw-r--r--pkg/i18n/dutch.go9
-rw-r--r--pkg/i18n/english.go9
-rw-r--r--pkg/i18n/polish.go9
4 files changed, 48 insertions, 15 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index cb3355fc3..034a21fb6 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -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
}
diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go
index f4ab0c768..f4cecf4c8 100644
--- a/pkg/i18n/dutch.go
+++ b/pkg/i18n/dutch.go
@@ -137,9 +137,6 @@ func addDutch(i18nObject *i18n.Bundle) error {
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",
}, &i18n.Message{
@@ -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?",
},
)
}
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 6bca0589d..e7a16484a 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -157,9 +157,6 @@ func addEnglish(i18nObject *i18n.Bundle) error {
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",
}, &i18n.Message{
@@ -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?",
},
)
}
diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go
index e42d726e2..54ba3bd2c 100644
--- a/pkg/i18n/polish.go
+++ b/pkg/i18n/polish.go
@@ -129,9 +129,6 @@ func addPolish(i18nObject *i18n.Bundle) error {
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",
}, &i18n.Message{
@@ -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?",
},
)
}