Created
November 22, 2016 06:14
-
-
Save math2001/dfea287edc7090a85747f9511ac40ab0 to your computer and use it in GitHub Desktop.
Validate the length of my commit's message using python
This file contains 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 | |
# put this file here: .git/hooks/commit-msg | |
exec < /dev/tty | |
.git/hooks/validate-commit.py $1 |
This file contains 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
#!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