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:
- "ABC-123/ticket-task blah blha"
- "ABC-234/ticket-task fixed some things"
- "ABC-123/ticket-task added some"
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
if [[ ! 'ABC-123/something' =~ /([A-Z]+[-][\d]+\/\S+)/ ]]; then echo 'no match'; else echo 'match'; fi
has the outputno match
. Specifically it seems to be backslash escaping, asif [[ ! 'ABC-123/something' =~ ^[A-Z]+-[0-9]+ ]]; then echo 'no match'; else echo 'match'; fi
does outputmatch
.UXD-12/
and this should be out. I tried with this^[A-Z]+-[0-9][/]+
but this also is not working at all, I need to check also the slash and at least a character.^[A-Z]+-[0-9]+/[a-zA-Z]
? Or you'll need to work out how to handle backslashes (so you can use\d
too).[/]+
would be a character class containing a single character, the forward slash, repeated one or more times, which is both an unnecessary class and not what you're describing.[[ ABC-123/some =~ [A-Z]+-[0-9]+/[^\ ]+ ]] && echo yes || echo no
(result isyes
).