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.
This commit is contained in:
Jacob Magar 2026-04-05 20:38:53 -04:00
parent 02251b3f9f
commit 0085fe83d4
2 changed files with 21 additions and 0 deletions

View file

@ -21,3 +21,11 @@ repos:
entry: bash bin/ensure-ignore-files.sh --check
language: system
pass_filenames: false
- id: block-env-commits
name: Block .env file commits (allow only .env.example)
entry: bash bin/block-env-commits.sh
language: system
pass_filenames: false
files: '\.env'
exclude: '\.env\.example$'

13
bin/block-env-commits.sh Executable file
View file

@ -0,0 +1,13 @@
#!/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