#!/bin/sh # # An example hook script to blocks unannotated tags from entering. # Called by git-receive-pack with arguments: refname sha1-old sha1-new # # Config # ------ # hooks.update-allow-tags-branches.unannotatedtag # This boolean sets whether unannotated tags will be allowed into the # repository. By default they won't be. # hooks.update-allow-tags-branches.deletetag # This boolean sets whether deleting tags will be allowed in the # repository. By default they won't be. # hooks.update-allow-tags-branches.deletebranch # This boolean sets whether deleting branches will be allowed in the # repository. By default they won't be. # hooks.update-allow-tags-branches.nakedtag # This boolean sets whether tags are allowed into the repo to commits # that are not pointed to by a branch. By default they won't be. # . $(dirname $0)/functions # --- Command line refname="$1" oldrev="$2" newrev="$3" # --- Config allowunannotatedtag=$(git config --bool hooks.update-allow-tags-branches.unannotatedtag) allowdeletebranch=$(git config --bool hooks.update-allow-tags-branches.deletebranch) allowdeletetag=$(git config --bool hooks.update-allow-tags-branches.deletetag) allownakedtag=$(git config --bool hooks.update-allow-tags-branches.nakedtag) # --- Check types # if $newrev is 0000...0000, it's a commit to delete a ref. if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then newrev_type=delete else newrev_type=$(git-cat-file -t $newrev) fi case "$refname","$newrev_type" in refs/tags/*,commit) # un-annotated tag short_refname=${refname##refs/tags/} if [ "$allowunannotatedtag" != "true" ]; then display_error_message "Unannotated tags ($short_refname) are not allowed" exit 1 fi contains=$(git branch --contains "$newrev" | wc -l) if [ $contains -eq 0 -a "$allownakedtag" != "true" ] ; then display_error_message "The tag $short_refname is not included in any branch" exit 1 fi ;; refs/tags/*,delete) # delete tag if [ "$allowdeletetag" != "true" ]; then display_error_message "Deleting tags is not allowed" exit 1 fi ;; refs/tags/*,tag) # annotated tag short_refname=${refname##refs/tags/} contains=$(git branch --contains "$newrev" | wc -l) if [ $contains -eq 0 -a "$allownakedtag" != "true" ] ; then display_error_message "The tag $short_refname is not included in any branch" exit 1 fi ;; refs/heads/*,commit) # branch ;; refs/heads/*,delete) # delete branch if [ "$allowdeletebranch" != "true" ]; then echo "*** Deleting a branch is not allowed in this repository" >&2 exit 1 fi ;; refs/remotes/*,commit) # tracking branch ;; refs/remotes/*,delete) # delete tracking branch if [ "$allowdeletebranch" != "true" ]; then echo "*** Deleting a tracking branch is not allowed in this repository" >&2 exit 1 fi ;; *) # Anything else (is there anything else?) echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 exit 1 ;; esac # --- Finished exit 0