[BUGFIX] Apply enableFields in JOIN's ON condition
[Packages/TYPO3.CMS.git] / Build / Scripts / cglFixMyCommit.sh
1 #!/usr/bin/env bash
2
3 #########################
4 #
5 # CGL fix.
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 # --------------------------
15 # --- default parameters ---
16 # --------------------------
17 # check files in last commit
18 filestype=commit
19 # non-dryrun is default
20 DRYRUN=""
21 DRYRUN_OPTIONS="--dry-run --diff --diff-format udiff"
22
23 # ----------------------
24 # --- automatic vars ---
25 # ----------------------
26 progname=$(basename $0)
27
28 # ------------------------
29 # --- print usage info ---
30 # ------------------------
31 usage()
32 {
33 echo "Usage: $0 [options] "
34 echo " "
35 echo "no arguments/default: fix all php files in last commit "
36 echo " "
37 echo "Options: "
38 echo " -f <commit|cache|stdin> "
39 echo " specifies which files to check: "
40 echo " - commit (default): all files in latest commit "
41 echo " - cache : all files in git cache (staging area) "
42 echo " - stdin : read list of files from stdin "
43 echo " "
44 echo " -n "
45 echo " dryrun only, do not fix anything! "
46 echo " "
47 echo " -h "
48 echo " help "
49 echo " "
50 echo "Note: In order to still support command line options of "
51 echo " older versions of this script, you can use the argument "
52 echo " dryrun. "
53 echo " "
54 echo " THIS IS NOT RECOMMENDED but will still work for now "
55 echo " Usage: $0 [options] [dryrun] "
56 exit 0
57 }
58
59 # -----------------------
60 # --- parsing of args ---
61 # -----------------------
62 OPTIND=1
63
64 while getopts "hnf:" opt;do
65 case "$opt" in
66 h)
67 usage
68 ;;
69 f)
70 filestype=$OPTARG
71 echo "$0 files type=$filestype"
72 ;;
73 n)
74 echo "$progname: dryrun mode"
75 DRYRUN="$DRYRUN_OPTIONS"
76 ;;
77 esac
78 done
79
80 shift $((OPTIND-1))
81
82 if [ "$1" = "dryrun" ]
83 then
84 echo "$progname: dryrun mode"
85 DRYRUN="$DRYRUN_OPTIONS"
86 fi
87
88 # --------------------------------------
89 # --- check if php executable exists ---
90 # --------------------------------------
91 exist_php_executable() {
92 which php >/dev/null 2>/dev/null
93 if [ $? -ne 0 ];then
94 echo "$progname: No php executable found\n"
95 exit 1
96 fi
97 }
98
99
100 # ------------------------------
101 # --- run php without xdebug ---
102 # ------------------------------
103 php_no_xdebug ()
104 {
105 temporaryPath="$(mktemp -t php.XXXX).ini"
106 php -i | grep "\.ini" | grep -o -e '\(/[A-Za-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' > "${temporaryPath}"
107 php -n -c "${temporaryPath}" "$@"
108 RETURN=$?
109 rm -f "${temporaryPath}"
110 exit $RETURN
111 }
112
113 # ------------------------------------
114 # --- get a list of files to check ---
115 # ------------------------------------
116 if [[ $filestype == commit ]];then
117 echo "$progname: Searching for php files in latest git commit ..."
118 DETECTED_FILES=`git diff-tree --no-commit-id --name-only -r HEAD | grep '.php$' 2>/dev/null`
119 elif [[ $filestype == cache ]];then
120 echo "$progname: Searching for php files in git cache ..."
121 DETECTED_FILES=`git diff --cached --name-only | grep '.php$' 2>/dev/null`
122 elif [[ $filestype == stdin ]];then
123 echo "$progname: reading list of php files to check from stdin"
124 DETECTED_FILES=$(cat)
125 else
126 echo "$progname: ERROR: unknown filetype, possibly used -f with wrong argument"
127 usage
128 fi
129 if [ -z "${DETECTED_FILES}" ]
130 then
131 echo "$progname: No PHP files to check, all is well."
132 exit 0
133 fi
134
135 # ---------------------------------
136 # --- run php-cs-fixer on files ---
137 # ---------------------------------
138 exist_php_executable
139 php_no_xdebug ./bin/php-cs-fixer fix \
140 -v ${DRYRUN} \
141 --path-mode intersection \
142 --config=Build/.php_cs \
143 `echo ${DETECTED_FILES} | xargs ls -d 2>/dev/null`
144
145 exit $?