diff --git a/examples/pre-commit-hook.sh b/examples/pre-commit-hook.sh new file mode 100644 index 0000000..c23d51c --- /dev/null +++ b/examples/pre-commit-hook.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Pre-commit hook for Code Privacy Shield +# Add this to .git/hooks/pre-commit + +set -e + +# Find the project root +ROOT_DIR="$(git rev-parse --show-toplevel)" + +# Check if CPS is available +if command -v cps &> /dev/null; then + echo "Running Code Privacy Shield check..." + + # Check staged Python files + FILES=$(git diff --cached --name-only -- '*.py' '*.js' '*.ts' '*.json' '*.yaml' '*.yml' 2>/dev/null || true) + + if [ -n "$FILES" ]; then + # Preview what would be redacted + echo "$FILES" | xargs -I {} sh -c 'echo "Checking {}"; cps preview "{}" 2>/dev/null || true' + fi +fi + +exit 0