CodeIgniter4/admin/pre-commit

41 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

#!/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$`
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
composer cs
if [ $? != 0 ]; then
echo "There are PHP files which are not following the coding standards. Please fix them before commit."
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
exit $?