From 3f8c68b9d4094c7789287b130ae61d295506a006 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Sat, 30 Jun 2018 16:54:47 +0100 Subject: [PATCH] Allow for ocaml-typo=prune --- tools/ci/travis/travis-ci.sh | 28 +++++++++++++++++++++++++--- tools/pre-commit-githook | 20 +++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tools/ci/travis/travis-ci.sh b/tools/ci/travis/travis-ci.sh index e8aa38aca..e30cc4959 100755 --- a/tools/ci/travis/travis-ci.sh +++ b/tools/ci/travis/travis-ci.sh @@ -157,6 +157,24 @@ EOF testsuite > /dev/null && exit 1 || echo pass } +# Test to see if any part of the directory name has been marked prune +not_pruned () { + DIR=$(dirname "$1") + if [ "$DIR" = "." ] ; then + return 0 + else + case ",$(git check-attr ocaml-typo "$DIR" | sed -e 's/.*: //')," in + ,prune,) + return 1 + ;; + *) + + not_pruned $DIR + return $? + esac + fi +} + CheckTypoTree () { export OCAML_CT_HEAD=$1 export OCAML_CT_LS_FILES="git diff-tree --no-commit-id --name-only -r $2 --" @@ -166,9 +184,13 @@ CheckTypoTree () { git diff-tree --diff-filter=d --no-commit-id --name-only -r $1 \ | (while IFS= read -r path do - echo "Checking $1: $path" - if ! tools/check-typo $path ; then - touch check-typo-failed + if not_pruned $path ; then + echo "Checking $1: $path" + if ! tools/check-typo $path ; then + touch check-typo-failed + fi + else + echo "NOT checking $1: $path (ocaml-typo=prune)" fi done) rm -f tmp-index diff --git a/tools/pre-commit-githook b/tools/pre-commit-githook index 49648f1d8..45d11fed5 100755 --- a/tools/pre-commit-githook +++ b/tools/pre-commit-githook @@ -45,6 +45,24 @@ if ! git diff-index --check --cached $against -- $FILES ; then exit 1 fi +# Test to see if any part of the directory name has been marked prune +not_pruned () { + DIR=$(dirname "$1") + if [ "$DIR" = "." ] ; then + return 0 + else + case ",$(git check-attr ocaml-typo "$DIR" | sed -e 's/.*: //')," in + ,prune,) + return 1 + ;; + *) + + not_pruned $DIR + return $? + esac + fi +} + # Now run check-typo over all the files in the index ERRORS=0 export OCAML_CT_PREFIX=: @@ -52,7 +70,7 @@ export OCAML_CT_CAT="git cat-file --textconv" export OCAML_CT_CA_FLAG=--cached git diff --diff-filter=d --staged --name-only | (while IFS= read -r path do - if ! tools/check-typo $path ; then + if not_pruned $path && ! tools/check-typo $path ; then ERRORS=1 fi done; exit $ERRORS)