Skip to content

Commit 757db07

Browse files
committed
Add a pre-commit hook to ensure pep8
1 parent 994f420 commit 757db07

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tools/githook/pre-commit

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
if git rev-parse --verify HEAD >/dev/null 2>&1
4+
then
5+
against=HEAD
6+
else
7+
# Initial commit: diff against an empty tree object
8+
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
9+
fi
10+
11+
FILES=$(git diff-index --name-only --diff-filter=ACMR --cached $against -- |egrep ".py$")
12+
if [ "$FILES" != "" ]; then
13+
# We want to look at the staged version only, so we have to run it once for
14+
# each file.
15+
E=0
16+
for F in ${FILES}; do
17+
P=$(git show ":$F" | python3 -c "import sys; compile(sys.stdin.read(), '/dev/null', 'exec')")
18+
if [ "$?" != "0" ]; then
19+
echo "Errors in $F"
20+
echo $P
21+
E=1
22+
continue
23+
fi
24+
25+
R=$(git show ":$F" | pep8 -)
26+
if [ "$?" != "0" ]; then
27+
echo "Errors in $F"
28+
echo "$R"
29+
E=1
30+
fi
31+
done
32+
if [ "$E" != "0" ]; then
33+
exit 1
34+
fi
35+
36+
echo Basic python checks passed.
37+
fi
38+

0 commit comments

Comments
 (0)