lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

commitPrefixes not working

Open max-two opened this issue 3 years ago • 1 comments

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:

  1. Add configuration from https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#predefined-commit-message-prefix to config file
  2. Make a commit on a branch that should match the regex pattern (trevordavis/sc-138414/migrate-selectinterviewers-to-rktq in my case)
  3. 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): image

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: image

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

max-two avatar Oct 11 '22 20:10 max-two

Also tried copying the posted example and couldn't get it to work?

HarrisonFretwell avatar Mar 07 '23 15:03 HarrisonFretwell

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)
}

longlhh90 avatar May 08 '23 20:05 longlhh90

This is fixed now on master (by https://github.com/jesseduffield/lazygit/pull/2612). I'll push a new patch for this soon

jesseduffield avatar May 17 '23 07:05 jesseduffield

I got same bug, but it behaves differently. image

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.

zeromask1337 avatar Nov 27 '23 08:11 zeromask1337

@jesseduffield can you comment this?

zeromask1337 avatar Dec 06 '23 16:12 zeromask1337

@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)

jesseduffield avatar Dec 07 '23 01:12 jesseduffield

It really worked! Thank you

zeromask1337 avatar Dec 07 '23 08:12 zeromask1337