File: pre-commit

package info (click to toggle)
mmlib 1.4.2-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,716 kB
  • sloc: ansic: 18,071; makefile: 431; sh: 135; python: 63
file content (44 lines) | stat: -rwxr-xr-x 1,211 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

# check the necesessary tools exist
command -v uncrustify >/dev/null
if [ $? != 0 ]; then
	echo "uncrustify missing. Please run: apt-get install uncrustify" 2>&1
	exit 1
fi

hook_script=${GIT_DIR:-.git}/hooks/pre-commit

# go to git top level directory
GIT_ROOT_DIR=$(git rev-parse --show-toplevel)
cd $GIT_ROOT_DIR

# Check for newer (actually, different) versions of the pre-commit script
if [ -z "$1" ] && [ -f "$hook_script" ]; then
    if ! cmp -s "$hook_script" tools/pre-commit; then
        echo "Pre-commit hook script is outdated, please update!" 2>&1
		echo "cmd: cp -uv tools/pre-commit ${hook_script}" 2>&1
		exit 1
    fi
fi

CONFIG=tools/uncrustify.cfg
if [ ! -e $CONFIG ] ; then
	echo "uncrustify config file not found." 2>&1
	exit 1
fi

# consider staged C files only
FILE_LIST=$(git diff --staged --name-status HEAD | grep -v "^D" | cut -f2 | grep "\.[ch]$")

if [ -z "$FILE_LIST" ] ; then
	exit 0
fi

uncrustify  --version
uncrustify --check -c ${CONFIG} $FILE_LIST
if [ ! $? -eq 0 ] ; then
	echo "Error: your files do not comply with mmlib coding style. Please run from $GIT_ROOT_DIR:" 2>&1
	echo "uncrustify --replace -c tools/uncrustify.cfg $(echo $FILE_LIST)" 2>&1
	exit 1
fi