From d9eab477fd2d0aabc1cf05029987f10874eb999f Mon Sep 17 00:00:00 2001 From: Cyprian Laskowski Date: Fri, 21 Feb 2020 20:44:39 +0100 Subject: [PATCH] IssueID #1104: separated git hook from command script (so it can be run independently) --- scripts/install_git_hooks | 2 +- scripts/validate_examples | 31 ++++++++++++++----------------- scripts/validate_examples_hook | 9 +++++++++ 3 files changed, 24 insertions(+), 18 deletions(-) create mode 100755 scripts/validate_examples_hook diff --git a/scripts/install_git_hooks b/scripts/install_git_hooks index 7eb145b..d4c81af 100755 --- a/scripts/install_git_hooks +++ b/scripts/install_git_hooks @@ -2,5 +2,5 @@ top_dir=`git rev-parse --show-toplevel` cd $top_dir/.git/hooks -ln -s ../../scripts/validate_examples pre-commit +ln -s ../../scripts/validate_examples_hook pre-commit diff --git a/scripts/validate_examples b/scripts/validate_examples index b4c0726..d3870b3 100755 --- a/scripts/validate_examples +++ b/scripts/validate_examples @@ -1,23 +1,20 @@ #!/bin/bash -branch=`git rev-parse --abbrev-ref HEAD` script_dir="$(dirname "$(readlink -f "$0")")" cd $script_dir -if [[ $branch == "master" ]]; then - schema_dir=../resources/schema - example_dir=../examples - for example_subdir in $example_dir/* + +schema_dir=../resources/schema +example_dir=../examples +for example_subdir in $example_dir/* +do + base=${example_subdir##*/} + schema=$schema_dir/$base.xsd + for example_file in $example_subdir/*.xml do - base=${example_subdir##*/} - schema=$schema_dir/$base.xsd - for example_file in $example_subdir/*.xml - do - command="xmllint -schema $schema $example_file --noout" - echo $command - if ! $command; then - exit 1 - fi - done + command="xmllint -schema $schema $example_file --noout" + echo $command + if ! $command; then + exit 1 + fi done -fi -exit 0 +done diff --git a/scripts/validate_examples_hook b/scripts/validate_examples_hook new file mode 100755 index 0000000..d67c25b --- /dev/null +++ b/scripts/validate_examples_hook @@ -0,0 +1,9 @@ +#!/bin/bash + +branch=`git rev-parse --abbrev-ref HEAD` +script_dir="$(dirname "$(readlink -f "$0")")" +cd $script_dir + +if [[ $branch == "master" ]]; then + ./validate_examples +fi