Created
November 3, 2017 16:49
-
-
Save wbob/e72dcc74e0b89ad3587b44585ac9adce to your computer and use it in GitHub Desktop.
shopware pre-commit hook for the forgetful
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# some sanity checks for shopware | |
# | |
# install: move to .git/hooks/pre-commit and chmod +x the file | |
# colors for output | |
nocolor='\033[0m' | |
green='\033[0;32m' | |
orange='\033[0;33m' | |
red='\033[0;31m' | |
warn() { | |
echo -e "${orange} WARN: $1 ${nocolor}" 2>&1 | |
} | |
err() { | |
echo -e "${red} ERROR: $1 ${nocolor}" 2>&1 | |
} | |
# absolute paths of changes: added, modified, deleted, renamed, copied | |
changepath=$(git status --porcelain | grep -E '^[AMDRC]' | awk '{ print $2 }') | |
# mention paths that usually go untouched | |
whitelist="engine/Shopware/Plugins/" | |
while read -r corepath; do | |
if echo "$changepath" | grep -v "$whitelist" | grep -Eq "$corepath"; then | |
warn "core application path modified - $corepath" | |
fi | |
done <<'EOF' | |
^engine/ | |
^vendor/ | |
^themes/Backend/ | |
^themes/Frontend/Bare/ | |
^themes/Frontend/Responsive/ | |
EOF | |
for file in $changepath; do | |
# is this a file | |
if [ -e "$file" ]; then | |
# call out big file commits | |
limit=10000000 # 10 megabytes | |
filesize=$(stat --printf=\%s "$file") | |
if [ $filesize -gt $limit ]; then | |
warn "filesize exceeds 10 MB limit - $filesize bytes $file" | |
fi | |
# equivalent to runPhpLint | |
if echo "$file" | grep -Eq '\.php'; then | |
line=$(php -l $file 2>&1 >/dev/null) | |
if [ -n "$line" ]; then | |
err "$line" | |
fi | |
fi | |
fi | |
done | |
# shopware does additional checks in build/gitHooks/pre-commit: | |
# | |
# runPhpCsFixer | |
# runEsLint | |
# runMigrationCheck |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment