302c208fc5
Add common error function in hooks Error messages are printed in stderr Reviewed By: tcberner, #portmgr Differential Revision: https://reviews.freebsd.org/D38026
32 lines
1,007 B
Bash
Executable file
32 lines
1,007 B
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# 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
|
|
pre_commit_error "dropped PORTEPOCH ${old_epoch} in ${makefile}"
|
|
exit 1
|
|
fi
|
|
if [ -n "${old_epoch}" ] ; then
|
|
if [ ${new_epoch} -lt ${old_epoch} ] ; then
|
|
pre_commit_error "PORTEPOCH decreasing from ${old_epoch} to ${new_epoch} in ${makefile}"
|
|
exit 2
|
|
fi
|
|
fi
|
|
}
|
|
|
|
modified_makefiles=$(git diff --name-only --cached --diff-filter=M -GPORTEPOCH | grep -E '^[^/]+/[^/]+/Makefile$')
|
|
if [ $? -eq 0 ] ; then
|
|
for modified_makefile in ${modified_makefiles} ; do
|
|
check_epoch ${modified_makefile}
|
|
done
|
|
fi
|