Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147530551
D38026.1783682128.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D38026.1783682128.diff
View Options
diff --git a/.hooks/pre-commit.d/check_category_makefile b/.hooks/pre-commit.d/check_category_makefile
--- 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 @@
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
--- 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
--- 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 @@
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
--- 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 @@
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
--- 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 @@
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
--- 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
--- /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: $*"
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 10, 11:15 AM (6 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29057177
Default Alt Text
D38026.1783682128.diff (6 KB)
Attached To
Mode
D38026: Add common error function in hooks
Attached
Detach File
Event Timeline
Log In to Comment