git: 4426b60c97 - main - Add the prepare-commit-msg hook to the repository

Li-Wen Hsu <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.doc
Message-ID <[email protected]>
The branch main has been updated by lwhsu:

URL: https://cgit.FreeBSD.org/doc/commit/?id=4426b60c97365a0095d5ac8e6e946d51319c04f7

commit 4426b60c97365a0095d5ac8e6e946d51319c04f7
Author:     Li-Wen Hsu <[email protected]>
AuthorDate: 2022-08-16 13:33:25 +0000
Commit:     Li-Wen Hsu <[email protected]>
CommitDate: 2022-08-16 13:33:25 +0000

    Add the prepare-commit-msg hook to the repository
    
    This is a merged and modified version from src and ports repositories.
    
    The easiest way to install is run the following command in the repository:
    
        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/
    
    Approved by:    carlavilla (doceng)
    Differential Revision:  https://reviews.freebsd.org/D36203
---
 .hooks/prepare-commit-msg | 75 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/.hooks/prepare-commit-msg b/.hooks/prepare-commit-msg
new file mode 100755
index 0000000000..aec38c7d06
--- /dev/null
+++ b/.hooks/prepare-commit-msg
@@ -0,0 +1,75 @@
+#!/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)
+exec 3> "$outfile"
+
+# 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.
+
+awk '1;/^#$/{exit}' "$1" >&3
+
+cat >&3 <<EOF
+# <Component>: Subject goes here, max 50 cols  --|
+# <then a blank line>
+#                                                         72 columns --|
+#
+# Do not add a "Submitted by:" line.  If someone besides the committer sent in
+# the change, the commit author should be set using \`git commit --author\`.
+#
+# 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>
+# 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/freebsd-doc/pull/###>
+# Differential Revision:	<https://reviews.freebsd.org/D###>
+#
+# "Pull Request" and "Differential Revision" require the *full* GitHub or
+# Phabricator URL.
+EOF
+
+awk '/^#$/,EOF' "$1" >&3
+
+exec 3>&-
+
+mv "$outfile" "$1"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.