3 # An example hook script to blocks unannotated tags from entering.
4 # Called by git-receive-pack with arguments: refname sha1-old sha1-new
8 # hooks.update-allow-tags-branches.unannotatedtag
9 # This boolean sets whether unannotated tags will be allowed into the
10 # repository. By default they won't be.
11 # hooks.update-allow-tags-branches.deletetag
12 # This boolean sets whether deleting tags will be allowed in the
13 # repository. By default they won't be.
14 # hooks.update-allow-tags-branches.deletebranch
15 # This boolean sets whether deleting branches will be allowed in the
16 # repository. By default they won't be.
17 # hooks.update-allow-tags-branches.nakedtag
18 # This boolean sets whether tags are allowed into the repo to commits
19 # that are not pointed to by a branch. By default they won't be.
22 . $(dirname $0)/functions
30 allowunannotatedtag=$(git config --bool hooks.update-allow-tags-branches.unannotatedtag)
31 allowdeletebranch=$(git config --bool hooks.update-allow-tags-branches.deletebranch)
32 allowdeletetag=$(git config --bool hooks.update-allow-tags-branches.deletetag)
33 allownakedtag=$(git config --bool hooks.update-allow-tags-branches.nakedtag)
36 # if $newrev is 0000...0000, it's a commit to delete a ref.
37 if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then
40 newrev_type=$(git-cat-file -t $newrev)
43 case "$refname","$newrev_type" in
46 short_refname=${refname##refs/tags/}
47 if [ "$allowunannotatedtag" != "true" ]; then
48 display_error_message "Unannotated tags ($short_refname) are not allowed"
51 contains=$(git branch --contains "$newrev" | wc -l)
52 if [ $contains -eq 0 -a "$allownakedtag" != "true" ] ; then
53 display_error_message "The tag $short_refname is not included in any branch"
59 if [ "$allowdeletetag" != "true" ]; then
60 display_error_message "Deleting tags is not allowed"
66 short_refname=${refname##refs/tags/}
67 contains=$(git branch --contains "$newrev" | wc -l)
68 if [ $contains -eq 0 -a "$allownakedtag" != "true" ] ; then
69 display_error_message "The tag $short_refname is not included in any branch"
78 if [ "$allowdeletebranch" != "true" ]; then
79 echo "*** Deleting a branch is not allowed in this repository" >&2
83 refs/remotes/*,commit)
86 refs/remotes/*,delete)
87 # delete tracking branch
88 if [ "$allowdeletebranch" != "true" ]; then
89 echo "*** Deleting a tracking branch is not allowed in this repository" >&2
94 # Anything else (is there anything else?)
95 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2