Fix unicode bug from python3 conversion
[pgweb/local.git] / tools / githook / pre-commit
blobc1b36a0ed311002d33aa196bc91cc56d95ab43f2
1 #!/bin/sh
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
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
25 R=$(git show ":$F" | pycodestyle -)
26 if [ "$?" != "0" ]; then
27 echo "Errors in $F"
28 echo "$R"
29 E=1
31 done
32 if [ "$E" != "0" ]; then
33 exit 1
36 echo Basic python checks passed.