update-ensure-follows to force stable tracking.
authorStephen Haberman <stephen@exigencecorp.com>
Wed, 13 Aug 2008 17:19:29 +0000 (12:19 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Wed, 13 Aug 2008 17:19:29 +0000 (12:19 -0500)
server/update-ensure-follows [new file with mode: 0644]
tests/t2700-server-ensure-follows.sh [new file with mode: 0644]

diff --git a/server/update-ensure-follows b/server/update-ensure-follows
new file mode 100644 (file)
index 0000000..09239ba
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# When updating a branch, it must include the tip of stable.
+#
+
+# Command line
+refname="$1"
+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
+fi
+
+follows=($follows)
+count=${#follows[@]}
+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
+               echo "----------------------------------------------------"
+               exit 1
+       fi
+done
+
+exit 0
+
diff --git a/tests/t2700-server-ensure-follows.sh b/tests/t2700-server-ensure-follows.sh
new file mode 100644 (file)
index 0000000..68a0052
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/sh
+
+test_description='server update ensure follows'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       echo "setup" >a &&
+       git add a &&
+       git commit -m "setup" &&
+       git clone ./. server &&
+       rm -fr server/.git/hooks &&
+       git remote add origin ./server &&
+       git config --add branch.master.remote origin &&
+       git config --add branch.master.merge refs/heads/master &&
+       git fetch
+'
+
+install_update_hook 'update-ensure-follows'
+
+test_expect_success 'pushing stable works' '
+       git checkout -b stable &&
+       git push origin stable
+'
+
+test_expect_success 'branch with unmoved stable is okay' '
+       cd server &&
+       git config hooks.ensure-follows stable &&
+       cd .. &&
+
+       git checkout -b topic1 &&
+       echo "$test_name" >a.topic1 &&
+       git add a.topic1 &&
+       git commit -m "Add on topic1." &&
+       git push origin topic1
+'
+
+test_expect_success 'branch with moved stable requires merge' '
+       git checkout stable &&
+       echo "$test_name" >a &&
+       git commit -a -m "Change on stable" &&
+       git push origin stable &&
+
+       git checkout 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" &&
+
+       git merge stable &&
+       git push origin topic1
+'
+
+test_expect_success 'branch with moved stable as second branch requires merge' '
+       cd server &&
+       git config hooks.ensure-follows "foo stable" &&
+       cd .. &&
+
+       git checkout stable &&
+       echo "$test_name" >a &&
+       git commit -a -m "Change on stable" &&
+       git push origin stable &&
+
+       git checkout 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" &&
+
+       git merge stable &&
+       git push origin topic1
+'
+
+test_done
+