Skip to content

Commit 3d8f5dd

Browse files
committed
fix(hooks): align pre-push .env detection with pre-commit/commit-msg
The pre-push hook used a narrow regex (/^\.env(\.local)?$/) that only matched root-level .env and .env.local files. Meanwhile pre-commit and commit-msg use basename() with a broader pattern that catches .env files at any depth and with any suffix (excluding example/test/precommit). Since pre-push is the mandatory enforcement layer that catches things bypassed via --no-verify, it must be at least as strict. Use the same basename()-based detection pattern from the other hooks.
1 parent cc065a7 commit 3d8f5dd

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

.git-hooks/pre-push.mts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import { spawnSync } from 'node:child_process'
1919
import { existsSync, statSync } from 'node:fs'
20+
import { basename } from 'node:path'
2021

2122
import process from 'node:process'
2223

@@ -190,8 +191,15 @@ const scanFilesInRange = (range: string): number => {
190191
return 0
191192
}
192193

193-
// Top-level sensitive filenames in the change set.
194-
const envHits = changed.filter(f => /^\.env(\.local)?$/.test(f))
194+
// .env files at any depth — allow only .env.example, .env.test,
195+
// .env.precommit (templates / tracked placeholders).
196+
const envHits = changed.filter(f => {
197+
const base = basename(f)
198+
return (
199+
/^\.env(\.[^/]+)?$/.test(base) &&
200+
!/^\.env\.(example|test|precommit)$/.test(base)
201+
)
202+
})
195203
if (envHits.length > 0) {
196204
out(red('✗ BLOCKED: Attempting to push .env file!'))
197205
out(`Files: ${envHits.join(', ')}`)

0 commit comments

Comments
 (0)