EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/110235
Change subject: Implement pre-commit hook running less, jshint, and phplint checks ...................................................................... Implement pre-commit hook running less, jshint, and phplint checks Change-Id: I52e734e06b8ae1d4d2e8bbcf67df4408b3db77b4 --- M scripts/pre-commit 1 file changed, 53 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/35/110235/1 diff --git a/scripts/pre-commit b/scripts/pre-commit index ece93b5..1d53688 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -5,23 +5,61 @@ # Code from https://gist.github.com/holysugar/1318698 , simpler than # http://stackoverflow.com/a/6262715/451712 -function error() { +function whitespace_error() { echo "'$1' has trailing whitespace\n" >&2 } -# FIXME this reads the version of the file on-disk, which may not be the version -# about to be committed if you made changes to it since `git add`. -git diff --cached --name-only | (while read f; do - ERROR=0 - if grep -n '[[:space:]]$' "$f" ; then - error $f - ERROR=1 - fi -done; exit $ERROR) +function is_vagrant() { + DEST='.' + while [ "$(realpath $DEST)" != "/" ]; do + if [ -f $DEST/Vagrantfile ]; then + return 0; + fi + DEST="$DEST/.." + done + return 1 +} -if [ $? -eq 0 -o "$IGNORE_WHITESPACE" ]; then - exit -else - echo "if you know what you are doing, use 'IGNORE_WHITESPACE=1 git commit'" - exit 1 +function make() { + if is_vagrant; then + vagrant ssh -- cd /vagrant/mediawiki/extensions/Flow '&&' make $* || exit 1 + else + /usr/bin/env make $* || exit 1 + fi +} + +if [ "$IGNORE_WHITESPACE" != "1" ]; then + # FIXME this reads the version of the file on-disk, which may not be the version + # about to be committed if you made changes to it since `git add`. + git diff --cached --name-only | (while read f; do + ERROR=0 + if grep -n '[[:space:]]$' "$f" ; then + whitespace_error $f + ERROR=1 + fi + done; exit $ERROR) + + if [ $? -ne 0 ];then + echo "if you know what you are doing, use 'IGNORE_WHITESPACE=1 git commit'" + exit 1 + fi fi + +COMMANDS="" + +if git diff --name-only --cached | grep -P '\.less$'; then + COMMANDS="checkless $COMMANDS" +fi + +if git diff --name-only --cached | grep -P '\.js$'; then + COMMANDS="jshint $COMMANDS" +fi + +if git diff --name-only --cached | grep -P '\.php$'; then + COMMANDS="phplint $COMMANDS" +fi + +if [ "$COMMANDS" != "" ]; then + make $COMMANDS || exit 1 +fi + -- To view, visit https://gerrit.wikimedia.org/r/110235 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I52e734e06b8ae1d4d2e8bbcf67df4408b3db77b4 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits