Blame | Last modification | View Log | RSS feed
#!/bin/sh## An example hook script to blocks unannotated tags from entering.# Called by "git receive-pack" with arguments: refname sha1-old sha1-new## To enable this hook, rename this file to "update".## Config# ------# hooks.allowunannotated# This boolean sets whether unannotated tags will be allowed into the# repository. By default they won't be.# hooks.allowdeletetag# This boolean sets whether deleting tags will be allowed in the# repository. By default they won't be.# hooks.allowmodifytag# This boolean sets whether a tag may be modified after creation. By default# it won't be.# hooks.allowdeletebranch# This boolean sets whether deleting branches will be allowed in the# repository. By default they won't be.# hooks.denycreatebranch# This boolean sets whether remotely creating branches will be denied# in the repository. By default this is allowed.## --- Command linerefname="$1"oldrev="$2"newrev="$3"# --- Safety checkif [ -z "$GIT_DIR" ]; thenecho "Don't run this script from the command line." >&2echo " (if you want, you could supply GIT_DIR then run" >&2echo " $0 <ref> <oldrev> <newrev>)" >&2exit 1fiif [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; thenecho "Usage: $0 <ref> <oldrev> <newrev>" >&2exit 1fi# --- Configallowunannotated=$(git config --bool hooks.allowunannotated)allowdeletebranch=$(git config --bool hooks.allowdeletebranch)denycreatebranch=$(git config --bool hooks.denycreatebranch)allowdeletetag=$(git config --bool hooks.allowdeletetag)allowmodifytag=$(git config --bool hooks.allowmodifytag)# check for no descriptionprojectdesc=$(sed -e '1q' "$GIT_DIR/description")case "$projectdesc" in"Unnamed repository"* | "")echo "*** Project description file hasn't been set" >&2exit 1;;esac# --- Check types# if $newrev is 0000...0000, it's a commit to delete a ref.zero="0000000000000000000000000000000000000000"if [ "$newrev" = "$zero" ]; thennewrev_type=deleteelsenewrev_type=$(git cat-file -t $newrev)ficase "$refname","$newrev_type" inrefs/tags/*,commit)# un-annotated tagshort_refname=${refname##refs/tags/}if [ "$allowunannotated" != "true" ]; thenecho "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2exit 1fi;;refs/tags/*,delete)# delete tagif [ "$allowdeletetag" != "true" ]; thenecho "*** Deleting a tag is not allowed in this repository" >&2exit 1fi;;refs/tags/*,tag)# annotated tagif [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1thenecho "*** Tag '$refname' already exists." >&2echo "*** Modifying a tag is not allowed in this repository." >&2exit 1fi;;refs/heads/*,commit)# branchif [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; thenecho "*** Creating a branch is not allowed in this repository" >&2exit 1fi;;refs/heads/*,delete)# delete branchif [ "$allowdeletebranch" != "true" ]; thenecho "*** Deleting a branch is not allowed in this repository" >&2exit 1fi;;refs/remotes/*,commit)# tracking branch;;refs/remotes/*,delete)# delete tracking branchif [ "$allowdeletebranch" != "true" ]; thenecho "*** Deleting a tracking branch is not allowed in this repository" >&2exit 1fi;;*)# Anything else (is there anything else?)echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2exit 1;;esac# --- Finishedexit 0