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
This commit is contained in:
parent
8bdd13c7aa
commit
302c208fc5
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
7
.hooks/pre-commit.d/common.sh
Normal file
7
.hooks/pre-commit.d/common.sh
Normal file
@ -0,0 +1,7 @@
|
||||
error() {
|
||||
echo -e "$*" > /dev/stderr
|
||||
}
|
||||
|
||||
pre_commit_error() {
|
||||
error "[pre-commit] ERROR: $*"
|
||||
}
|
Loading…
Reference in New Issue
Block a user