#!/usr/bin/env bash # Distributed under the terms of the GNU General Public License v2 # Copyright (c) 2006 Fernando J. Pereda # # Adapted version of the one found under howto/update-hook-example.txt # # Leave this or gremlings will attack your system umask 002 GLOBIGNORE=* # Need to debug? debug=false # Do you really want it to be quiet? reallyquiet=false refname=$1 oldsha1=$2 newsha1=$3 user=$(id -u -n) info() { ${reallyquiet} || echo >&2 "(II) $1" } debug() { ${debug} && echo >&2 "(--) $1" } grant() { ${reallyquiet} || echo >&2 "(**) $1" exit 0 } deny() { ${reallyquiet} || echo >&2 "(EE) $1" exit 1 } [[ ${oldsha1} =~ '^0*$' ]] && isnew=true || isnew=false case "${refname}" in refs/tags/*) if [[ -f ${GIT_DIR}/${refname} ]] ; then deny "Trying to overwrite a tag (${refname##*/}), thats bad." fi ;; refs/heads/tmp/*) if ${isnew} ; then info "New temporal branch '${refname##refs/heads/tmp/}' created." else info "Forde-updating temporal branch '${refname##refs/heads/tmp/}'." fi ;; refs/heads/*) if ${isnew} ; then info "New branch '${refname##refs/heads/}' created." else base=$(git merge-base "${oldsha1}" "${newsha1}") case "${base},${oldsha1}" in "${oldsha1},${base}") debug "Update is a fast-forward." ;; *) deny "This is not a fast-forward update." ;; esac fi ;; *) deny "Branch not under refs/heads/ or refs/tags/? Give up the crack." ;; esac while read refpat userpatts ; do if [[ ${refname} =~ ${refpat} ]] ; then debug "Pattern '${refpat}' matches '${refname}'" for p in ${userpatts} ; do debug "Checking '${user}' against '${p}'" if [[ ${user} =~ ${p} ]] ; then grant "Access granted. Please come back soon." fi done fi done < ${GIT_DIR}/info/users-allowed deny "You are not allowed to update this ref. Please come back soon."