File indexing completed on 2024-03-03 04:10:29

0001 #!/bin/sh
0002 #
0003 # hook script to verify what is about to be committed.
0004 # Called by git-commit with no arguments.  The hook should
0005 # exit with non-zero status after issuing an appropriate message if
0006 # it wants to stop the commit.
0007 #
0008 # To enable this hook, copy it to .git/hooks/pre-commit
0009 
0010 if git-rev-parse --verify HEAD >/dev/null 2>&1
0011 then
0012         against=HEAD
0013 else
0014         # Initial commit: diff against an empty tree object
0015         against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
0016 fi
0017 
0018 # If you want to allow non-ascii filenames set this variable to true.
0019 allownonascii=$(git config hooks.allownonascii)
0020 
0021 # Cross platform projects tend to avoid non-ascii filenames; prevent
0022 # them from being added to the repository. We exploit the fact that the
0023 # printable range starts at the space character and ends with tilde.
0024 if [ "$allownonascii" != "true" ] &&
0025         # Note that the use of brackets around a tr range is ok here, (it's
0026         # even required, for portability to Solaris 10's /usr/bin/tr), since
0027         # the square bracket bytes happen to fall in the designated range.
0028         test "$(git diff --cached --name-only --diff-filter=A -z $against |
0029           LC_ALL=C tr -d '[ -~]\0')"
0030 then
0031         echo "Error: Attempt to add a non-ascii file name."
0032         echo
0033         echo "This can cause problems if you want to work"
0034         echo "with people on other platforms."
0035         echo
0036         echo "To be portable it is advisable to rename the file ..."
0037         echo
0038         echo "If you know what you are doing you can disable this"
0039         echo "check using:"
0040         echo
0041         echo "  git config hooks.allownonascii true"
0042         echo
0043         exit 1
0044 fi
0045 
0046 for file in `git diff --cached --name-only`
0047 do
0048         test -r $file || continue
0049         test $file = src/qt4reactor.py && continue
0050         if test `expr $file : '.*.py$'` -ne 0
0051         then
0052                 cmakefile=$file
0053                 if test $cmakefile != src/scoringtest.py -a $cmakefile != src/kajonggtest.py -a $cmakefile != src/setup.py -a $cmakefile != src/winprep.py
0054                 then
0055                         if ! grep -w $cmakefile CMakeLists.txt >/dev/null
0056                         then
0057                                 echo $cmakefile missing in CMakeLists.txt
0058                                 exit 1
0059                         fi
0060                 fi
0061                 if grep -ne '[[:alnum:]]?*   *[[:alnum:]]' $file
0062                 then
0063                         echo $file has double spaces
0064                         exit 1
0065                 fi
0066         fi
0067         test `expr $file : '.*.svgz'` -ne 0 && continue
0068         test `expr $file : '.*.png'` -ne 0 && continue
0069         test `expr $file : '.*.ogg'` -ne 0 && continue
0070         set - `wc $file`
0071         bytes=`expr $3 - 1`
0072         set - `dd if=$file bs=1 skip=$bytes count=1 2>/dev/null | od -a`
0073         if [ $2 != nl ]
0074         then
0075                 echo "$file: The last line does not end with LF"
0076                 exit 1
0077         fi
0078 done
0079 
0080 # checks for trailing whitespace and space before tab:
0081 git diff-index --check --cached $against --
0082 result=$?
0083 if [ $result -ne 0 ]
0084 then
0085         exit $result
0086 fi
0087 
0088 # we want to do the content tests only against cached changes
0089 # to be committed, ignoring other changes which are not yet on
0090 # the index.
0091 # git stash --keep-index is nice but then my working directory
0092 # would change twice - before and after committing. And I would
0093 # need a wrapper around git commit which could be circumvented.
0094 # I prefer something more atomic.
0095 
0096 checkfiles=$(git diff --cached --name-only | grep src/ | fgrep .py | sed 's%src/%%g')
0097 if test x"$checkfiles" = x
0098 then
0099         echo "no changes in source found"
0100         exit 0
0101 fi
0102 
0103 MIRROR=$(mktemp -dt kajongg-pre-commit.XXXXX)
0104 trap "rm -rf $MIRROR" 0
0105 
0106 git checkout-index --prefix=$MIRROR/ -af
0107 cd $MIRROR/src
0108 ln -s /home/wr/src/kajongg/src/twisted twisted
0109 
0110 if test x$skip_pylint = x
0111 then
0112         for file in $checkfiles
0113         do
0114                 test $file = qt4reactor.py && continue
0115                 echo -n pylint3 for $file in `pwd`...
0116                 pylint3 $file
0117                 result=$?
0118                 echo done
0119                 [ $result -ne 0 ] && break
0120         done
0121         if [ $result -ne 0 ]
0122         then
0123                 echo "trying pylint over all source files"
0124                 pylint3 --reports=n *y
0125                 result=$?
0126         fi
0127         if [ $result -ne 0 ]
0128         then
0129                 echo "pylint must be quiet"
0130                 exit $result
0131         fi
0132 fi
0133 ./scoringtest.py
0134 ./kajongg.py --demo --rounds=1
0135 
0136 result=$?
0137 if [ $result -ne 0 ]
0138 then
0139         echo "scoringtest.py failed"
0140         exit $result
0141 fi
0142 
0143 exit 0