forked from GNUsocial/gnu-social
[TOOLS][git] Add option to skip pre-commit steps by defining one of SKIP_ALL
, SKIP_CS_FIX
, SKIP_DOC_CHECK
, SKIP_PHPSTAN
variables before the git commit
command
Example: `SKIP_PHPSTAN=1 git commit`
This commit is contained in:
parent
f81bf4a257
commit
9742a07bae
@ -5,11 +5,11 @@ root="$(git rev-parse --show-toplevel)"
|
|||||||
# get the list of changed files
|
# get the list of changed files
|
||||||
staged_files="$(git status --porcelain | sed -rn "s/^[^ ][ ] (.*)/\1/p")"
|
staged_files="$(git status --porcelain | sed -rn "s/^[^ ][ ] (.*)/\1/p")"
|
||||||
|
|
||||||
|
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); then
|
||||||
echo "Running php-cs-fixer on edited files"
|
echo "Running php-cs-fixer on edited files"
|
||||||
|
|
||||||
for staged in ${staged_files}; do
|
for staged in ${staged_files}; do
|
||||||
# work only with existing files
|
# work only with existing files
|
||||||
if [ -f "${staged}" ] && [[ "${staged}" = *.php ]]
|
if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$'
|
||||||
then
|
then
|
||||||
# use php-cs-fixer and get flag of correction
|
# use php-cs-fixer and get flag of correction
|
||||||
if "${root}/bin/php-cs-fixer" -q fix "${staged}"
|
if "${root}/bin/php-cs-fixer" -q fix "${staged}"
|
||||||
@ -18,16 +18,19 @@ for staged in ${staged_files}; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then
|
||||||
echo "Running php-doc-checker"
|
echo "Running php-doc-checker"
|
||||||
|
|
||||||
if echo "${staged_files}" | grep -F ".php"; then
|
if echo "${staged_files}" | grep -F ".php"; then
|
||||||
"${root}/bin/php-doc-check" src plugins components
|
"${root}/bin/php-doc-check" src plugins components
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_PHPSTAN?}") 2>/dev/null); then
|
||||||
echo "Running phpstan"
|
echo "Running phpstan"
|
||||||
|
|
||||||
"${root}/vendor/bin/phpstan" --memory-limit=2G analyse src tests components plugins
|
"${root}/vendor/bin/phpstan" --memory-limit=2G analyse src tests components plugins
|
||||||
|
fi
|
||||||
|
|
||||||
# Only commit if there wasn't an error
|
# Only commit if there wasn't an error
|
||||||
exit $?
|
exit $?
|
||||||
|
Loading…
Reference in New Issue
Block a user