commitPrefixes not working
Describe the bug I'm pretty certain this is user error rather than an actual bug, but I didn't know where else to ask. I have just installed lazygit and wanted to add a commit prefix but I cannot get it to work and I'm unsure how to debug this.
I have added the exact config from the docs and tested the regex in regexr.com against my branch name (trevordavis/sc-138414/migrate-selectinterviewers-to-rktq) and it matches correctly.
To Reproduce Steps to reproduce the behavior:
- Add configuration from https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix to config file
- Make a commit on a branch that should match the regex pattern (trevordavis/sc-138414/migrate-selectinterviewers-to-rktq in my case)
- See that commit does not have prefix in commit message
Expected behavior I would expect the prefix to be in the commit message
Screenshots
My config (the nerd font icons do show up, so I'm confident the config is being read from):

I did try to run in debug mode and saw this error log when running a commit. Not entirely sure what to make of it though:

Version info:
Run lazygit --version and paste the result here
commit=367b0d331836c90c015bf0c45f88612f3d94d08a, build date=2022-07-20T09:27:56Z, build source=binaryRelease, version=0.35, os=darwin, arch=amd64
Run git --version and paste the result here
git version 2.37.3
Also tried copying the posted example and couldn't get it to work?
Yesterday, when I updated lazygit to the newest version, my commitPrefixes is not working anymore. Actually, it's not working when I start lazygit and start committing. If I commit it as WIP and cancel and recommit again prefix will show.
It was working perfectly fine in old version (I couldn't remember which one).
I think it's because of this line: https://github.com/jesseduffield/lazygit/blob/0accb07dcc211347c23ad40bc7a749f3f4233d88/pkg/gui/controllers/helpers/working_tree_helper.go#L163
So commitPrefix can work if I have something in my commit message.
func (self *WorkingTreeHelper) HandleCommitPress() error {
message := self.contexts.CommitMessage.GetPreservedMessage()
if message != "" { <--- message can be empty
commitPrefixConfig := self.commitPrefixConfigForRepo()
if commitPrefixConfig != nil {
prefixPattern := commitPrefixConfig.Pattern
prefixReplace := commitPrefixConfig.Replace
rgx, err := regexp.Compile(prefixPattern)
if err != nil {
return self.c.ErrorMsg(fmt.Sprintf("%s: %s", self.c.Tr.LcCommitPrefixPatternError, err.Error()))
}
prefix := rgx.ReplaceAllString(self.refHelper.GetCheckedOutRef().Name, prefixReplace)
message = prefix
}
}
return self.HandleCommitPressWithMessage(message)
}
This is fixed now on master (by https://github.com/jesseduffield/lazygit/pull/2612). I'll push a new patch for this soon
I got same bug, but it behaves differently.
I have my config like this
gui:
language: 'en'
git:
commitPrefixes:
black_ore_frontend:
pattern: "/([a-zA-Z0-9]+-?\\d+)/"
replace: '[$1] some text lol'
And for some reason my commit message only has branch name, no brackets or other text. Tried different methods, such as commenting parts of config. Pretty confident that its either my missunderstanding of config, or bug with reading replace property.
@jesseduffield can you comment this?
@zeromask1337 Those forward slashes in your pattern are not necessary and I suspect if you remove them then it'll work (note I'm on break atm so am slow to respond)
It really worked! Thank you