Skip to content

Commit ea0ddd7

Browse files
committed
fix: address secrets hook review comments
1 parent 8da9d60 commit ea0ddd7

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/utils/installPushProtectionHook.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ ${buildHookBlock(cliPath)}
2121
*/
2222
function buildHookBlock(cliPath) {
2323
if (cliPath) {
24+
const quotedCliPath = `'${cliPath.replace(/'/g, "'\\''")}'`;
2425
return `${HOOK_MARKER}
2526
# Auto-installed by CodeAnt AI — blocks commits containing secrets.
2627
# To disable: delete this hook or run "codeant push-protection disable"
2728
# Uses the CLI bundled with the VS Code extension.
2829
# Reopen stdin from terminal so the CLI can show an interactive bypass prompt.
2930
# In non-interactive environments (CI), this silently fails and the commit is blocked.
3031
exec < /dev/tty 2>/dev/null || true
31-
if [ -f "${cliPath}" ] && command -v node >/dev/null 2>&1; then
32-
node "${cliPath}" secrets --staged --hook
32+
if [ -f ${quotedCliPath} ] && command -v node >/dev/null 2>&1; then
33+
node ${quotedCliPath} secrets --staged --hook
3334
else
34-
command -v codeant >/dev/null 2>&1 || exit 0
35+
command -v codeant >/dev/null 2>&1 || exit 1
3536
codeant secrets --staged --hook
3637
fi
3738
${HOOK_MARKER_END}`;
@@ -40,7 +41,7 @@ ${HOOK_MARKER_END}`;
4041
# Auto-installed by CodeAnt AI — blocks commits containing secrets.
4142
# To disable: delete this hook or run "codeant push-protection disable"
4243
exec < /dev/tty 2>/dev/null || true
43-
command -v codeant >/dev/null 2>&1 || exit 0
44+
command -v codeant >/dev/null 2>&1 || exit 1
4445
codeant secrets --staged --hook
4546
${HOOK_MARKER_END}`;
4647
}
@@ -127,7 +128,7 @@ export function installPushProtectionHook(workspacePath, cliPath) {
127128
}
128129
// There's a user-managed hook — append only for shell hooks to avoid breaking non-shell scripts
129130
const firstLine = existing.split('\n', 1)[0] || '';
130-
const isShellHook = firstLine.startsWith('#!') ? /\/(ba|z|k)?sh(\s|$)/.test(firstLine) : true;
131+
const isShellHook = firstLine.startsWith('#!') ? /^#!\s*(?:\/\S*\/|\/usr\/bin\/env\s+(?:-S\s+)?)(ba|z|k)?sh(\s|$)/.test(firstLine) : true;
131132
if (!isShellHook) {
132133
return { installed: false, hookPath, message: 'Existing pre-commit hook is non-shell; cannot append CodeAnt block safely' };
133134
}

0 commit comments

Comments
 (0)