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