Test the conflict diff email.
[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 # Command line
13 refname="$1"
14 oldrev="$2"
15 newrev="$3"
16
17 # Look up the config variable and exit if not set
18 follows=$(git config hooks.update-ensure-follows.branches)
19 if [[ $? -ne 0 ]] ; then
20         exit 0
21 fi
22
23 # Branch deletions are okay
24 if expr "$newrev" : '0*$' >/dev/null ; then
25         exit 0
26 fi
27
28 # We only care about branches moving--ignore tags.
29 case "$refname" in
30         refs/heads/*)
31                 short_refname=${refname##refs/heads/}
32                 ;;
33         *)
34                 exit 0
35                 ;;
36 esac
37
38 excused=" $(git config hooks.update-ensure-follows.excused) "
39 if [[ $excused =~ " $short_refname " ]] ; then
40         exit 0
41 fi
42
43 follows=($follows)
44 count=${#follows[@]}
45 for ((i = 0 ; i < count ; i++)) do
46         follow="${follows[$i]}"
47         git rev-parse "$follow"
48         if [ $? -eq 0 ] ; then
49                 missing_commits=$(git log ^$newrev $follow --pretty=oneline | wc -l)
50                 if [ $missing_commits -ne 0 ] ; then
51                         echo "----------------------------------------------------"
52                         echo
53                         echo "You need to merge $follow into $short_refname"
54                         echo
55                         echo "----------------------------------------------------"
56                         exit 1
57                 fi
58         fi
59 done
60
61 exit 0
62