Merge branch 'np/pack'
[git] / templates / hooks--update
1 #!/bin/sh
2 #
3 # An example hook script to blocks unannotated tags from entering.
4 # Called by git-receive-pack with arguments: refname sha1-old sha1-new
5 #
6 # To enable this hook, make this file executable by "chmod +x update".
7 #
8 # Config
9 # ------
10 # hooks.allowunannotated
11 #   This boolean sets whether unannotated tags will be allowed into the
12 #   repository.  By default they won't be.
13 #
14
15 # --- Command line
16 refname="$1"
17 oldrev="$2"
18 newrev="$3"
19
20 # --- Safety check
21 if [ -z "$GIT_DIR" ]; then
22         echo "Don't run this script from the command line." >&2
23         echo " (if you want, you could supply GIT_DIR then run" >&2
24         echo "  $0 <ref> <oldrev> <newrev>)" >&2
25         exit 1
26 fi
27
28 if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
29         echo "Usage: $0 <ref> <oldrev> <newrev>" >&2
30         exit 1
31 fi
32
33 # --- Config
34 allowunannotated=$(git-repo-config --bool hooks.allowunannotated)
35
36 # check for no description
37 projectdesc=$(sed -e '1p' "$GIT_DIR/description")
38 if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb" ]; then
39         echo "*** Project description file hasn't been set" >&2
40         exit 1
41 fi
42
43 # --- Check types
44 # if $newrev is 0000...0000, it's a commit to delete a branch
45 if [ -z "${newrev##0*}" ]; then
46         newrev_type=commit
47 else
48         newrev_type=$(git-cat-file -t $newrev)
49 fi
50
51 case "$refname","$newrev_type" in
52         refs/tags/*,commit)
53                 # un-annotated tag
54                 short_refname=${refname##refs/tags/}
55                 if [ "$allowunannotated" != "true" ]; then
56                         echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
57                         echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
58                         exit 1
59                 fi
60                 ;;
61         refs/tags/*,tag)
62                 # annotated tag
63                 ;;
64         refs/heads/*,commit)
65                 # branch
66                 ;;
67         refs/remotes/*,commit)
68                 # tracking branch
69                 ;;
70         *)
71                 # Anything else (is there anything else?)
72                 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
73                 exit 1
74                 ;;
75 esac
76
77 # --- Finished
78 exit 0