aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Arnold <mat@FreeBSD.org>2021-04-20 09:50:42 +0000
committerMathieu Arnold <mat@FreeBSD.org>2021-04-20 11:50:57 +0000
commit043e196d694c84978db30432358dd10ad90b3246 (patch)
treef613eff569b2e42a794dce58c1e162a1c7e749a0
parentf7329c715332a9c10836cde1859498d5a5bb400d (diff)
downloadports-043e196d694c84978db30432358dd10ad90b3246.tar.gz
ports-043e196d694c84978db30432358dd10ad90b3246.zip
Add the prepare-commit-msg hook to the repository.
To make use of it, the easiest way is to run: git config --add core.hooksPath .hooks Discussed with: bapt (cherry picked from commit bbc2474ef7a65eb8561c8ecf7af80c2bfed1f248)
-rwxr-xr-x.hooks/prepare-commit-msg69
1 files changed, 69 insertions, 0 deletions
diff --git a/.hooks/prepare-commit-msg b/.hooks/prepare-commit-msg
new file mode 100755
index 000000000000..d2d1536cfcca
--- /dev/null
+++ b/.hooks/prepare-commit-msg
@@ -0,0 +1,69 @@
+#!/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 either setting the configuration of the repository to:
+# git config --add core.hooksPath .hooks
+# or copy it to the hooks directory, but it will not get automatically updated:
+# cp .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.
+ grep -E -q '^#' "$1" || exit 0
+ ;;
+template)
+ exit 0
+ ;;
+merge)
+ exit 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")
+# category/port: subject goes here, max 50 cols -|
+# <then a blank line>
+# 72 columns --|
+#
+# Uncomment and complete these metadata fields, as appropriate:
+#
+# PR: <If and which Problem Report is related.>
+# Reported by: <If someone else reported the issue.>
+# Reviewed by: <If someone else reviewed your modification.>
+# Tested by: <If someone else tested the change.>
+# Approved by: <If you needed approval for this commit.>
+# Obtained from: <If the change is from a third party.>
+# Fixes: <Short hash and title line of commit fixed by this change>
+# 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. The commit author should be set appropriately, using
+# \`git commit --author\` if someone besides the committer sent in the change.
+$(awk '/^#$/,EOF' "$1")
+EOF
+
+mv "$outfile" "$1"