jesseduffield / lazygit

simple terminal UI for git commands
MIT License
47.94k stars 1.72k forks source link

Commit prefix is added even when there is no regex match #3695

Open phaze-ZA opened 5 days ago

phaze-ZA commented 5 days ago

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:

  1. Set commitPrefix pattern and replace in config.yaml
  2. Create a branch that doesn't match your pattern
  3. Start a commit
  4. 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 image

image

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