gnu-social/bin/pre-commit

34 lines
849 B
Bash
Executable File

#!/usr/bin/env sh
root="$(git rev-parse --show-toplevel)"
# get the list of changed files
staged_files="$(git status --porcelain | sed -rn "s/^[^ ][ ] (.*)/\1/p")"
echo "Running php-cs-fixer on edited files"
for staged in ${staged_files}; do
# work only with existing files
if [ -f "${staged}" ] && [[ "${staged}" = *.php ]]
then
# use php-cs-fixer and get flag of correction
if "${root}/bin/php-cs-fixer" -q fix "${staged}"
then
git add "${staged}" # execute git add directly
fi
fi
done
echo "Running php-doc-checker"
if echo "${staged_files}" | grep -F ".php"; then
"${root}/bin/php-doc-check" src plugins components
fi
echo "Running phpstan"
"${root}/vendor/bin/phpstan" --memory-limit=2G analyse src tests components plugins
# Only commit if there wasn't an error
exit $?