unraid-mcp/bin/block-env-commits.sh
Jacob Magar 0085fe83d4 feat(rl3u): add block-env-commits pre-commit hook
Blocks any *.env* file from being committed except .env.example.
Prevents credential leaks like the .env.backup incidents.
2026-04-05 20:38:53 -04:00

13 lines
419 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
staged=$(git diff --cached --name-only)
blocked=$(printf '%s
' "$staged" | grep -E '(^|/)[^/]*\.env[^/]*$' | grep -v '\.env\.example$' || true)
if [[ -n "$blocked" ]]; then
echo "block-env-commits: BLOCKED — .env file(s) staged for commit:" >&2
echo "$blocked" | sed 's/^/ /' >&2
echo "Only .env.example is allowed. Remove staged file(s) and try again." >&2
exit 1
fi