my customized lib

Committer:
DuyLionTran
Date:
Sun Nov 26 15:08:14 2017 +0000
Revision:
0:8094b249013c
Initial commit

Who changed what in which revision?

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