#!/usr/bin/env python3 # © 2026 TechnoLibre (http://www.technolibre.ca) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) """Hook commit-msg : refuse un sujet hors convention. Installation : git config core.hooksPath script/git/hooks Contournement pour un cas légitime : `git commit --no-verify`. """ import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from commit_msg_lib import check # noqa: E402 sys.path.insert(0, str(Path(__file__).resolve().parents[3])) try: from script.todo.todo_i18n import t except Exception: # pragma: no cover - repli si i18n indisponible def t(key: str) -> str: return key def main() -> int: if len(sys.argv) < 2: print(t("commit-msg: no message file received"), file=sys.stderr) return 1 path = Path(sys.argv[1]) try: message = path.read_text(encoding="utf-8") except OSError as exc: print(f"commit-msg : {exc}", file=sys.stderr) return 1 problems = check(message) if not problems: return 0 print("\n ✗ %s\n" % t("commit message off convention"), file=sys.stderr) for problem in problems: print(f" - {problem}", file=sys.stderr) print( t( "\n The rule: .claude/rules/04-code-conventions.md" "\n The manual: conf/template_claude_commands_commit.md" "\n Override for a legitimate case: git commit --no-verify\n" ), file=sys.stderr, ) return 1 if __name__ == "__main__": sys.exit(main())