Rien ne tenait la convention sur le sujet : le tag est respecté partout, c'est la longueur qui glisse. Le hook refuse le mécanique et rien de plus — tag absent, plus de 72 caractères, sujet ouvrant sur une citation ; dire sur quoi porte le code reste un jugement qu'aucun hook ne rendra. Il compte des caractères et non des octets, sans quoi un sujet français de 72 caractères tomberait sur ses accents. Le refus enseigne le repli vers des mots-clés plutôt que la troncature, et nomme `--no-verify` : un garde-fou qui refuse trop est désinstallé. Les tests pèsent donc autant les acceptations, « Merge branch » ou fixup de rebase. Le lanceur balaie le préfixe test_git_ : 32 tests jamais exécutés, le total va de 1021 à 1071. --- EN --- Nothing held the subject convention: the tag is respected everywhere, it is the length that slips. The hook refuses the mechanical and nothing more — no tag, over 72 characters, a subject opening on a quotation; whether it says what the code is about stays a judgement no hook will make. It counts characters, not bytes, or a 72-character French subject would fall on its accents. The refusal teaches the fallback to keywords rather than truncation, and names `--no-verify`: a guard rail that refuses too much gets uninstalled. So the tests weigh the acceptances as much, a "Merge branch" or a rebase fixup. The runner sweeps the test_git_ prefix: 32 tests never ran, and the total goes from 1021 to 1071. Assisted-by: Claude Opus 5 (cherry picked from commit c9abf4d1b723ae8ff3762d39bfe1d6982400d12d)
48 lines
1.3 KiB
Python
Executable file
48 lines
1.3 KiB
Python
Executable file
#!/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
|
|
|
|
|
|
def main() -> int:
|
|
if len(sys.argv) < 2:
|
|
print("commit-msg : aucun fichier de message reçu", 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 ✗ sujet de commit hors convention\n", file=sys.stderr)
|
|
for problem in problems:
|
|
print(f" - {problem}", file=sys.stderr)
|
|
print(
|
|
"\n La règle : .claude/rules/04-code-conventions.md"
|
|
"\n Le mode d'emploi : conf/template_claude_commands_commit.md"
|
|
"\n Passer outre pour un cas légitime : git commit --no-verify\n",
|
|
file=sys.stderr,
|
|
)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|