Skip to content

Commit

Permalink
doc: Add commit-msg hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Dec 12, 2018
1 parent 823fe8f commit 226f339
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions commit-msg.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 226f339

Please sign in to comment.