exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

uncrustify_precommit (2335B)


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