commit-check 2.19.4__py3-none-any.whl → 2.20.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,7 +21,7 @@ from dataclasses import dataclass
21
21
  from functools import lru_cache
22
22
 
23
23
  from commit_check.ai_signatures_data import ALL_KNOWN_TOOLS as _ALL_KNOWN_TOOLS
24
- from commit_check.ai_signatures_data import GENERIC_AI, ROLE_DISCLOSURE
24
+ from commit_check.ai_signatures_data import GENERIC_AI, ROLE_CO_AUTHOR, ROLE_DISCLOSURE
25
25
 
26
26
  # Re-export for convenience — consumers can import everything from
27
27
  # commit_check.ai_signatures without knowing about the data/logic split.
@@ -235,6 +235,26 @@ def detect_ai_signatures(message: str) -> list[dict[str, str]]:
235
235
  return results
236
236
 
237
237
 
238
+ def detect_ai_author(name: str, email: str) -> str | None:
239
+ """The AI tool a commit's author identity names, or ``None``.
240
+
241
+ An author is judged exactly as the same identity would be on a
242
+ ``Co-authored-by:`` line, so the two can never disagree about who is a
243
+ tool: ``google-labs-jules[bot]``, ``openhands <openhands@all-hands.dev>``,
244
+ a name ending in ``(aider)``, any name at Copilot's account address.
245
+ """
246
+ name = " ".join(name.split())
247
+ email = "".join(email.split())
248
+ if not name and not email:
249
+ return None
250
+ identity = f"{name} <{email}>" if email else name
251
+ signatures = detect_ai_signatures(f"x\n\nCo-authored-by: {identity}")
252
+ return next(
253
+ (s["tool"] for s in signatures if s["role"] == ROLE_CO_AUTHOR),
254
+ None,
255
+ )
256
+
257
+
238
258
  def has_ai_signature(message: str) -> bool:
239
259
  """Return ``True`` if *message* contains any known AI signature.
240
260
 
@@ -130,6 +130,15 @@ def _identity(value_pattern: str, label: str) -> list[AiSignaturePattern]:
130
130
  ]
131
131
 
132
132
 
133
+ def _app_bot(login: str) -> list[AiSignaturePattern]:
134
+ """The identity of a tool's GitHub App: ``<login>[bot]``, with any address.
135
+
136
+ A GitHub App commits under its own ``[bot]`` account, and no person can
137
+ hold that name, so the address needs no anchoring.
138
+ """
139
+ return _identity(rf"{re.escape(login)}\[bot\][ \t]*(?:<[^>\n]*>)?", f"{login}[bot]")
140
+
141
+
133
142
  def _disclosure(key: str, description: str) -> AiSignaturePattern:
134
143
  """A trailer that exists to disclose AI assistance, whatever its value."""
135
144
  return _trailer((key,), r"\S[^\n]*", ROLE_DISCLOSURE, description)
@@ -180,6 +189,8 @@ CLAUDE_CODE = KnownAiTool(
180
189
  # variants such as "Claude Opus 4.5 (1M context)" that the pattern
181
190
  # above misses.
182
191
  *_identity(r"[^<\n]*<noreply@anthropic\.com>", "... <noreply@anthropic.com>"),
192
+ # The Claude GitHub App, which commits as itself.
193
+ *_app_bot("claude"),
183
194
  # Body marker: generated-with notice
184
195
  _body_marker(
185
196
  r"🤖\s*Generated\s+(?:with|by)\s+\[?Claude",
@@ -221,6 +232,8 @@ CODEX = KnownAiTool(
221
232
  name_pattern=_names(r"codex"),
222
233
  patterns=[
223
234
  *_identity(r"Codex[ \t]*(?:<[^>\n]*>)?", "Codex"),
235
+ # Codex in the cloud commits through its GitHub App.
236
+ *_app_bot("chatgpt-codex-connector"),
224
237
  ],
225
238
  )
226
239
 
@@ -242,6 +255,8 @@ CURSOR = KnownAiTool(
242
255
  # Cursor's agent signs as ``Cursor Agent <cursoragent@cursor.com>``;
243
256
  # the address catches it under any display name.
244
257
  *_identity(r"[^<\n]*<cursoragent@cursor\.com>", "... <cursoragent@cursor.com>"),
258
+ # Cursor's background agent commits through its GitHub App.
259
+ *_app_bot("cursor"),
245
260
  # Cursor's own mark on commits it writes:
246
261
  # https://forum.cursor.com/t/allow-disabling-made-with-cursor-commit-trailer/154494
247
262
  _trailer(
@@ -280,6 +295,10 @@ AIDER = KnownAiTool(
280
295
  name_pattern=_names(r"aider"),
281
296
  patterns=[
282
297
  *_identity(r"Aider[ \t]*(?:<[^>\n]*>)?", "Aider"),
298
+ # aider's own trailer names the model, on by default since v0.85:
299
+ # "Co-authored-by: aider (<model>) <aider@aider.chat>", see
300
+ # https://github.com/Aider-AI/aider/blob/main/aider/repo.py
301
+ *_identity(r"[^<\n]*<aider@aider\.chat>", "... <aider@aider.chat>"),
283
302
  # aider appends "(aider)" to the author name
284
303
  *_identity(r"[^<\n]+\(aider\)[ \t]*(?:<[^>\n]*>)?", "... (aider)"),
285
304
  ],
@@ -356,6 +375,72 @@ JULES = KnownAiTool(
356
375
  ],
357
376
  )
358
377
 
378
+ # --- Continue (continue.dev) ---
379
+ # The Continue CLI injects a commit signature by default, unless
380
+ # CONTINUE_CLI_DISABLE_COMMIT_SIGNATURE is set: a "Generated with [Continue]"
381
+ # body marker and a Co-authored-by trailer with the continue.dev address.
382
+ # https://github.com/continuedev/continue/blob/main/extensions/cli/src/systemMessage.ts
383
+ # "Continue" is a common English word (and a possible surname), so the
384
+ # co-author / sign-off patterns are anchored to the continue.dev address and
385
+ # the body marker to its URL; the tool gets no broad name_pattern, so a bare
386
+ # "continue" in prose or a human co-author is never flagged.
387
+ CONTINUE = KnownAiTool(
388
+ name="Continue",
389
+ patterns=[
390
+ *_identity(
391
+ r"[^<\n]*<noreply@continue\.dev>", "Continue <noreply@continue.dev>"
392
+ ),
393
+ _body_marker(
394
+ r"Generated with \[Continue\]\(https://continue\.dev\)",
395
+ "``Generated with [Continue](https://continue.dev)`` body marker",
396
+ ),
397
+ ],
398
+ )
399
+
400
+ # --- Mistral Vibe ---
401
+ # Vibe's system prompt tells the model to end every commit with a signature,
402
+ # on unless include_commit_signature = false in config.toml:
403
+ # "Generated by Mistral Vibe." and a Co-Authored-By trailer with vibe@mistral.ai.
404
+ # https://github.com/mistralai/mistral-vibe/blob/main/vibe/core/system_prompt.py
405
+ # The model writes the signature itself, so the name and the address are each
406
+ # matched on their own. "Vibe" alone is a common word, so only "Mistral Vibe"
407
+ # names the tool.
408
+ MISTRAL_VIBE = KnownAiTool(
409
+ name="Mistral Vibe",
410
+ name_pattern=_names(r"mistral[ \t-]?vibe"),
411
+ patterns=[
412
+ *_identity(r"Mistral[ \t]+Vibe[ \t]*(?:<[^>\n]*>)?", "Mistral Vibe"),
413
+ *_identity(r"[^<\n]*<vibe@mistral\.ai>", "... <vibe@mistral.ai>"),
414
+ _body_marker(
415
+ r"^Generated by Mistral Vibe\b", "``Generated by Mistral Vibe`` body marker"
416
+ ),
417
+ ],
418
+ )
419
+
420
+ # --- Qwen Code (Alibaba) ---
421
+ # Qwen Code appends "Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>"
422
+ # to the commits it makes, on unless the gitCoAuthor.commit setting is off:
423
+ # https://github.com/QwenLM/qwen-code/blob/main/packages/core/src/config/config.ts
424
+ QWEN_CODE = KnownAiTool(
425
+ name="Qwen Code",
426
+ name_pattern=_names(r"qwen[ \t-]?code|qwen-coder"),
427
+ patterns=[
428
+ *_identity(r"Qwen-Coder[ \t]*(?:<[^>\n]*>)?", "Qwen-Coder"),
429
+ *_identity(
430
+ r"[^<\n]*<qwen-coder@alibabacloud\.com>",
431
+ "... <qwen-coder@alibabacloud.com>",
432
+ ),
433
+ ],
434
+ )
435
+
436
+ # --- Amazon Q Developer ---
437
+ # The Amazon Q Developer agent commits through its GitHub App.
438
+ AMAZON_Q = KnownAiTool(
439
+ name="Amazon Q Developer",
440
+ name_pattern=_names(r"amazon[ \t]+q(?:[ \t]+developer)?|amazon-q-developer"),
441
+ patterns=[*_app_bot("amazon-q-developer")],
442
+ )
443
+
359
444
  # --- Generic / catch-all AI patterns ---
360
445
  GENERIC_AI = KnownAiTool(
361
446
  name="Generic AI",
@@ -416,5 +501,9 @@ ALL_KNOWN_TOOLS: list[KnownAiTool] = [
416
501
  OPENHANDS,
417
502
  FACTORY_DROID,
418
503
  JULES,
504
+ CONTINUE,
505
+ MISTRAL_VIBE,
506
+ QWEN_CODE,
507
+ AMAZON_Q,
419
508
  GENERIC_AI,
420
509
  ]
commit_check/config.py CHANGED
@@ -7,19 +7,13 @@ import io
7
7
  import os
8
8
  import stat
9
9
  import sys
10
+ import tomllib
10
11
  import urllib.error
11
12
  import urllib.request
12
13
  from pathlib import Path
13
14
  from typing import Any
14
15
 
15
- try:
16
- import tomllib
17
-
18
- toml_load = tomllib.load
19
- except ImportError:
20
- import tomli # type: ignore
21
-
22
- toml_load = tomli.load
16
+ toml_load = tomllib.load
23
17
 
24
18
 
25
19
  class ConfigError(ValueError):
@@ -253,8 +247,7 @@ def _resolve_inherit_from(
253
247
  # Fail open, as documented: a parent that cannot be loaded leaves the
254
248
  # local config in force. Say so on stderr rather than silently, and keep
255
249
  # stdout clean for --format json.
256
- # TOMLDecodeError (tomllib and tomli alike) is a ValueError; URLError is
257
- # an OSError.
250
+ # TOMLDecodeError is a ValueError; URLError is an OSError.
258
251
  try:
259
252
  parent = _load_parent_config(inherit_from, base_dir)
260
253
  except (OSError, ValueError) as e:
@@ -116,6 +116,12 @@ def get_default_config() -> dict[str, Any]:
116
116
  #: ``[jira]`` and ``[pull_request]`` by the GitHub App.
117
117
  _OTHER_KEYS = frozenset({"warn", "jira", "pull_request"})
118
118
 
119
+ #: Keys inside the CLI's own tables that only the GitHub App reads:
120
+ #: ``require_verified`` needs GitHub's verdict on a commit's signature.
121
+ _OTHER_SETTINGS: dict[str, frozenset[str]] = {
122
+ "commit": frozenset({"require_verified"}),
123
+ }
124
+
119
125
 
120
126
  def unknown_setting_warnings(config: dict[str, Any]) -> list[str]:
121
127
  """One line per setting in a config file that nothing reads.
@@ -134,6 +140,7 @@ def unknown_setting_warnings(config: dict[str, Any]) -> list[str]:
134
140
  (f"[{section}] {key}", key, defaults[section])
135
141
  for key in value
136
142
  if key not in defaults[section]
143
+ and key not in _OTHER_SETTINGS.get(section, ())
137
144
  )
138
145
  warnings = []
139
146
  for shown, name, known in names:
commit_check/engine.py CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import os
5
6
  import re
6
7
  import shlex
7
8
  import subprocess
@@ -19,6 +20,7 @@ from commit_check import (
19
20
  ai_policy,
20
21
  )
21
22
  from commit_check.ai_signatures import (
23
+ detect_ai_author,
22
24
  detect_ai_signatures,
23
25
  )
24
26
  from commit_check.fixes import (
@@ -43,6 +45,7 @@ from commit_check.util import (
43
45
  get_git_config_value,
44
46
  get_git_remotes,
45
47
  get_git_user_identity,
48
+ get_pending_author_identity,
46
49
  get_push_commits,
47
50
  get_tags_at,
48
51
  get_upstream_branch,
@@ -74,6 +77,10 @@ def is_merge_subject(subject: str) -> bool:
74
77
  _WIP_MARKER = re.compile(r"^[ \t]*(?:\[wip\]|wip\b)", re.IGNORECASE)
75
78
 
76
79
 
80
+ #: The git config key naming the person who will author the next commit.
81
+ _USER_NAME = "user.name"
82
+
83
+
77
84
  class ValidationResult(IntEnum):
78
85
  """Validation result codes.
79
86
 
@@ -265,8 +272,10 @@ class BaseValidator(ABC):
265
272
 
266
273
  *Prospective message* (``stdin_text`` or ``commit_file`` is set):
267
274
  the user is about to create a new commit. The last commit's author
268
- is unrelated — the relevant identity is the local git config
269
- (``user.name``), i.e. the person who will author the pending commit.
275
+ is unrelated — the relevant identity is the one git would record:
276
+ ``GIT_AUTHOR_NAME`` when set (how a tool commits under its own name,
277
+ and how the Action passes on the author of a commit it pipes in),
278
+ else ``user.name``.
270
279
 
271
280
  *Existing commit* (no ``stdin_text``, no ``commit_file``):
272
281
  the last commit is the one being validated. Use its own author
@@ -278,8 +287,12 @@ class BaseValidator(ABC):
278
287
  # fact about that commit, so the config never enters into it.
279
288
  return get_commit_info("an", context.rev)
280
289
  if context.stdin_text is not None or context.commit_file is not None:
281
- return get_git_config_value("user.name") or get_commit_info("an")
282
- return get_commit_info("an") or get_git_config_value("user.name")
290
+ return (
291
+ os.environ.get("GIT_AUTHOR_NAME", "").strip()
292
+ or get_git_config_value(_USER_NAME)
293
+ or get_commit_info("an")
294
+ )
295
+ return get_commit_info("an") or get_git_config_value(_USER_NAME)
283
296
 
284
297
  @staticmethod
285
298
  def _message_was_supplied(context: ValidationContext) -> bool:
@@ -695,7 +708,7 @@ class AuthorValidator(BaseValidator):
695
708
  return supplied.strip()
696
709
 
697
710
  git_config_map = {
698
- "author_name": "user.name",
711
+ "author_name": _USER_NAME,
699
712
  "author_email": "user.email",
700
713
  }
701
714
  git_log_map = {
@@ -1613,6 +1626,45 @@ class AiAttributionValidator(BaseValidator):
1613
1626
  return ValidationResult.FAIL
1614
1627
 
1615
1628
 
1629
+ class AiAuthorValidator(BaseValidator):
1630
+ """Rejects a commit whose author is an AI tool (CC017).
1631
+
1632
+ Under both ``forbid`` and ``disclose``: a tool in the author's place,
1633
+ with the person behind it at most a ``Co-authored-by:`` line, is the
1634
+ strongest attribution a commit can make. An existing commit (``--rev``,
1635
+ or HEAD) is judged by its recorded author; a message not yet committed
1636
+ by the author git would record for it, which honours ``GIT_AUTHOR_NAME``
1637
+ and ``GIT_AUTHOR_EMAIL`` the way ``git commit`` does.
1638
+ """
1639
+
1640
+ def validate(self, context: ValidationContext) -> ValidationResult:
1641
+ if self._should_skip_commit_validation(context):
1642
+ return ValidationResult.SKIP
1643
+
1644
+ if context.rev is None and (
1645
+ context.stdin_text is not None or context.commit_file is not None
1646
+ ):
1647
+ name, email = get_pending_author_identity()
1648
+ else:
1649
+ name, email = get_commit_author_identity(context.rev or "HEAD")
1650
+ identity = f"{name} <{email}>" if email else name
1651
+ self._checked_value = identity
1652
+ tool = detect_ai_author(name, email)
1653
+ if tool is None:
1654
+ return ValidationResult.PASS
1655
+
1656
+ suggest = "Author the commit yourself: git commit --amend --reset-author"
1657
+ if self.rule.value == "disclose":
1658
+ trailers = self.rule.allowed or list(DEFAULT_AI_DISCLOSURE_TRAILERS)
1659
+ suggest += f', and disclose the tool with "{trailers[0]}: {tool}"'
1660
+ self._print_failure(
1661
+ identity,
1662
+ error=f"An AI tool is the commit author: {tool}",
1663
+ suggest=suggest,
1664
+ )
1665
+ return ValidationResult.FAIL
1666
+
1667
+
1616
1668
  class ValidationEngine:
1617
1669
  """Main validation engine that orchestrates all validations."""
1618
1670
 
@@ -1639,6 +1691,7 @@ class ValidationEngine:
1639
1691
  "ai_disclosure": AiAttributionValidator,
1640
1692
  "ai_co_author": AiAttributionValidator,
1641
1693
  "ai_signoff": AiAttributionValidator,
1694
+ "ai_author": AiAuthorValidator,
1642
1695
  "tag": TagValidator,
1643
1696
  "file_size": FilesValidator,
1644
1697
  "file_pattern": FilesValidator,
commit_check/main.py CHANGED
@@ -22,6 +22,7 @@ from commit_check.rule_builder import RuleBuilder
22
22
  from commit_check.rules_catalog import BRANCH_CHECKS, FILES_CHECKS, MESSAGE_CHECKS
23
23
  from commit_check.util import (
24
24
  get_remote_branch_sha,
25
+ git_repository_error,
25
26
  git_rev_parse_verify,
26
27
  print_error_header,
27
28
  split_message_comments,
@@ -136,8 +137,8 @@ def _get_parser() -> argparse.ArgumentParser:
136
137
  "exit codes:\n"
137
138
  " 0 every enforced check passed, or --dry-run was given\n"
138
139
  " 1 a check failed\n"
139
- " 2 the run could not start: bad usage, or a missing or "
140
- "invalid config file"
140
+ " 2 the run could not start: bad usage, a missing or invalid "
141
+ "config file, or git cannot read the repository"
141
142
  ),
142
143
  )
143
144
 
@@ -308,7 +309,7 @@ def _get_parser() -> argparse.ArgumentParser:
308
309
  type=parse_int,
309
310
  default=None,
310
311
  metavar="INT",
311
- help="maximum length of commit subject",
312
+ help="maximum length of commit subject; 0 turns the check off",
312
313
  )
313
314
 
314
315
  commit_group.add_argument(
@@ -316,7 +317,7 @@ def _get_parser() -> argparse.ArgumentParser:
316
317
  type=parse_int,
317
318
  default=None,
318
319
  metavar="INT",
319
- help="minimum length of commit subject",
320
+ help="minimum length of commit subject; 0 turns the check off",
320
321
  )
321
322
 
322
323
  commit_group.add_argument(
@@ -601,6 +602,38 @@ def _resolve_commit_message_source(
601
602
  return stdin_content or None, None
602
603
 
603
604
 
605
+ def _reads_repository(
606
+ args: argparse.Namespace,
607
+ stdin_content: str | None,
608
+ commit_file_path: str | None,
609
+ ) -> bool:
610
+ """Whether a requested check has to read the repository.
611
+
612
+ A message that comes from a file or stdin needs no repository, and
613
+ neither does a branch name or author piped in on stdin. Anything else
614
+ asks git, and when git cannot read the repository each of those checks
615
+ would come back skipped, which exits 0 as if the run had been judged.
616
+ """
617
+ if args.message and stdin_content is None and commit_file_path is None:
618
+ return True
619
+ if args.tag or args.files or args.no_force_push:
620
+ return True
621
+ if args.branch or args.author_name or args.author_email:
622
+ # Beside --message, stdin is the message, so these read git.
623
+ return args.message or stdin_content is None
624
+ return False
625
+
626
+
627
+ def _report_unreadable_repository(reason: str) -> int:
628
+ """Say that git cannot read the repository, and exit as a setup error."""
629
+ print(
630
+ "Error: git cannot read a repository here, so nothing can be checked:",
631
+ file=sys.stderr,
632
+ )
633
+ print(reason, file=sys.stderr)
634
+ return EXIT_CONFIG_ERROR
635
+
636
+
604
637
  def _resolve_stdin_for_non_message(
605
638
  args: argparse.Namespace, stdin_reader: StdinReader
606
639
  ) -> tuple[str | None, bool]:
@@ -714,6 +747,9 @@ def main() -> int:
714
747
  "--rev and a commit message file both name the "
715
748
  "thing to check; pass one or the other"
716
749
  )
750
+ repo_error = git_repository_error()
751
+ if repo_error:
752
+ return _report_unreadable_repository(repo_error)
717
753
  # Fail here, with the revision named, rather than deep inside a
718
754
  # validator where the error would surface as a missing message.
719
755
  if not git_rev_parse_verify(args.rev):
@@ -787,6 +823,13 @@ def main() -> int:
787
823
  # Next to --message, piped stdin is the message; other checks read git.
788
824
  stdin_is_message = args.message and stdin_content is not None
789
825
 
826
+ if args.rev is None and _reads_repository(
827
+ args, stdin_content, commit_file_path
828
+ ):
829
+ repo_error = git_repository_error()
830
+ if repo_error:
831
+ return _report_unreadable_repository(repo_error)
832
+
790
833
  if args.fix and not commit_file_path:
791
834
  parser.error("--fix rewrites a commit message file; pass one")
792
835
  if args.fix and commit_file_path and not args.dry_run:
@@ -35,11 +35,12 @@ from commit_check.util import format_size, parse_size
35
35
 
36
36
  #: The checks each ``ai_attribution`` policy builds. ``forbid`` rejects every
37
37
  #: AI signature under one rule; ``disclose`` asks for three things, one rule
38
- #: each, so a project can warn on one while enforcing the others.
38
+ #: each, so a project can warn on one while enforcing the others. Both reject
39
+ #: a tool as the commit's author (CC017).
39
40
  _AI_CHECKS_BY_POLICY: dict[str, frozenset[str]] = {
40
41
  "ignore": frozenset(),
41
- "forbid": frozenset({"ai_attribution"}),
42
- "disclose": frozenset({"ai_disclosure", "ai_co_author", "ai_signoff"}),
42
+ "forbid": frozenset({"ai_attribution", "ai_author"}),
43
+ "disclose": frozenset({"ai_disclosure", "ai_co_author", "ai_signoff", "ai_author"}),
43
44
  }
44
45
  _AI_CHECKS: frozenset[str] = frozenset().union(*_AI_CHECKS_BY_POLICY.values())
45
46
 
@@ -575,7 +576,7 @@ class RuleBuilder:
575
576
  def _build_length_rule(
576
577
  self, catalog_entry: RuleCatalogEntry, config_key: str
577
578
  ) -> ValidationRule | None:
578
- """Build subject length validation rule."""
579
+ """Build subject length validation rule; 0 switches the rule off."""
579
580
  length = self.commit_config.get(config_key)
580
581
  if length is None:
581
582
  return None
@@ -585,6 +586,11 @@ class RuleBuilder:
585
586
  raise ConfigError(
586
587
  f"{setting} must be a whole number, got {length!r}", setting=setting
587
588
  )
589
+ # 0 turns the rule off, as max_path_length = 0 does. It used to be a
590
+ # limit of 0 characters, so a project that only wanted the AI check
591
+ # had to pick an arbitrary large number to get rid of the length one.
592
+ if length <= 0:
593
+ return None
588
594
 
589
595
  # The suggestion is templated on the same values as the error: naming
590
596
  # the configured length is the whole point of the advice, and "the
@@ -656,7 +662,7 @@ class RuleBuilder:
656
662
  ) -> ValidationRule | None:
657
663
  """Build one of the AI attribution rules, when the policy asks for it.
658
664
 
659
- ``forbid`` builds CC013 alone. ``disclose`` builds CC014–CC016, each
665
+ ``forbid`` builds CC013 and CC017. ``disclose`` builds CC014–CC017, each
660
666
  carrying the accepted trailers and the value pattern, so any one of
661
667
  them can judge a message by itself. ``ignore`` builds nothing.
662
668
  """
@@ -850,7 +856,9 @@ class RuleBuilder:
850
856
  # is anchored at both ends so a name has to match the whole branch
851
857
  # name, not merely its start ("main-backup" is not "main"). develop
852
858
  # is the specification's third trunk branch, beside main and master.
853
- names_pattern = "master|main|develop|HEAD|PR-.+"
859
+ # gh-readonly-queue/<base>/pr-<N>-<sha> is the branch GitHub's merge
860
+ # queue creates and runs merge_group checks on; nobody names it.
861
+ names_pattern = "master|main|develop|HEAD|PR-.+|gh-readonly-queue/.+"
854
862
  if allowed_names:
855
863
  names_pattern += "|" + "|".join(allowed_names)
856
864
  description_pattern = (
@@ -218,6 +218,16 @@ COMMIT_RULES = [
218
218
  error="An AI tool signed off the commit",
219
219
  suggest="Only a person can certify the Developer Certificate of Origin: remove the AI Signed-off-by line and sign off yourself (git commit --signoff)",
220
220
  ),
221
+ # Under both forbid and disclose: a tool in the author's place is the
222
+ # strongest attribution there is. Read from the commit, so it judges
223
+ # existing commits (--rev, or HEAD) and passes a message not yet committed.
224
+ RuleCatalogEntry(
225
+ rule_id="CC017",
226
+ check="ai_author",
227
+ regex=None,
228
+ error="An AI tool is the commit author",
229
+ suggest="Author the commit yourself: git commit --amend --reset-author",
230
+ ),
221
231
  ]
222
232
 
223
233
  # Push rules
commit_check/util.py CHANGED
@@ -539,6 +539,35 @@ def has_commits() -> bool:
539
539
  return False
540
540
 
541
541
 
542
+ def git_repository_error() -> str | None:
543
+ """Why git cannot read a repository here, or ``None`` when it can.
544
+
545
+ git refuses outright outside a work tree, and in one owned by another
546
+ user unless ``safe.directory`` allows it (a mounted checkout in a
547
+ container, say). Every git call then fails, and each check would read
548
+ that as "nothing to check" and pass the run as skipped, so the reason
549
+ git gives is what the caller reports instead.
550
+
551
+ A repository with no commits yet is readable: this asks for the git
552
+ directory, not for HEAD.
553
+
554
+ :returns: git's own message, or a sentence saying git could not run.
555
+ """
556
+ try:
557
+ result = subprocess.run(
558
+ ["git", "rev-parse", "--git-dir"],
559
+ capture_output=True,
560
+ check=False,
561
+ encoding="utf-8",
562
+ errors="replace",
563
+ )
564
+ except OSError as e:
565
+ return f"git could not be run: {e}"
566
+ if result.returncode == 0:
567
+ return None
568
+ return result.stderr.strip() or f"git rev-parse exited {result.returncode}"
569
+
570
+
542
571
  def git_rev_parse_verify(rev: str) -> bool:
543
572
  """Check whether a revision resolves in the current repository.
544
573
  :param rev: any revision expression, e.g. ``HEAD^2``
@@ -687,6 +716,21 @@ def get_git_user_identity() -> tuple[str, str]:
687
716
  return identity["user.name"], identity["user.email"]
688
717
 
689
718
 
719
+ def get_pending_author_identity() -> tuple[str, str]:
720
+ """The author name and email the next commit will carry, or two blanks.
721
+
722
+ ``git var GIT_AUTHOR_IDENT`` answers as ``git commit`` would: from
723
+ ``GIT_AUTHOR_NAME`` / ``GIT_AUTHOR_EMAIL`` when they are set (a tool
724
+ that commits under its own name sets them), else from ``user.name`` /
725
+ ``user.email``. With neither, git prints an error, which matches nothing.
726
+ """
727
+ output = cmd_output(["git", "var", "GIT_AUTHOR_IDENT"]).strip()
728
+ match = re.fullmatch(r"(.*) <([^<>\n]*)> \d+ [+-]\d{4}", output)
729
+ if not match:
730
+ return "", ""
731
+ return match.group(1).strip(), match.group(2).strip()
732
+
733
+
690
734
  def get_commit_author_identity(sha: str = "HEAD") -> tuple[str, str]:
691
735
  """The author name and email of a commit, in one git call."""
692
736
  name, _, email = get_commit_info("an%x1f%ae", sha).partition("\x1f")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commit-check
3
- Version: 2.19.4
3
+ Version: 2.20.0
4
4
  Summary: Commit policy as code for teams and AI agents: check commit messages, branch names, authors, tags, files and AI attribution.
5
5
  Author-email: Xianpeng Shen <xianpeng.shen@gmail.com>
6
6
  License-Expression: MIT
@@ -12,7 +12,6 @@ Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: Natural Language :: English
14
14
  Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3.10
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
@@ -21,12 +20,11 @@ Classifier: Programming Language :: Python :: 3.15
21
20
  Classifier: Topic :: Utilities
22
21
  Classifier: Topic :: Software Development :: Build Tools
23
22
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
- Requires-Python: >=3.10
23
+ Requires-Python: >=3.11
25
24
  Description-Content-Type: text/markdown
26
25
  License-File: LICENSE
27
- Requires-Dist: tomli>=1.1.0; python_version < "3.11"
28
26
  Provides-Extra: dev
29
- Requires-Dist: nox==2026.8.17; extra == "dev"
27
+ Requires-Dist: nox==2026.10.20; extra == "dev"
30
28
  Provides-Extra: test
31
29
  Requires-Dist: coverage; extra == "test"
32
30
  Requires-Dist: pytest; extra == "test"
@@ -74,7 +72,7 @@ free for public repositories and personal accounts.
74
72
  ## Quick start
75
73
 
76
74
  ```bash
77
- pip install commit-check # Python 3.10+
75
+ pip install commit-check # Python 3.11+
78
76
  commit-check --message --branch
79
77
  ```
80
78
 
@@ -88,7 +86,7 @@ Stop bad commits before they exist. In `.pre-commit-config.yaml`:
88
86
  ```yaml
89
87
  repos:
90
88
  - repo: https://github.com/commit-check/commit-check
91
- rev: v2.19.4
89
+ rev: v2.19.5
92
90
  hooks:
93
91
  - id: check-message
94
92
  - id: check-branch
@@ -115,7 +113,7 @@ The same `cchk.toml` drives all of them:
115
113
  | Check | Flag | Rules |
116
114
  |---|---|---|
117
115
  | Commit message — Conventional Commits, subject length, case and mood, WIP and fixup commits, body, sign-off | `--message` | CC001–CC012 |
118
- | AI attribution — forbid it, or require an `Assisted-by:` disclosure | `--message` | CC013–CC016 |
116
+ | AI attribution — forbid it, or require an `Assisted-by:` disclosure | `--message` | CC013–CC017 |
119
117
  | Author name and email | `--author-name` `--author-email` | CC101–CC102 |
120
118
  | Branch name — Conventional Branch, rebased onto a target | `--branch` | CC201–CC202 |
121
119
  | Force push | `--no-force-push` | CC301 |
@@ -157,8 +155,8 @@ Priority: CLI > env > TOML > default. Booleans accept `true/false`, `yes/no`,
157
155
  | `commit.message_pattern` | `""` | — | `CCHK_MESSAGE_PATTERN` | Custom regex the whole message must match; when set it replaces the Conventional Commits check (still reported as CC001) |
158
156
  | `commit.subject_capitalized` | `false` | `--subject-capitalized` | `CCHK_SUBJECT_CAPITALIZED` | Require the subject to start with a capital letter (CC002) |
159
157
  | `commit.subject_imperative` | `false` | `--subject-imperative` | `CCHK_SUBJECT_IMPERATIVE` | Require the subject to use the imperative mood (CC003) |
160
- | `commit.subject_max_length` | `80` | `--subject-max-length` | `CCHK_SUBJECT_MAX_LENGTH` | Maximum subject length (CC004) |
161
- | `commit.subject_min_length` | `5` | `--subject-min-length` | `CCHK_SUBJECT_MIN_LENGTH` | Minimum subject length (CC005) |
158
+ | `commit.subject_max_length` | `80` | `--subject-max-length` | `CCHK_SUBJECT_MAX_LENGTH` | Maximum subject length (CC004); `0` turns it off |
159
+ | `commit.subject_min_length` | `5` | `--subject-min-length` | `CCHK_SUBJECT_MIN_LENGTH` | Minimum subject length (CC005); `0` turns it off |
162
160
  | `commit.allow_commit_types` | `feat, fix, docs, style, refactor, test, chore, perf, build, ci` | `--allow-commit-types` | `CCHK_ALLOW_COMMIT_TYPES` | Allowed `<type>` values in the subject |
163
161
  | `commit.allow_merge_commits` | `true` | `--allow-merge-commits` | `CCHK_ALLOW_MERGE_COMMITS` | Allow merge commits (CC006) |
164
162
  | `commit.allow_revert_commits` | `true` | `--allow-revert-commits` | `CCHK_ALLOW_REVERT_COMMITS` | Allow revert commits (CC007) |
@@ -168,7 +166,7 @@ Priority: CLI > env > TOML > default. Booleans accept `true/false`, `yes/no`,
168
166
  | `commit.require_body` | `false` | `--require-body` | `CCHK_REQUIRE_BODY` | Require a commit body (CC011) |
169
167
  | `commit.require_signed_off_by` | `false` | `--require-signed-off-by` | `CCHK_REQUIRE_SIGNED_OFF_BY` | Require a `Signed-off-by:` trailer (CC012) |
170
168
  | `commit.ignore_authors` | `[]` | `--ignore-authors` | `CCHK_IGNORE_AUTHORS` | Authors and co-authors whose commits skip the commit checks |
171
- | `commit.ai_attribution` | `"ignore"` | `--ai-attribution` | `CCHK_AI_ATTRIBUTION` | `ignore`, `forbid` or `disclose`. `forbid` rejects commits carrying known AI tool signatures (CC013); `disclose` accepts AI assistance disclosed with one of `ai_disclosure_trailers` (CC014) and rejects the tool as a co-author (CC015) or as a sign-off (CC016) |
169
+ | `commit.ai_attribution` | `"ignore"` | `--ai-attribution` | `CCHK_AI_ATTRIBUTION` | `ignore`, `forbid` or `disclose`. `forbid` rejects commits carrying known AI tool signatures (CC013); `disclose` accepts AI assistance disclosed with one of `ai_disclosure_trailers` (CC014) and rejects the tool as a co-author (CC015) or as a sign-off (CC016); both reject a commit whose author is an AI tool (CC017) |
172
170
  | `commit.ai_disclosure_trailers` | `Assisted-by, Generated-by` | `--ai-disclosure-trailers` | `CCHK_AI_DISCLOSURE_TRAILERS` | Trailers that disclose AI assistance under `disclose`; the first is the one a fix is written with. List `Co-authored-by` to accept the tool as a co-author |
173
171
  | `commit.ai_disclosure_pattern` | `""` | `--ai-disclosure-pattern` | `CCHK_AI_DISCLOSURE_PATTERN` | Regex the disclosure's value must match under `disclose`, e.g. `^\S+/\S+` for `agent/model`; empty accepts any value, but a trailer with no value at all is always reported |
174
172
  | `commit.author_email_pattern` | `"^.+@.+$"` | `--author-email-pattern` | `CCHK_AUTHOR_EMAIL_PATTERN` | Regex the author email must match (CC102, with `--author-email`) |
@@ -176,7 +174,7 @@ Priority: CLI > env > TOML > default. Booleans accept `true/false`, `yes/no`,
176
174
  | `branch.conventional_branch` | `true` | `--conventional-branch` | `CCHK_CONVENTIONAL_BRANCH` | Enforce `<type>/<description>` branch names (CC201) |
177
175
  | `branch.require_description_grammar` | `false` | `--require-description-grammar` | `CCHK_REQUIRE_DESCRIPTION_GRAMMAR` | Also hold the description after `<type>/` to the Conventional Branch grammar: lowercase alphanumeric words joined by single hyphens, dots allowed inside a word (CC201). Off by default, since bot branches such as `dependabot/npm_and_yarn/lodash-4.17.21` do not follow it |
178
176
  | `branch.allow_branch_types` | `feature, bugfix, hotfix, release, chore, feat, fix, build, ci, docs, perf, refactor, test, style, ai, claude, codex, copilot, cursor, agents, dependabot, renovate` | `--allow-branch-types` | `CCHK_ALLOW_BRANCH_TYPES` | Allowed branch `<type>` prefixes; each entry is a regex matched against the whole type |
179
- | `branch.allow_branch_names` | `[]` | `--allow-branch-names` | `CCHK_ALLOW_BRANCH_NAMES` | Extra branch names allowed besides `main`, `master`, `develop`, `HEAD`, `PR-.+`; each entry is a regex matched against the whole branch name, so `create-pull-request/.+` allows a family of them |
177
+ | `branch.allow_branch_names` | `[]` | `--allow-branch-names` | `CCHK_ALLOW_BRANCH_NAMES` | Extra branch names allowed besides `main`, `master`, `develop`, `HEAD`, `PR-.+`, `gh-readonly-queue/.+` (GitHub merge queue); each entry is a regex matched against the whole branch name, so `create-pull-request/.+` allows a family of them |
180
178
  | `branch.require_rebase_target` | `""` | `--require-rebase-target` | `CCHK_REQUIRE_REBASE_TARGET` | Branch the current branch must be rebased onto (CC202); empty disables |
181
179
  | `branch.ignore_authors` | `[]` | `--branch-ignore-authors` | `CCHK_BRANCH_IGNORE_AUTHORS` | Authors whose branches skip the branch checks |
182
180
  | `push.allow_force_push` | `true` | — (`--no-force-push` runs the check) | `CCHK_ALLOW_FORCE_PUSH` | Reserved; has no effect today. CC301 runs only with `--no-force-push`, which always rejects a non-fast-forward push |
@@ -237,7 +235,8 @@ page covers each function and how to load a repository's file.
237
235
  Exit codes: `0` passed · `1` a check failed · `2` nothing was checked — bad
238
236
  usage, or a config that is missing, is not valid TOML, names an unknown rule,
239
237
  holds a regex that does not compile or gives a `[commit]` or `[branch]` setting
240
- a value of the wrong type (`subject_max_length = "abc"`). A `[files]` value it
238
+ a value of the wrong type (`subject_max_length = "abc"`), or git cannot read the
239
+ repository (not a repository, or "dubious ownership"). A `[files]` value it
241
240
  cannot use turns that rule off with a notice instead. `--dry-run` reports everything and exits `0`. More output formats: [examples](https://commit-check.com/example/).
242
241
 
243
242
  ## Why Commit Check
@@ -0,0 +1,21 @@
1
+ commit_check/__init__.py,sha256=UAg0cSgL4QKAOc9GEbqFdoQ94JejOupRGoGgaDwIcF0,5456
2
+ commit_check/ai_policy.py,sha256=gYC3ROLgGL1TDyhPkFXkV-NiYbvMt80Qt0MFrJcbJY4,8131
3
+ commit_check/ai_signatures.py,sha256=qPbyVndU5egHRtDtu3S2vEO5_lKyDsz1PLUWqKPMMvU,11054
4
+ commit_check/ai_signatures_data.py,sha256=2-CL95wbCuQ60AOVtTrxvdagIe36LTkKh5EtUpT2AoM,19028
5
+ commit_check/api.py,sha256=07bvBtV8PrhZIOwCDHiHfu_7CXsX_4U2_K2xMAucd6c,12905
6
+ commit_check/config.py,sha256=I7yMZBJynjVUuY-GWAkuu9a59aT9fDTJsGh4znu2hDU,13941
7
+ commit_check/config_merger.py,sha256=52m45cPOVzQnjvxgjf8pHPbK3BKVHPrvBMmtocztU-0,13707
8
+ commit_check/engine.py,sha256=1ki13LXKaYXxnTQFbB3ZXWECVb515KA1BCt6gbkNMwY,76156
9
+ commit_check/fixes.py,sha256=BpbdoHsKDyw2WfsqymwYpnrW73aHdCDGr8tMF6Ho2RU,7305
10
+ commit_check/imperatives.py,sha256=dEd_ssu4G0j6Cann6jqPdB97lw5Adua43K0_Odg_FyA,9518
11
+ commit_check/main.py,sha256=0vlfDrc81xWL7AeTXYIVJmrlzz4V-vMAePa3BHF_FNo,29839
12
+ commit_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ commit_check/rule_builder.py,sha256=kujszrki8VKXAarrmUwOCu0Yv7QzIiu5lm5mRBAQVns,34950
14
+ commit_check/rules_catalog.py,sha256=5HofiYXnnX-wIj8JfksG1DB7clN-xrAOdrrk_RqgDqM,12378
15
+ commit_check/util.py,sha256=dCMbRKMPiysjxcOQWOIM-vJT2DdE2BsnGDgvTJsgnFs,34486
16
+ commit_check-2.20.0.dist-info/licenses/LICENSE,sha256=9mdTva71kQhrpWh_nZulxrdCnUrl5c6xJYh5hdo4p_s,1070
17
+ commit_check-2.20.0.dist-info/METADATA,sha256=9gbCi40aqpr8Osvp5GkWP5Gly8tc62C3gW2Y3MJQA0k,16482
18
+ commit_check-2.20.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
19
+ commit_check-2.20.0.dist-info/entry_points.txt,sha256=YMrkFGeub-3-IanV1d9qnopXVaRQM7MA9foXKW9iZ88,86
20
+ commit_check-2.20.0.dist-info/top_level.txt,sha256=Wf46u-ooHBMJNHbhfrBNQw3wC5_m8wt-o_Lfbc4QpRg,13
21
+ commit_check-2.20.0.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- commit_check/__init__.py,sha256=UAg0cSgL4QKAOc9GEbqFdoQ94JejOupRGoGgaDwIcF0,5456
2
- commit_check/ai_policy.py,sha256=gYC3ROLgGL1TDyhPkFXkV-NiYbvMt80Qt0MFrJcbJY4,8131
3
- commit_check/ai_signatures.py,sha256=0HTZy4othuwKVqfGZ2J7PaIMUPmQArhEQa0k7zGnCzs,10251
4
- commit_check/ai_signatures_data.py,sha256=dgTJxur3IqYLbmj0PzhG6LWb8mY2QwWUJVaFCLQJYzo,15258
5
- commit_check/api.py,sha256=07bvBtV8PrhZIOwCDHiHfu_7CXsX_4U2_K2xMAucd6c,12905
6
- commit_check/config.py,sha256=SB8Zvcll-kFOZgQ-olzYLv9CLJqaYIaCb37bcrjVNOE,14068
7
- commit_check/config_merger.py,sha256=umsjoTcWG7WXufxn7dIMlHrek0a8VWmqjynJR-A4LYQ,13406
8
- commit_check/engine.py,sha256=rot2jQ9rc8h3-pERCRR7GHsZt62BHtbDVThjHLUwZ7k,74064
9
- commit_check/fixes.py,sha256=BpbdoHsKDyw2WfsqymwYpnrW73aHdCDGr8tMF6Ho2RU,7305
10
- commit_check/imperatives.py,sha256=dEd_ssu4G0j6Cann6jqPdB97lw5Adua43K0_Odg_FyA,9518
11
- commit_check/main.py,sha256=LR3uyJXXHHLsVS90pshHbB7FfyTiUr-OmecI8wwvgEo,28157
12
- commit_check/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- commit_check/rule_builder.py,sha256=XqTjDrPcepC6jP-ui0RyiMFYSVvKXGuRxwllg_XxvKI,34391
14
- commit_check/rules_catalog.py,sha256=-C3Jo721vXRrY7-LzJs9iNF3ffXKEFldDfmBoLtujt4,11920
15
- commit_check/util.py,sha256=Q9nI_0yYu6WEJLD55vMnFozWhZzfP2Z4xrElecmqZBQ,32755
16
- commit_check-2.19.4.dist-info/licenses/LICENSE,sha256=9mdTva71kQhrpWh_nZulxrdCnUrl5c6xJYh5hdo4p_s,1070
17
- commit_check-2.19.4.dist-info/METADATA,sha256=Nmu5vjvJVhOUeHNlCRmoVzk-HMjHnU-l8VLPLh1x_ns,16369
18
- commit_check-2.19.4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
19
- commit_check-2.19.4.dist-info/entry_points.txt,sha256=YMrkFGeub-3-IanV1d9qnopXVaRQM7MA9foXKW9iZ88,86
20
- commit_check-2.19.4.dist-info/top_level.txt,sha256=Wf46u-ooHBMJNHbhfrBNQw3wC5_m8wt-o_Lfbc4QpRg,13
21
- commit_check-2.19.4.dist-info/RECORD,,