Skip to content

Instantly share code, notes, and snippets.

@math2001
Created November 22, 2016 06:14
Show Gist options
  • Save math2001/dfea287edc7090a85747f9511ac40ab0 to your computer and use it in GitHub Desktop.
Save math2001/dfea287edc7090a85747f9511ac40ab0 to your computer and use it in GitHub Desktop.
Validate the length of my commit's message using python
#!/bin/sh
# put this file here: .git/hooks/commit-msg
exec < /dev/tty
.git/hooks/validate-commit.py $1
#!python
# the path to your python.exe
import sys, os
message_file = sys.argv[1]
with open(message_file) as fp:
for i, line in enumerate(fp):
if i == 0 and len(line) > 50:
print('The first line of your commit should have less than 50 chars. Got {}.'.format(len(line)))
sys.exit(1)
elif len(line) > 72:
print('Your lines shouldn\'t have more than 72 chars. Got {}.'.format(len(line)))
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment