aboutsummaryrefslogtreecommitdiff
path: root/tools/pre-commit-hook
diff options
context:
space:
mode:
authorLars Kellogg-Stedman <lars@redhat.com>2014-10-14 12:17:47 -0400
committerLars Kellogg-Stedman <lars@redhat.com>2014-10-14 15:21:22 -0400
commitbfbf1b8c9b3a0abba86474aeb72b950142723d73 (patch)
tree6dd25e33a223a6f9011375b01a38302fe83e1968 /tools/pre-commit-hook
parent20e88776bc9b85b2a3a0f7a86004f6b04520e9a8 (diff)
downloadkolla-bfbf1b8c9b3a0abba86474aeb72b950142723d73.tar.gz
kolla-bfbf1b8c9b3a0abba86474aeb72b950142723d73.zip
add better validation checks (part 1)
This patch adds a script for validating YAML files, and replaces the existing JSON checks with one largely identical to the YAML check. This also provides a script that can be installed as a pre-commit hook that will perform this checks when you commit changes. You can install the hook by running tools/pre-commit-hook --install. Change-Id: Ib4742a9db062362cfa61d669c691151bc1ca376c
Diffstat (limited to 'tools/pre-commit-hook')
-rwxr-xr-xtools/pre-commit-hook45
1 files changed, 45 insertions, 0 deletions
diff --git a/tools/pre-commit-hook b/tools/pre-commit-hook
new file mode 100755
index 000000000..699cb978e
--- /dev/null
+++ b/tools/pre-commit-hook
@@ -0,0 +1,45 @@
+#!/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 ==="
+
+find . -type f -print0 |
+ xargs -0 --no-run-if-empty egrep -lZ '^#!/bin/(ba)?sh' |
+ xargs -0 bashate || RES=1
+
+echo "=== yaml checks ==="
+
+find . -name '*.yaml' -print0 |
+ xargs -0 --no-run-if-empty python ${TOPLEVEL}/tools/try-parse-yaml.py
+
+echo "=== json checks ==="
+
+find . -name '*.json' -print0 |
+ xargs -0 -n1 --no-run-if-empty python -mjson.tool \
+ || RES=1
+
+exit $RES
+