Index: .hooks/pre-commit.d/check_rmport =================================================================== --- /dev/null +++ .hooks/pre-commit.d/check_rmport @@ -0,0 +1,65 @@ +#!/bin/sh + +# Check that a removed port is in moved, and not referenced by other ports anymore. + +check_moved() { + local status=0 + local removed_port=$1 + local rm_moved=$(awk -F '|' -vrm=${removed_port} '$1==rm && length($2)==0' MOVED) + if [ -z "${rm_moved}" ] ; then + echo "[pre-commit] ERROR: no MOVED entry for '${removed_port}'." + status=1 + fi + local mv_moved=$(awk -F '|' -vrm=${removed_port} '$2==rm' MOVED) + if [ -n "${mv_moved}" ] ; then + echo "[pre-commit] ERROR: ports are marked moved to '${removed_port}' in MOVED." + status=1 + fi + return $status +} + +check_deps() { + local status=0 + local removed_port=$1 + # check other port Makefiles for the port -- check for lines ala "...=...foo/bar" + references=`find $(make -VSUBDIR) -type f -name Makefile\* -depth 2 | xargs grep -lE "[^#]*=.*${removed_port}(@[a-z0-9-]+)?\s*[\\]?$"` + if [ -n "${references}" ] ; then + echo "[pre-commit] ERROR: port '${removed_port}' still referenced in:" + for reference in ${references} ; do + echo " * ${reference}" + done + status=1 + fi + # check framework files for the port -- check for lines ala "...=...foo/bar" + references=`find Mk -type f -name \*.mk | xargs grep -lE "[^#]*=.*${removed_port}(@[a-z0-9-]+)?\s*[\\]?$"` + if [ -n "${references}" ] ; then + echo "[pre-commit] ERROR: port '${removed_port}' still referenced in:" + for reference in ${references} ; do + echo " * ${reference}" + done + status=1 + fi + return $status +} + +status=0 +category_regex="($(make -VSUBDIR | sed 's# #\|#g'))" +removed_makefiles=$(git diff --name-only --cached --diff-filter=D | grep -E "^${category_regex}/[^/]+/Makefile$") +if [ $? -eq 0 ] ; then + for removed_makefile in ${removed_makefiles} ; do + category=$(echo "${removed_makefile}" | awk -F '/' '{print $1}') + port=$(echo "${removed_makefile}" | awk -F '/' '{print $2}') + check_moved ${category}/${port} + if [ $? -ne 0 ] ; then + status=1 + fi + check_deps ${category}/${port} + if [ $? -ne 0 ] ; then + status=1 + fi + done +fi +if [ ${status} -eq 1 ] ; then + echo "[pre-commit] ERROR: removal of ports is incomplete. Please fix above issues." + exit 1 +fi