fix(claude-hooks): strip commit-message contents before pattern match (false positive)
This commit is contained in:
parent
4a33347aee
commit
0bbfd0e13e
1 changed files with 15 additions and 0 deletions
|
|
@ -48,12 +48,27 @@ PATTERNS: list[tuple[str, str]] = [
|
|||
]
|
||||
|
||||
|
||||
def strip_commit_messages(cmd: str) -> str:
|
||||
"""Вырезает содержимое -m/--message аргументов git commit.
|
||||
|
||||
Иначе false-positive: `git commit -m "запретили rm -rf"` блокируется из-за
|
||||
текста сообщения. Пейлоады обёрток (powershell -c "git push --force") не
|
||||
страдают — они не привязаны к -m.
|
||||
"""
|
||||
return re.sub(
|
||||
r"(\s(?:-m|--message))\s+(\"(?:[^\"\\]|\\.)*\"|'[^']*')",
|
||||
r"\1 MSG",
|
||||
cmd,
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
try:
|
||||
data = json.load(sys.stdin)
|
||||
if data.get("tool_name") != "Bash":
|
||||
return 0
|
||||
cmd = (data.get("tool_input") or {}).get("command") or ""
|
||||
cmd = strip_commit_messages(cmd)
|
||||
for pattern, reason in PATTERNS:
|
||||
if re.search(pattern, cmd):
|
||||
print(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue