0
votes

My eventual goal is as follows:

We want to create full traceability of code changes in our issue management software (Atlassion Jira in our case). We already force user to require Jira ticket numbers (although it is a soft requirement). One of the things our developers often have to do is fix small issues in the code as they encounter them. For proper traceability they would need to go to jira and register a ticket and use that ticket number to commit the change. But this is really tedious and time consuming.

So our plan is to make it easier to commit small fixed to the code base but do have individual tickets for those changes in our issue management system.

So the best way to do this is to simply process a macro defined in the commit message that automatically creates the ticket. e.g.

#improvement NPE fix on whatchamacallit it. This will gracefully handle 
empty values. But in places when thingamabob expects an exception, it will
no longer receive it.

This should log automatically log a ticket in our jira on the project "Quick Fixes". This ticket generation would result in a ticket with id QF-1234.

This is all doable from a pre-commit hook. However, we want to have the ticket number QF-1234 in the commit message rather than the '#improvement' macro. This way the SVN clients can link to the ticket number.

I would prefer to have this mechanism work in a synchronous and block manner. The obvious side effect would be, if jira cannot be reached, the commit fails. But this is ok/acceptable.

The automatic ticket creation is achievable from within a pre-commit hook. But I do not see a method to update the commit message before the commit is finalized.

So my question is as follows, does anyone know how I would be able to update the commit message within a SVN transaction (without creating a modified SVN library). Or have some other reliable way to achieve the same result. I know I can update a commit message in a new transaction, but this has a lot of undesired side effects.

Note, I am perfectly happy with an fragile solution that will fail the commit if anything goes wrong. Recommitting is cheap, and creating issues manually takes less than 1 minute (but I rather not waste that minute).

1

1 Answers

1
votes

does anyone know how I would be able to update the commit message within a SVN transaction

Changing content of transaction in hooks is (even if theoretically possible) very unsafe and not recommended policy. In short: NEVER DO IT, IF YOU WANT TO HAVE PREDICTABLE RESULTS!

If you have to have replacements in log-message, you have to do it in next, independent commit (which may happens in post-commit hook) with propedit|propdel-propset (second form of commands for managing revision's properties)

Short test of post-commit hook task

Starting point for revision 4

>svn log file:///Z:/PE-TEST/trunk
------------------------------------------------------------------------
r4 | Badger | 2013-02-16 14:41:46 +0600 (Сб, 16 фев 2013) | 1 line

Replacement
------------------------------------------------------------------------
r3 | Badger | 2013-02-16 14:33:46 +0600 (Сб, 16 фев 2013) | 1 line

Extended version
------------------------------------------------------------------------
r2 | Badger | 2013-02-16 14:32:00 +0600 (Сб, 16 фев 2013) | 1 line

Initial data
------------------------------------------------------------------------
r1 | Badger | 2013-02-16 14:27:49 +0600 (Сб, 16 фев 2013) | 1 line

Imported folder structure
------------------------------------------------------------------------

First attempt

>svn propset svn:log --revprop -r 4 "Replacement for #1234" file:///Z:/PE-TEST/
svn: E165006: Repository has not been enabled to accept revision propchanges;
ask the administrator to create a pre-revprop-change hook

pre-revprop-change hook

type z:\PE-TEST\hooks\pre-revprop-change.bat
exit 0

Final action

>svn propset svn:log --revprop -r 4 "Replacement for #1234" file:///Z:/PE-TEST/
property 'svn:log' set on repository revision 4

Testing results

>svn log file:///Z:/PE-TEST/trunk -r 4
------------------------------------------------------------------------
r4 | Badger | 2013-02-16 14:41:46 +0600 (Сб, 16 фев 2013) | 1 line

Replacement for #1234
------------------------------------------------------------------------

Some notes

You may to want to suppress all output of propset inside hook with -q option and write (with propget) / read (with propset) log-data from text file (pipe for get, -F file option for set)