3 # When updating a branch, ensure it has the latest changes
4 # from other branches, e.g. stable.
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
13 # hooks.update-ensure-follows.branches
14 # Space-separated list of branches that other branches must merge with
15 # hooks.update-ensure-follows.excused
16 # Space-separated list of branches that are excused from following (e.g. gitconfig)
19 . $(dirname $0)/functions
26 # Look up the config variable and exit if not set
27 follows=$(git config hooks.update-ensure-follows.branches)
28 if [[ $? -ne 0 ]] ; then
32 # Branch deletions are okay
33 if expr "$newrev" : '0*$' >/dev/null ; then
37 # We only care about branches moving--ignore tags.
40 short_refname=${refname##refs/heads/}
47 excused=" $(git config hooks.update-ensure-follows.excused) "
48 if [[ $excused =~ " $short_refname " ]] ; then
54 for ((i = 0 ; i < count ; i++)) do
55 follow="${follows[$i]}"
56 git rev-parse --verify --quiet "$follow"
57 if [ $? -eq 0 ] ; then
58 missing_commits=$(git log ^$newrev $follow --pretty=oneline | wc -l)
59 if [ $missing_commits -ne 0 ] ; then
60 # If for some reason people are stupid and push with a --force flag,
61 # we should warn them to update first in case one of their teammates
62 # already merged for them
63 if [ "0000000000000000000000000000000000000000" != "$oldrev" -a "$(git merge-base $oldrev $newrev)" != "$oldrev" ] ; then
64 display_error_message "You need to update your local branch $short_refname"
66 display_error_message "You need to merge $follow into $short_refname"