From f6d6f6ff6570a8d1860fd900f6a8f96ba30acdd0 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 1 Feb 2017 22:21:33 +0100 Subject: AStyle pass Added style check to pre-commit hook --- util/pre-commit.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'util/pre-commit.py') diff --git a/util/pre-commit.py b/util/pre-commit.py index f8242f6..9282854 100755 --- a/util/pre-commit.py +++ b/util/pre-commit.py @@ -2,18 +2,35 @@ import os import sys +import subprocess import glob import license # stash unstaged files before running test os.system("git stash -q --keep-index") -print("Running pre-commit hook in {0}".format(os.getcwd())) +#print("Running pre-commit hook in {0}".format(os.getcwd())) +problems = False -problems = 0 -problems += license.lint("util/header-gpl3.txt", glob.glob("src/**/*.cpp") + glob.glob("src/**/*.h"), True) +# check license +print("Checking license...") +if license.lint("util/header-gpl3.txt", glob.glob("src/**/*.cpp") + glob.glob("src/**/*.h"), True) > 0: + problems = True + print("Run <<./util/license.py -l util/header-gpl3.txt src/**/*.cpp src/**/*.h>> to autofix") + +# check style +print("Checking style...") +astyle = subprocess.run(['astyle', '--dry-run', '--formatted', '--options=astyle.rc'] + glob.glob("src/**/*.cpp") + glob.glob("src/**/*.h"), stdout=subprocess.PIPE) +if len(astyle.stdout.splitlines()) > 0: + problems = True + for line in astyle.stdout.splitlines(): + print(line.decode('utf-8')) + print("Run <> to autofix") # restore stash os.system("git stash pop -q") -sys.exit(problems) +if problems: + sys.exit(-1) +else: + sys.exit(0) -- cgit v1.2.1