#!/bin/bash # .git/hooks/pre-receive SCRIPTPATH=$(dirname $(realpath -s $0)) while read oldrev newrev ref do echo "Ref $ref received. Checking for post-receive hook modification..." if [ ! git diff --name-only $1..$2 | grep 'post-receive' ]; then echo "Updated post-receive hook detected. Installing..." git archive $newrev | tar -x -C /tmp/newrev cp /tmp/newrev/post-receive $SCRIPTPATH/post-receive rm -rf /tmp/newrev fi done