{"record":{"id":"67f2d64bf6a99a40","repo":"jesseduffield/lazygit","slug":"error-in-commitprefix-pattern-s","errorCode":null,"errorMessage":"Error in commitPrefix pattern: %s","messagePattern":"Error in commitPrefix pattern: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/controllers/helpers/working_tree_helper.go","lineNumber":216,"sourceCode":"\t}\n\treturn self.HandleCommitPressWithMessage(initialMessage, true)\n}\n\nfunc (self *WorkingTreeHelper) HandleCommitPress() error {\n\tvar initialMessage string\n\tpreservedMessage := self.c.Contexts().CommitMessage.GetPreservedMessageAndLogError()\n\tif preservedMessage == \"\" {\n\t\tcommitPrefixConfigs := self.commitPrefixConfigsForRepo()\n\t\tfor _, commitPrefixConfig := range commitPrefixConfigs {\n\t\t\tprefixPattern := commitPrefixConfig.Pattern\n\t\t\tif prefixPattern == \"\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprefixReplace := commitPrefixConfig.Replace\n\t\t\tbranchName := self.refHelper.GetCheckedOutRef().Name\n\t\t\trgx, err := regexp.Compile(prefixPattern)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"%s: %s\", self.c.Tr.CommitPrefixPatternError, err.Error())\n\t\t\t}\n\n\t\t\tif rgx.MatchString(branchName) {\n\t\t\t\tinitialMessage = rgx.ReplaceAllString(branchName, prefixReplace)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\treturn self.HandleCommitPressWithMessage(initialMessage, false)\n}\n\nfunc (self *WorkingTreeHelper) WithEnsureCommittableFiles(handler func() error) error {\n\tif len(self.c.Model().Files) == 0 {\n\t\treturn errors.New(self.c.Tr.NoFilesStagedTitle)\n\t}\n\n\tif !self.AnyStagedFiles() {","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/jesseduffield/lazygit/blob/c477a2959b229fbf3284be0d4d2904ab61ec3c94/pkg/gui/controllers/helpers/working_tree_helper.go#L198-L234","documentation":"WorkingTreeHelper (pkg/gui/controllers/helpers/working_tree_helper.go) builds the initial commit message from a commitPrefix pattern: for each matching config entry it regexp.Compile's the pattern and, on compile failure, wraps the Go regex error with the CommitPrefixPatternError prefix. Only a syntactically invalid Go regexp triggers it — no match simply skips the entry.","triggerScenarios":"Setting git.commitPrefix[n].pattern (or a repo-specific commitPrefixes entry) to an invalid Go regex such as 'feature/(\\w+' (unclosed group) or '{2,1}' (bad repetition) in the user config, then pressing the commit key while no preserved message exists.","commonSituations":"Patterns written for PCRE with unsupported syntax; unescaped parentheses/braces; missing closing group when copying from issue templates; repo-specific commitPrefixes in .lazygitconfig with a typo.","solutions":["Fix the pattern in the user config so it compiles as a Go regexp (balance groups, escape metacharacters with a double backslash in YAML).","Test it quickly: go run with regexp.MustCompile, or any online Go-regex checker — JS/PCRE flavors differ.","If prefixes are unwanted, remove the commitPrefix section entirely instead of leaving a broken pattern."],"exampleFix":"# before\ngit:\n  commitPrefix:\n    - pattern: \"^feature/(\\w+\"\n      replacement: \"[$1] \"\n\n# after\ngit:\n  commitPrefix:\n    - pattern: \"^feature/(\\w+)\"\n      replacement: \"[$1] \"","handlingStrategy":"validation","validationCode":"// Compile-check prefix patterns at config load time:\nfor _, p := range cfg.Git.CommitPrefix {\n\tif _, err := regexp.Compile(p.Pattern); err != nil {\n\t\treturn fmt.Errorf(\"commitPrefix pattern %q invalid: %w\", p.Pattern, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write patterns as Go (RE2) regex, not PCRE — no lookaheads/backreferences.","In YAML, escape backslashes (\"\\\\w+\"), and balance all groups.","Smoke-test configs with a tiny Go program or lazygit startup after every pattern edit."],"tags":["config","regex","commit-prefix"],"backgroundTag":null,"analyzedSha":"c477a2959b229fbf3284be0d4d2904ab61ec3c94","analyzedAt":"2026-08-15T08:34:32.451Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}