Skip to content

Instantly share code, notes, and snippets.

@keithamus
Created June 7, 2012 13:28
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 keithamus/2888810 to your computer and use it in GitHub Desktop.
Save keithamus/2888810 to your computer and use it in GitHub Desktop.
Tim Pope's Commit Message format - BDFL version. http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
#!/bin/sh
message=`sed '/^#/,$d' $1`
firstLine=`echo "$message" | awk 'NR>1{exit};1'`
exitCode=0
txtred=$(tput setaf 1) # Red
txtrst=$(tput sgr0) # Text reset
if [[ "`echo "$firstLine" | awk '{print length()}'`" -gt 49 ]]; then
echo "${txtred}[POLICY] Ensure first line in your commit message is no longer than 50 characters${txtrst}"
exitCode=1
fi
if [[ "`echo "$message" | awk ' { if ( length > x ) { x = length } }END{ print x }'`" -gt "71" ]]; then
echo "${txtred}[POLICY] Ensure no lines in your commit message are no longer than 72 chars${txtrst}"
exitCode=1
fi
if [[ "$exitCode" -gt "0" ]]; then
echo "Your commit message was:\n"
echo "$message" | awk '{ print " " $0 }'
echo ""
fi
exit $exitCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment