2020-03-16 06:21:11 +09:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-11-07 01:50:42 +09:00
|
|
|
root="$(git rev-parse --show-toplevel)"
|
2020-03-16 06:21:11 +09:00
|
|
|
|
2020-11-07 01:50:42 +09:00
|
|
|
# get the list of changed files
|
|
|
|
staged_files="$(git diff --cached --name-only)"
|
2020-03-16 06:21:11 +09:00
|
|
|
|
|
|
|
echo "Running php-cs-fixer on edited files"
|
|
|
|
|
|
|
|
for staged in ${staged_files}; do
|
|
|
|
# work only with existing files
|
2021-04-14 23:50:19 +09:00
|
|
|
if [ -f "${staged}" ] && [[ "${staged}" = *.php ]]
|
|
|
|
then
|
2020-03-16 06:21:11 +09:00
|
|
|
# use php-cs-fixer and get flag of correction
|
2020-11-07 01:50:42 +09:00
|
|
|
"${root}/bin/php-cs-fixer" -q fix "${staged}"
|
2020-03-16 06:21:11 +09:00
|
|
|
|
|
|
|
# if php-cs-fixer fix works, it returns 0
|
2021-04-14 23:50:19 +09:00
|
|
|
if [ "$?" -eq 0 ]
|
|
|
|
then
|
2020-03-16 06:21:11 +09:00
|
|
|
git add "${staged}" # execute git add directly
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-11-07 01:50:42 +09:00
|
|
|
echo "Running php-doc-checker"
|
|
|
|
|
|
|
|
"${root}/bin/php-doc-check" src plugins components
|
|
|
|
|
|
|
|
# Only commit if there wasn't an error
|
|
|
|
exit $?
|