kolla-ansible/tools/pre-commit-hook
Liping Mao (limao) 6531dc9668 Fix pre-commit-hook can't work
remove unused validate-all-json.sh and validate-all-dockerfiles.

Change-Id: Ia534c200f771c23d015ab32b0cc952ca36354451
Closes-Bug: #1778146
2018-06-24 15:32:50 +08:00

37 lines
691 B
Bash
Executable File

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