File: prepare-commit-msg

package info (click to toggle)
php-elisp 1.27.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,268 kB
  • sloc: lisp: 7,468; php: 5,396; makefile: 42; sh: 10
file content (35 lines) | stat: -rwxr-xr-x 1,187 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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