cfg/bin/git-autohook
Knut Ahlers 542937d93f
Add error handling to git-* scripts
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-07-17 11:55:39 +02:00

18 lines
391 B
Bash
Executable file

#!/bin/bash
set -o pipefail
set -e
HOOKTYPE=$1
if ! [ -e Makefile ]; then
exit 0
fi
TARGETS=$(make -pRrq : 2>/dev/null | \
awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | \
sort | egrep -v -e '^[^[:alnum:]]' | sed 's/:$//' | xargs)
if ( echo $TARGETS | grep -q "auto-hook-${HOOKTYPE}" ); then
exec make "auto-hook-${HOOKTYPE}"
fi