px4-firmware/Tools/astyle/check_code_style.sh

25 lines
774 B
Bash
Raw Normal View History

#!/usr/bin/env bash
FILE=$1
2016-04-21 18:29:49 -03:00
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
if [ -f "$FILE" ]; then
CHECK_FAILED=$(${DIR}/fix_code_style.sh --dry-run --formatted $FILE)
if [ -n "$CHECK_FAILED" ]; then
${DIR}/fix_code_style.sh --quiet < $FILE > $FILE.pretty
2016-06-21 12:49:42 -03:00
echo -e 'Formatting issue found in' $FILE
2016-06-21 12:49:42 -03:00
echo
git --no-pager diff --no-index --minimal --histogram --color=always $FILE $FILE.pretty | grep -vE -e "^.{,4}diff.*\.pretty.{,3}$" -e "^.{,4}--- a/.*$" -e "^.{,4}\+\+\+ b/.*$" -e "^.{,5}@@ .* @@.*$" -e "^.{,4}index .{10}\.\."
rm -f $FILE.pretty
2016-06-21 12:49:42 -03:00
echo
if [[ $PX4_ASTYLE_FIX -eq 1 ]]; then
${DIR}/fix_code_style.sh $FILE
else
echo 'to fix automatically run "make format" or "./Tools/astyle/fix_code_style.sh' $FILE'"'
exit 1
fi
fi
fi