Add auto-hook system for git-c and git-pot

This commit is contained in:
Knut Ahlers 2016-12-12 16:57:39 +01:00
parent 21ddcf3483
commit f889caa78d
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 52 additions and 2 deletions

15
bin/git-autohook Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
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

View file

@ -17,9 +17,15 @@ git setmail
step "Loading passphrase for GPG key..."
vault-gpg $(git config user.signingkey)
step "Execute pre-commit auto-hook"
git autohook pre-commit
step "Issuing commit..."
git commit -S -v "$@"
step "Execute post-commit auto-hook"
git autohook post-commit
### Count productivity habit
step "Recording work..."

View file

@ -1,5 +1,34 @@
#!/bin/bash -ex
#!/bin/bash -e
STEP_COLOR="\033[0;36m"
NO_COLOR="\033[0m"
function step {
echo -e ${STEP_COLOR}[$(date +%H:%M:%S)] $1${NO_COLOR}
}
### Determine what to push
step "Collect refs to push to origin"
CURRENT_BRANCH=$(git branch --list | awk '/^\*/{print $2}')
REQUIRED=$(git show-ref --tags | grep -v -F "$(git ls-remote --tags origin | grep -v '\^{}' | cut -f 2)" | cut -d '/' -f 3 | xargs)
exec git push origin ${CURRENT_BRANCH} --tags
if ( test "$(git show-ref refs/heads/${CURRENT_BRANCH} | cut -d ' ' -f 1)" != "$(git show-ref refs/remotes/origin/${CURRENT_BRANCH} | cut -d ' ' -f 1)" ); then
REQUIRED="${REQUIRED} ${CURRENT_BRANCH}"
fi
if [ -z "${REQUIRED}" ]; then
exit 0
fi
step "Execute pre-push auto-hook"
git autohook pre-push
step "Execute pushes..."
for ref in ${REQUIRED}; do
git push origin ${ref}
done
step "Execute post-push auto-hook"
git autohook post-push