kolla/tools/pre-commit-hook
Chen Zhiwei 76c1fe6371 Change the default shell to bash
Unify the shell to bash in all Kolla scripts.

Change-Id: Ib9591b2f8f344eb88455c5e9b7ecf2164fb5960a
Implements: blueprint use-bash-shell
2015-04-27 13:26:37 +08:00

45 lines
857 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
echo "=== json checks ==="
${TOPLEVEL}/tools/validate-all-json.sh || RES=1
echo "=== maintainer checks ==="
${TOPLEVEL}/tools/validate-all-maintainer.sh || RES=1
exit $RES