#!/bin/bash STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.php') # Disable if it's a merge git merge HEAD &> /dev/null IS_MERGE_PROCESS=$? if [ $IS_MERGE_PROCESS -ne 0 ] then echo -e "Skipping pre-commit hook." exit $? fi # Skip if no staged files if [[ "$STAGED_FILES" = "" ]]; then echo -e "No staged files. Skipping pre-commit hook." exit 0 fi echo -e "Running pre-commit hooks..." ./artisan hooks:pre-commit if [[ "$?" == 0 ]]; then echo -e "Pre-commit hooks passed!" else echo -e "Pre-commit hooks failed!" echo -e "If you want to skip pre-commit hooks, use --no-verify option." exit 1 fi git add $STAGED_FILES exit 0