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