2018-10-29 23:22:30 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
|
2021-10-05 22:09:41 +08:00
|
|
|
STAGED_PHP_FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php$`
|
|
|
|
STAGED_RST_FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.rst$`
|
2018-10-29 23:22:30 -05:00
|
|
|
|
2020-09-02 20:23:58 +08:00
|
|
|
echo "Starting CodeIgniter precommit..."
|
|
|
|
|
2021-10-05 22:09:41 +08:00
|
|
|
if [ "$STAGED_PHP_FILES" != "" ]; then
|
2021-06-06 22:03:20 +08:00
|
|
|
echo "Linting PHP code..."
|
2021-10-05 22:09:41 +08:00
|
|
|
for FILE in $STAGED_PHP_FILES; do
|
2021-06-06 22:03:20 +08:00
|
|
|
php -l -d display_errors=0 "$PROJECT/$FILE"
|
2021-07-24 17:01:13 +08:00
|
|
|
|
|
|
|
if [ $? != 0 ]; then
|
2021-06-06 22:03:20 +08:00
|
|
|
echo "Fix the error(s) before commit."
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-07-24 17:01:13 +08:00
|
|
|
|
2021-06-06 22:03:20 +08:00
|
|
|
FILES="$FILES $FILE"
|
|
|
|
done
|
2020-09-02 20:23:58 +08:00
|
|
|
fi
|
|
|
|
|
2021-07-24 17:01:13 +08:00
|
|
|
if [ "$FILES" != "" ]; then
|
|
|
|
echo "Running PHP CS Fixer..."
|
|
|
|
|
|
|
|
# Run on whole codebase to skip on unnecessary filtering
|
2024-07-24 18:49:12 +08:00
|
|
|
composer cs
|
2022-03-04 09:36:15 +09:00
|
|
|
|
|
|
|
if [ $? != 0 ]; then
|
2024-07-24 18:49:12 +08:00
|
|
|
echo "There are PHP files which are not following the coding standards. Please fix them before commit."
|
2022-03-04 09:36:15 +09:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-07-24 17:01:13 +08:00
|
|
|
fi
|
|
|
|
|
2021-10-05 22:09:41 +08:00
|
|
|
if [ "$STAGED_RST_FILES" != "" ]; then
|
|
|
|
echo "Checking for tabs in RST files"
|
|
|
|
php ./utils/check_tabs_in_rst.php
|
|
|
|
fi
|
|
|
|
|
2018-10-29 23:22:30 -05:00
|
|
|
exit $?
|