Permalink
Browse files

Merge pull request #10287 from mickaelandrieu/fix/pre-commit-hook

Fixed pre-commit hook script
  • Loading branch information...
matks committed Sep 5, 2018
2 parents ca67d30 + c001ea6 commit d6723d8272b02989d0b2939479635bd8535bfe1f
Showing with 21 additions and 23 deletions.
  1. +7 −10 .github/contrib/install.php
  2. +14 −13 .github/contrib/pre-commit
@@ -24,18 +24,15 @@
* International Registered Trademark & Property of PrestaShop SA
*/
if (file_exists('.git/hooks/pre-commit')) {
copy('.git/hooks/pre-commit', '.git/hooks/pre-commit.back');
echo "A Git precommit file was found, a backup was created.\n";
}
if (file_exists('pre-commit')) {
file_put_contents(
'.git/hooks/pre-commit',
file_get_contents(__DIR__.'/pre-commit'),
FILE_APPEND | LOCK_EX
);
chmod('.git/hooks/pre-commit', 0750);
echo "\e[32mPre-commit Hook has been installed.\e[0;m\n";
}
file_put_contents(
'.git/hooks/pre-commit',
file_get_contents(__DIR__.'/pre-commit')
);
chmod('.git/hooks/pre-commit', 0750);
echo "\e[32mPre-commit Hook has been installed.\e[0;m\n";
@@ -1,32 +1,33 @@
#!/bin/sh
PROJECT_PATH=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
PHP_BINARY=`which php`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
PROJECT_PATH=$(cd "$( dirname "$0" )/../../" && pwd)
# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}
echo "Checking PHP Lint..."
for FILE in $SFILES
do
php -l -d display_errors=0 $PROJECT_PATH/$FILE
if [ $? != 0 ]
then
echo "Error(s), please fix it before commit."
exit 1
fi
$PHP_BINARY -l -d display_errors=0 $PROJECT_PATH/$FILE
if [ $? != 0 ]
then
echo "Error(s), please fix it before commit."
exit 1
fi
done
echo "Running PHP CS Fixer..."
php bin/php-cs-fixer fix
$PHP_BINARY ./vendor/bin/php-cs-fixer fix
exit $?

0 comments on commit d6723d8

Please sign in to comment.