From: Stephen Haberman Date: Thu, 14 Aug 2008 04:15:44 +0000 (-0500) Subject: Rename update-trac -> update-ensure-ticket-reference. X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=3de011bf5dceb9f25fd8f2168b6605601c196b91;p=git-central.git Rename update-trac -> update-ensure-ticket-reference. --- diff --git a/cbas/update b/cbas/update index b8b2226..4d197bb 100755 --- a/cbas/update +++ b/cbas/update @@ -5,7 +5,7 @@ oldrev="$2" newrev="$3" ruby /srv/git/hooks/server/update-lock-check.rb "$refname" "$oldrev" "$newrev" && -sh /srv/git/hooks/server/update-trac "$refname" "$oldrev" "$newrev" && +sh /srv/git/hooks/server/update-ensure-ticket-reference "$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" && sh /srv/git/hooks/server/update-prefer-underscores "$refname" "$oldrev" "$newrev" && diff --git a/server/update-ensure-ticket-reference b/server/update-ensure-ticket-reference new file mode 100644 index 0000000..5d6014c --- /dev/null +++ b/server/update-ensure-ticket-reference @@ -0,0 +1,24 @@ +#!/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 + # Have log dump the "subject line, new line, body" of each commit message for grepping + 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 "----------------------------------------------------" >&2 + echo "" >&2 + echo "Commit $commit does not reference a ticket" >&2 + echo "" >&2 + echo "----------------------------------------------------" >&2 + exit 1 + fi +done + diff --git a/server/update-trac b/server/update-trac deleted file mode 100644 index 5d6014c..0000000 --- a/server/update-trac +++ /dev/null @@ -1,24 +0,0 @@ -#!/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 - # Have log dump the "subject line, new line, body" of each commit message for grepping - 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 "----------------------------------------------------" >&2 - echo "" >&2 - echo "Commit $commit does not reference a ticket" >&2 - echo "" >&2 - echo "----------------------------------------------------" >&2 - exit 1 - fi -done - diff --git a/tests/t2000-server-update-ensure-ticket-reference.sh b/tests/t2000-server-update-ensure-ticket-reference.sh new file mode 100644 index 0000000..d96fa92 --- /dev/null +++ b/tests/t2000-server-update-ensure-ticket-reference.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +test_description='server update trac ticket enforcer' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo This is a test. >a && + git add a && + git commit -m "a" && + 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 update hook +install_server_hook 'update-ensure-ticket-reference' 'update' + +test_expect_success 'reject with bad message' ' + 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' ' + echo $test_name >a && + git commit --amend -m "$test_name re #3222" && + git push +' + +test_expect_success 'accept with re on second line' ' + echo $test_name >a && + echo "first subject line" >msg + echo "second line re #322" >>msg + git commit -a -F msg && + git push +' + +test_expect_success 'reject with bad message in second of three' ' + echo "$test_name first" >a && + git commit -a -m "$test_name first re #3222" && + + # the bad one + echo "$test_name second" >a && + git commit -a -m "$test_name second" && + head=$(git rev-parse HEAD) && + echo "head=$head" && + + echo "$test_name third" >a && + git commit -a -m "$test_name third re #3222" && + + ! git push >push.out 2>push.err && + cat push.err | grep "Commit $head does not reference a ticket" +' + +test_expect_success 'accept with re in all of three' ' + git reset --hard HEAD^^^ && + echo "$test_name first" >a && + git commit -a -m "$test_name first re #3222" && + + # the bad one + echo "$test_name second" >a && + git commit -a -m "$test_name second re #3222" && + head=$(git rev-parse HEAD) && + + echo "$test_name third" >a && + git commit -a -m "$test_name third re #3222" && + + git push +' + +test_done + diff --git a/tests/t2000-server-update-trac.sh b/tests/t2000-server-update-trac.sh deleted file mode 100644 index ff600f2..0000000 --- a/tests/t2000-server-update-trac.sh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/sh - -test_description='server update trac ticket enforcer' - -. ./test-lib.sh - -test_expect_success 'setup' ' - echo This is a test. >a && - git add a && - git commit -m "a" && - 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 update hook -install_server_hook 'update-trac' 'update' - -test_expect_success 'reject with bad message' ' - 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' ' - echo $test_name >a && - git commit --amend -m "$test_name re #3222" && - git push -' - -test_expect_success 'accept with re on second line' ' - echo $test_name >a && - echo "first subject line" >msg - echo "second line re #322" >>msg - git commit -a -F msg && - git push -' - -test_expect_success 'reject with bad message in second of three' ' - echo "$test_name first" >a && - git commit -a -m "$test_name first re #3222" && - - # the bad one - echo "$test_name second" >a && - git commit -a -m "$test_name second" && - head=$(git rev-parse HEAD) && - echo "head=$head" && - - echo "$test_name third" >a && - git commit -a -m "$test_name third re #3222" && - - ! git push >push.out 2>push.err && - cat push.err | grep "Commit $head does not reference a ticket" -' - -test_expect_success 'accept with re in all of three' ' - git reset --hard HEAD^^^ && - echo "$test_name first" >a && - git commit -a -m "$test_name first re #3222" && - - # the bad one - echo "$test_name second" >a && - git commit -a -m "$test_name second re #3222" && - head=$(git rev-parse HEAD) && - - echo "$test_name third" >a && - git commit -a -m "$test_name third re #3222" && - - git push -' - -test_done - diff --git a/tests/t2001-server-update-ensure-ticket-reference-merges.sh b/tests/t2001-server-update-ensure-ticket-reference-merges.sh new file mode 100644 index 0000000..71d694e --- /dev/null +++ b/tests/t2001-server-update-ensure-ticket-reference-merges.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +test_description='server update trac 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 'update-ensure-ticket-reference' 'update' + +test_expect_success 'accept merge with merge message' ' + git checkout -b topic1 master && + echo "$test_name" >a1 && + git add a1 && + git commit -m "$test_name topic1 re #1" && + git push origin topic1 && + + git checkout -b topic2 master && + echo "$test_name" >a2 && + git add a2 && + git commit -m "$test_name topic2 re #2" && + git push origin topic2 && + + git checkout topic1 && + echo "$test_name" >>a1 && + git commit -a -m "$test_name topic1 re #1 again" && + git merge topic2 && + git push +' + +test_done + diff --git a/tests/t2001-server-update-trac-merges.sh b/tests/t2001-server-update-trac-merges.sh deleted file mode 100644 index a8851a0..0000000 --- a/tests/t2001-server-update-trac-merges.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -test_description='server update trac 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 'update-trac' 'update' - -test_expect_success 'accept merge with merge message' ' - git checkout -b topic1 master && - echo "$test_name" >a1 && - git add a1 && - git commit -m "$test_name topic1 re #1" && - git push origin topic1 && - - git checkout -b topic2 master && - echo "$test_name" >a2 && - git add a2 && - git commit -m "$test_name topic2 re #2" && - git push origin topic2 && - - git checkout topic1 && - echo "$test_name" >>a1 && - git commit -a -m "$test_name topic1 re #1 again" && - git merge topic2 && - git push -' - -test_done - diff --git a/tests/t2002-server-update-ensure-ticket-reference-branches.sh b/tests/t2002-server-update-ensure-ticket-reference-branches.sh new file mode 100644 index 0000000..be34923 --- /dev/null +++ b/tests/t2002-server-update-ensure-ticket-reference-branches.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +test_description='server update trac 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 'update-ensure-ticket-reference' 'update' + +test_expect_success 'reject new branch with bad message' ' + git checkout -b topic1 master && + 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' ' + git checkout -b topic2 master && + echo $test_name >a && + git commit --amend -m "$test_name re #3222" && + git push origin topic2 +' + +test_expect_success 'reject new branch with bad message in second of three' ' + git checkout -b topic3 master && + echo "$test_name first" >a && + git commit -a -m "$test_name first re #3222" && + + # the bad one + echo "$test_name second" >a && + git commit -a -m "$test_name second" && + head=$(git rev-parse HEAD) && + + echo "$test_name third" >a && + git commit -a -m "$test_name third re #3222" && + + ! git push origin topic3 >push.out 2>push.err && + cat push.err | grep "Commit $head does not reference a ticket" +' + +test_expect_success 'accept new branch with re in all of three' ' + git checkout -b topic4 master && + echo "$test_name first" >a && + git commit -a -m "$test_name first re #3222" && + + # the bad one + echo "$test_name second" >a && + git commit -a -m "$test_name second re #3222" && + head=$(git rev-parse HEAD) && + + echo "$test_name third" >a && + git commit -a -m "$test_name third re #3222" && + + git push origin topic4 +' + +test_done + diff --git a/tests/t2002-server-update-trac-branches.sh b/tests/t2002-server-update-trac-branches.sh deleted file mode 100644 index 437dbe6..0000000 --- a/tests/t2002-server-update-trac-branches.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh - -test_description='server update trac 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 'update-trac' 'update' - -test_expect_success 'reject new branch with bad message' ' - git checkout -b topic1 master && - 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' ' - git checkout -b topic2 master && - echo $test_name >a && - git commit --amend -m "$test_name re #3222" && - git push origin topic2 -' - -test_expect_success 'reject new branch with bad message in second of three' ' - git checkout -b topic3 master && - echo "$test_name first" >a && - git commit -a -m "$test_name first re #3222" && - - # the bad one - echo "$test_name second" >a && - git commit -a -m "$test_name second" && - head=$(git rev-parse HEAD) && - - echo "$test_name third" >a && - git commit -a -m "$test_name third re #3222" && - - ! git push origin topic3 >push.out 2>push.err && - cat push.err | grep "Commit $head does not reference a ticket" -' - -test_expect_success 'accept new branch with re in all of three' ' - git checkout -b topic4 master && - echo "$test_name first" >a && - git commit -a -m "$test_name first re #3222" && - - # the bad one - echo "$test_name second" >a && - git commit -a -m "$test_name second re #3222" && - head=$(git rev-parse HEAD) && - - echo "$test_name third" >a && - git commit -a -m "$test_name third re #3222" && - - git push origin topic4 -' - -test_done -