Skip to content

Instantly share code, notes, and snippets.

@raymyers
Last active August 28, 2023 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raymyers/22270902d5a5414e4054b09d328ffd92 to your computer and use it in GitHub Desktop.
Save raymyers/22270902d5a5414e4054b09d328ffd92 to your computer and use it in GitHub Desktop.
Simple git hook enforcing Arlo Belshee's commit notation with hints, put in a repo as .git/hooks/commit-msg
#!/usr/bin/env python
import sys, os, re
from subprocess import check_output
# Collect the parameters
commit_msg_filepath = sys.argv[1]
allowed_prefixes = (
'f - ', 'F - ', 'F!! ', 'F**',
'b - ', 'B - ', 'B!! ', 'B**',
'r - ', 'R - ', 'R!! ', 'R**',
'd - ', 'D - ', 'D!! ', 'D**',
)
with open(commit_msg_filepath, 'r') as f:
content = f.read()
if not content.startswith(allowed_prefixes):
print("commit-msg: ERROR! The commit message must start with one of '%s'" % ', '.join(allowed_prefixes))
print()
print("Consider: ")
print("F!! Change includes unit tests for new behavior")
print("F** No automatic tests, or unfinished implementation")
print("R** Remodeled by editing code, even in small chunks")
print("Or see the full list at https://github.com/RefactoringCombos/ArlosCommitNotation")
sys.exit(1)
@raymyers
Copy link
Author

Nice article about what this is by @mscottford

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment