diff --git a/bin/git-autohook b/bin/git-autohook new file mode 100755 index 0000000..7572162 --- /dev/null +++ b/bin/git-autohook @@ -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 diff --git a/bin/git-c b/bin/git-c index 5b1e648..f3f10ee 100755 --- a/bin/git-c +++ b/bin/git-c @@ -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..." diff --git a/bin/git-pot b/bin/git-pot index d547302..f6074f7 100755 --- a/bin/git-pot +++ b/bin/git-pot @@ -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