Skip to content

chore: validate commit scope in commit-msg hook#385

Merged
kevinswiber merged 2 commits into
mainfrom
chore/cog-toml-scope-check
May 19, 2026
Merged

chore: validate commit scope in commit-msg hook#385
kevinswiber merged 2 commits into
mainfrom
chore/cog-toml-scope-check

Conversation

@kevinswiber

Copy link
Copy Markdown
Owner

Summary

cog verify in cocogitto 6.x does not validate the scope component of a conventional commit header against the configured scopes list (cocogitto/cocogitto#516). Fixed upstream in v7.0.0 by cocogitto/cocogitto#541, but mmdflux can't move to cog 7 yet because of the open cocogitto/cocogitto#558 monorepo bump_order regression.

Add an inline shell check to [git_hooks.commit-msg] that extracts the scope from the header (handling the optional breaking-change ! marker) and rejects anything not in the cog.toml scopes list. Single-line scopes = [...] parsing via awk; multi-line arrays would need a real TOML parser. Unscoped commits (root crate, per the project convention) continue to pass through.

This avoids the round-trip cost of pushing a commit with an unrecognized scope and only finding out in CI. The block is tagged with the upstream issue references so the next person knows when it's safe to drop.

Test plan

Exercised the snippet against six representative commit headers from outside the worktree (no actual commit needed):

Header Expected Result
docs(mmds): ... (the original miss) reject reject
feat(mmds-core): ... accept accept
docs: ... (no scope, root crate) accept accept
feat(wasm)!: ... (breaking change) accept accept
feat(typo)!: ... (breaking change, bad scope) reject reject
chore(version): ... accept accept
  • Six-case dry run passes.
  • cog check HEAD~1..HEAD clean on this commit.
  • Contributors re-running just setup-hooks from the main repo (not from a worktree — cog install-hook chokes on worktree .git files) pick up the new hook automatically.

Cleanup

Drop the marked block when both cocogitto/cocogitto#558 lands upstream and mmdflux moves to cog >= 7.

cog verify in cocogitto 6.x does not validate the scope component of
a conventional commit header against the configured `scopes` list
(cocogitto/cocogitto#516). Fixed upstream in v7.0.0 by
cocogitto/cocogitto#541, but mmdflux can't move to v7 yet because of
the open cocogitto/cocogitto#558 monorepo bump_order regression.

Add an inline shell check to [git_hooks.commit-msg] that extracts the
scope from the header (handling the optional breaking-change `!`
marker) and rejects anything not in the cog.toml scopes list.
Single-line `scopes = [...]` parsing via awk; multi-line arrays would
need a real TOML parser. Unscoped commits (root crate, per the
project convention) continue to pass through.

This avoids the round-trip cost of pushing a commit with an
unrecognized scope and only finding out in CI. The block is tagged
with the upstream issue references so the next person knows to drop
it once both upstream changes are shippable.

Contributors re-running `just setup-hooks` from the main repo will
pick up the new hook automatically.
@kevinswiber kevinswiber force-pushed the chore/cog-toml-scope-check branch from c49eb31 to dc8e17f Compare May 19, 2026 17:59
@kevinswiber kevinswiber merged commit 5b9912f into main May 19, 2026
7 checks passed
@kevinswiber kevinswiber deleted the chore/cog-toml-scope-check branch May 19, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant