laravel-hooks/stubs/pre-commit

35 lines
685 B
Plaintext
Raw Normal View History

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