[SCRIPTS] pre-commit now has variables double quoted

This commit is contained in:
Diogo Peralta Cordeiro 2021-04-14 15:50:19 +01:00 committed by Hugo Sales
parent 9997b231d4
commit 55b06705d5
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -1,4 +1,3 @@
#!/usr/bin/env bash
root="$(git rev-parse --show-toplevel)"
@ -10,12 +9,14 @@ 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
if [ -f "${staged}" ] && [[ "${staged}" = *.php ]]
then
# use php-cs-fixer and get flag of correction
"${root}/bin/php-cs-fixer" -q fix "${staged}"
# if php-cs-fixer fix works, it returns 0
if [[ $? -eq 0 ]]; then
if [ "$?" -eq 0 ]
then
git add "${staged}" # execute git add directly
fi
fi