Add pre-commit hook (#13)

Co-authored-by: Antonio Andelic <antonio.andelic@memgraph.io>
This commit is contained in:
antonio2368
2020-10-06 13:57:33 +02:00
committed by GitHub
parent 9d6b578237
commit 1b50dc60f9
4 changed files with 53 additions and 0 deletions

23
tools/git-clang-format Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env python3
import re
import sys
import subprocess
# Run this script through arc lint
MESSAGE = "Wrong formatting!"
data = subprocess.run(
["clang-format", "--output-replacements-xml", sys.argv[1]],
stdout=subprocess.PIPE, check=True).stdout.decode(
"utf-8").strip().split("\n")
has_error = False
for row in data:
match = re.match(
r"^<replacement offset='([0-9]+)' length='([0-9]+)'>", row)
if match:
has_error = True
offset = int(match.group(1)) + int(match.group(2))
print("warning:{}:{}".format(offset, MESSAGE))
sys.exit(1 if has_error else 0)