chiark / gitweb /
Merge branch 'some-bug-fixes' into 'master'
[fdroidserver.git] / hooks / pre-commit
1 #!/bin/sh
2 #
3 # Simple pre-commit hook to check that there are no errors in the fdroid
4 # metadata files.
5
6 # Redirect output to stderr.
7 exec 1>&2
8
9 FILES="fdroid makebuildserver setup.py examples/*.py buildserver/*.py fdroidserver/*.py"
10
11 cmd_exists() {
12         command -v $1 1>/dev/null
13 }
14
15 # For systems that switched to python3, first check for the python2 versions
16 if cmd_exists pyflakes-python2; then
17         PYFLAKES=pyflakes-python2
18 elif cmd_exists pyflakes; then
19         PYFLAKES=pyflakes
20 else
21         echo "pyflakes is not installed!"
22 fi
23
24 if cmd_exists pep8-python2; then
25         PEP8=pep8-python2
26 elif cmd_exists pep8; then
27         PEP8=pep8
28 else
29         echo "pep8 is not installed!"
30 fi
31
32 # If there are python errors or warnings, print them and fail.
33 [ -n $PYFLAKES ] && $PYFLAKES $FILES
34 [ -n $PEP8 ] && $PEP8 --ignore=E123,E501 $FILES
35
36
37 #------------------------------------------------------------------------------#
38 # check the syntax of included shell scripts
39
40 basedir=`cd $(dirname $0)/.. && pwd`
41 echo basedir: $basedir
42
43 if [ $(basename $basedir) = ".git" ]; then
44     basedir=$(dirname $basedir)
45 fi
46
47 exitstatus=0
48 # use bash to check that the syntax is correct
49 for f in $basedir/fd-commit $basedir/jenkins-build $basedir/docs/*.sh $basedir/hooks/pre-commit; do
50     if bash -n $f; then
51         : # success! do nothing
52     else
53         echo "FAILED!"
54         exitstatus=1
55     fi
56 done
57
58 exit $exitstatus