summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorKristijan Husak <husakkristijan@gmail.com>2020-04-20 10:42:24 +0200
committerJesse Duffield <jessedduffield@gmail.com>2020-04-20 18:47:50 +1000
commit68586ec49a3316db4d5685e8cbbb0e4b1b540d66 (patch)
treea1a342519a7220d1f90b0e8948e0baaf475aa4a4 /pkg
parent6cf75af0afbec83a269b313d9253bb32b758737d (diff)
Handle regex compilation errors and show them to the user.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/files_panel.go5
-rw-r--r--pkg/i18n/dutch.go3
-rw-r--r--pkg/i18n/english.go3
-rw-r--r--pkg/i18n/polish.go3
4 files changed, 13 insertions, 1 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index 8129b02a4..36665fe3c 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -291,7 +291,10 @@ func (gui *Gui) handleCommitPress(g *gocui.Gui, filesView *gocui.View) error {
prefixPattern := gui.Config.GetUserConfig().GetString("git.commitPrefixes." + utils.GetCurrentRepoName() + ".pattern")
prefixReplace := gui.Config.GetUserConfig().GetString("git.commitPrefixes." + utils.GetCurrentRepoName() + ".replace")
if len(prefixPattern) > 0 && len(prefixReplace) > 0 {
- rgx := regexp.MustCompile(prefixPattern)
+ rgx, err := regexp.Compile(prefixPattern)
+ if err != nil {
+ return gui.createErrorPanel(fmt.Sprintf("%s: %s", gui.Tr.SLocalize("commitPrefixPatternError"), err.Error()))
+ }
prefix := rgx.ReplaceAllString(gui.getCheckedOutBranch().Name, prefixReplace)
gui.renderString(g, "commitMessage", prefix)
if err := commitMessageView.SetCursor(len(prefix), 0); err != nil {
diff --git a/pkg/i18n/dutch.go b/pkg/i18n/dutch.go
index fbde75d69..f4ab0c768 100644
--- a/pkg/i18n/dutch.go
+++ b/pkg/i18n/dutch.go
@@ -763,6 +763,9 @@ func addDutch(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "IgnoreTrackedPrompt",
Other: "Are you sure you want to ignore a tracked file?",
+ }, &i18n.Message{
+ ID: "commitPrefixPatternError",
+ Other: "Error in commitPrefix pattern",
},
)
}
diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go
index 7a2f5c88a..fa5a3ba65 100644
--- a/pkg/i18n/english.go
+++ b/pkg/i18n/english.go
@@ -1137,6 +1137,9 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "copyBranchNameToClipboard",
Other: "copy branch name to clipboard",
+ }, &i18n.Message{
+ ID: "commitPrefixPatternError",
+ Other: "Error in commitPrefix pattern",
},
)
}
diff --git a/pkg/i18n/polish.go b/pkg/i18n/polish.go
index 5e9db605a..e42d726e2 100644
--- a/pkg/i18n/polish.go
+++ b/pkg/i18n/polish.go
@@ -746,6 +746,9 @@ func addPolish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{
ID: "IgnoreTrackedPrompt",
Other: "Are you sure you want to ignore a tracked file?",
+ }, &i18n.Message{
+ ID: "commitPrefixPatternError",
+ Other: "Error in commitPrefix pattern",
},
)
}