Skip to content

Commit a2700dd

Browse files
Chhinnaclaude
andcommitted
Fix ENOENT crash when hooks directory does not exist
Create the hooks directory before writing the pre-push hook file, preventing a crash when core.hooksPath points to a missing directory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 382c256 commit a2700dd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/utils/installPushProtectionHook.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execSync } from 'child_process';
2-
import { readFileSync, writeFileSync, chmodSync, existsSync, unlinkSync } from 'fs';
2+
import { readFileSync, writeFileSync, chmodSync, existsSync, unlinkSync, mkdirSync } from 'fs';
33
import path from 'path';
44

55
const HOOK_MARKER = '# codeant-push-protection';
@@ -98,6 +98,9 @@ export function installPushProtectionHook(workspacePath, options = {}) {
9898
}
9999

100100
const hooksDir = getHooksDir(gitRoot);
101+
if (!existsSync(hooksDir)) {
102+
mkdirSync(hooksDir, { recursive: true });
103+
}
101104
const hookPath = path.join(hooksDir, 'pre-push');
102105

103106
// If hook already exists, check if it's ours

0 commit comments

Comments
 (0)