Created
November 14, 2015 13:04
-
-
Save pmalek/02d73a8cc942d3bcb461 to your computer and use it in GitHub Desktop.
commit-msg hook checking whether there already exists a commit in git repository with passed in commit message
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/python | |
from subprocess import check_output | |
import sys | |
class Colors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
COMMIT_MSG = "" | |
for s in [(s) for s in sys.argv if s == ".git/COMMIT_EDITMSG"]: | |
with open(s, 'r') as f: | |
COMMIT_MSG = f.read().rstrip() | |
for line in check_output(["git", "log", "--pretty=format:%s"]).splitlines(): | |
if line.rstrip() == COMMIT_MSG: | |
print Colors.FAIL, "[DUPLICATE]", | |
print "There has already been a commit in this repository with '", line.rstrip(), | |
print "' commit message!" | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment