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