From 41ad9946ad7ef5318acff855e767fc71c4639ce2 Mon Sep 17 00:00:00 2001 From: kushalsingh007 Date: Sun, 8 Mar 2015 07:21:07 +0530 Subject: [PATCH] Adding a script to check for line endings (valid UNIX ending) -Created a bash script using grep to check for carriage return at line endings. -Works for modified and new files only (if choosen) -Modified build_and_run.sh to include the new check.sh and run it. --- dist/tools/endingcheck/check.sh | 51 +++++++++++++++++++++ dist/tools/travis-scripts/build_and_test.sh | 3 ++ 2 files changed, 54 insertions(+) create mode 100755 dist/tools/endingcheck/check.sh diff --git a/dist/tools/endingcheck/check.sh b/dist/tools/endingcheck/check.sh new file mode 100755 index 0000000000..f6a97b06be --- /dev/null +++ b/dist/tools/endingcheck/check.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# +# Copyright (C) 2015 Kushal Singh +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +BRANCH=${1} +ENDREGEX='^M$' + +# If no branch but an option is given, unset BRANCH. +# Otherwise, consume this parameter. +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 + +# 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)" +else + FILES="$(git diff ${DIFFFILTER} --name-only ${BRANCH})" +fi + +if [ -z "${FILES}" ]; then + exit +fi + +grep -E -R -l ${ENDREGEX} ${FILES} > /dev/null + +if [ $? -eq 0 ] +then + echo "ERROR: carriage return error found" + exit 1 +else + exit 0 +fi diff --git a/dist/tools/travis-scripts/build_and_test.sh b/dist/tools/travis-scripts/build_and_test.sh index 20346b4d36..90e39f2797 100755 --- a/dist/tools/travis-scripts/build_and_test.sh +++ b/dist/tools/travis-scripts/build_and_test.sh @@ -45,6 +45,9 @@ then ./dist/tools/externc/check.sh master RESULT=$(set_result $? $RESULT) + ./dist/tools/endingcheck/check.sh riot/master --diff-filter=MA + RESULT=$(set_result $? $RESULT) + # TODO: # Remove all but `master` parameters to cppcheck (and remove second # invocation) once all warnings of cppcheck have been taken care of