Skip to content

Instantly share code, notes, and snippets.

@DogeVenci
Last active August 30, 2018 03:45
Show Gist options
  • Save DogeVenci/d68cdc5e2ea22e76533d3f8c5cff7e39 to your computer and use it in GitHub Desktop.
Save DogeVenci/d68cdc5e2ea22e76533d3f8c5cff7e39 to your computer and use it in GitHub Desktop.
[git钩子Python]git pre-receive python script #git
#!/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