diff --git a/scripts/clang-format-apply.sh b/scripts/clang-format-apply.sh new file mode 100755 index 0000000000000000000000000000000000000000..b0a364e9dffb12483c1235206f2489660349725b --- /dev/null +++ b/scripts/clang-format-apply.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# +# This is apllying clang-format +# by doing a filtering step and then +# applying ./scripts/clang-format-and-fix-macros.sh +# + +# check that we are in a clean state in order to prevent accidential +# changes +if [ ! -z "$(git status --porcelain)" ]; then + echo "Script must be applied on a clean git state" + exit 1 +fi + + +# Retrieve list of files that were changed in source branch +# with respect to master (target branch) +tb="master" +# we disregard the test/static_analysis directory since this contains LLVM code + headers +filelist=`git diff ${tb}... --name-only | grep -v -i -e linkdef | grep -v -e nudy -e cmsToyGV -e examples/physics/Geant4` + +# function to check if C++ file (based on suffix) +# can probably be done much shorter +function checkCPP(){ + if [[ $1 == *.cc ]];then + return 0 + elif [[ $1 == *.cpp ]];then + return 0 + elif [[ $1 == *.cxx ]];then + return 0 + elif [[ $1 == *.C ]];then + return 0 + elif [[ $1 == *.c++ ]];then + return 0 + elif [[ $1 == *.c ]];then + return 0 + elif [[ $1 == *.CPP ]];then + return 0 + # header files + elif [[ $1 == *.h ]];then + return 0 + elif [[ $1 == *.hpp ]];then + return 0 + elif [[ $1 == *.hh ]];then + return 0 + elif [[ $1 == *.icc ]];then + return 0 + fi + return 1 +} + +echo +echo "Checking formatting using the following clang-format version:" +clang-format --version +echo + +# check list of files +for f in $filelist; do + if checkCPP $f; then + echo "CHECKING MATCHING FILE ${f}" + # apply the clang-format script + ./scripts/clang-format-and-fix-macros.sh ${f} + fi +done + +# check if something was modified +notcorrectlist=`git status | grep "modified"` +# if nothing changed ok +if [[ -z $notcorrectlist ]]; then + # send a negative message to gitlab + echo "Excellent. **VERY GOOD FORMATTING!** :thumbsup:" + exit 0; +else + echo "The following files have clang-format problems (showing patches)"; + for f in $notcorrectlist; do + echo $f + git diff $f + done +fi + +exit 1 + + + diff --git a/scripts/clang-format-test.sh b/scripts/clang-format-test.sh index 40f7fb5258450b4e8b4a56f6ed944ffe0759051f..4098577be72d8ff793afc5394d4897aba4e9948d 100755 --- a/scripts/clang-format-test.sh +++ b/scripts/clang-format-test.sh @@ -6,83 +6,12 @@ # the result of applying ./scripts/clang-format-and-fix-macros.sh # -# check that we are in a clean state in order to prevent accidential -# changes -if [ ! -z "$(git status --porcelain)" ]; then - echo "Script must be applied on a clean git state" - exit 1 -fi - - -# Retrieve list of files that were changed in source branch -# with respect to master (target branch) -tb="master" -# we disregard the test/static_analysis directory since this contains LLVM code + headers -filelist=`git diff ${tb}... --name-only | grep -v -i -e linkdef | grep -v -e nudy -e cmsToyGV -e examples/physics/Geant4` - -# function to check if C++ file (based on suffix) -# can probably be done much shorter -function checkCPP(){ - if [[ $1 == *.cc ]];then - return 0 - elif [[ $1 == *.cpp ]];then - return 0 - elif [[ $1 == *.cxx ]];then - return 0 - elif [[ $1 == *.C ]];then - return 0 - elif [[ $1 == *.c++ ]];then - return 0 - elif [[ $1 == *.c ]];then - return 0 - elif [[ $1 == *.CPP ]];then - return 0 - # header files - elif [[ $1 == *.h ]];then - return 0 - elif [[ $1 == *.hpp ]];then - return 0 - elif [[ $1 == *.hh ]];then - return 0 - elif [[ $1 == *.icc ]];then - return 0 - fi - return 1 -} - -echo -echo "Checking formatting using the following clang-format version:" -clang-format --version -echo +./scripts/clang-format-apply.sh +res=$? -# check list of files -for f in $filelist; do - if checkCPP $f; then - echo "CHECKING MATCHING FILE ${f}" - # apply the clang-format script - ./scripts/clang-format-and-fix-macros.sh ${f} - fi -done - -# check if something was modified -notcorrectlist=`git status | grep "modified"` -# if nothing changed ok -if [[ -z $notcorrectlist ]]; then - # send a negative message to gitlab - echo "Excellent. **VERY GOOD FORMATTING!** :thumbsup:" - exit 0; -else - echo "The following files have clang-format problems (showing patches)"; - for f in $notcorrectlist; do - echo $f - git diff $f - done +if [ $res -eq 0 ] ; then + # cleanup changes in git + echo git reset HEAD --hard fi -# cleanup changes in git -git reset HEAD --hard - -exit 1 - - - +exit $res