diff --git a/dist/tools/cppcheck/check.sh b/dist/tools/cppcheck/check.sh index c88a6e04b7e0c072f81af45301dfd050406ff873..2cb965107baed2c1537a5ffcdd3ddcca6d5c1e2b 100755 --- a/dist/tools/cppcheck/check.sh +++ b/dist/tools/cppcheck/check.sh @@ -3,18 +3,28 @@ BRANCH=${1} FILEREGEX='\.([sScHh]|cpp)$' -# if branch is an option, unset branch, consume parameter otherwise +# If no branch but an option is given, unset BRANCH. +# Otherwise, consume this parameter. if echo "${BRANCH}" | grep -q '^-'; then BRANCH="" else shift 1 fi +# If the --diff-filter option is given, consume this parameter. +# Set the default DIFFFILTER option otherwise. +DIFFFILTER="${1}" +if echo "${DIFFFILTER}" | grep -q '^--diff-filter='; then + shift 1 +else + DIFFFILTER="--diff-filter=ACMR" +fi + # select either all or only touched-in-branch files, filter through FILEREGEX if [ -z "${BRANCH}" ]; then FILES="$(git ls-tree -r --full-tree --name-only HEAD | grep -E ${FILEREGEX})" else - FILES="$(git diff --diff-filter=ACMR --name-only ${BRANCH} | grep -E ${FILEREGEX})" + FILES="$(git diff ${DIFFFILTER} --name-only ${BRANCH} | grep -E ${FILEREGEX})" fi if [ -z "${FILES}" ]; then