Bug
scripts/commit-validate.js's extractMessage() misidentifies non-git commit Bash commands as commit messages, causing the PreToolUse hook to block unrelated work.
Root cause
The -m/--message/heredoc/-F/--file sub-patterns in extractMessage() run unconditionally on the full command string, with no upfront check that the command actually invokes git commit. Two concrete false positives:
-
Any heredoc in a Bash command matches the heredocAny regex (line ~30) and its first content line gets validated as a commit subject — even for something totally unrelated, e.g.:
cat > file.py << 'EOF'
import json
EOF
This blocks with "Commit message must follow conventional commits..." even though there's no git invocation at all.
-
Any -m "..." flag on any command (not just git commit -m) gets captured as a "commit message" by the shortFlag regex, e.g. tools that happen to take a -m flag for unrelated purposes.
Fix
Add a guard at the top of extractMessage() that returns early unless the command actually matches a real git commit invocation, before running any of the sub-pattern checks:
function extractMessage(command) {
if (!command) return { msg: null, form: 'empty' };
if (!/\bgit\s+(?:-[^\s]+\s+)*commit\b/.test(command)) {
return { msg: null, form: 'not-a-commit' };
}
const shortFlag = command.match(/(?:^|\s)-m\s+(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|(\S+))/);
// ... rest unchanged
Verified locally: heredoc/non-commit commands now pass through silently (exit 0), a real invalid commit message still blocks correctly (exit 2), and a valid conventional commit still passes (exit 0).
Happy to open a PR with this exact change if useful — flagging as an issue first in case there's a preferred approach or existing WIP on this.
Bug
scripts/commit-validate.js'sextractMessage()misidentifies non-git commitBash commands as commit messages, causing the PreToolUse hook to block unrelated work.Root cause
The
-m/--message/heredoc/-F/--filesub-patterns inextractMessage()run unconditionally on the full command string, with no upfront check that the command actually invokesgit commit. Two concrete false positives:Any heredoc in a Bash command matches the
heredocAnyregex (line ~30) and its first content line gets validated as a commit subject — even for something totally unrelated, e.g.:This blocks with "Commit message must follow conventional commits..." even though there's no git invocation at all.
Any
-m "..."flag on any command (not justgit commit -m) gets captured as a "commit message" by theshortFlagregex, e.g. tools that happen to take a-mflag for unrelated purposes.Fix
Add a guard at the top of
extractMessage()that returns early unless the command actually matches a real git commit invocation, before running any of the sub-pattern checks:Verified locally: heredoc/non-commit commands now pass through silently (exit 0), a real invalid commit message still blocks correctly (exit 2), and a valid conventional commit still passes (exit 0).
Happy to open a PR with this exact change if useful — flagging as an issue first in case there's a preferred approach or existing WIP on this.