Last active
June 17, 2024 12:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice article about what this is by @mscottford