From 639cce8f3d2d63565b2dcbcc4a990586c5d5ee90 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Tue, 24 Jun 2008 12:30:12 -0500 Subject: [PATCH] Convert trac to update instead of pre-receive. --- cbas/pre-receive | 4 +- cbas/update | 5 +- server/pre-receive-trac | 19 ----- server/pre-receive-trac-then-noop | 11 --- server/update-trac | 19 +++++ ...ve-trac.sh => t2000-server-update-trac.sh} | 6 +- .../t2001-server-pre-receive-trac-via-shim.sh | 77 ------------------- ....sh => t2001-server-update-trac-merges.sh} | 4 +- ...h => t2002-server-update-trac-branches.sh} | 4 +- 9 files changed, 30 insertions(+), 119 deletions(-) delete mode 100644 server/pre-receive-trac delete mode 100644 server/pre-receive-trac-then-noop create mode 100644 server/update-trac rename tests/{t2000-server-pre-receive-trac.sh => t2000-server-update-trac.sh} (92%) delete mode 100644 tests/t2001-server-pre-receive-trac-via-shim.sh rename tests/{t2003-server-pre-receive-trac-merges.sh => t2001-server-update-trac-merges.sh} (87%) rename tests/{t2002-server-pre-receive-trac-branches.sh => t2002-server-update-trac-branches.sh} (93%) diff --git a/cbas/pre-receive b/cbas/pre-receive index fa7e124..800f366 100755 --- a/cbas/pre-receive +++ b/cbas/pre-receive @@ -7,7 +7,5 @@ while read newref oldref refname ; do done echo -n "$input" | sh /srv/git/hooks/server/pre-receive-only-one && -echo -n "$input" | sh /srv/git/hooks/server/pre-receive-prefer-rebase && -echo -n "$input" | sh /srv/git/hooks/server/pre-receive-stable && -echo -n "$input" | sh /srv/git/hooks/server/pre-receive-trac +echo -n "$input" | sh /srv/git/hooks/server/pre-receive-stable diff --git a/cbas/update b/cbas/update index d03ca30..baa1bdb 100755 --- a/cbas/update +++ b/cbas/update @@ -4,6 +4,7 @@ refname="$1" oldrev="$2" newrev="$3" -/srv/git/hooks/server/update-allow-tags-branches "$refname" "$oldrev" "$newrev" && -/srv/git/hooks/server/update-prefer-rebase "$refname" "$oldrev" "$newrev" +sh /srv/git/hooks/server/update-trac "$refname" "$oldrev" "$newrev" && +sh /srv/git/hooks/server/update-allow-tags-branches "$refname" "$oldrev" "$newrev" && +sh /srv/git/hooks/server/update-prefer-rebase "$refname" "$oldrev" "$newrev" diff --git a/server/pre-receive-trac b/server/pre-receive-trac deleted file mode 100644 index 8296f23..0000000 --- a/server/pre-receive-trac +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -while read oldrev newrev refname ; do - if expr "$oldrev" : '0*$' >/dev/null ; then - git rev-parse --not --branches | git rev-list --stdin --no-merges $newrev - else - git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin --no-merges $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 ] ; then - echo "Commit $commit does not reference a ticket" - exit 1 - fi - done - if [ $? -ne 0 ] ; then - exit 1 - fi -done - diff --git a/server/pre-receive-trac-then-noop b/server/pre-receive-trac-then-noop deleted file mode 100644 index 4cc3f7f..0000000 --- a/server/pre-receive-trac-then-noop +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -nl=$'\n' -input="" -while read line ; do - input="$input$line$nl" -done - -echo -n "$input" | sh $GIT_DIR/hooks/pre-receive-trac && -echo -n "$input" | sh $GIT_DIR/hooks/noop - diff --git a/server/update-trac b/server/update-trac new file mode 100644 index 0000000..3b97545 --- /dev/null +++ b/server/update-trac @@ -0,0 +1,19 @@ +#!/bin/sh + +# Command line +refname="$1" +oldrev="$2" +newrev="$3" + +if expr "$oldrev" : '0*$' >/dev/null ; then + git rev-parse --not --branches | git rev-list --stdin --no-merges $newrev +else + git rev-parse --not --branches | git rev-list --stdin --no-merges $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 ] ; then + echo "Commit $commit does not reference a ticket" + exit 1 + fi +done + diff --git a/tests/t2000-server-pre-receive-trac.sh b/tests/t2000-server-update-trac.sh similarity index 92% rename from tests/t2000-server-pre-receive-trac.sh rename to tests/t2000-server-update-trac.sh index 38d3946..ff600f2 100644 --- a/tests/t2000-server-pre-receive-trac.sh +++ b/tests/t2000-server-update-trac.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='server pre-receive trac ticket enforcer' +test_description='server update trac ticket enforcer' . ./test-lib.sh @@ -15,8 +15,8 @@ test_expect_success 'setup' ' git config --add branch.master.merge refs/heads/master ' -# setup the pre-receive hook -install_server_hook 'pre-receive-trac' 'pre-receive' +# setup the update hook +install_server_hook 'update-trac' 'update' test_expect_success 'reject with bad message' ' echo $test_name >a && diff --git a/tests/t2001-server-pre-receive-trac-via-shim.sh b/tests/t2001-server-pre-receive-trac-via-shim.sh deleted file mode 100644 index 82e35e3..0000000 --- a/tests/t2001-server-pre-receive-trac-via-shim.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/sh - -test_description='server pre-receive trac ticket enforcer via shim' - -. ./test-lib.sh - -test_expect_success 'setup' ' - echo This is a test. >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 shim -install_server_hook 'noop' 'noop' -install_server_hook 'pre-receive-trac' 'pre-receive-trac' -install_server_hook 'pre-receive-trac-then-noop' 'pre-receive' - -test_expect_success 'reject with bad message via shim' ' - echo $test_name >a && - git commit -a -m "$test_name" && - head=$(git rev-parse HEAD) && - ! git push >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 with re via shim' ' - echo $test_name >a && - git commit --amend -m "$test_name re #3222" && - git push -' - -test_expect_success 'reject second push line has bad message via shim' ' - # make a new remote branch - git branch topic1 master && - git push origin topic1 && - - # change master - echo $test_name >a && - git commit -a -m "$test_name re #3222" && - - # change topic1 with no re - git checkout topic1 && - echo "$test_name topic1" >a && - git commit -a -m "$test_name" && - head=$(git rev-parse HEAD) && - - ! git push >push.out 2>push.err && - cat push.err | grep "Commit $head does not reference a ticket" -' - -test_expect_success 'reject first push line has bad message via shim' ' - # make a new remote branch - git branch topic2 master && - git push origin topic2 && - - # change master first with no re - echo $test_name >a && - git commit -a -m "$test_name" && - head=$(git rev-parse HEAD) && - - # change topic2 with re - git checkout topic2 && - echo "$test_name topic2" >a && - git commit -a -m "$test_name re #3222" && - - ! git push >push.out 2>push.err && - cat push.err | grep "Commit $head does not reference a ticket" -' - -test_done - diff --git a/tests/t2003-server-pre-receive-trac-merges.sh b/tests/t2001-server-update-trac-merges.sh similarity index 87% rename from tests/t2003-server-pre-receive-trac-merges.sh rename to tests/t2001-server-update-trac-merges.sh index 7d3180d..a8851a0 100644 --- a/tests/t2003-server-pre-receive-trac-merges.sh +++ b/tests/t2001-server-update-trac-merges.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='server pre-receive trac ticket enforcer via shim' +test_description='server update trac ticket enforcer via shim' . ./test-lib.sh @@ -16,7 +16,7 @@ test_expect_success 'setup' ' ' # setup the hook -install_server_hook 'pre-receive-trac' 'pre-receive' +install_server_hook 'update-trac' 'update' test_expect_success 'accept merge with merge message' ' git checkout -b topic1 master && diff --git a/tests/t2002-server-pre-receive-trac-branches.sh b/tests/t2002-server-update-trac-branches.sh similarity index 93% rename from tests/t2002-server-pre-receive-trac-branches.sh rename to tests/t2002-server-update-trac-branches.sh index 3588124..437dbe6 100644 --- a/tests/t2002-server-pre-receive-trac-branches.sh +++ b/tests/t2002-server-update-trac-branches.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='server pre-receive trac ticket enforcer via shim' +test_description='server update trac ticket enforcer via shim' . ./test-lib.sh @@ -16,7 +16,7 @@ test_expect_success 'setup' ' ' # setup the hook -install_server_hook 'pre-receive-trac' 'pre-receive' +install_server_hook 'update-trac' 'update' test_expect_success 'reject new branch with bad message' ' git checkout -b topic1 master && -- 2.39.5