I have validation statement (full githooks commit-msg): #!/bin/sh
read -r message<$1
if [[ $text =~ ^[a-z] ]]
then
printf "$warning Check commit message.\n"
exit 1
fi
When I make commit with text: "This is my test commit", githooks responds with:
[WARNING] Check commit message.
But when I make it with something like this: "this is my test commit", I get tge same result.
What an I doing wrong?
I am using Wind10, Git version 2.20.1.windows.1 and GitBash.
I just tested such a similar hook, but using the commit-msg
, not the pre-commit
one.
(Git 2.23, Windows 10, CMD session)
myrepo/.git/hooks/commit-msg
#!/bin/sh
echo "1='$1'"
cat $1
if [[ $(cat $1) =~ ^[a-z] ]]
then
printf "$warning Check commit message.\n"
exit 1
fi
It works as advertised: if your commit message starts with a lowercase, it will block the commit creation:
D:\git\rr>git add .
D:\git\rr>git commit -m "aaa"
aaa
Check commit message.
The commit-msg
hook receives .git/COMMIT_EDITMSG
as first parameter.
With an upercase first-letter, it will work:
D:\git\rr>git commit -m "Aaa"
Aaa
[master 222cffb] Aaa
1 file changed, 1 insertion(+)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With