From: Stephen Haberman Date: Mon, 29 Sep 2008 09:33:54 +0000 (-0500) Subject: Pass the output of git describe --tags to trac as well. X-Git-Url: http://git.droids-corp.org/?p=git-central.git;a=commitdiff_plain;h=c186e8f56dfd478940a92e749e6722d5d839d2af Pass the output of git describe --tags to trac as well. --- diff --git a/server/functions b/server/functions index ff16d51..b5065d3 100644 --- a/server/functions +++ b/server/functions @@ -157,3 +157,19 @@ function set_describe() { fi } +# Sets: $describe_tags +# Assumes: $rev +# +# The email subject will contain the best description of the ref that we can build from the parameters +function set_describe_tags() { + rev_to_describe="$rev" + if [ "$1" != "" ] ; then + rev_to_describe="$1" + fi + + describe_tags=$(git describe --tags $rev_to_describe 2>/dev/null) + if [ -z "$describe_tags" ]; then + describe_tags=$rev_to_describe + fi +} + diff --git a/server/post-receive-trac b/server/post-receive-trac index 1cd5e9f..4748adc 100644 --- a/server/post-receive-trac +++ b/server/post-receive-trac @@ -21,7 +21,8 @@ while read oldrev newrev refname ; do echo "$new_commits" | git rev-list --reverse --stdin | while read commit ; do set_describe "$commit" - "$PYTHON" "$POST_RECEIVE_TRAC" "$TRAC_ENV" "$short_refname" "$describe" "$commit" + set_describe_tags "$commit" + "$PYTHON" "$POST_RECEIVE_TRAC" "$TRAC_ENV" "$short_refname" "$describe" "$describe_tags" "$commit" done done diff --git a/server/post-receive-trac.py b/server/post-receive-trac.py index 69672f0..78ab6e4 100644 --- a/server/post-receive-trac.py +++ b/server/post-receive-trac.py @@ -19,7 +19,8 @@ from trac.versioncontrol.api import NoSuchChangeset project = sys.argv[1] refname = sys.argv[2] describe = sys.argv[3] -rev = sys.argv[4] +describe_tags = sys.argv[4] +rev = sys.argv[5] def refs(ticket): pass @@ -65,7 +66,7 @@ for ticketId, commands in tickets.iteritems(): username = authorPattern.findall(changeset.author)[0] now = datetime.now(utc) - message = "(On %s [changeset:%s %s]) %s" % (refname, rev, describe, changeset.message) + message = "(On %s [changeset:%s %s]) %s" % (refname, rev, describe_tags, changeset.message) ticket['branch'] = refname ticket.save_changes(username, message, now, db, cnum+1) db.commit() diff --git a/tests/t3000-server-post-receive-trac.sh b/tests/t3000-server-post-receive-trac.sh index 9caa5ca..8c8c556 100644 --- a/tests/t3000-server-post-receive-trac.sh +++ b/tests/t3000-server-post-receive-trac.sh @@ -25,14 +25,14 @@ test_expect_success 'new branch' ' git commit -a -m "changed on topic1" && new_commit_hash=$(git rev-parse HEAD) && git push origin topic1 2>push.err && - cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic1 $new_commit_hash $new_commit_hash" + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic1 $new_commit_hash $new_commit_hash $new_commit_hash" ' test_expect_success 'new branch with already existing does not double tap' ' git checkout -b topic2 topic1 && existing_commit_hash=$(git rev-parse HEAD) && git push origin topic2 2>push.err && - ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $existing_commit_hash $existing_commit_hash" + ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2" ' test_expect_success 'update branch' ' @@ -41,7 +41,7 @@ test_expect_success 'update branch' ' git commit -a -m "changed on topic2" && new_commit_hash=$(git rev-parse HEAD) && git push origin topic2 2>push.err && - cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $new_commit_hash $new_commit_hash" + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $new_commit_hash $new_commit_hash $new_commit_hash" ' test_expect_success 'update branch to an already published commit does not double tap' ' @@ -55,8 +55,8 @@ test_expect_success 'update branch to an already published commit does not doubl git push 2>push.err && - ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $topic2_hash $topic2_hash" - ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic1 $topic1_hash $topic1_hash" + ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2" + ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic1" ' test_expect_success 'update branch with abbreviation' ' @@ -69,7 +69,7 @@ test_expect_success 'update branch with abbreviation' ' new_commit_describe=$(git describe HEAD) && new_commit_hash=$(git rev-parse HEAD) && git push origin topic2 2>push.err && - cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $new_commit_describe $new_commit_hash" + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $new_commit_describe $new_commit_describe $new_commit_hash" ' test_expect_success 'update branch with abbreviation and two commits' ' @@ -84,8 +84,8 @@ test_expect_success 'update branch with abbreviation and two commits' ' second_commit_hash=$(git rev-parse HEAD) && git push origin topic2 2>push.err && - cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $first_commit_describe $first_commit_hash" && - cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $second_commit_describe $second_commit_hash" + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $first_commit_describe $first_commit_describe $first_commit_hash" && + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $second_commit_describe $second_commit_describe $second_commit_hash" ' test_done diff --git a/tests/t3001-server-post-receive-trac-with-commit-numbers.sh b/tests/t3001-server-post-receive-trac-with-commit-numbers.sh new file mode 100644 index 0000000..7e8abdc --- /dev/null +++ b/tests/t3001-server-post-receive-trac-with-commit-numbers.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +test_description='server post receive trac with commit numbers' + +. ./test-lib.sh + +export PYTHON=echo +export POST_RECEIVE_TRAC=/foo/post-receive-trac.py +export TRAC_ENV=/foo/trac + +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 +' + +install_post_receive_hook 'post-receive-assign-commit-numbers' 'post-receive-trac' + +test_expect_success 'new branch' ' + git checkout -b topic1 master && + echo "$test_name" >a && + git commit -a -m "changed on topic1" && + new_commit_hash=$(git rev-parse HEAD) && + git push origin topic1 2>push.err && + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic1 $new_commit_hash r/1 $new_commit_hash" +' + +test_expect_success 'new branch with already existing does not double tap' ' + git checkout -b topic2 topic1 && + existing_commit_hash=$(git rev-parse HEAD) && + git push origin topic2 2>push.err && + ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2" +' + +test_expect_success 'update branch' ' + # Already on topic2 + echo "$test_name" >a && + git commit -a -m "changed on topic2" && + new_commit_hash=$(git rev-parse HEAD) && + git push origin topic2 2>push.err && + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $new_commit_hash r/2 $new_commit_hash" +' + +test_expect_success 'update branch to an already published commit does not double tap' ' + # Make topic1 catch up to topic2, which will be a fast forward that does need re-tapped + git checkout topic2 && + topic2_hash=$(git rev-parse HEAD) && + + git checkout topic1 && + git merge topic2 && + topic1_hash=$(git rev-parse HEAD) && + + git push 2>push.err && + + ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2" + ! cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic1" +' + +test_expect_success 'update branch with abbreviation' ' + git checkout topic2 + git tag -m "release1" release1 && + git push --tags && + + echo "$test_name" >a && + git commit -a -m "changed on topic2" && + new_commit_describe=$(git describe HEAD) && + new_commit_hash=$(git rev-parse HEAD) && + git push origin topic2 2>push.err && + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $new_commit_describe r/3 $new_commit_hash" +' + +test_expect_success 'update branch with abbreviation and two commits' ' + echo "$test_name 1" >a && + git commit -a -m "changed on topic2 1" && + first_commit_describe=$(git describe HEAD) && + first_commit_hash=$(git rev-parse HEAD) && + + echo "$test_name 2" >a && + git commit -a -m "changed on topic2 2" && + second_commit_describe=$(git describe HEAD) && + second_commit_hash=$(git rev-parse HEAD) && + + git push origin topic2 2>push.err && + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $first_commit_describe r/4 $first_commit_hash" && + cat push.err | grep "/foo/post-receive-trac.py /foo/trac topic2 $second_commit_describe r/5 $second_commit_hash" +' + +test_done +