1#!/bin/sh 2# 3# An example hook script to blocks unannotated tags from entering. 4# Called by git-receive-pack with arguments: refname sha1-old sha1-new 5# 6# To enable this hook, rename this file to "update". 7# 8# Config 9# ------ 10# hooks.allowunannotated 11# This boolean sets whether unannotated tags will be allowed into the 12# repository. By default they won't be. 13# hooks.allowdeletetag 14# This boolean sets whether deleting tags will be allowed in the 15# repository. By default they won't be. 16# hooks.allowdeletebranch 17# This boolean sets whether deleting branches will be allowed in the 18# repository. By default they won't be. 19# 20 21# --- Command line 22refname="$1" 23oldrev="$2" 24newrev="$3" 25 26# --- Safety check 27if[-z"$GIT_DIR"];then 28echo"Don't run this script from the command line.">&2 29echo" (if you want, you could supply GIT_DIR then run">&2 30echo"$0<ref> <oldrev> <newrev>)">&2 31exit1 32fi 33 34if[-z"$refname"-o -z"$oldrev"-o -z"$newrev"];then 35echo"Usage:$0<ref> <oldrev> <newrev>">&2 36exit1 37fi 38 39# --- Config 40allowunannotated=$(git config --bool hooks.allowunannotated) 41allowdeletebranch=$(git config --bool hooks.allowdeletebranch) 42allowdeletetag=$(git config --bool hooks.allowdeletetag) 43 44# check for no description 45projectdesc=$(sed -e '1q' "$GIT_DIR/description") 46case"$projectdesc"in 47"Unnamed repository"* |"") 48echo"*** Project description file hasn't been set">&2 49exit1 50;; 51esac 52 53# --- Check types 54# if $newrev is 0000...0000, it's a commit to delete a ref. 55if["$newrev"="0000000000000000000000000000000000000000"];then 56 newrev_type=delete 57else 58 newrev_type=$(git-cat-file -t $newrev) 59fi 60 61case"$refname","$newrev_type"in 62 refs/tags/*,commit) 63# un-annotated tag 64 short_refname=${refname##refs/tags/} 65if["$allowunannotated"!="true"];then 66echo"*** The un-annotated tag,$short_refname, is not allowed in this repository">&2 67echo"*** Use 'git tag [ -a | -s ]' for tags you want to propagate.">&2 68exit1 69fi 70;; 71 refs/tags/*,delete) 72# delete tag 73if["$allowdeletetag"!="true"];then 74echo"*** Deleting a tag is not allowed in this repository">&2 75exit1 76fi 77;; 78 refs/tags/*,tag) 79# annotated tag 80;; 81 refs/heads/*,commit) 82# branch 83;; 84 refs/heads/*,delete) 85# delete branch 86if["$allowdeletebranch"!="true"];then 87echo"*** Deleting a branch is not allowed in this repository">&2 88exit1 89fi 90;; 91 refs/remotes/*,commit) 92# tracking branch 93;; 94 refs/remotes/*,delete) 95# delete tracking branch 96if["$allowdeletebranch"!="true"];then 97echo"*** Deleting a tracking branch is not allowed in this repository">&2 98exit1 99fi 100;; 101*) 102# Anything else (is there anything else?) 103echo"*** Update hook: unknown type of update to ref$refnameof type$newrev_type">&2 104exit1 105;; 106esac 107 108# --- Finished 109exit0