Created
May 26, 2014 19:59
-
-
Save ordnungswidrig/b7f5413bec0b098f5838 to your computer and use it in GitHub Desktop.
Git commit-msg hook to check for maximum line lengths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# .git/hooks/commit-msg | |
# | |
# Check for maximum line lengths | |
# | |
# A git hook script to check the commit log message. | |
# Called by "git commit" with one argument, the name of the file | |
# that has the commit message. The hook should exit with non-zero | |
# status after issuing an appropriate message if it wants to stop the | |
# commit. | |
# | |
cat "$1" | head -1 | grep -e '^..\{50\}' >/dev/null && { | |
echo >&2 "First line exceeds 50 char limit." | |
exit 1 | |
} | |
cat "$1" | head -2 | tail -1 | grep -e '^\S*$' 2>/dev/null || | |
echo >&2 "Second line must be empty." | |
exit 1 | |
} | |
cat "$1" | tail -n +2 | grep -e '^..\{72\}' >/dev/null && { | |
echo >&2 "Line exceeds 72 char limit." | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. Are you using this?