3 # Simple pre-commit hook to check that there are no errors in the fdroidserver
6 # Redirect output to stderr.
9 files=`git diff-index --cached HEAD 2>&1 | sed 's/^:.* //' | uniq | cut -b100-500`
10 if [ -z $files ]; then
11 PY_FILES="fdroid makebuildserver setup.py examples/*.py buildserver/*.py fdroidserver/*.py"
12 PY_TEST_FILES="tests/*.TestCase"
13 SH_FILES="hooks/pre-commit"
14 BASH_FILES="fd-commit jenkins-build docs/update.sh completion/bash-completion"
15 RB_FILES="buildserver/cookbooks/*/recipes/*.rb"
17 # if actually committing right now, then only run on the files
18 # that are going to be committed at this moment
37 if head -1 $f | grep '^#!/bin/sh' > /dev/null 2>&1; then
39 elif head -1 $f | grep '^#!/bin/bash' > /dev/null 2>&1; then
41 elif head -1 $f | grep '^#!.*python' > /dev/null 2>&1; then
49 # In the default configuration, the checks E123, E133, E226, E241 and E242 are
50 # ignored because they are not rules unanimously accepted
51 # On top of those, we ignore:
52 # * E501: line too long (82 > 79 characters)
53 # - Recommended for readability but not enforced
54 # - Some lines are awkward to wrap around a char limit
55 # * W503: line break before binary operator
59 PEP8_IGNORE="E123,E133,E226,E241,E242,E501,W503"
67 command -v $1 1>/dev/null
70 if cmd_exists pyflakes-python2; then
71 PYFLAKES=pyflakes-python2
72 elif cmd_exists pyflakes; then
75 err "pyflakes is not installed!"
78 if cmd_exists pep8-python2; then
80 elif cmd_exists pep8; then
83 err "pep8 is not installed!"
86 if [ "$PY_FILES $PY_TEST_FILES" != " " ]; then
87 if ! $PYFLAKES $PY_FILES $PY_TEST_FILES; then
88 err "pyflakes tests failed!"
92 if [ "$PY_FILES" != "" ]; then
93 if ! $PEP8 --ignore=$PEP8_IGNORE $PY_FILES; then
94 err "pep8 tests failed!"
98 # The tests use a little hack in order to cleanly import the fdroidserver
99 # package locally like a regular package. pep8 doesn't see that, so this
100 # makes pep8 skip E402 on the test files that need that hack.
101 if [ "$PY_TEST_FILES" != "" ]; then
102 if ! $PEP8 --ignore=$PEP8_IGNORE,E402 $PY_TEST_FILES; then
103 err "pep8 tests failed!"
107 for f in $SH_FILES; do
108 if ! dash -n $f; then
109 err "dash tests failed!"
113 for f in $BASH_FILES; do
114 if ! bash -n $f; then
115 err "bash tests failed!"
119 for f in $RB_FILES; do
120 if ! ruby -c $f 1>/dev/null; then
121 err "ruby tests failed!"