merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

uncrustify_precommit (1879B)


      1 #!/bin/bash
      2 
      3 # use as .git/hooks/pre-commit
      4 exec 1>&2
      5 
      6 RET=0
      7 changed=$(git diff --cached --name-only | grep -v mustach)
      8 crustified=""
      9 
     10 # If nothing (important) has changed, return here
     11 [ -z "$changed" ] && exit 0
     12 
     13 ( echo "$changed" | grep -q '\.[ch] *$*') && \
     14   echo "Checking formatting with uncrustify..."
     15 
     16 for f in $changed;
     17 do
     18  if echo $f | grep \\.[c,h]\$ > /dev/null
     19  then
     20     # compare result of uncrustify with changes
     21     #
     22     # only change any of the invocations here if
     23     # they are portable across all cmp and shell
     24     # implementations !
     25     uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f -
     26     if test $? = 1 ;
     27     then
     28       crustified=" $crustified $f"
     29       RET=1
     30     fi
     31   fi
     32 done
     33 
     34 if [ $RET = 1 ];
     35 then
     36   echo "Run"
     37   echo "uncrustify --replace -c uncrustify.cfg ${crustified}"
     38   echo "before committing."
     39   exit $RET
     40 fi
     41 
     42 # Make sure we have no stupid spelling error
     43 if (which codespell > /dev/null)
     44 then
     45     export REPORT=$(mktemp /tmp/codespellXXXXXX)
     46     ( set -o pipefail;
     47       echo "Checking for spelling errors with codespell..."
     48       contrib/ci/jobs/0-codespell/job.sh src 2> ${REPORT};
     49     ) || { echo "Please fix the code spell errors in ${REPORT} first"; exit 2; }
     50 else
     51     echo "No codespell installed, skipping spell check."
     52     echo "** Please consider installing codespell! **"
     53 fi
     54 
     55 
     56 # Make sure doxygen is happy with our annotations
     57 if (which doxygen > /dev/null)
     58 then
     59     export REPORT=$(mktemp /tmp/doxygenXXXXXX)
     60     [ -f doc/doxygen/Makefile ] && \
     61     ( set -o pipefail;
     62       echo "Checking that doxygen is happy..."
     63       cd doc/doxygen;
     64       make fast 2>&1 | tee ${REPORT} | (grep  error:; exit 0);
     65     ) || { echo "Please fix the errors reported by doxygen in ${REPORT} first"; exit 3; }
     66 else
     67     echo "No doxygen installed, skipping check."
     68     echo "** Please consider installing doxygen! **"
     69 fi
     70 
     71 echo "Commit is all clear!"