diff options
-rwxr-xr-x | scripts/pre-commit.sh | 24 |
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 |