Last active
May 9, 2019 13:22
-
-
Save sera527/bcb9015d36a85f0ee2abb14a7ef0cc4f to your computer and use it in GitHub Desktop.
Git Hook, що спрацьовує в момент коміту. Перевіряє файли розширенням php, js, tpl, volt на наявність фраз "console.log", "var_dump", "dump". Цей файл потрібно закинути в папку .git/hooks. Якщо потрібно ігнорувати хук, до команди потрібно додати "--no-verify"
This file contains 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
#!/bin/bash | |
blackList="console.log\|var_dump\|dump[ ]*(" | |
result=0 | |
while read FILE; do | |
if [[ -f $FILE ]]; then | |
if [[ "$FILE" =~ ^.+(php|html|js|volt|tpl)$ ]]; then | |
RESULT=$(grep -i -m 1 "$blackList" "$FILE") | |
if [[ ! -z $RESULT ]]; then | |
echo "$FILE contains denied word: $RESULT" | |
result=1 | |
fi | |
fi | |
fi | |
done << EOT | |
$(git diff --cached --name-only) | |
EOT | |
if [ $result -ne 0 ]; then | |
echo "Aborting commit due to denied words" | |
exit $result | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment