chiark / gitweb /
add test files to pre-commit hook and fix pep8 errors
[fdroidserver.git] / hooks / pre-commit
1 #!/bin/sh
2 #
3 # Simple pre-commit hook to check that there are no errors in the fdroidserver
4 # source files.
5
6 # Redirect output to stderr.
7 exec 1>&2
8
9 PY_FILES="fdroid makebuildserver setup.py examples/*.py buildserver/*.py fdroidserver/*.py tests/*.TestCase"
10 SH_FILES="hooks/pre-commit"
11 BASH_FILES="fd-commit jenkins-build docs/update.sh completion/bash-completion"
12 RB_FILES="buildserver/cookbooks/*/recipes/*.rb"
13
14 # In the default configuration, the checks E123, E133, E226, E241 and E242 are
15 # ignored because they are not rules unanimously accepted
16 # On top of those, we ignore:
17 # * E501: line too long (82 > 79 characters)
18 #   - Recommended for readability but not enforced
19 #   - Some lines are awkward to wrap around a char limit
20 # * W503: line break before binary operator
21 #   - It's quite new
22 #   - Quite pedantic
23
24 PEP8_IGNORE="E123,E133,E226,E241,E242,E501,W503"
25
26 err() {
27         echo ERROR: "$@"
28         exit 1
29 }
30
31 cmd_exists() {
32         command -v $1 1>/dev/null
33 }
34
35 if cmd_exists pyflakes-python2; then
36         PYFLAKES=pyflakes-python2
37 elif cmd_exists pyflakes; then
38         PYFLAKES=pyflakes
39 else
40         err "pyflakes is not installed!"
41 fi
42
43 if cmd_exists pep8-python2; then
44         PEP8=pep8-python2
45 elif cmd_exists pep8; then
46         PEP8=pep8
47 else
48         err "pep8 is not installed!"
49 fi
50
51 if ! $PYFLAKES $PY_FILES; then
52         err "pyflakes tests failed!"
53 fi
54
55 if ! $PEP8 --ignore=$PEP8_IGNORE $PY_FILES; then
56         err "pep8 tests failed!"
57 fi
58
59
60 for f in $SH_FILES; do
61         if ! dash -n $f; then
62                 err "dash tests failed!"
63         fi
64 done
65
66 for f in $BASH_FILES; do
67         if ! bash -n $f; then
68                 err "bash tests failed!"
69         fi
70 done
71
72 for f in $RB_FILES; do
73         if ! ruby -c $f 1>/dev/null; then
74                 err "ruby tests failed!"
75         fi
76 done
77
78 exit 0