Skip to content

Instantly share code, notes, and snippets.

@Hafiz-Waleed-Hussain
Created March 18, 2018 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hafiz-Waleed-Hussain/159928ce7d0901a3f22f53830143da65 to your computer and use it in GitHub Desktop.
Save Hafiz-Waleed-Hussain/159928ce7d0901a3f22f53830143da65 to your computer and use it in GitHub Desktop.
Commit Message Hook Script
#!/bin/sh
msg=`head -n 1 $1`
if echo $msg | egrep -qv '(Android-\d{3,4}.{20,})'; then
echo "[Message Format] Your message is not formatted correctly. Correct message format\n
#Ticket Number - Minimum 20 or more Character \n
like #Android-123 Bug fixed for login issue"
exit 1;
fi
@kenchoong
Copy link

kenchoong commented Apr 12, 2020

hey sir,just wanna to ask a quick question

This is my commit message
git commit -m "#Android-2345 I sure this is more than 25 characters,but this validation is still cannot pass with error"

but seem like the validation is always failed even though I make a correct commit message format.

my commit-msg file in .git->hooks is exactly the same with script above..

Do u mind to tell me what I missing out??

@Hafiz-Waleed-Hussain
Copy link
Author

Did you remove the .sample extension from the commit-msg file?

@kenchoong
Copy link

yup..I removed the .sample extension ady..now the hook file is only commit-msg

@kenchoong
Copy link

kenchoong commented Apr 13, 2020

End up I have the script like this :

#!/bin/sh
if ! grep -E 'Android-[0-9]{3,4}.{20,}' "$1"; then
  printf "[Message Format] Your message is not formatted correctly. Correct message format: 
    #Ticket Number - Minimum 20 or more Character 
    like #Android-123 Bug fixed for login issue\n"
  exit 1;
fi

not sure is this work,but it done exactly same operation u mention in the tutorial

@Hafiz-Waleed-Hussain
Copy link
Author

Its mean commit hook is working but logic has some issue. Can you try to add simple validation As a minimum 5 characters required?

@kenchoong
Copy link

ok let me try it later and get back to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment