5. Save WP database with each commit
Pre-commit hook
#!/bin/sh
mkdir -p _db_snapshot
./vendor/bin/wp db export _db_snapshot/database.sql
git add _db_snapshot/database.sql
6. Check PHP syntax errors before commit
Pre-commit hook
git diff --cached --name-only | while read FILE; do
if [[ "$FILE" =~ ^.+(php|inc|module|install|test)$ ]]; then
# Courtesy of swytsh from the comments below.
if [[ -f $FILE ]]; then
php -l "$FILE" 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "e[1;31mtAborting commit due to files with syntax errors.e[0m" >&2
exit 1
fi
fi
fi
done || exit $?
7. Spellchecking commit messages
Pre-commit hook
ASPELL=$(which aspell)
if [ $? -ne 0 ]; then
echo "Aspell not installed - unable to check spelling" >&2
exit
else
WORDS=$($ASPELL list < "$1")
fi
if [ -n "$WORDS" ]; then
echo -e "e[1;33mtPossible spelling errors found in commit message.
Use git commit --amend to change the message.
ntPossible mispelled words: " $WORDS ".e[0m" >&2
fi
9. Useful composer comands
composer init # To create a new composer.json file in a project
composer show # display all project packages
composer search some_package # search for a package
composer suggests # suggests packages based on installed ones
composer require somepackage/somepackage:someversion # install a dependancy
composer update # update required packages
composer remove package/name # remove package
composer dump-autoload --optimize # optimize autoloader for production