Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ $(AUTOLOADS): php-project.el php-mode.el
clean:
rm -f $(ELCS) $(AUTOLOADS)

# Perform any operations that will be useful for developers
# who contribute to PHP Mode.
dev:
cp etc/git/prepare-commit-msg .git/hooks/prepare-commit-msg
chmod u+x .git/hooks/prepare-commit-msg

# Runs all unit tests from php-mode-test.el and shows the results. The
# script will exit with the status code zero if all tests pass. If any
# test fails the script exits with a non-zero status and shows
Expand Down
13 changes: 13 additions & 0 deletions etc/git/commit-template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SUBJECT, 50 Characters, No Period
# "If applied, this commit will..."

# BODY, 72 Characters
# Answers the question, "Why?", not, "How?"

# METADATA
# GitHub-Issue:
# Resolves:
# See-also:
# Reviewed-by:
# Special-thanks:
# HANGING INDENT
35 changes: 35 additions & 0 deletions etc/git/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
#
# prepare-commit-msg
# ==================
#
# ## SYNOPSIS
#
# This hook fills the user's editor with a pre-written commit message
# template, intended to help contributors adhere to good style and
# practices when it comes to writing Git commit messages.
#
########################################################################

# This hook will always recieve three arguments. We only care about the
# first for our purposes, but still assign useful names to the others
# in case we need them in the future.
COMMIT_MESSAGE=$1
COMMIT_SOURCE=$2
COMMIT_SHA1=$3

# If the commit message already contains content then the developer
# is probably using his or her own template. In which case we do not
# trample over it. We test for a pre-existing template by reading
# the first line of the commit message this hook recieved, and check
# so see if it is an empty string (apply our template) or not (leave
# the message alone).
TITLE_LINE=$(head -n1 $COMMIT_MESSAGE)

if [ -z "$TITLE_LINE" ]; then
project_dir=$(git rev-parse --show-toplevel)
template="$project_dir/etc/git/commit-template.txt"
echo "$(cat $template)\n$(cat $COMMIT_MESSAGE)" > $COMMIT_MESSAGE
fi

exit 0