git: 242b704fb593 - main - framework: add hook to notify about lingering 'Created by' lines

From: Tobias C. Berner <tcberner_at_FreeBSD.org>
Date: Wed, 20 Jul 2022 13:10:29 UTC
The branch main has been updated by tcberner:

URL: https://cgit.FreeBSD.org/ports/commit/?id=242b704fb593876a9945cd5888e1f7804df3f0d3

commit 242b704fb593876a9945cd5888e1f7804df3f0d3
Author:     Tobias C. Berner <tcberner@FreeBSD.org>
AuthorDate: 2022-07-20 13:08:21 +0000
Commit:     Tobias C. Berner <tcberner@FreeBSD.org>
CommitDate: 2022-07-20 13:09:29 +0000

    framework: add hook to notify about lingering 'Created by' lines
---
 .hooks/pre-commit.d/check_created_by | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/.hooks/pre-commit.d/check_created_by b/.hooks/pre-commit.d/check_created_by
new file mode 100755
index 000000000000..6e4d8d8bc3cc
--- /dev/null
+++ b/.hooks/pre-commit.d/check_created_by
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# Check that ports do not contain a 'Created by' tag
+#
+
+makefiles=$(git diff --name-only --cached --diff-filter=ACMR | grep -E '^[^/]+/[^/]+/Makefile$')
+if [ $? -eq 0 ] ; then
+	for makefile in ${makefiles} ; do
+		created_by=$(head -n1 ${makefile} | awk -F : '/Created by/{print $NF}')
+		if [ -n "${created_by}" ] ; then
+			echo -e "[pre-commit] ERROR: ${makefile} contains obsolete 'Created by' line\n" \
+			        "                    Please remove the the line, and append:\n\n" \
+			        "                    - Removed 'Created by ${created_by}'.\n\n" \
+			        "                    to your commit message."
+			exit 1
+		fi
+	done
+fi