Files
kolla-ansible/tools/pre-commit-hook
Michal Nasiadka 180721846e Remove egrep usage from scripts
egrep: warning: egrep is obsolescent; using grep -E

Change-Id: I4df0d520546da141cafc15e9464149059fdc06a6
Signed-off-by: Michal Nasiadka <mnasiadka@gmail.com>
2025-07-21 12:31:40 +00:00

37 lines
699 B
Bash
Executable File

#!/usr/bin/env bash
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=$(grep -ErlI '^#!/(bin/|usr/bin/env )(ba)?sh' .)
[ "$files" ] && (bashate $files || RES=1)
echo "=== yaml checks ==="
${TOPLEVEL}/tools/validate-all-yaml.sh || RES=1
exit $RES