diff --git a/.travis.yml b/.travis.yml index c921a3d14c25a44eb4226359894e50c35f4d225b..cc1e614a23accfbc4edfdfea9df871bfdd9e0024 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,8 @@ script: - make -s -C ./examples/default info-concurrency - git rebase riot/master || git rebase --abort - - ./dist/tools/licenses/check.sh master || exit + - ./dist/tools/licenses/check.sh master --diff-filter=MR --error-exitcode=0 || exit + - ./dist/tools/licenses/check.sh master --diff-filter=AC || exit # TODO: # Remove the `AC` argument when all headers have been diff --git a/dist/tools/licenses/check.sh b/dist/tools/licenses/check.sh index 5830064d92c1a5be07ae7c85713d6338c712af48..0ebd94bb93c05cc9bda4b25a6e6a8274e667a9b5 100755 --- a/dist/tools/licenses/check.sh +++ b/dist/tools/licenses/check.sh @@ -11,7 +11,7 @@ TMP="${CHECKROOT}/.tmp" ROOT=$(git rev-parse --show-toplevel) LICENSES=$(ls "${LICENSEDIR}") EXIT_CODE=0 -BRANCH="${1}" +ERROR_EXIT_CODE="1" # reset output dir rm -fr "${OUTPUT}" @@ -20,11 +20,38 @@ for LICENSE in ${LICENSES}; do echo -n '' > "${OUTPUT}/${LICENSE}" done +# If no branch but an option is given, unset BRANCH. +# Otherwise, consume this parameter. +BRANCH="${1}" +if echo "${BRANCH}" | grep -q '^-'; then + BRANCH="" +else + if [ -n "${BRANCH}" ]; then + shift 1 + fi +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 + +# If the --error-exitcode option is given, consume this parameter +# and overwrite the default ERROR_EXIT_CODE. +if echo "${1}" | grep -q '^--error-exitcode='; then + ERROR_EXIT_CODE=$(echo ${1} | sed -e 's/--error-exitcode=//') + shift 1 +fi + # select files to check if [ -z "${BRANCH}" ]; then FILES="$(git ls-tree -r --full-tree --name-only HEAD | grep -E '\.([sSch]|cpp)$')" else - FILES="$(git diff --diff-filter=ACMR --name-only ${BRANCH} | grep -E '\.([sSchp]|cpp)$')" + FILES="$(git diff ${DIFFFILTER} --name-only ${BRANCH} | grep -E '\.([sSchp]|cpp)$')" fi # categorize files @@ -41,7 +68,7 @@ for FILE in ${FILES}; do if [ ${FAIL} = 1 ]; then echo "${FILE}" >> "${UNKNOWN}" echo "file has an unknown license header: '${FILE}'" - EXIT_CODE=1 + EXIT_CODE=${ERROR_EXIT_CODE} fi done