Created
September 19, 2018 12:37
-
-
Save kirillsulim/a60a7501a33219316e34b9050c5a1758 to your computer and use it in GitHub Desktop.
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 python3 | |
# Should be in pre-commit file without .py extension | |
from subprocess import call | |
import sys | |
import os.path as path | |
HOOK_LIST_NAME = "pre-commit.list" | |
hook_list_file = path.join(path.dirname(path.abspath(str(sys.argv[0]))), HOOK_LIST_NAME) | |
if path.exists(hook_list_file) and path.isfile(hook_list_file): | |
with open(hook_list_file, 'r') as f: | |
lines = f.readlines() | |
for line in lines: | |
line = line.strip() | |
if not line: | |
continue | |
command = line.split(' ') | |
code = call(command) | |
if code: | |
print("Command '{}' terminated witn code {}".format(line, code)) | |
exit(code) | |
else: | |
print("Missing {} file".format(HOOK_LIST_NAME)) | |
exit(1) | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment