Skip to content

Instantly share code, notes, and snippets.

@pmalek
Created November 14, 2015 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmalek/02d73a8cc942d3bcb461 to your computer and use it in GitHub Desktop.
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
#!/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