mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 09:37:26 +00:00
Add php pre-commit hook
This commit is contained in:
parent
0f61fb6d89
commit
5b4f57ef37
6 changed files with 78 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ composer
|
|||
.ht*
|
||||
/vendor/
|
||||
.DS_Store
|
||||
.php_cs.cache
|
3
dev.sh
3
dev.sh
|
@ -13,6 +13,9 @@ if ! which $PHPBIN 2>/dev/null; then
|
|||
PHPBIN=php
|
||||
fi
|
||||
|
||||
# Installing git hook
|
||||
$DIR/hooks/install.sh
|
||||
|
||||
$PHPBIN composer.phar install
|
||||
|
||||
$PHPBIN --server localhost:8000 --docroot "$DIR/web" "$DIR/web/index.php"
|
|
@ -7,6 +7,9 @@ if [ ! -e "$DIR/data/config.php" ]; then
|
|||
cp "$DIR/data/config.php.example" "$DIR/data/config.php"
|
||||
fi
|
||||
|
||||
# Installing git hook
|
||||
$DIR/hooks/install.sh
|
||||
|
||||
docker run --rm -it --name "dev.lbry.io" \
|
||||
-v "$DIR:/usr/src/lbry.io" \
|
||||
-w "/usr/src/lbry.io" \
|
||||
|
@ -14,4 +17,5 @@ docker run --rm -it --name "dev.lbry.io" \
|
|||
-u "$(id -u):$(id -g)" \
|
||||
php:7-alpine \
|
||||
php composer.phar install
|
||||
|
||||
php --server "0.0.0.0:8000" --docroot "web/" "index.php"
|
18
hooks/install.sh
Executable file
18
hooks/install.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ -e .git/hooks/pre-commit ];
|
||||
then
|
||||
PRE_COMMIT_EXISTS=1
|
||||
else
|
||||
PRE_COMMIT_EXISTS=0
|
||||
fi
|
||||
|
||||
cp ./hooks/pre-commit .git/hooks/pre-commit
|
||||
chmod +x .git/hooks/pre-commit
|
||||
|
||||
if [ "$PRE_COMMIT_EXISTS" = 0 ];
|
||||
then
|
||||
echo "Pre-commit git hook is installed!"
|
||||
else
|
||||
echo "Pre-commit git hook is updated!"
|
||||
fi
|
40
hooks/pre-commit
Normal file
40
hooks/pre-commit
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/bin/sh
|
||||
|
||||
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
|
||||
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
|
||||
|
||||
# Determine if a file list is passed
|
||||
if [ "$#" -eq 1 ]
|
||||
then
|
||||
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/$FILE
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo "Fix the error before commit."
|
||||
exit 1
|
||||
fi
|
||||
FILES="$FILES $PROJECT/$FILE"
|
||||
done
|
||||
|
||||
if [ "$FILES" != "" ]
|
||||
then
|
||||
echo "Running php-cs-fixer"
|
||||
$PROJECT/php-cs-fixer fix $FILES
|
||||
git add $FILES
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo "Error was found"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit $?
|
BIN
php-cs-fixer
Executable file
BIN
php-cs-fixer
Executable file
Binary file not shown.
Loading…
Add table
Reference in a new issue