scripts-setup: Add example pre commit hook

To support the upcoming OE4T contributor guide wiki page, add
a script which generates a pre-commit hook with Signed-off-by
message appended.

Signed-off-by: Dan Walkes <danwalkes@boulderai.com>
This commit is contained in:
Dan Walkes
2020-11-15 11:12:30 -07:00
committed by Matt Madison
parent 5fdcde820a
commit e6bd1d9aaf
3 changed files with 36 additions and 0 deletions

18
scripts-setup/setup-git-hooks Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
set -e
BASEDIR=$(git rev-parse --show-toplevel)
SCRIPTDIR=$(dirname $0)
for GITHOOKDIR in ${BASEDIR}/.git/hooks ${BASEDIR}/.git/modules/repos/*/hooks
do
for GITHOOK in ${SCRIPTDIR}/git-scripts/*
do
GITHOOKFILE=$(basename $GITHOOK)
if [ -e ${GITHOOKDIR}/${GITHOOKFILE} ]; then
echo "A git hook file aleady exists at ${GITHOOKDIR}/${GITHOOKFILE}, leaving as-is"
else
echo "Adding ${GITHOOKFILE} to ${GITHOOKDIR}"
cp ${GITHOOK} ${GITHOOKDIR}
chmod a+x ${GITHOOKDIR}/${GITHOOKFILE}
fi
done
done