From b0d252d6a4a43a3143b488bba5a61c83e93a1301 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 22 Aug 2019 14:40:27 +0200 Subject: scripts: Add a pre-commit hook to validate YAML project files To enable: ln -s ../../scripts/pre-commit.sh .git/hooks/pre-commit Signed-off-by: Geert Uytterhoeven --- scripts/pre-commit.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/pre-commit.sh diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 0000000..38894f4 --- /dev/null +++ b/scripts/pre-commit.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + base=HEAD +else + # Initial commit: diff against an empty tree object + base=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +error=0 + +# Validate new/modified YAML project files +for i in $(git diff --cached --name-only --diff-filter=AM $base -- "*yaml" | grep -vF .schema.yaml) +do + echo -n "Validating $i: " + if ! scripts/validator "$i" + then + echo "ERROR: $i failed to validate" + error=1 + fi +done + +exit $error -- cgit v1.2.3