#!/bin/sh
#
-# When updating a branch, it must include the tip of stable.
+# When updating a branch, ensure it has the latest changes
+# from other branches, e.g. stable.
+#
+# While this forces merging sooner than devs may like, it
+# assures deployment and qa staff that the latest revisions
+# they are qa'ing will always have the last stable release
+# in it.
#
# Command line
oldrev="$2"
newrev="$3"
-# Branch deletions are okay
-# if expr "$newrev" : '0*$' >/dev/null ; then
-# exit 0
-# fi
-
# Look up the config variable and exit if not set
follows=$(git config hooks.ensure-follows)
if [[ $? -ne 0 ]] ; then
- exit 0
+ exit 0
fi
+# Branch deletions are okay
+if expr "$newrev" : '0*$' >/dev/null ; then
+ exit 0
+fi
+
+# We only care about branches moving--ignore tags.
+case "$refname" in
+ refs/heads/*)
+ short_refname=${refname##refs/heads/}
+ ;;
+ *)
+ exit 0
+ ;;
+esac
+
follows=($follows)
count=${#follows[@]}
-for (( i = 0 ; i < count ; i++)) do
+for ((i = 0 ; i < count ; i++)) do
follow="${follows[$i]}"
missing_commits=$(git log ^$newrev $follow --pretty=oneline | wc -l)
if [ $missing_commits -ne 0 ] ; then
echo "----------------------------------------------------"
echo
- echo "You need to merge with $follow"
+ echo "You need to merge $follow into $short_refname"
echo
echo "----------------------------------------------------"
exit 1
echo "$test_name" >a.topic1 &&
git commit -a -m "Change on topic1." &&
! git push origin topic1 2>push.err &&
- cat push.err | grep "You need to merge with stable" &&
+ cat push.err | grep "You need to merge stable into topic1" &&
git merge stable &&
git push origin topic1
echo "$test_name" >a.topic1 &&
git commit -a -m "Change on topic1." &&
! git push origin topic1 2>push.err &&
- cat push.err | grep "You need to merge with stable" &&
+ cat push.err | grep "You need to merge stable into topic1" &&
git merge stable &&
git push origin topic1
'
+test_expect_success 'tag with moved stable is okay' '
+ git checkout stable &&
+ echo "$test_name" >a &&
+ git commit -a -m "Change on stable" &&
+ git push origin stable &&
+
+ git checkout topic1 &&
+ git tag topic1-tag1
+ git push --tags
+'
+
+test_expect_success 'branch deletion with moved stable is okay' '
+ git checkout stable &&
+ echo "$test_name" >a &&
+ git commit -a -m "Change on stable" &&
+ git push origin :stable
+'
+
test_done