annotate modules/contrib/migrate_upgrade/.git/hooks/update.sample @ 0:c75dbcec494b

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