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