summaryrefslogtreecommitdiff
path: root/.hooks/pre-commit.d/check_mk_indentations
blob: d5f6e601554ab821e78f7b5860c535b0978774d4 (plain) (blame)
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
#!/bin/sh
#
# Check that Mk/ files are properly indented
#

common_functions="$(realpath "$(dirname "$0")")/common.sh"
if [ -r "${common_functions}" ]; then
	. "${common_functions}"
fi

check_indentation() {
	local mkfile="$1"
	local name=$(echo "${mkfile}" | awk -F / '{print $NF}')
	local tempdir=$(mktemp -d -t check_indentations-${name})
	if [ $? -ne 0 ] ; then
		echo "[pre-commit] failed to create tempdir"
		exit 2
	fi
	cp ${mkfile} ${tempdir} && Tools/scripts/indent_make_if.pl ${tempdir}/${name}
	if [ $? -ne 0 ] ; then
		pre_commit_error "failed to run Tools/scripts/indent_make_if.pl"
		exit 2
	fi
	cmp -s ${tempdir}/*
	if [ $? -ne 0 ] ; then
		pre_commit_error "${name} is not properly indented -- please use ${tempdir}/${name} which was created using Tools/scripts/indent_make_if.pl"
		exit 1
	fi
}

modified_mks=$(git diff --name-only --cached --diff-filter=ACRM | grep -E '^Mk/.*\.mk$')
if [ $? -eq 0 ] ; then
	for modified_mk in ${modified_mks} ; do
		check_indentation "${modified_mk}"
	done
fi