chiark / gitweb /
pre-commit: differentiate sh and bash files
[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"
10 SH_FILES="hooks/pre-commit"
11 BASH_FILES="fd-commit jenkins-build docs/update.sh"
12 RB_FILES="buildserver/cookbooks/*/recipes/*.rb"
13
14 err() {
15         echo ERROR: "$@"
16         exit 1
17 }
18
19 cmd_exists() {
20         command -v $1 1>/dev/null
21 }
22
23 if cmd_exists pyflakes-python2; then
24         PYFLAKES=pyflakes-python2
25 elif cmd_exists pyflakes; then
26         PYFLAKES=pyflakes
27 else
28         err "pyflakes is not installed!"
29 fi
30
31 if cmd_exists pep8-python2; then
32         PEP8=pep8-python2
33 elif cmd_exists pep8; then
34         PEP8=pep8
35 else
36         err "pep8 is not installed!"
37 fi
38
39 if ! $PYFLAKES $PY_FILES; then
40         err "pyflakes tests failed!"
41 fi
42
43 if ! $PEP8 --ignore=E123,E501 $PY_FILES; then
44         err "pep8 tests failed!"
45 fi
46
47
48 for f in $SH_FILES; do
49         if ! dash -n $f; then
50                 err "dash tests failed!"
51         fi
52 done
53
54 for f in $BASH_FILES; do
55         if ! bash -n $f; then
56                 err "bash tests failed!"
57         fi
58 done
59
60 for f in $RB_FILES; do
61         if ! ruby -c $f 1>/dev/null; then
62                 err "ruby tests failed!"
63         fi
64 done
65
66 exit 0