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