Last active
August 30, 2018 03:45
-
-
Save DogeVenci/d68cdc5e2ea22e76533d3f8c5cff7e39 to your computer and use it in GitHub Desktop.
[git钩子Python]git pre-receive python script #git
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 | |
#coding:utf-8 | |
print '----- pre-receive start -----' | |
import sys,subprocess,re | |
def validate_commit_msg(msg): | |
if len(msg)<10: | |
return False | |
else: | |
return True | |
for line in sys.stdin: | |
(base,commit,ref)=line.strip().split() | |
#print base,commit,ref | |
commit_list=subprocess.Popen(["git log --pretty=oneline " + base+ ".." + commit],shell=True,stdout=subprocess.PIPE).stdout | |
for item in commit_list: | |
hash,msg=item.strip().split(' ') | |
if not validate_commit_msg(msg): | |
sys.exit('commit message format error!!! %s'%hash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment