xref: /OK3568_Linux_fs/external/recovery/hooks/pre-commit (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2
3echo "[git-hook]: before commit, format code use astyle ..."
4
5ASTYLE_PARAMETERS="--style=linux \
6    --indent=spaces=4 \
7    --indent-labels \
8    --min-conditional-indent=0 \
9    --max-instatement-indent=80 \
10    --pad-oper \
11    --pad-header \
12    --keep-one-line-blocks \
13    --keep-one-line-statements \
14    --convert-tabs\
15    --suffix=none"
16
17if ! astyle --version 2>/dev/null; then
18    echo "astyle is missing, please install it: sudo apt-get install astyle"
19    exit 1
20fi
21
22format_file=$(find . -type f | grep -E "\.c$|\.h$")
23astyle --quiet $ASTYLE_PARAMETERS $format_file
24
25if git status -s | grep -q "^ M "; then
26    echo "[git-hook]: code changed after formating, please commit again."
27    git status
28    echo "if you have completed all file formatting but there are still files in the workspace "
29    echo "use --no-verify to skip hook"
30    exit 1
31fi
32
33echo "[git-hook]: nothing change after formating, commit continues."