#!/bin/bash # One-time setup for git hooks on this machine echo "🔒 Installing pre-push safety hook to prevent pushing with uncommitted submodule changes..." # Create hooks directory mkdir -p .git/hooks # Create pre-push hook cat >.git/hooks/pre-push <<'EOF' #!/bin/bash # Prevent pushing if submodules have uncommitted changes uncommitted=$(git submodule foreach --quiet 'if [ "$(git status --porcelain)" != "" ]; then echo $name; fi') if [ -n "$uncommitted" ]; then echo "❌ ERROR: Submodules have uncommitted changes:" echo "$uncommitted" echo "Commit submodules first (or use git sc-commit)" exit 1 fi EOF # Make hook executable chmod +x .git/hooks/pre-push # Add git alias for submodule commit git config --global alias.sc-commit '!sh -c "git submodule foreach \"git add -A && git commit -m \\\"$1\\\" && git push\"" -' echo "✅ Git hooks and alias installed!" echo " - Pre-push hook: Checks for uncommitted submodule changes" echo " - Alias: 'git sc-commit' to commit and push all submodules"