forked from phrocker/sharkbite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.sh
More file actions
32 lines (26 loc) · 762 Bytes
/
pre-commit.sh
File metadata and controls
32 lines (26 loc) · 762 Bytes
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
32
#!/bin/bash
OPTIONS="-A8 -t8 --lineend=linux"
ASTYLE=$(which astyle)
if [ $? -ne 0 ];
then
echo "[!] astyle not installed. Unable to check source file format policy." >&2
exit 1
fi
RETURN=0
git diff --cached --name-status --diff-filter=ACMR | {
# Command grouping to workaround subshell issues. When the while loop is
# finished, the subshell copy is discarded, and the original variable
# RETURN of the parent hasn't changed properly.
while read STATUS FILE; do
if [[ "$FILE" =~ ^.+(c|cpp|h)$ ]]; then
$ASTYLE $OPTIONS < $FILE > $FILE.beautified
mv $FILE.beautified $FILE
fi
done
if [ $RETURN -eq 1 ]; then
echo ""
echo "Make sure you have run astyle with the following options:" >&2
echo $OPTIONS >&2
fi
exit $RETURN
}