Created
October 26, 2018 05:26
-
-
Save qsLI/eca506f70b7b48805598a8500c4ed0d0 to your computer and use it in GitHub Desktop.
git pre commit
This file contains hidden or 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 -*- | |
import sys | |
import re | |
import subprocess | |
from sys import argv | |
reload(sys) | |
sys.setdefaultencoding("utf-8") | |
BRANCH_PATTERN = r"refs/heads/(task|bug)-\d+-\d{8}-.*" | |
line = sys.stdin.read() | |
(base, commit, ref) = line.strip().split() | |
print "base -> %s, commit -> %s, ref -> %s" % (base, commit, ref) | |
if commit == '0000000000000000000000000000000000000000': | |
print 'You are deleting branch %s!' % ref | |
sys.exit(0) | |
if commit.startswith('refs/tags'): | |
print 'Pushing tag' | |
sys.exit(0) | |
if 'master' in commit: | |
print 'master branch' | |
sys.exit(0) | |
if commit == '0000000000000000000000000000000000000000': | |
print 'Pushing new branch' | |
print 'Did you run mvn compile?'.center(90) | |
print 'Did you format the code?'.center(90) | |
matched = re.match(BRANCH_PATTERN, ref) | |
if not matched: | |
print " ==== WARNING ==== ".center(90) | |
print " new branch must be the following pattern: ".center(90) | |
print " task-[taskId]-yyyyMMdd-[other info] ".center(90) | |
print (" your's is %s " % ref).center(90) | |
sys.exit(-1) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment