]> git.ipfire.org Git - thirdparty/git.git/blame - templates/hooks--update
Officially deprecate repo-config.
[thirdparty/git.git] / templates / hooks--update
CommitLineData
8d5afef0
JH
1#!/bin/sh
2#
46d409d0 3# An example hook script to blocks unannotated tags from entering.
c65a9470 4# Called by git-receive-pack with arguments: refname sha1-old sha1-new
8d5afef0 5#
829a686f 6# To enable this hook, make this file executable by "chmod +x 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.
16# hooks.allowdeletebranch
17# This boolean sets whether deleting branches will be allowed in the
18# repository. By default they won't be.
829a686f 19#
829a686f
AP
20
21# --- Command line
22refname="$1"
23oldrev="$2"
24newrev="$3"
25
26# --- Safety check
27if [ -z "$GIT_DIR" ]; then
28 echo "Don't run this script from the command line." >&2
29 echo " (if you want, you could supply GIT_DIR then run" >&2
30 echo " $0 <ref> <oldrev> <newrev>)" >&2
31 exit 1
32fi
33
34if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
35 echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
36 exit 1
37fi
38
39# --- Config
5c66d0d4
JH
40allowunannotated=$(git config --bool hooks.allowunannotated)
41allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
42allowdeletetag=$(git config --bool hooks.allowdeletetag)
8a3ee7c3 43
0a0d080b 44# check for no description
1756fed9
GP
45projectdesc=$(sed -e '1q' "$GIT_DIR/description")
46if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb." ]; then
0a0d080b
AP
47 echo "*** Project description file hasn't been set" >&2
48 exit 1
49fi
50
829a686f 51# --- Check types
ad7638b2 52# if $newrev is 0000...0000, it's a commit to delete a ref.
c32da692 53if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then
ad7638b2 54 newrev_type=delete
91776491
GP
55else
56 newrev_type=$(git-cat-file -t $newrev)
57fi
829a686f
AP
58
59case "$refname","$newrev_type" in
60 refs/tags/*,commit)
3dff5379 61 # un-annotated tag
829a686f 62 short_refname=${refname##refs/tags/}
b8ac23bc 63 if [ "$allowunannotated" != "true" ]; then
46d409d0 64 echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
829a686f
AP
65 echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
66 exit 1
8a3ee7c3 67 fi
829a686f 68 ;;
ad7638b2
GP
69 refs/tags/*,delete)
70 # delete tag
71 if [ "$allowdeletetag" != "true" ]; then
72 echo "*** Deleting a tag is not allowed in this repository" >&2
73 exit 1
74 fi
75 ;;
829a686f
AP
76 refs/tags/*,tag)
77 # annotated tag
8a3ee7c3 78 ;;
829a686f
AP
79 refs/heads/*,commit)
80 # branch
829a686f 81 ;;
ad7638b2
GP
82 refs/heads/*,delete)
83 # delete branch
84 if [ "$allowdeletebranch" != "true" ]; then
85 echo "*** Deleting a branch is not allowed in this repository" >&2
86 exit 1
87 fi
88 ;;
829a686f
AP
89 refs/remotes/*,commit)
90 # tracking branch
829a686f 91 ;;
ad7638b2
GP
92 refs/remotes/*,delete)
93 # delete tracking branch
94 if [ "$allowdeletebranch" != "true" ]; then
95 echo "*** Deleting a tracking branch is not allowed in this repository" >&2
96 exit 1
97 fi
98 ;;
829a686f
AP
99 *)
100 # Anything else (is there anything else?)
46d409d0 101 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
829a686f
AP
102 exit 1
103 ;;
104esac
105
829a686f 106# --- Finished
8d5afef0 107exit 0