1#!/bin/sh
2
3case "$2" in
4commit|message)
5	# It appears git invokes this script for interactive rebase but does
6	# not remove commented lines, so just exit if we're not called with the
7	# default (comment-containing) template.
8	egrep -q '^#' "$1" || return 0
9	;;
10template)
11	return 0
12	;;
13merge)
14	return 0
15	;;
16esac
17
18outfile=$(mktemp /tmp/freebsd-git-commit.XXXXXXXX)
19
20# Create a commit message template from three parts:
21#
22# 1. The beginning of the git-provided template (up to the first comment-only
23#    line) which explains commented lines and such.
24# 2. Our template.
25# 3. The remainder of the git-provided template (from the first comment-only
26#    line to the end of the file) which lists files staged for commit, files
27#    not staged, and untracked files.
28
29cat >$outfile <<EOF
30$(awk '1;/^#$/{exit}' $1)
31#                                                         72 columns --|
32#
33# Uncomment and complete these metadata fields, as appropriate:
34# 
35# PR:		<If and which Problem Report is related.>
36# Submitted by:	<If someone else sent in the change.>
37# Reported by:	<If someone else reported the issue.>
38# Reviewed by:	<If someone else reviewed your modification.>
39# Approved by:	<If you needed approval for this commit.>
40# Obtained from:	<If the change is from a third party.>
41# MFC after:	<N [day[s]|week[s]|month[s]].  Request a reminder email>
42# MFH:		<Ports tree branch name.  Request approval for merge.>
43# Relnotes:	<Set to 'yes' for mention in release notes.>
44# Security:	<Vulnerability reference (one per line) or description.>
45# Sponsored by:	<If the change was sponsored by an organization.>
46# Pull Request:	<https://github.com/freebsd/<repo>/pull/###>
47# Differential Revision:	<https://reviews.freebsd.org/D###>
48#
49# "Pull Request" and "Differential Revision" require the *full* GitHub or
50# Phabricator URL.
51$(awk '/^#$/,EOF' $1)
52EOF
53
54mv $outfile $1
55