commit 4f7f2d4a4a0d65117de0fceb022775bc8fd61f10 parent 7c5cbc6a4d67184d3534f6a10dab3b1334ac7d8d Author: Florian Dold <florian.dold@gmail.com> Date: Sun, 2 Oct 2016 22:10:06 +0200 git hook Diffstat:
| A | githooks/update | | | 32 | ++++++++++++++++++++++++++++++++ |
1 file changed, 32 insertions(+), 0 deletions(-)
diff --git a/githooks/update b/githooks/update @@ -0,0 +1,32 @@ +#!/bin/bash + +set -ue + +refname="$1" +oldrev="$2" +newrev="$3" + +if [ -z "${1+x}" ] || [ -z "${2+x}" ] || [ -z "${3+x}" ]; then + echo "Usage: $0 REFNAME OLDREV NEWREF" + exit 1 +fi + + +[[ -z "$(git rev-list --max-count 1 "$oldrev".."$newrev" || echo "fail")" ]] +is_ff=$? + +if $is_ff; then + # always allow fast forwards + exit 0 +fi + +if [[ "$refname" != refs/heads/master ]]; then + # allow force-pushing if it's not master + exit 0 +fi + +case $USER in +*) + exit 1 + ;; +esac