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