From 9b164637d709b52dae97b5607d9405e3e0c8cb3c Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sun, 12 Apr 2026 13:26:57 -0400 Subject: [PATCH] chore: Add git hook setup script for submodule safety This script installs a pre-push hook that prevents pushing commits when submodules have uncommitted changes, helping avoid accidental commits with dirty submodule states. The hook checks all submodules for uncommitted changes before allowing a push, protecting against pushing incomplete work that includes submodule modifications. --- scripts/setup-git-hooks.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 scripts/setup-git-hooks.sh diff --git a/scripts/setup-git-hooks.sh b/scripts/setup-git-hooks.sh new file mode 100755 index 0000000..cd9ca02 --- /dev/null +++ b/scripts/setup-git-hooks.sh @@ -0,0 +1,18 @@ +#!/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 pre-push hook +mkdir -p .git/hooks +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 + +echo "✅ Git hooks installed! Submodule changes will be checked before pushing."