From: Stephen Haberman Date: Fri, 20 Jun 2008 01:21:29 +0000 (-0500) Subject: Server side (non-trac) commit message enforcement. X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=ed7e166b66f4d6eba57bd0ac95a134afcf253a59;p=git-central.git Server side (non-trac) commit message enforcement. --- diff --git a/client/commit-msg b/client/commit-msg index 60f638e..0800f02 100644 --- a/client/commit-msg +++ b/client/commit-msg @@ -4,7 +4,7 @@ grep -i '\(\(re\|refs\|qa\) #[0-9]\+\)\|\(no ticket\)' "$1" > /dev/null if [ $? -ne 0 ] then - echo "Please reference a ticket" - exit 1 + echo "Please reference a ticket" + exit 1 fi diff --git a/server/post-receive-trac b/server/post-receive-trac index fc8d0e1..ab9362c 100644 --- a/server/post-receive-trac +++ b/server/post-receive-trac @@ -9,8 +9,8 @@ while read oldrev newrev refname ; do git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin $newrev else git rev-parse --not --branches | grep -v $(git rev-parse $refname) | git rev-list --stdin $oldrev..$newrev - fi | while read com ; do - /home/BIPFS/shaberman/local/bin/python /srv/git/hooks/trac-post-commit-hook.py -p "$TRAC_ENV" -r "$com" + fi | while read commit ; do + /home/BIPFS/shaberman/local/bin/python /srv/git/hooks/trac-post-commit-hook.py -p "$TRAC_ENV" -r "$commit" done done diff --git a/server/pre-receive-ticket b/server/pre-receive-ticket new file mode 100644 index 0000000..7858585 --- /dev/null +++ b/server/pre-receive-ticket @@ -0,0 +1,18 @@ +#!/bin/sh + +while read oldrev newrev refname ; do + if expr "$oldrev" : '0*$' >/dev/null + then + git rev-list $newrev + else + git rev-list $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 +done + diff --git a/tests/t1000-commit-msg-ticket-hook.sh b/tests/t1000-commit-msg-ticket-hook.sh index 033f08a..6a0b591 100644 --- a/tests/t1000-commit-msg-ticket-hook.sh +++ b/tests/t1000-commit-msg-ticket-hook.sh @@ -1,10 +1,9 @@ #!/bin/sh -test_description='commit-msg ticket hook' +test_description='client commit-msg ticket enforcer' . ./test-lib.sh - # setup the commit-msg hook install_client_hook 'commit-msg' 'commit-msg' diff --git a/tests/t2000-server-pre-receive-ticket.sh b/tests/t2000-server-pre-receive-ticket.sh new file mode 100644 index 0000000..b84dca5 --- /dev/null +++ b/tests/t2000-server-pre-receive-ticket.sh @@ -0,0 +1,46 @@ + +#!/bin/sh + +test_description='server pre-receive 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 pre-receive hook +install_server_hook 'pre-receive-ticket' 'pre-receive' + +test_expect_success 'reject with bad message' ' + echo $test_name >a && + git commit -a -m "foo" && + git push >push.out 2>push.err + head=$(git rev-parse HEAD) + 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 "foo 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_done + diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 1db8ebd..feb64c6 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -435,3 +435,9 @@ install_client_hook () { chmod +x "$TRASH_HOOKS/$2" } +install_server_hook () { + mkdir -p "server/.git/hooks" + cp "../../server/$1" "server/.git/hooks/$2" + chmod +x "server/.git/hooks/$2" +} +