git: 951773c013b9 - main - framework: add new hook to validate MOVED lines

From: Tobias C. Berner <tcberner_at_FreeBSD.org>
Date: Tue, 23 Aug 2022 13:08:57 UTC
The branch main has been updated by tcberner:

URL: https://cgit.FreeBSD.org/ports/commit/?id=951773c013b9bfc73bba33617757660ddc34ebce

commit 951773c013b9bfc73bba33617757660ddc34ebce
Author:     Tobias C. Berner <tcberner@FreeBSD.org>
AuthorDate: 2022-08-23 13:01:59 +0000
Commit:     Tobias C. Berner <tcberner@FreeBSD.org>
CommitDate: 2022-08-23 13:08:11 +0000

    framework: add new hook to validate MOVED lines
    
    A possible error message will look like:
    
    [pre-commit] ERROR: MOVED contains errors.
                        Please apply the suggested changes:
    
    17537: date going backwards from 2022-08-20 to 2022-08-13 from this line
    17538: date going backwards from 2022-08-20 to 2022-08-13 to this line
    
    Reviewed by:            bapt
    Differential Revision:  https://reviews.freebsd.org/D35042
---
 .hooks/pre-commit.d/check_moved | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/.hooks/pre-commit.d/check_moved b/.hooks/pre-commit.d/check_moved
new file mode 100755
index 000000000000..3d6a3209aef0
--- /dev/null
+++ b/.hooks/pre-commit.d/check_moved
@@ -0,0 +1,21 @@
+#!/bin/sh
+#
+# Check that newly added MOVED lines are valid
+#
+
+
+moved_changed=$(git diff --name-only --cached --diff-filter=M | grep -E '^MOVED$')
+if [ $? -eq 0 ] ; then
+	# git changes to root directory of the tree to run hooks
+	tree=$(git rev-parse --show-toplevel)
+	# check the last seven days
+	lastdate=$(date -v-7d "+%Y-%m-%d")
+
+	errors=$(PORTSDIR=${tree} Tools/scripts/MOVEDlint.awk -v lastdate="${lastdate}")
+	if [ $? -ne 0 ] ; then
+		echo -e "[pre-commit] ERROR: MOVED contains errors.\n" \
+			"                   Please apply the suggested changes:\n"
+		echo "${errors}"
+		exit 1
+	fi
+fi