3 # An example hook script to blocks unannotated tags from entering.
4 # Called by git-receive-pack with arguments: refname sha1-old sha1-new
6 # To enable this hook, rename this file to "update".
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.
30 if [ -z "$GIT_DIR" ]; then
31 echo "Don't run this script from the command line." >&2
32 echo " (if you want, you could supply GIT_DIR then run" >&2
33 echo " $0 <ref> <oldrev> <newrev>)" >&2
37 if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
38 echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
43 allowunannotated=$(git config --bool hooks.allowunannotated)
44 allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
45 denycreatebranch=$(git config --bool hooks.denycreatebranch)
46 allowdeletetag=$(git config --bool hooks.allowdeletetag)
48 # check for no description
49 projectdesc=$(sed -e '1q' "$GIT_DIR/description")
50 case "$projectdesc" in
51 "Unnamed repository"* | "")
52 echo "*** Project description file hasn't been set" >&2
58 # if $newrev is 0000...0000, it's a commit to delete a ref.
59 zero="0000000000000000000000000000000000000000"
60 if [ "$newrev" = "$zero" ]; then
63 newrev_type=$(git-cat-file -t $newrev)
66 case "$refname","$newrev_type" in
69 short_refname=${refname##refs/tags/}
70 if [ "$allowunannotated" != "true" ]; then
71 echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
72 echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
78 if [ "$allowdeletetag" != "true" ]; then
79 echo "*** Deleting a tag is not allowed in this repository" >&2
88 if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
89 echo "*** Creating a branch is not allowed in this repository" >&2
95 if [ "$allowdeletebranch" != "true" ]; then
96 echo "*** Deleting a branch is not allowed in this repository" >&2
100 refs/remotes/*,commit)
103 refs/remotes/*,delete)
104 # delete tracking branch
105 if [ "$allowdeletebranch" != "true" ]; then
106 echo "*** Deleting a tracking branch is not allowed in this repository" >&2
111 # Anything else (is there anything else?)
112 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2