summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2019-02-06 19:41:59 +0000
committerMagnus Hagander2019-02-06 19:41:59 +0000
commit757db07889ad8f3bc8c6c273ad3bfae4005a7c15 (patch)
treecfc3f1804f37ab520db525d660d560d096f34b5c
parent994f42086a18dab09caea5409eb86c37c6f69244 (diff)
Add a pre-commit hook to ensure pep8
-rwxr-xr-xtools/githook/pre-commit38
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/githook/pre-commit b/tools/githook/pre-commit
new file mode 100755
index 0000000..47cc50d
--- /dev/null
+++ b/tools/githook/pre-commit
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+if git rev-parse --verify HEAD >/dev/null 2>&1
+then
+ against=HEAD
+else
+ # Initial commit: diff against an empty tree object
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
+fi
+
+FILES=$(git diff-index --name-only --diff-filter=ACMR --cached $against -- |egrep ".py$")
+if [ "$FILES" != "" ]; then
+ # We want to look at the staged version only, so we have to run it once for
+ # each file.
+ E=0
+ for F in ${FILES}; do
+ P=$(git show ":$F" | python3 -c "import sys; compile(sys.stdin.read(), '/dev/null', 'exec')")
+ if [ "$?" != "0" ]; then
+ echo "Errors in $F"
+ echo $P
+ E=1
+ continue
+ fi
+
+ R=$(git show ":$F" | pep8 -)
+ if [ "$?" != "0" ]; then
+ echo "Errors in $F"
+ echo "$R"
+ E=1
+ fi
+ done
+ if [ "$E" != "0" ]; then
+ exit 1
+ fi
+
+ echo Basic python checks passed.
+fi
+