2021-09-08 05:16:47 +09:00
|
|
|
#!/usr/bin/env sh
|
2020-03-16 06:21:11 +09:00
|
|
|
|
2020-11-07 01:50:42 +09:00
|
|
|
root="$(git rev-parse --show-toplevel)"
|
2020-03-16 06:21:11 +09:00
|
|
|
|
2021-12-26 18:49:03 +09:00
|
|
|
# get the list of changed files that didn't get only partially added
|
2021-07-27 00:45:37 +09:00
|
|
|
staged_files="$(git status --porcelain | sed -rn "s/^[^ ][ ] (.*)/\1/p")"
|
2020-03-16 06:21:11 +09:00
|
|
|
|
2021-09-09 04:57:30 +09:00
|
|
|
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); then
|
2021-12-25 23:26:59 +09:00
|
|
|
files=""
|
2021-09-09 04:57:30 +09:00
|
|
|
for staged in ${staged_files}; do
|
|
|
|
# work only with existing files
|
2021-09-09 08:40:34 +09:00
|
|
|
if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then
|
2021-09-09 04:57:30 +09:00
|
|
|
# use php-cs-fixer and get flag of correction
|
2021-12-25 23:26:59 +09:00
|
|
|
files="${staged} ${files}"
|
2020-03-16 06:21:11 +09:00
|
|
|
fi
|
2021-09-09 04:57:30 +09:00
|
|
|
done
|
2021-12-25 23:26:59 +09:00
|
|
|
if [ -n "${files}" ]; then
|
2021-12-26 18:49:03 +09:00
|
|
|
echo "Running php-cs-fixer on edited files"
|
|
|
|
make cs-fixer "${files}"
|
|
|
|
git add "${files}"
|
2021-12-25 23:26:59 +09:00
|
|
|
fi
|
2021-04-17 00:52:47 +09:00
|
|
|
fi
|
2020-11-07 01:50:42 +09:00
|
|
|
|
2021-09-09 04:57:30 +09:00
|
|
|
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then
|
2021-12-25 23:26:59 +09:00
|
|
|
if echo "${staged_files}" | grep -F ".php" > /dev/null 2>&1; then
|
2021-12-26 18:49:03 +09:00
|
|
|
echo "Running php-doc-checker"
|
|
|
|
make doc-check < /dev/tty
|
2021-09-09 04:57:30 +09:00
|
|
|
fi
|
|
|
|
fi
|
2021-09-07 02:45:14 +09:00
|
|
|
|
2021-09-09 04:57:30 +09:00
|
|
|
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_PHPSTAN?}") 2>/dev/null); then
|
|
|
|
echo "Running phpstan"
|
2021-09-09 08:40:34 +09:00
|
|
|
make phpstan
|
2021-09-09 04:57:30 +09:00
|
|
|
fi
|
2021-09-07 02:45:14 +09:00
|
|
|
|
2020-11-07 01:50:42 +09:00
|
|
|
# Only commit if there wasn't an error
|
|
|
|
exit $?
|