Test branch creation--turns out we still need to only log new commits to avoid valida...
authorStephen Haberman <stephen@exigencecorp.com>
Fri, 20 Jun 2008 01:39:41 +0000 (20:39 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Fri, 20 Jun 2008 01:39:41 +0000 (20:39 -0500)
server/pre-receive-ticket
tests/t2002-server-pre-receive-ticket-branches.sh [new file with mode: 0644]

index 7858585..7614975 100644 (file)
@@ -3,9 +3,9 @@
 while read oldrev newrev refname ; do
        if expr "$oldrev" : '0*$' >/dev/null
        then
-               git rev-list $newrev
+               git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin $newrev
        else
-               git rev-list $oldrev..$newrev
+               git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin $oldrev..$newrev
        fi | while read commit ; do
                git log -n 1 '--pretty=format:%s%n%b' "$commit" | grep -i '\(\(re\|refs\|qa\) #[0-9]\+\)\|\(no ticket\)' > /dev/null
                if [ $? -ne 0 ]
diff --git a/tests/t2002-server-pre-receive-ticket-branches.sh b/tests/t2002-server-pre-receive-ticket-branches.sh
new file mode 100644 (file)
index 0000000..f9bfea0
--- /dev/null
@@ -0,0 +1,39 @@
+
+#!/bin/sh
+
+test_description='server pre-receive ticket enforcer via shim'
+
+. ./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
+'
+
+# setup the hook
+install_server_hook 'pre-receive-ticket' 'pre-receive'
+
+test_expect_success 'reject new branch with bad message' '
+       git checkout -b topic1
+       echo $test_name >a &&
+       git commit -a -m "$test_name" &&
+       head=$(git rev-parse HEAD)
+       git push origin topic1 >push.out 2>push.err
+       cat push.err | grep "Commit $head does not reference a ticket"
+'
+
+# the last test has a dirty commit message, so ammend it with a good message
+test_expect_success 'accept new branch with re' '
+       echo $test_name >a &&
+       git commit --amend -m "$test_name re #3222" &&
+       git push origin topic1
+'
+
+test_done
+