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