summaryrefslogtreecommitdiff
path: root/tools/pre-commit-hook
blob: a136b97b466cf98619fb85c12cf6fc1ca04d1d3c (plain)
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

TOPLEVEL=$(git rev-parse --show-toplevel)
RES=0

cd $TOPLEVEL

if [ "$1" = "--install" ]; then
    ln -sf ../../tools/pre-commit-hook .git/hooks/pre-commit
    exit
fi

tmpdir=$(mktemp -d precommit.XXXXXX) || exit 1
trap "rm -rf $TOPLEVEL/$tmpdir" 0

git diff --cached --name-only --diff-filter=ACMR |
    xargs git checkout-index --prefix=$tmpdir/ --

cd $tmpdir

echo "=== starting pre-commit checks ==="

echo "Checking the following files:"

find . -type f

echo "=== bashate checks ==="

files=$(egrep -rlI '^#!/(bin/|usr/bin/env )(ba)?sh' .)
[ "$files" ] && (bashate $files || RES=1)

echo "=== yaml checks ==="

${TOPLEVEL}/tools/validate-all-yaml.sh || RES=1

echo "=== json checks ==="

${TOPLEVEL}/tools/validate-all-json.sh || RES=1

echo "=== maintainer checks ==="

${TOPLEVEL}/tools/validate-all-maintainer.sh || RES=1

exit $RES