Skip to content

Instantly share code, notes, and snippets.

@amochkin
Last active May 4, 2023 15:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amochkin/35d8bd93046412d9a9e33a2bf1c0f444 to your computer and use it in GitHub Desktop.
Save amochkin/35d8bd93046412d9a9e33a2bf1c0f444 to your computer and use it in GitHub Desktop.
Oneliner that creates and installs a conventional commit enforcement script for git. Run this oneliner in your git repo root.
printf '#!/bin/sh\n
# Get the commit message
commit_message=$(cat "$1")\n
# Regular expression pattern for conventional commits
pattern='\''^(feat|fix|docs|style|refactor|test|chore)(\([a-z0-9-]+\))?!?: [^\s].{0,100}$'\''\n
# Check if the commit message matches the pattern
if echo "$commit_message" | grep -qE "$pattern"; then
\techo "Commit message is compliant with conventional commits."
else
\techo "Commit message is not compliant with conventional commits. See https://www.conventionalcommits.org/en/v1.0.0/#summary"; exit 1
fi' > .git/hooks/commit-msg && chmod +x .git/hooks/commit-msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment