Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Created May 26, 2014 19:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ordnungswidrig/b7f5413bec0b098f5838 to your computer and use it in GitHub Desktop.
Save ordnungswidrig/b7f5413bec0b098f5838 to your computer and use it in GitHub Desktop.
Git commit-msg hook to check for maximum line lengths
#!/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
}
@jcf
Copy link

jcf commented May 26, 2014

Nice. Are you using this?

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