Skip to content

Instantly share code, notes, and snippets.

@evhen14
Created September 17, 2014 23:16
Show Gist options
  • Select an option

  • Save evhen14/428d98b7cb1c388715e4 to your computer and use it in GitHub Desktop.

Select an option

Save evhen14/428d98b7cb1c388715e4 to your computer and use it in GitHub Desktop.
update script for commit message format validation on Git server
#!/usr/bin/env python
import sys,os,re
refname = sys.argv[1]
oldmsg = sys.argv[2]
newmsg = sys.argv[3]
def check_message_format():
print "Ref name: ", refname
print "Old msgision: ", oldmsg
print "New msgision: ", newmsg
command = """git log --pretty=format:"%s" """ + oldmsg + ".." + newmsg
msgCursor = os.popen(command)
for msg in msgCursor:
match = re.match("^(((Revert \")*[A-Z]{2,4}-[0-9]{1,6}(\:)?[ ])|(Merge))", msg.strip())
if not match:
print
print "Message format check failed. Message: " + msg
print
print "Supported formats are:"
print " UI-123: Making it finally work"
print " UI-123 Fixing previous commit"
print " Merge master/rubbish"
print
sys.exit(13)
msgCursor.close()
check_message_format()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment