forked from xfoukas/flexran-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
31 lines (25 loc) · 851 Bytes
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# Installation:
# cp pre-commit .git/hooks
# chmod +x .git/hooks/pre-commit
OPTIONS="--convert-tabs --indent=spaces=2 --indent-switches --indent-col1-comments --break-blocks --delete-empty-lines --align-pointer=name --keep-one-line-blocks --keep-one-line-statements --lineend=linux"
RETURN=0
ASTYLE=$(which astyle)
if [ $? -ne 0 ]; then
echo "[!] astyle not installed. Unable to check source file format policy." >&2
exit 1
fi
FILES=`git diff --cached --name-only --diff-filter=ACMR | grep -E "\.(c|cpp|h)$"`
for FILE in $FILES; do
$ASTYLE $OPTIONS < $FILE | cmp -s $FILE -
if [ $? -ne 0 ]; then
echo "[!] $FILE does not respect the agreed coding style." >&2
RETURN=1
fi
done
if [ $RETURN -eq 1 ]; then
echo "" >&2
echo "Make sure you have run astyle with the following options:" >&2
echo $OPTIONS >&2
fi
exit $RETURN