Discard stderr when using rev ranges
[dragonfly.git] / update
CommitLineData
4aa2f496
SS
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, rename this file to "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# 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.
19#
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
40allowunannotated=$(git config --bool hooks.allowunannotated)
41allowdeletebranch=$(git config --bool hooks.allowdeletebranch)
42allowdeletetag=$(git config --bool hooks.allowdeletetag)
d9e73c58 43allownonfastfwd=$(git config --bool hooks.allownonfastfwd)
4aa2f496
SS
44
45# check for no description
46projectdesc=$(sed -e '1q' "$GIT_DIR/description")
47if [ -z "$projectdesc" -o "$projectdesc" = "Unnamed repository; edit this file to name it for gitweb." ]; then
48 echo "*** Project description file hasn't been set" >&2
49 exit 1
50fi
51
52# --- Check types
53# if $newrev is 0000...0000, it's a commit to delete a ref.
54if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then
55 newrev_type=delete
56else
21241201 57 newrev_type=$(git cat-file -t $newrev)
4aa2f496
SS
58fi
59
60case "$refname","$newrev_type" in
61 refs/tags/*,commit)
62 # un-annotated tag
63 short_refname=${refname##refs/tags/}
64 if [ "$allowunannotated" != "true" ]; then
65 echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
66 echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
67 exit 1
68 fi
69 ;;
70 refs/tags/*,delete)
71 # delete tag
72 if [ "$allowdeletetag" != "true" ]; then
73 echo "*** Deleting a tag is not allowed in this repository" >&2
74 exit 1
75 fi
76 ;;
77 refs/tags/*,tag)
78 # annotated tag
79 ;;
80 refs/heads/*,commit)
81 # branch
70c3cac4 82 if [ -n "$(git rev-list $newrev..$oldrev 2>/dev/null)" -a "$allownonfastfwd" != "true" ]; then
d9e73c58
SS
83 echo "*** Non fast forward pushes are not allowed in this repository" >&2
84 exit 1
85 fi
4aa2f496
SS
86 ;;
87 refs/heads/*,delete)
88 # delete branch
89 if [ "$allowdeletebranch" != "true" ]; then
90 echo "*** Deleting a branch is not allowed in this repository" >&2
91 exit 1
92 fi
93 ;;
94 refs/remotes/*,commit)
95 # tracking branch
96 ;;
97 refs/remotes/*,delete)
98 # delete tracking branch
99 if [ "$allowdeletebranch" != "true" ]; then
100 echo "*** Deleting a tracking branch is not allowed in this repository" >&2
101 exit 1
102 fi
103 ;;
104 *)
105 # Anything else (is there anything else?)
106 echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
107 exit 1
108 ;;
109esac
110
111# --- Finished
112exit 0