Use MatchString before ReplaceAllString in HandleCommitPress
Describe the bug
When using the commitPrefix(es) pattern and replace config, the expectation is that any non-match should not result in the replace being returned. For e.g. if I have pattern: "^(JIRA-\\d+)-.*" replace: "$1: " and my branch name is master then the return should just be an empty string, not master.
To Reproduce Steps to reproduce the behavior:
- Set
commitPrefixpattern and replace in config.yaml - Create a branch that doesn't match your pattern
- Start a commit
- Notice the branch name is in the commit box even though there was no match
Expected behavior There should be no commit prefix if there was no regex match
Screenshots
Version info: commit=6fcb7eb8bb616c170506312870b3bf15f3dbe37c, build date=2024-05-19T10:15:28Z, build source=binaryRelease, version=0.42.0, os=darwin, arch=arm64, git version=2.39.3 (Apple Git-146)
git version=2.39.3 (Apple Git-146)
Additional context I've set up a couple of Go Playgrounds to demonstrate more or less the expected behaviour. Expected: https://go.dev/play/p/se9Sex7v9YG Current: https://go.dev/play/p/6Kt1NM9ZA2t
Just change the branch_name variable to see your thingy things
This would be the area that requires changing: https://github.com/jesseduffield/lazygit/blob/63a523c2fcfac708c1c070cd4b550b4f41986555/pkg/gui/controllers/helpers/working_tree_helper.go#L147-L165