-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·42 lines (36 loc) · 986 Bytes
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
PROJECT=$(git rev-parse --show-toplevel)
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD`
# Determine if a file list is passed
if [[ "$#" -eq 1 ]]
then
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}
for FILE in $SFILES
do
FILES="$FILES $PROJECT/$FILE"
done
if [[ "$FILES" != "" ]]
then
echo "Running Code Sniffer..."
./vendor/bin/phpcs --standard=PSR12 --colors --encoding=utf-8 --extensions=php --parallel=8 -n -p $FILES
if [[ $? != 0 ]]
then
echo "Coding standards errors have been detected. Running phpcbf..."
./vendor/bin/phpcbf --standard=PSR12 --colors --encoding=utf-8 --extensions=php --parallel=8 -n -p $FILES
git add $FILES
echo "Running Code Sniffer again..."
./vendor/bin/phpcs --standard=PSR12 --colors --encoding=utf-8 --extensions=php --parallel=8 -n -p $FILES
if [[ $? != 0 ]]
then
echo "Errors found not fixable automatically"
exit 1
fi
fi
fi
exit $?