annotate vendor/drupal/coder/.git/hooks/update.sample @ 19:fa3358dc1485 tip

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