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