diff --git a/.githooks/post-commit b/.githooks/post-commit new file mode 100755 index 0000000..dca7b29 --- /dev/null +++ b/.githooks/post-commit @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -u + +REPO_ROOT="$(git rev-parse --show-toplevel)" +cd "$REPO_ROOT" + +BRANCH="$(git branch --show-current)" + +if [ -z "$BRANCH" ]; then + echo "âš ī¸ [post-commit] Detached HEAD detected; skipping auto-push." + exit 0 +fi + +echo "🚀 [post-commit] Syncing '${BRANCH}' to origin..." + +if git push origin "$BRANCH"; then + echo "✨ [post-commit] Brain synchronized successfully." +else + echo "âš ī¸ [post-commit] Push failed (network or remote unreachable)." + echo "â„šī¸ [post-commit] Commit remains saved locally. Run 'git push' when online to synchronize." +fi diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..49f526d --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +set -u + +REPO_ROOT="$(git rev-parse --show-toplevel)" +cd "$REPO_ROOT" + +echo "🔍 [pre-commit] Validating Brain structure..." + +if python3 scripts/validate-brain.py; then + echo "✅ [pre-commit] Brain structure valid." +else + echo "❌ [pre-commit] Brain validation failed. Commit aborted." + echo "💡 [pre-commit] Fix structural issues or move uncurated drafts into inbox/." + exit 1 +fi diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh new file mode 100644 index 0000000..0bc8804 --- /dev/null +++ b/scripts/install-hooks.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "${REPO_ROOT}" + +chmod +x .githooks/pre-commit .githooks/post-commit +git config core.hooksPath .githooks + +echo "✅ Git hooks configured successfully:" +echo " â€ĸ core.hooksPath set to .githooks" +echo " â€ĸ pre-commit: structural validation via validate-brain.py" +echo " â€ĸ post-commit: auto-push to origin"