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