Debian Codegraph @

tools/pre-commit

raw
1 #!/bin/sh
2
3 # check the necesessary tools exist
4 command -v uncrustify >/dev/null
5 if [ $? != 0 ]; then
6 echo "uncrustify missing. Please run: apt-get install uncrustify" 2>&1
7 exit 1
8 fi
9
10 hook_script=${GIT_DIR:-.git}/hooks/pre-commit
11
12 # go to git top level directory
13 GIT_ROOT_DIR=$(git rev-parse --show-toplevel)
14 cd $GIT_ROOT_DIR
15
16 # Check for newer (actually, different) versions of the pre-commit script
17 if [ -z "$1" ] && [ -f "$hook_script" ]; then
18 if ! cmp -s "$hook_script" tools/pre-commit; then
19 echo "Pre-commit hook script is outdated, please update!" 2>&1
20 echo "cmd: cp -uv tools/pre-commit ${hook_script}" 2>&1
21 exit 1
22 fi
23 fi
24
25 CONFIG=tools/uncrustify.cfg
26 if [ ! -e $CONFIG ] ; then
27 echo "uncrustify config file not found." 2>&1
28 exit 1
29 fi
30
31 # consider staged C files only
32 FILE_LIST=$(git diff --staged --name-status HEAD | grep -v "^D" | cut -f2 | grep "\.[ch]$")
33
34 if [ -z "$FILE_LIST" ] ; then
35 exit 0
36 fi
37
38 uncrustify --version
39 uncrustify --check -c ${CONFIG} $FILE_LIST
40 if [ ! $? -eq 0 ] ; then
41 echo "Error: your files do not comply with mmlib coding style. Please run from $GIT_ROOT_DIR:" 2>&1
42 echo "uncrustify --replace -c tools/uncrustify.cfg $(echo $FILE_LIST)" 2>&1
43 exit 1
44 fi