Last active
November 7, 2016 14:39
-
-
Save Ritesh-patel/7af384456816ee03aaf1f71466cef20c to your computer and use it in GitHub Desktop.
WordPress Plugin pre-commit
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
#!/bin/bash | |
# WordPress Plugin pre-commit hook | |
set -e | |
message="Checking staged changes..." | |
git_status_egrep='^[MARC].+' | |
for i; do | |
case "$i" | |
in | |
-m) | |
message="Checking any uncommitted changes..." | |
git_status_egrep='^.?[MARC].+' | |
shift;; | |
esac | |
done | |
echo $message | |
# Check for staged PHP files | |
IFS=$'\n' staged_php_files=( $(git status --porcelain | sed 's/[^ ]* -> *//g' | egrep $git_status_egrep'\.php$' | cut -c4-) ) | |
if [ ${#staged_php_files[@]} != 0 ]; then | |
# PHP_CodeSniffer WordPress Coding Standards | |
echo "## phpcs" | |
if command -v phpcs >/dev/null 2>&1; then | |
phpcs_standard=WordPress-Core | |
phpcs -p -s -v --standard=$phpcs_standard "${staged_php_files[@]}" | |
else | |
echo "Skipping phpcs since not installed" | |
fi | |
fi | |
# Make sure the readme.md never gets out of sync with the readme.txt | |
generate_markdown_readme=$(find . -name generate-markdown-readme -print -quit) | |
if [ -n "$generate_markdown_readme" ]; then | |
markdown_readme_path=$($generate_markdown_readme) | |
git add $markdown_readme_path | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pre-commit Hook
Create a
build
directory inside plugin and putpre-commit
inside build directory.Make
pre-commit
executable:Symlink to
pre-commit
from your project's.git/hooks/pre-commit
: