axel
axel

Reputation: 4127

How to fix the pre-commit-msg in my git environment?

Has someone have experienced a weird behaviour of .git/hooks/pre-commit-msg? The file has proper permission in being executed. And actually it is executed. The issue is that the commits, any commits with correct or uncorrect messages, make the execution goes into the error. Always.

The correct message should be something like these examples:

where the first word after [test], or [fix], or [feat] is chosen between a set (like Added, Fixed, Upgraded..)

Working on OSX, with git, with zsh shell.

#!/bin/bash
#

commit_message=$(cat .git/COMMIT_EDITMSG)
commit_error="Error in the commit message. Prefix with 
JIRA ticket. For example UXD-1234/git-hook"


if [[ ! $commit_message =~ /([A-Z]+[-][\d]+\/\S+)/  ]]; then
  echo >&2 $commit_error
  exit 1
fi

Is there an error in this code?

Thanks in advance

Upvotes: 1

Views: 1313

Answers (1)

axel
axel

Reputation: 4127

So here is the correct answer

^[A-Z]+-[0-9]+/[a-zA-Z]

Thanks to @jonrsharpe

Upvotes: 1

Related Questions