From ae1544d96682f4b32e29450e46833e6886ca48ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bigler?= Date: Wed, 7 Jan 2015 20:55:20 +0100 Subject: [PATCH] [FEATURE] Git hook for code analysation --- nbproject/project.properties | 1 + scripts/hooks/pre-commit | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100755 scripts/hooks/pre-commit diff --git a/nbproject/project.properties b/nbproject/project.properties index 786bd222..3db0cf99 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -11,6 +11,7 @@ auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=4 auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=80 auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap=none auxiliary.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project +auxiliary.org-netbeans-modules-editor-indent.text.x-php5.CodeStyle.project.blankLinesAfterFunction=0 auxiliary.org-netbeans-modules-editor-indent.text.x-php5.CodeStyle.project.blankLinesBeforeField=0 auxiliary.org-netbeans-modules-editor-indent.text.x-php5.CodeStyle.project.classDeclBracePlacement=NEW_LINE auxiliary.org-netbeans-modules-editor-indent.text.x-php5.CodeStyle.project.expand-tabs=true diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit new file mode 100755 index 00000000..34f907af --- /dev/null +++ b/scripts/hooks/pre-commit @@ -0,0 +1,48 @@ +#!/bin/bash + +# Hook for git which can test code for each commit. +# To install and use it just copy or symlink it to .git/hooks/pre-commit +# example (project base dir): pushd .git/hooks/; ln -s ../../scripts/hooks/pre-commit .; popd + +if [ -e "php-cs-fixer.phar" ] +then + PHPCSFIXER="php php-cs-fixer.phar" +elif hash php-cs-fixer +then + PHPCSFIXER="php-cs-fixer" +fi + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +FIXERS='indentation,linefeed,trailing_spaces,short_tag,braces,controls_spaces,eof_ending,visibility' + +ST=0 # Global exit status + +# Loop through all committed files +for file in $(git diff-index --name-only $against); do + echo -n "testing $file..." + + FIXEROUT=$(php-cs-fixer fix --dry-run -v --fixers=$FIXERS "$file" | grep -P '\d\)' | sed -r "s~^.*?${file} ~~"; exit ${PIPESTATUS[0]}) + FIXERST=$? + + PARSEROUT=$(php --syntax-check "$file" 2>&1 | egrep -v 'No syntax errors|Errors parsing'; exit ${PIPESTATUS[0]}) + PARSERST=$? + + echo -e -n "\r${file}..." + if [ $FIXERST != 0 ]; then + echo $FIXEROUT + elif [ $PARSERST != 0 ]; then + echo $PARSEROUT + else + echo "OK " + fi + ST=$(($ST | $FIXERST | $PARSERST)) +done + +exit $ST