3
# An example hook script to block unannotated tags from entering.
4
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
6
# To enable this hook, rename this file to "update".
10
# hooks.allowbadwhitespace
11
# This boolean sets whether a commit that adds bad whitespace will be
12
# allowed in the repository. By default they won't be.
13
# hooks.allowunannotated
14
# This boolean sets whether unannotated tags will be allowed into the
15
# repository. By default they won't be.
17
# This boolean sets whether deleting tags will be allowed in the
18
# repository. By default they won't be.
20
# This boolean sets whether a tag may be modified after creation. By default
22
# hooks.allowdeletebranch
23
# This boolean sets whether deleting branches will be allowed in the
24
# repository. By default they won't be.
25
# hooks.denycreatebranch
26
# This boolean sets whether remotely creating branches will be denied
27
# in the repository. By default this is allowed.
36
if [ -z "$GIT_DIR" ]; then
37
echo "Don't run this script from the command line." >&2
38
echo " (if you want, you could supply GIT_DIR then run" >&2
39
echo " $0 <ref> <oldrev> <newrev>)" >&2
43
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
44
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
49
allowunannotated=$(git config --type=bool hooks.allowunannotated)
50
allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)
51
denycreatebranch=$(git config --type=bool hooks.denycreatebranch)
52
allowdeletetag=$(git config --type=bool hooks.allowdeletetag)
53
allowmodifytag=$(git config --type=bool hooks.allowmodifytag)
55
# check for no description
56
projectdesc=$(sed -e '1q' "$GIT_DIR/description")
58
"Unnamed repository"* | "")
59
echo "*** Project description file hasn't been set" >&2
65
# if $newrev is 0000...0000, it's a commit to delete a ref.
66
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
67
if [ "$newrev" = "$zero" ]; then
70
newrev_type=$(git cat-file -t $newrev)
74
case "$refname","$newrev_type" in
77
short_refname=${refname##refs/tags/}
78
if [ "$allowunannotated" != "true" ]; then
79
echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
80
echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
86
if [ "$allowdeletetag" != "true" ]; then
87
echo "*** Deleting a tag is not allowed in this repository" >&2
93
if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
95
echo "*** Tag '$refname' already exists." >&2
96
echo "*** Modifying a tag is not allowed in this repository." >&2
103
if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
104
echo "*** Creating a branch is not allowed in this repository" >&2
110
if [ "$allowdeletebranch" != "true" ]; then
111
echo "*** Deleting a branch is not allowed in this repository" >&2
115
refs/remotes/*,commit)
119
refs/remotes/*,delete)
120
# delete tracking branch
121
if [ "$allowdeletebranch" != "true" ]; then
122
echo "*** Deleting a tracking branch is not allowed in this repository" >&2
127
# Anything else (is there anything else?)
128
echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
133
if [ $check_diff = yes ]; then
134
allow_bad_whitespace=$(git config --bool hooks.allowbadwhitespace)
135
if [ "$allow_bad_whitespace" != true ]; then
136
# If pushing a new branch, compare it with the empty object.
137
[ "$oldrev" != "$zero" ] ||
138
oldrev=4b825dc642cb6eb9a060e54bf8d69288fbee4904
139
exec git diff --check "$oldrev" "$newrev" --