Extracting SVN info from cli (command line)

For one of my project, I needed to have the SVN Repo URL for one of the file.

When doing svn info, this returns the URL in a readable format. I wanted a format that less likely to change over time (when I upgrade svn for example).

Without being set in stone, I think that an XML version of this information will less likely change! (Maybe I am wrong).

HURRAY, svn supports this!

$ svn info --xml

<?xml version="1.0"?>
<info>
<entry
  kind="dir"
  path="."
  revision="3097">
<url>https://svn.example.com/svn/projects/fubar/trunk</url>
<repository>
<root>https://svn.example.com/svn/projects/fubar</root>
<uuid>1a819d2a-f4ff-46bb-9fd0-7749d8846de9</uuid>
</repository>
<wc-info>
<schedule>normal</schedule>
<depth>infinity</depth>
</wc-info>
<commit
  revision="3097">
<author>some.user</author>
<date>2009-12-04T08:24:04.996830Z</date>
</commit>
</entry>
</info>

I was building a shell script, so I added to be able to parse XML from the command line.

I found : XMLStarlet
http://xmlstar.sourceforge.net/

Ubuntu installation:

$ sudo apt-get install xmlstarlet

CentOS Installation:

  1. http://sourceforge.net/projects/xmlstar/files/
  2. http://www.dil.univ-mrs.fr/linux/dil/centos/5/

Here is an example on how to use it:

$ svn info path/to/file --xml | xmlstarlet sel -t -v 'info/entry/url'

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You may post PHP code. You should include <?php ?> tags.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options