From nobody Thu Jan 12 21:11:17 2023 X-Original-To: dev-commits-ports-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NtHKK50r5z2qxxm; Thu, 12 Jan 2023 21:11:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NtHKK4Js9z4YRp; Thu, 12 Jan 2023 21:11:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673557877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n/Nlv5AaaSgK7ib+GC+LYJuQdG4Ht0hLcgnPUAlQG+0=; b=tuWgTX35Fj+pGbtr8rQFfSnvFPBXVVZCgj5bisJynBh039in0iHsUX4a9gbKEztu+pVn0G 2GW1pwQZc6eeZuopBPvck8tphoDCu/cX7xiqYky0U+Z9+dn7l/GLXi79W6FIeG3ThXMbIf zx9qhANuJ3Y42ZtLs7AGhC4g4EMxVNJ1Xsz98MARmwvmfRNIj2JpRnXhZZCEnnbaIg8VM/ FyBgtJu5hj2jrzLAlMoeFep1raU8LektfRTgWUKAhi/E7Qzym12tFdAYdpiMcmCuilzhQp AAugcQMRLXQX6E24xC6B+65PLmuIFm10n7WZK4ZUzuUMF+nHEUkTAOBg+ZYVPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673557877; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=n/Nlv5AaaSgK7ib+GC+LYJuQdG4Ht0hLcgnPUAlQG+0=; b=wPbqEuiZ2iRosfTh4qW5GL1Ez0TC6juP/r0g+21M8KXVtFEIBwLht3TtjdXjQ3d1zwDktK 5olzuZ7eNJ2bc1JryAJ8JKYdesryyvMz9Fq6jFMPx3EjnEJ3/N5JgKLKnUppm4QsKEzqS0 2IrGssslzh5MDlCqqgkkGx/WVdHLP4Iesa97U/TvbAoYwPXBAH3wF2hLiEvwoHmohK0b12 560lHan1UHqOZcTa7BaRNAnlsU7nPsD7nNrOJBLR1QGhqauklOUIWpCl1NQZsspt2f/O7A MHNHtE9ZlHs0sdP/UedI10qzTYelLIBRznR6V/vJnP0O3fRiKXSKYEJ9ZZtBMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673557877; a=rsa-sha256; cv=none; b=XAiN7i5oIeSU0BiFo4S9+deuoeQbi7Y5HBXCYTBI1pIXcXuTR6vi7IXIv6zCKkOlfn+YKA LZbuzzRqYEfVfDrUyNt/oNuIQHF6gKNFTePx7P3IXto+wtCaPrO9UUWmEfsuUnL7zW9Etc 3+i+qMvNQ9S/GDNPEqbcKQUUMHP6MV4TqYq7/O5lEojHIhBTYg0fruTeQz1bFW3Kb86BjA f4qLnqbSVeKcd2oB5+A1GhoZLGg4osUUn7z8R5AZEJC2ZzLq76vlkCzNYI8a8QzKL6ow+G vr76QsyQKPhpoPsCy/xgTgYJi1LAcPFWFvRnVCQO63xU5ie/DAh8JX4ag04g8A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NtHKK3McfzjHc; Thu, 12 Jan 2023 21:11:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30CLBHfI064112; Thu, 12 Jan 2023 21:11:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30CLBHYn064111; Thu, 12 Jan 2023 21:11:17 GMT (envelope-from git) Date: Thu, 12 Jan 2023 21:11:17 GMT Message-Id: <202301122111.30CLBHYn064111@gitrepo.freebsd.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org From: Luca Pizzamiglio Subject: git: 302c208fc513 - main - Component: git hooks List-Id: Commits to the main branch of the FreeBSD ports repository List-Archive: https://lists.freebsd.org/archives/dev-commits-ports-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-ports-main@freebsd.org X-BeenThere: dev-commits-ports-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pizzamig X-Git-Repository: ports X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 302c208fc51342e75b089d56da612d8c740a7ac1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by pizzamig: URL: https://cgit.FreeBSD.org/ports/commit/?id=302c208fc51342e75b089d56da612d8c740a7ac1 commit 302c208fc51342e75b089d56da612d8c740a7ac1 Author: Luca Pizzamiglio AuthorDate: 2023-01-12 21:09:50 +0000 Commit: Luca Pizzamiglio CommitDate: 2023-01-12 21:09:50 +0000 Component: git hooks Add common error function in hooks Error messages are printed in stderr Reviewed By: tcberner, #portmgr Differential Revision: https://reviews.freebsd.org/D38026 --- .hooks/pre-commit.d/check_category_makefile | 7 ++++++- .hooks/pre-commit.d/check_created_by | 13 +++++++++---- .hooks/pre-commit.d/check_files | 9 +++++++-- .hooks/pre-commit.d/check_mk_indentations | 9 +++++++-- .hooks/pre-commit.d/check_moved | 10 +++++++--- .hooks/pre-commit.d/check_portepoch | 9 +++++++-- .hooks/pre-commit.d/common.sh | 7 +++++++ 7 files changed, 50 insertions(+), 14 deletions(-) diff --git a/.hooks/pre-commit.d/check_category_makefile b/.hooks/pre-commit.d/check_category_makefile index fb43d4353256..fea09ef6325c 100755 --- a/.hooks/pre-commit.d/check_category_makefile +++ b/.hooks/pre-commit.d/check_category_makefile @@ -3,6 +3,11 @@ # Check that ports are hooked into the build # +common_functions="$(realpath "$(dirname "$0")")/common.sh" +if [ -r "${common_functions}" ]; then + . "${common_functions}" +fi + newish_makefiles=$(git diff --name-only --cached --diff-filter=ACR | grep -E '^[^/]+/[^/]+/Makefile$') if [ $? -eq 0 ] ; then for newish_makefile in ${newish_makefiles} ; do @@ -10,7 +15,7 @@ if [ $? -eq 0 ] ; then port=$(echo "${newish_makefile}" | awk -F '/' '{print $2}') grep -q -E "^[[:space:]]+SUBDIR[[:space:]]\+=[[:space:]]*${port}\$" ${category}/Makefile if [ $? -ne 0 ] ; then - echo "[pre-commit] ERROR: Missing 'SUBDIR += ${port}' in ${category}/Makefile" + pre_commit_error "Missing 'SUBDIR += ${port}' in ${category}/Makefile" exit 1 fi done diff --git a/.hooks/pre-commit.d/check_created_by b/.hooks/pre-commit.d/check_created_by index 6e4d8d8bc3cc..4d22b3fdd607 100755 --- a/.hooks/pre-commit.d/check_created_by +++ b/.hooks/pre-commit.d/check_created_by @@ -3,15 +3,20 @@ # Check that ports do not contain a 'Created by' tag # +common_functions="$(realpath "$(dirname "$0")")/common.sh" +if [ -r "${common_functions}" ]; then + . "${common_functions}" +fi + 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." + 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 diff --git a/.hooks/pre-commit.d/check_files b/.hooks/pre-commit.d/check_files index e9891f3cc827..300c10bfc6b4 100755 --- a/.hooks/pre-commit.d/check_files +++ b/.hooks/pre-commit.d/check_files @@ -8,6 +8,11 @@ # pkg-.* # +common_functions="$(realpath "$(dirname "$0")")/common.sh" +if [ -r "${common_functions}" ]; then + . "${common_functions}" +fi + category_regex="($(make -VSUBDIR | sed 's# #\|#g'))" newish_files=$(git diff --name-only --cached --diff-filter=ACR | grep -E "^${category_regex}/[^/]+/[^/]+$") @@ -19,12 +24,12 @@ if [ $? -eq 0 ] ; then file=$(echo "${newish_file}" | awk -F '/' '{print $3}') valid=$(echo "${file}" | grep -Eq '^((Makefile|distinfo|pkg-)(.*))|(.*\.mk)$') if [ $? -ne 0 ] ; then - echo "[pre-commit] ERROR: invalid file '${file}' in '${category}/${port}'" + pre_commit_error "ERROR: invalid file '${file}' in '${category}/${port}'" status=1 fi done fi if [ ${status} -eq 1 ] ; then - echo " Consider moving non-standard files to files/ or force-ignore this hook." + error " Consider moving non-standard files to files/ or force-ignore this hook." exit 1 fi diff --git a/.hooks/pre-commit.d/check_mk_indentations b/.hooks/pre-commit.d/check_mk_indentations index 00fdb16f24cf..d5f6e601554a 100755 --- a/.hooks/pre-commit.d/check_mk_indentations +++ b/.hooks/pre-commit.d/check_mk_indentations @@ -3,6 +3,11 @@ # Check that Mk/ files are properly indented # +common_functions="$(realpath "$(dirname "$0")")/common.sh" +if [ -r "${common_functions}" ]; then + . "${common_functions}" +fi + check_indentation() { local mkfile="$1" local name=$(echo "${mkfile}" | awk -F / '{print $NF}') @@ -13,12 +18,12 @@ check_indentation() { fi cp ${mkfile} ${tempdir} && Tools/scripts/indent_make_if.pl ${tempdir}/${name} if [ $? -ne 0 ] ; then - echo "[pre-commit] failed to run Tools/scripts/indent_make_if.pl" + pre_commit_error "failed to run Tools/scripts/indent_make_if.pl" exit 2 fi cmp -s ${tempdir}/* if [ $? -ne 0 ] ; then - echo "[pre-commit] ${name} is not properly indented -- please use ${tempdir}/${name} which was created using Tools/scripts/indent_make_if.pl" + pre_commit_error "${name} is not properly indented -- please use ${tempdir}/${name} which was created using Tools/scripts/indent_make_if.pl" exit 1 fi } diff --git a/.hooks/pre-commit.d/check_moved b/.hooks/pre-commit.d/check_moved index 3d6a3209aef0..5a0a507ab061 100755 --- a/.hooks/pre-commit.d/check_moved +++ b/.hooks/pre-commit.d/check_moved @@ -3,6 +3,10 @@ # Check that newly added MOVED lines are valid # +common_functions="$(realpath "$(dirname "$0")")/common.sh" +if [ -r "${common_functions}" ]; then + . "${common_functions}" +fi moved_changed=$(git diff --name-only --cached --diff-filter=M | grep -E '^MOVED$') if [ $? -eq 0 ] ; then @@ -13,9 +17,9 @@ if [ $? -eq 0 ] ; then 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}" + pre_commit_error "MOVED contains errors.\n" \ + " Please apply the suggested changes:\n" + error "${errors}" exit 1 fi fi diff --git a/.hooks/pre-commit.d/check_portepoch b/.hooks/pre-commit.d/check_portepoch index 34d93e2efcf4..1e93cd595708 100755 --- a/.hooks/pre-commit.d/check_portepoch +++ b/.hooks/pre-commit.d/check_portepoch @@ -3,17 +3,22 @@ # Check that PORTEPOCH is not being dropped, and is non-decreasing # +common_functions="$(realpath "$(dirname "$0")")/common.sh" +if [ -r "${common_functions}" ]; then + . "${common_functions}" +fi + check_epoch() { local makefile="$1" local old_epoch=$(git diff --cached -U0 "${makefile}" | grep '^-PORTEPOCH.*=' | grep -oE '[0-9]+') local new_epoch=$(git diff --cached -U0 "${makefile}" | grep '^+PORTEPOCH.*=' | grep -oE '[0-9]+') if [ -z "${new_epoch}" -a -n "${old_epoch}" ] ; then - echo "[pre-commit] dropped PORTEPOCH ${old_epoch} in ${makefile}" + pre_commit_error "dropped PORTEPOCH ${old_epoch} in ${makefile}" exit 1 fi if [ -n "${old_epoch}" ] ; then if [ ${new_epoch} -lt ${old_epoch} ] ; then - echo "[pre-commit] PORTEPOCH decreasing from ${old_epoch} to ${new_epoch} in ${makefile}" + pre_commit_error "PORTEPOCH decreasing from ${old_epoch} to ${new_epoch} in ${makefile}" exit 2 fi fi diff --git a/.hooks/pre-commit.d/common.sh b/.hooks/pre-commit.d/common.sh new file mode 100644 index 000000000000..6b4a82fb62dc --- /dev/null +++ b/.hooks/pre-commit.d/common.sh @@ -0,0 +1,7 @@ +error() { + echo -e "$*" > /dev/stderr +} + +pre_commit_error() { + error "[pre-commit] ERROR: $*" +}