Last active
September 12, 2016 08:59
-
-
Save o-shabashov/e09626c78f464f9f566afb01fca49b08 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
import sys, os, re | |
from subprocess import check_output | |
# Collect the parameters | |
commit_msg_filepath = sys.argv[1] | |
if len(sys.argv) > 2: | |
commit_type = sys.argv[2] | |
else: | |
commit_type = '' | |
if len(sys.argv) > 3: | |
commit_hash = sys.argv[3] | |
else: | |
commit_hash = '' | |
print "prepare-commit-msg: File: %s\nType: %s\nHash: %s" % (commit_msg_filepath, commit_type, commit_hash) | |
# Figure out which branch we're on | |
branch = check_output(['git', 'symbolic-ref', '--short', 'HEAD']).strip() | |
print "prepare-commit-msg: On branch '%s'" % branch | |
if commit_type == 'message': | |
with open(commit_msg_filepath, 'r+') as f: | |
content = f.read() | |
if re.search('\[[\!\!\*\+\-]+\]\s#[0-9]+\s@[0-9\.]+h\s.*', content): | |
sys.exit() | |
else: | |
print "Wrong message format. Example: [*] #4522 @3h Changed model behavior" | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment