aboutsummaryrefslogtreecommitdiff
path: root/tools/tools/git/hooks/prepare-commit-msg
blob: e453b73cc45d69fccff247bc5a10c738133a89fb (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

# prepare-commit-msg: Prepare a commit message upon `git commit` for the
# user to edit.  A script (rather than a static template) is used, so
# that we can insert our template text other than at the top of the
# message.
#
# Install by copying into the git hooks directory - for example,
# cp tools/tools/git/hooks/prepare-commit-msg .git/hooks/

case "$2" in
commit|message)
	# It appears git invokes this script for interactive rebase but does
	# not remove commented lines, so just exit if we're not called with the
	# default (comment-containing) template.
	egrep -q '^#' "$1" || return 0
	;;
template)
	return 0
	;;
merge)
	return 0
	;;
esac

outfile=$(mktemp /tmp/freebsd-git-commit.XXXXXXXX)

# Create a commit message template from three parts:
#
# 1. The beginning of the git-provided template (up to the first comment-only
#    line) which explains commented lines and such.
#
# 2. Our template.
#
# 3. The remainder of the git-provided template (from the first comment-only
#    line to the end of the file) which lists files staged for commit, files
#    not staged, and untracked files.

cat >$outfile <<EOF
$(awk '1;/^#$/{exit}' $1)
#                                                         72 columns --|
#
# Uncomment and complete these metadata fields, as appropriate:
# 
# PR:		<If and which Problem Report is related.>
# Submitted by:	<If someone else sent in the change.>
# Reported by:	<If someone else reported the issue.>
# Reviewed by:	<If someone else reviewed your modification.>
# Approved by:	<If you needed approval for this commit.>
# Obtained from:	<If the change is from a third party.>
# MFC after:	<N [day[s]|week[s]|month[s]].  Request a reminder email>
# MFH:		<Ports tree branch name.  Request approval for merge.>
# Relnotes:	<Set to 'yes' for mention in release notes.>
# Security:	<Vulnerability reference (one per line) or description.>
# Sponsored by:	<If the change was sponsored by an organization.>
# Pull Request:	<https://github.com/freebsd/<repo>/pull/###>
# Differential Revision:	<https://reviews.freebsd.org/D###>
#
# "Pull Request" and "Differential Revision" require the *full* GitHub or
# Phabricator URL.
$(awk '/^#$/,EOF' $1)
EOF

mv $outfile $1