From 786e5a2d031c741e676fe2f05ff5ec298407f247 Mon Sep 17 00:00:00 2001 From: Quentin Rouland Date: Sat, 21 Sep 2019 23:37:05 +0200 Subject: [PATCH] add some hooks --- README.md | 4 +--- pre-receive-hook-pep8-check.sh | 23 +++++++++++++++++++ pre-receive-hook-taiga-check-num-issue.sh | 27 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 pre-receive-hook-pep8-check.sh create mode 100644 pre-receive-hook-taiga-check-num-issue.sh diff --git a/README.md b/README.md index 0b20bf1..ddcbc7b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ # GitHooks - # HookGit - - Some hooks for git \ No newline at end of file + Some hooks for git diff --git a/pre-receive-hook-pep8-check.sh b/pre-receive-hook-pep8-check.sh new file mode 100644 index 0000000..a92ca9c --- /dev/null +++ b/pre-receive-hook-pep8-check.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +COMMAND='flake8' +TEMPDIR=`mktemp -d` + +while read oldrev newrev refname; do + files=`git diff --name-only ${oldrev} ${newrev}` + for file in ${files}; do + object=`git ls-tree --full-name -r ${newrev} | egrep "(\s)${file}\$" | awk '{ print $3 }'` + if [ -z ${object} ]; then continue; fi + mkdir -p "${TEMPDIR}/`dirname ${file}`" &> /dev/null + git cat-file blob ${object} > ${TEMPDIR}/${file} + done; +done + +# Change the filename here if your flake8 configuration +# has a different name. +git show HEAD:tox.ini > ${TEMPDIR}/tox.ini +${COMMAND} ${TEMPDIR} +STATUS=$? +rm -rf ${TEMPDIR} &> /dev/null +echo status $STATUS +exit ${STATUS} diff --git a/pre-receive-hook-taiga-check-num-issue.sh b/pre-receive-hook-taiga-check-num-issue.sh new file mode 100644 index 0000000..434be56 --- /dev/null +++ b/pre-receive-hook-taiga-check-num-issue.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +check_commit() { + # check the log message for ticket number + message=`git log --format=%s -1 $1` + ticket=`echo "$message" | grep -o "TG-[0-9]\+"` + if [ "$ticket" = "" ] ; then + echo "The first line of the commit message $1 don't contain a Taiga issue number (TG-)" + exit 1 + fi +} + +NULL_SHA1="0000000000000000000000000000000000000000" # 40 0's +new_list= +any_deleted=false +while read oldsha newsha refname; do + new_list="$new_list $newsha" +done + +git rev-list $new_list --not --all | +while read sha1; do + objtype=$(git cat-file -t $sha1) + case $objtype in + commit) check_commit $sha1;; + esac +done +