Skip to content

Commit b8fb9c8

Browse files
authored
Merge pull request #476 from emacs-php/add-commit-message-template
Add a default Git commit template message
2 parents cf1907b + 9204575 commit b8fb9c8

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ $(AUTOLOADS): php-project.el php-mode.el
1919
clean:
2020
rm -f $(ELCS) $(AUTOLOADS)
2121

22+
# Perform any operations that will be useful for developers
23+
# who contribute to PHP Mode.
24+
dev:
25+
cp etc/git/prepare-commit-msg .git/hooks/prepare-commit-msg
26+
chmod u+x .git/hooks/prepare-commit-msg
27+
2228
# Runs all unit tests from php-mode-test.el and shows the results. The
2329
# script will exit with the status code zero if all tests pass. If any
2430
# test fails the script exits with a non-zero status and shows

etc/git/commit-template.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SUBJECT, 50 Characters, No Period
2+
# "If applied, this commit will..."
3+
4+
# BODY, 72 Characters
5+
# Answers the question, "Why?", not, "How?"
6+
7+
# METADATA
8+
# GitHub-Issue:
9+
# Resolves:
10+
# See-also:
11+
# Reviewed-by:
12+
# Special-thanks:
13+
# HANGING INDENT

etc/git/prepare-commit-msg

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
#
3+
# prepare-commit-msg
4+
# ==================
5+
#
6+
# ## SYNOPSIS
7+
#
8+
# This hook fills the user's editor with a pre-written commit message
9+
# template, intended to help contributors adhere to good style and
10+
# practices when it comes to writing Git commit messages.
11+
#
12+
########################################################################
13+
14+
# This hook will always recieve three arguments. We only care about the
15+
# first for our purposes, but still assign useful names to the others
16+
# in case we need them in the future.
17+
COMMIT_MESSAGE=$1
18+
COMMIT_SOURCE=$2
19+
COMMIT_SHA1=$3
20+
21+
# If the commit message already contains content then the developer
22+
# is probably using his or her own template. In which case we do not
23+
# trample over it. We test for a pre-existing template by reading
24+
# the first line of the commit message this hook recieved, and check
25+
# so see if it is an empty string (apply our template) or not (leave
26+
# the message alone).
27+
TITLE_LINE=$(head -n1 $COMMIT_MESSAGE)
28+
29+
if [ -z "$TITLE_LINE" ]; then
30+
project_dir=$(git rev-parse --show-toplevel)
31+
template="$project_dir/etc/git/commit-template.txt"
32+
echo "$(cat $template)\n$(cat $COMMIT_MESSAGE)" > $COMMIT_MESSAGE
33+
fi
34+
35+
exit 0

0 commit comments

Comments
 (0)