[FOLLOWUP][TASK] Squeeze every bit of performance from CGL fixer
[Packages/TYPO3.CMS.git] / Build / Scripts / cglFixMyCommit.sh
1 #!/bin/bash
2
3 #########################
4 #
5 # CGL check latest core commit.
6 #
7 # It expects to be run from the core root.
8 #
9 # To auto-fix single files, use the php-cs-fixer command directly
10 # substitute $FILE with a filename
11 #
12 ##########################
13
14 php_no_xdebug () {
15 temporaryPath="$(mktemp -t php.XXXX).ini"
16 php -i | grep "\.ini" | grep -o -e '\(/[A-Za-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' > "${temporaryPath}"
17 php -n -c "${temporaryPath}" "$@"
18 RETURN=$?
19 rm -f "${temporaryPath}"
20 exit $RETURN
21 }
22
23 DRYRUN=""
24
25 if [ "$1" = "dryrun" ]
26 then
27 DRYRUN="--dry-run"
28 fi
29
30 DETECTED_FILES=`git diff-tree --no-commit-id --name-only -r HEAD | grep '.php$' 2>/dev/null`
31 if [ -z "${DETECTED_FILES}" ]
32 then
33 echo "No PHP files to check in current commit, all is well."
34 exit 0
35 fi
36
37 php_no_xdebug ./bin/php-cs-fixer fix \
38 -v ${DRYRUN} \
39 --config=Build/.php_cs \
40 `echo ${DETECTED_FILES} | xargs ls -d 2>/dev/null`
41
42 exit $?