diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64d8593..f695f12 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,9 +59,12 @@ Git commits should follow the seven rules in [How to Write a Git Commit Message][commit]. Also, prefix each commit message with the package it affects, e.g. `proto: Use smaller buffer for partial downloads`. If a commit affects multiple packages, use your best judgment to pick the most important -one, or use `all`. Lastly, put any references to issues (e.g. `Fixes #1234`) -in the issue body, **not** in the commit message. This prevents an issue from -being referenced over and over by the same commit when amending/rebasing. +one, or use `all`. A commit-msg hook is provided to enforce this style; to +install it, run `ln -s ../../commit-msg.sh .git/hooks/pre-commit`. + +Lastly, put any references to issues (e.g. `Fixes #1234`) in the issue body, +**not** in the commit message. This prevents an issue from being referenced +over and over by the same commit when amending/rebasing. Speaking of which, don't be afraid to rebase heavily when modifying a PR in response to review comments. Avoid commits with messages like `Address review diff --git a/commit-msg.sh b/commit-msg.sh new file mode 100755 index 0000000..e752e9f --- /dev/null +++ b/commit-msg.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# +# A commit-msg hook to enforce the us commit message style. + +if ! egrep ': [A-Z0-9]+' "$1" >/dev/null; then + echo >&2 "Commit message should be of the form \"lowercase: Uppercase\"" + echo >&2 "(Your commit message was saved in $1)" + exit 1 +fi +if head -n1 "$1" | grep "\.$"; then + echo >&2 "Commit message should not end in a period" + echo >&2 "(Your commit message was saved in $1)" + exit 1 +fi