Skip to content

Commit c49eb31

Browse files
committed
chore: validate commit scope in commit-msg hook
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.
1 parent ff52c16 commit c49eb31

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

cog.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ if echo "$header" | grep -q '\.$'; then
5050
echo "error: commit subject must not end with a period"
5151
exit 1
5252
fi
53+
54+
# Workaround for cocogitto/cocogitto#516: `cog verify` does not validate
55+
# scope against the configured `scopes` list. Fixed upstream in v7.0.0 via
56+
# cocogitto/cocogitto#541. Remove this block once mmdflux is on cog >= 7
57+
# (currently blocked on cocogitto/cocogitto#558). Single-line `scopes = [...]`
58+
# assumed; multi-line arrays would need a real TOML parser.
59+
scope=$(echo "$header" | sed -nE 's/^[a-z]+\(([^)]+)\)!?:.*/\1/p')
60+
if [ -n "$scope" ]; then
61+
allowed=$(awk -F'=' '/^scopes[[:space:]]*=/ {
62+
sub(/^.*=[[:space:]]*\[/, "")
63+
sub(/\].*$/, "")
64+
gsub(/[" ]/, "")
65+
print
66+
}' cog.toml)
67+
if ! echo "$allowed" | tr ',' '\n' | grep -qx "$scope"; then
68+
echo "error: scope '$scope' is not in cog.toml scopes list"
69+
echo " allowed: $allowed"
70+
exit 1
71+
fi
72+
fi
5373
'''
5474

5575
[git_hooks.pre-push]

0 commit comments

Comments
 (0)