From Subversion to Git

Yesterday I’ve converted the Asterisk-Java repositories from Subversion to git. It’s rather easy when you use git-svn:

sudo apt-get install git-svn
git svn clone file:///var/lib/svn/repos/asterisk-java \
  --no-metadata -A authors.txt \
  -t tags -b branches -T trunk asterisk-java

The authors file maps the users in Subversion to the git users. While Subversion usually uses a short username, git uses the full name with email address as a globally unique identifier for users. My authors file looked like this:

srt = Stefan Reuter <>
root = Stefan Reuter <>

As I had direct filesystem access to the Subversion repositories I chose to use the file protocol instead of HTTP so it was much faster. The --no-metadata option tells git-svn not to include the orignal Subversion revision number in every commit. This removes clutter from the history.

Finally git-svn creates branches for all tags in Subversion which is a bit nasty. So I converted them to git tags:

cd asterisk-java
for tag in `git branch -r | grep '^  tags' | sed 's,  tags/,,'`
  echo Converting Tag $tag
  git tag $tag tags/$tag
  git branch -r -d tags/$tag

There it is a nice git repository containing the full history. I only had to push it to github to make it available to everybody who is interested:

git remote add origin
git push origin master
git push --tags

Deleted a File by Accident?

You have deleted a file or directory and commited your change by accident? Subversion lets you undo your change quite easily.

Use svn merge -c -<revision> <URL> in your working directory. If you have local changes that you want to commit later do a fresh checkout of <URL> to a temporary directory and run svn merge there. After running svn merge you must commit your working directory for the undo to become effective.

As this completely reverses your change the same procedure can be used to recover a deleted directory or to undo other unwanted changes.

For more information see the undo section in Version Control with Subversion.

Extracting Jira Worklogs from Subversion

We are using Atlassian‘s Jira for issue and time tracking.
Time tracking discipline has been varying mainly because it interrupts your flow if you have to leave the IDE to log work done. As we already include the corresponding Jira issue key in all our Subversion commit messages the natural idea was to just add the time spent to the commit message.

The worklog above is created from the first line of this commit message:

[BAS-70] Added README file (20m)
[BAS-61] Removed old stuff and did so
 much that it doesn't fit on a line (1w2d4h)

svn-worklog.rb is the Ruby script I wrote to extract worklog information from commit messages and attach them to the associated Jira issue. It is called from the post-commit hook.

To be able to extract the worklog the following rules must be be applied:

  • The issue key (e.g. BAS-70) must be encloced by brackets and appear at the beginning of a line
  • The time must be enclosed in braces and appear at the end of a line
  • Multiple lines per issue are ok
  • Multiple issues (and worklogs) per commit message are ok
  • time format is the same you would use on Jira’s web UI

Installation is available here from our svn repo.

To install and configure it follow these steps:

  1. Make sure Ruby is installed
  2. Install Soap4R
  3. Install the latest Jira4R
  4. Deploy the modified atlassian-jira-rpc-plugin with support for impersonation
  5. Make sure “Accept remote API calls” in Jira’s General Settings is set to “ON”
  6. Add a new Jira user and set the “allowImpersonate” property to “true”
  7. Add svn-worklog.rb to the post-commit hook of your svn repo

Step 1: Make sure Ruby is installed

Ruby probably already comes with your distribution. On Ubuntu 7.10 you would install it through apt-get:

apt-get install ruby irb rubygems ruby1.8-dev
gem update --system

Step 2: Install Soap4R

svn-worklog.rb communicates with Jira through SOAP so you need the Ruby SOAP library. Install it through gem:

gem install soap4r

Step 3: Install the latest Jira4R

You can either download the latest Jira4R from their svn repo or grab the gem here.
Install it through gem:

gem install jira4r-0.0.1.gem

Step 4: Deploy the modified atlassian-jira-rpc-plugin with support for impersonation

svn-worklog.rb must be able to add the worklog for the user perfoming the svn commit but it does not know that user’s password. Therefore I’ve added support for impersonation to the Jira RPC Plugin.

You can either download the patch and compile it on your own or grab a precompiled version for Jira 3.11.

Shut down Jira and replace the plugin with the original version in the /WEB-INF/lib directory of your Jira instance.

Step 5: Make sure “Accept remote API calls” in Jira’s General Settings is set to “ON”

To be able to communicate with Jira through SOAP you must enable RPC calls in Jira. Go to “Administration/Global Permissions” and set “Accept remote API calls” to “ON”.

Step 6: Add a new Jira user and set the “allowImpersonate” property to “true”

svn-worklog.rb will use a master user with the permissions to perform actions on behalf of other users.

Create a new user in Jira (the example uses “issues”) and set the “allowImpersonate” user property to “true”.

Step 7: Add svn-worklog.rb to the post-commit hook of your svn repo

Download svn-worklog.rb and place it in the /usr/local/bin directory. Make it executable (chmod +x /usr/local/bin/svn-worklog.rb).

Create the configuration file /etc/subversion/svn-worklog.conf:

$username = "issues"
$password = "secret"

Use the username and password of the master user created in step 6.

Add svn-worklog.rb to the post-commit hook of your repository. For example /var/lib/svn/repos/hooks/post-commit:


# Log work to Jira
echo "== REPOS=$REPOS, REV=$REV ==" >> $LOG
date >> $LOG
/usr/local/bin/svn-worklog.rb "$REPOS" "$REV" >>$LOG 2>&1
echo >> $LOG

exit 0

Of course you can later remove the logging to /tmp/svn-worklog.log but make sure the output of svn-worklog.rb is redirected to /dev/null then as Jira4R currently contains some puts debugging statements that would otherwise confuse Subversion.

Update 2009-10-15

If you are using Fisheye the same and more can now be accomplished by the official Atlassian plugins. See Dragon Slayer Supplement: Action Issues with Commit Commands. Cool!