blob: 29614e0d6d2a3c971c81dbe6c3245a036e15df5e [file] [log] [blame]
#!/bin/bash
#VERSION=1
SELFNAME=$0
function getAbsolutePath() {
readlink -e $1
}
function printUsage() {
echo " $SELFNAME check coding style for HEAD in this git"
echo " $SELFNAME -h show this message"
}
function main() {
test "$1" == "-h" && printUsage && exit
test "$ANDROID_BUILD_TOP" == "" && echo "please run env setup" && exit
GITROOTDIR=`git rev-parse --show-toplevel`
test "$GITROOTDIR" == "" && echo "not inside a git repository" && exit
MODIFIED=`git status -s --untracked-files=no | wc -l`
test $MODIFIED -ne 0 && echo "please commit first" && exit
cd $GITROOTDIR
#basic check
local PARAMS=" --config_xml $ANDROID_BUILD_TOP/prebuilts/checkstyle/android-style.xml"
$ANDROID_BUILD_TOP/prebuilts/checkstyle/checkstyle.py $PARAMS
#commit message equal or less then 65 char for each line (suggested by lorenzo@20180625)
local MSG=`git rev-list --format=%B --max-count=1 HEAD`
local i=1
while read -r line; do
test `echo $line | wc -c` -gt 65 && echo "FAILED: Line $i exceed 65 chars limit: $line"
i=$((i+1))
done < <(echo "$MSG")
cd -
}
main $*