From 5677c23f2ac4b9e099e8e4e4fee72780f303b16c Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Fri, 23 Mar 2018 08:36:03 -0600 Subject: Added useful dev files --- useful_files/git-hooks/pre-commit.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 useful_files/git-hooks/pre-commit.py (limited to 'useful_files/git-hooks/pre-commit.py') diff --git a/useful_files/git-hooks/pre-commit.py b/useful_files/git-hooks/pre-commit.py new file mode 100755 index 0000000..565c363 --- /dev/null +++ b/useful_files/git-hooks/pre-commit.py @@ -0,0 +1,23 @@ +import subprocess + +try: + run_args = ["git", "clang-format"] + + print("Running clang-format...") + output = subprocess.check_output(run_args) + print output + changed_list = output.split('\n') + if changed_list[0] == 'changed files:': + changed_list.pop(0) + for changed in changed_list: + if len(changed.strip()) > 0: + add_output = subprocess.check_output(['git', 'add', changed.strip()]) + if len(add_output) > 0: + print(add_output) + exit(0) +except subprocess.CalledProcessError as e: + print(e.output) + exit(1) +except Exception as e: + print "Clang format not installed; please install: ", e + exit(0) -- cgit v1.2.3