summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeert Uytterhoeven <geert+renesas@glider.be>2019-08-22 14:40:27 +0200
committerGeert Uytterhoeven <geert+renesas@glider.be>2019-11-25 14:52:39 +0100
commitb0d252d6a4a43a3143b488bba5a61c83e93a1301 (patch)
tree7f825635da27919bfca8338e7e01e25cbe364469
parent6e401a9d38df6169f33485c3af25f755e1b144dd (diff)
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 <geert+renesas@glider.be>
-rwxr-xr-xscripts/pre-commit.sh24
1 files changed, 24 insertions, 0 deletions
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