From f51e0bd64cd7919bfa6e2b7d08445a8ea6c5c2da Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Wed, 13 Aug 2008 12:19:29 -0500 Subject: [PATCH] update-ensure-follows to force stable tracking. --- server/update-ensure-follows | 38 ++++++++++++++ tests/t2700-server-ensure-follows.sh | 75 ++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 server/update-ensure-follows create mode 100644 tests/t2700-server-ensure-follows.sh diff --git a/server/update-ensure-follows b/server/update-ensure-follows new file mode 100644 index 0000000..09239ba --- /dev/null +++ b/server/update-ensure-follows @@ -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 index 0000000..68a0052 --- /dev/null +++ b/tests/t2700-server-ensure-follows.sh @@ -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 + -- 2.39.5