Skip to content

Instantly share code, notes, and snippets.

@akoepcke
Created September 14, 2025 19:35
Show Gist options
  • Select an option

  • Save akoepcke/8128de1d947eced5974e556413be1e7c to your computer and use it in GitHub Desktop.

Select an option

Save akoepcke/8128de1d947eced5974e556413be1e7c to your computer and use it in GitHub Desktop.
Run version:generate on post-commit
#!/bin/bash
LOGFILE="/tmp/git-post-commit.log"
cd "$(git rev-parse --show-toplevel)" || exit 1
# Detect PHP binary in priority order: Herd → Homebrew → system php
if [ -x "/Users/$USER/Library/Application Support/Herd/bin/php" ]; then
PHP_BIN="/Users/$USER/Library/Application Support/Herd/bin/php"
elif command -v php >/dev/null 2>&1; then
PHP_BIN="$(command -v php)"
elif [ -x "/opt/homebrew/bin/php" ]; then
PHP_BIN="/opt/homebrew/bin/php"
elif [ -x "/usr/local/bin/php" ]; then
PHP_BIN="/usr/local/bin/php"
else
echo "ERROR: No PHP binary found" >> "$LOGFILE"
exit 1
fi
{
echo "=== Post-commit hook ran at $(date) ==="
echo "Using PHP binary: $PHP_BIN"
echo "Repo root: $(pwd)"
"$PHP_BIN" artisan version:generate
echo "Exit code: $?"
echo
} >> "$LOGFILE" 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment