2cf633801d715530bd93a5b3bc69c90b3b85e909
[git-central.git] / server / update-ensure-follows
1 #!/bin/sh
2 #
3 # When updating a branch, ensure it has the latest changes
4 # from other branches, e.g. stable.
5 #
6 # While this forces merging sooner than devs may like, it
7 # assures deployment and qa staff that the latest revisions
8 # they are qa'ing will always have the last stable release
9 # in it.
10 #
11
12 . $(dirname $0)/functions
13
14 # Command line
15 refname="$1"
16 oldrev="$2"
17 newrev="$3"
18
19 # Look up the config variable and exit if not set
20 follows=$(git config hooks.update-ensure-follows.branches)
21 if [[ $? -ne 0 ]] ; then
22         exit 0
23 fi
24
25 # Branch deletions are okay
26 if expr "$newrev" : '0*$' >/dev/null ; then
27         exit 0
28 fi
29
30 # We only care about branches moving--ignore tags.
31 case "$refname" in
32         refs/heads/*)
33                 short_refname=${refname##refs/heads/}
34                 ;;
35         *)
36                 exit 0
37                 ;;
38 esac
39
40 excused=" $(git config hooks.update-ensure-follows.excused) "
41 if [[ $excused =~ " $short_refname " ]] ; then
42         exit 0
43 fi
44
45 follows=($follows)
46 count=${#follows[@]}
47 for ((i = 0 ; i < count ; i++)) do
48         follow="${follows[$i]}"
49         git rev-parse --verify --quiet "$follow"
50         if [ $? -eq 0 ] ; then
51                 missing_commits=$(git log ^$newrev $follow --pretty=oneline | wc -l)
52                 if [ $missing_commits -ne 0 ] ; then
53                         display_error_message "You need to merge $follow into $short_refname"
54                         exit 1
55                 fi
56         fi
57 done
58
59 exit 0
60