Skip to content

Commit

Permalink
git repo: added commit template and basic coding-style check.
Browse files Browse the repository at this point in the history
check spaces after parenthesis, and spaces at the end of lines.
  • Loading branch information
tl-cea committed Aug 29, 2013
1 parent c5e9dbc commit bf5d771
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .commit-template
@@ -0,0 +1,10 @@
# Please use the following format for the commit message:
#
# <module>: short description of the change.
#
# More detailed description about the issue
# and the way it is addressed.
#
# Implementation details.
#

49 changes: 49 additions & 0 deletions scripts/check_commit.sh
@@ -0,0 +1,49 @@
#!/bin/bash

opt=""

function check_file
{
# check perenthesing
local said=0
git diff $opt $1 | grep "^+" | grep -v "^+++" | sed -e 's/^+//' > /tmp/code.$$
sed -e "s/( /(/g" -e "s/ )/)/g" /tmp/code.$$ > /tmp/indent.$$
diff /tmp/code.$$ /tmp/indent.$$ > /tmp/diff.$$
if (( $? )); then
echo "WARNINGS in $f:" && said=1
cat /tmp/diff.$$ | grep -E '^>|^<' | while read l; do
echo "$l"| sed -e 's/^</this line: /' -e 's/^>/should be: /'
done
echo
fi
# check spaces at EOL
while read l; do
(($said == 0)) && echo "WARNINGS in $f:" && said=1
# line
echo $l
#highlight
echo $l | sed -e "s/[^ ]/ /g" -e "s/ \$/ ^space at EOL/g"
done < <( grep -P "[\t ]\$" /tmp/code.$$ )
(($said == 1 )) && echo
}

if [ "$1" ]; then
cmd="cat $1"
opt="--cached"
else
cmd="git status"
fi
for f in $($cmd | grep -E 'added:|modified:|new file:' | cut -d ':' -f 2 | tr -d " "); do
check_file $f
done

exit 0
first=0
while read l; do
# line
echo $l
#highlight
echo $l | sed -e "s/[^ ]/ /g" -e "s/ \$/ ^space at EOL/g"
done < <( grep -e "[\t ]\$" /tmp/code.$$ )

rm -f /tmp/code.$$ /tmp/indent.$$ /tmp/diff.$$

0 comments on commit bf5d771

Please sign in to comment.