Keeping update-prefer-rebase from stepping on update-stable.
authorStephen Haberman <stephen@exigencecorp.com>
Sun, 13 Jul 2008 20:48:53 +0000 (15:48 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Sun, 13 Jul 2008 20:48:53 +0000 (15:48 -0500)
server/update-prefer-rebase
tests/t2101-server-update-stable-and-prefer-rebased.sh [new file with mode: 0644]
tests/test-lib.sh

index 5d9948a..7dc1ef8 100644 (file)
@@ -45,6 +45,11 @@ fi
 git rev-parse --not --branches | git rev-list --stdin $oldrev..$newrev | while read commit ; do
        number_of_parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit | wc -l)
        if [[ $number_of_parents > 1 ]] ; then
+               # Hack to not interfer with the update-stable "--no-ff" method
+               if [[ "$refname" == "refs/heads/stable" && "$commit" == "$newrev" ]] ; then
+                       exit 0
+               fi
+
                # Find the original branch point (B)
                parents=$(git rev-list -n 1 --parents $commit | sed 's/ /\n/g' | grep -v $commit)
                baserev=$(git merge-base $parents)
diff --git a/tests/t2101-server-update-stable-and-prefer-rebased.sh b/tests/t2101-server-update-stable-and-prefer-rebased.sh
new file mode 100644 (file)
index 0000000..b82f853
--- /dev/null
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+test_description='server update stable enforcer still works with prefer rebased'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+       echo setup >a &&
+       git add a &&
+       git commit -m "a" &&
+       git clone ./. server &&
+       git remote add origin ./server &&
+       rm -fr server/.git/hooks
+'
+
+# setup the update hook
+install_update_hook 'update-stable' 'update-prefer-rebase'
+
+test_expect_success 'initial stable commit works' '
+       # do one stable-less commit
+       echo $test_name >a &&
+       git commit -a -m "$test_name" &&
+       git push origin master &&
+
+       git checkout -b stable &&
+       git push origin stable &&
+       git config --add branch.stable.remote origin &&
+       git config --add branch.stable.merge refs/heads/stable
+'
+
+test_expect_success 'accept merge' '
+       # make one topic branch
+       git checkout -b topic1 stable &&
+       echo $test_name >topic1 &&
+       git add topic1 &&
+       git commit -m "$test_name topic1" &&
+       git push origin topic1 &&
+
+       # try merging topic1 into stable, which will get a merge commit, but
+       # it should have changes involved and so get rejected
+       git checkout stable &&
+       git merge --no-ff topic1 &&
+       git push
+'
+
+test_done
+
index 2c5413d..9d35ad6 100644 (file)
@@ -459,3 +459,15 @@ install_server_hook () {
     chmod +x "server/.git/hooks/$2"
 }
 
+install_update_hook () {
+       mkdir -p "server/.git/hooks"
+       hook="server/.git/hooks/update"
+       chmod +x $hook
+
+       echo "#!/bin/sh" >$hook
+       for ((i=1;i<=$#;i+=1)); do
+               eval script_name="$"$i
+               echo "../../../../server/$script_name \$1 \$2 \$3" >>$hook
+       done
+}
+