annotate graster/hacklab-engraver/.git/hooks/update.sample @ 15:8ad629298649

major refactoring
author Robert McIntyre <rlm@mit.edu>
date Sun, 29 Aug 2010 19:02:26 -0400
parents f952052e37b7
children
rev   line source
rlm@11 1 #!/bin/sh
rlm@11 2 #
rlm@11 3 # An example hook script to blocks unannotated tags from entering.
rlm@11 4 # Called by git-receive-pack with arguments: refname sha1-old sha1-new
rlm@11 5 #
rlm@11 6 # To enable this hook, rename this file to "update".
rlm@11 7 #
rlm@11 8 # Config
rlm@11 9 # ------
rlm@11 10 # hooks.allowunannotated
rlm@11 11 # This boolean sets whether unannotated tags will be allowed into the
rlm@11 12 # repository. By default they won't be.
rlm@11 13 # hooks.allowdeletetag
rlm@11 14 # This boolean sets whether deleting tags will be allowed in the
rlm@11 15 # repository. By default they won't be.
rlm@11 16 # hooks.allowmodifytag
rlm@11 17 # This boolean sets whether a tag may be modified after creation. By default
rlm@11 18 # it won't be.
rlm@11 19 # hooks.allowdeletebranch
rlm@11 20 # This boolean sets whether deleting branches will be allowed in the
rlm@11 21 # repository. By default they won't be.
rlm@11 22 # hooks.denycreatebranch
rlm@11 23 # This boolean sets whether remotely creating branches will be denied
rlm@11 24 # in the repository. By default this is allowed.
rlm@11 25 #
rlm@11 26
rlm@11 27 # --- Command line
rlm@11 28 refname="$1"
rlm@11 29 oldrev="$2"
rlm@11 30 newrev="$3"
rlm@11 31
rlm@11 32 # --- Safety check
rlm@11 33 if [ -z "$GIT_DIR" ]; then
rlm@11 34 echo "Don't run this script from the command line." >&2
rlm@11 35 echo " (if you want, you could supply GIT_DIR then run" >&2
rlm@11 36 echo " $0 <ref> <oldrev> <newrev>)" >&2
rlm@11 37 exit 1
rlm@11 38 fi
rlm@11 39
rlm@11 40 if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
rlm@11 41 echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
rlm@11 42 exit 1
rlm@11 43 fi
rlm@11 44
rlm@11 45 # --- Config
rlm@11 46 allowunannotated=$(git config --bool hooks.allowunannotated)
rlm@11 47 allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
rlm@11 48 denycreatebranch=$(git config --bool hooks.denycreatebranch)
rlm@11 49 allowdeletetag=$(git config --bool hooks.allowdeletetag)
rlm@11 50 allowmodifytag=$(git config --bool hooks.allowmodifytag)
rlm@11 51
rlm@11 52 # check for no description
rlm@11 53 projectdesc=$(sed -e '1q' "$GIT_DIR/description")
rlm@11 54 case "$projectdesc" in
rlm@11 55 "Unnamed repository"* | "")
rlm@11 56 echo "*** Project description file hasn't been set" >&2
rlm@11 57 exit 1
rlm@11 58 ;;
rlm@11 59 esac
rlm@11 60
rlm@11 61 # --- Check types
rlm@11 62 # if $newrev is 0000...0000, it's a commit to delete a ref.
rlm@11 63 zero="0000000000000000000000000000000000000000"
rlm@11 64 if [ "$newrev" = "$zero" ]; then
rlm@11 65 newrev_type=delete
rlm@11 66 else
rlm@11 67 newrev_type=$(git-cat-file -t $newrev)
rlm@11 68 fi
rlm@11 69
rlm@11 70 case "$refname","$newrev_type" in
rlm@11 71 refs/tags/*,commit)
rlm@11 72 # un-annotated tag
rlm@11 73 short_refname=${refname##refs/tags/}
rlm@11 74 if [ "$allowunannotated" != "true" ]; then
rlm@11 75 echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
rlm@11 76 echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
rlm@11 77 exit 1
rlm@11 78 fi
rlm@11 79 ;;
rlm@11 80 refs/tags/*,delete)
rlm@11 81 # delete tag
rlm@11 82 if [ "$allowdeletetag" != "true" ]; then
rlm@11 83 echo "*** Deleting a tag is not allowed in this repository" >&2
rlm@11 84 exit 1
rlm@11 85 fi
rlm@11 86 ;;
rlm@11 87 refs/tags/*,tag)
rlm@11 88 # annotated tag
rlm@11 89 if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
rlm@11 90 then
rlm@11 91 echo "*** Tag '$refname' already exists." >&2
rlm@11 92 echo "*** Modifying a tag is not allowed in this repository." >&2
rlm@11 93 exit 1
rlm@11 94 fi
rlm@11 95 ;;
rlm@11 96 refs/heads/*,commit)
rlm@11 97 # branch
rlm@11 98 if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
rlm@11 99 echo "*** Creating a branch is not allowed in this repository" >&2
rlm@11 100 exit 1
rlm@11 101 fi
rlm@11 102 ;;
rlm@11 103 refs/heads/*,delete)
rlm@11 104 # delete branch
rlm@11 105 if [ "$allowdeletebranch" != "true" ]; then
rlm@11 106 echo "*** Deleting a branch is not allowed in this repository" >&2
rlm@11 107 exit 1
rlm@11 108 fi
rlm@11 109 ;;
rlm@11 110 refs/remotes/*,commit)
rlm@11 111 # tracking branch
rlm@11 112 ;;
rlm@11 113 refs/remotes/*,delete)
rlm@11 114 # delete tracking branch
rlm@11 115 if [ "$allowdeletebranch" != "true" ]; then
rlm@11 116 echo "*** Deleting a tracking branch is not allowed in this repository" >&2
rlm@11 117 exit 1
rlm@11 118 fi
rlm@11 119 ;;
rlm@11 120 *)
rlm@11 121 # Anything else (is there anything else?)
rlm@11 122 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
rlm@11 123 exit 1
rlm@11 124 ;;
rlm@11 125 esac
rlm@11 126
rlm@11 127 # --- Finished
rlm@11 128 exit 0