April 24, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

A Crash Course in Subversion, Part 2, Page 3

  • May 6, 2005
  • By Garrett Rooney, Garrett Rooney
  • Send Email »
  • More Articles »

Changing a Repository URL with svn switch --relocate

There's one other time you might need to use svn switch , and that's when the URL you use to access your Subversion repository has changed. This could happen if the URL has moved to another machine, the path it's located at changes, or if you switch from one repository access layer to another (say you want to stop accessing the repository directly via a file:// URL, and start accessing over a network with a http://or svn:// URL). In these situations, you use the --relocate flag with svn switch, and give it the portions of the URL you're changing. For example, if the repository was accessed via ra_local on your local machine at the path /home/repos, and you need to change to accessing it over ra_svn, because this working copy has been moved to a different machine, you do something like this:

$ svn info | grep ^URL
$ svn switch --relocate file:///svn://servername/
$ svn info | grep ^URL

Note that svn switch --relocate will work only if the new URL points to the exact same repository. Each Subversion repository has its own UUID, and the client will compare the UUID for the new repository to the one from the old repository and ensure that they're the same before allowing the switch to complete.

Removing Old Branches

One more advantage of Subversion's "everything is a copy" design is that there's no need to keep old development branches around in the HEAD version of the repository. Once a branch's useful life has ended, a simple svn delete will remove it from HEAD, and users will no longer be bothered by its presence in the output of svn list commands. Of course, the branch will still exist in the history of the repository, so you can easily retrieve any of its contents later by just specifying the correct revision of the repository.


Subversion allows you to associate arbitrary metadata with files, directories, and even revisions in the repository. Each bit of metadata, or property, consists of a name, which can be any Unicode string, and an arbitrary value, which can be anything at all. Internally, this functionality is used to implement a variety of different features of Subversion (log entries are properties associated with each revision, for example), but it's also exposed to users for their own use. You could, for example, choose to mark files with a "maintainer" property to indicate which developer is responsible for it. In addition to your own properties, Subversion reserves all properties starting with the prefix svn:for itself, and you can manipulate several properties in that namespace to control Subversion's behavior in useful ways. Before diving into those, though, let's look at the commands you need to use to work with properties.

First, you'll need a way to tell what, if any, properties have been set on a particular versioned resource. The svn proplist command, as you might expect, does that for you. Let's take a look at how it works:

$ ls -a
$ svn proplist index.html
Properties on 'index.html':
$ svn proplist button.png
Properties on 'button.png':

Here you can see a working copy that holds the contents of a web site. The files index.html and button.png both have the svn:mime-type property, which is a special property Subversion uses internally to track the mime type of a file.

Well, now you've seen what properties have been set on a particular file, but that's not very useful unless you can determine what value they've been set to. The svn propget command prints out the value of a given property for you. The syntax for the command is simple. It takes as its first argument the name of the property you're printing out, and subsequent arguments are the files it should use as targets.

$ svn propget svn:mime-type index.html
$ svn propget svn:mime-type button.png

As you might have guessed, index.html has the svn:mime-type of text/html, and button.png has image/png.

To make use of properties, you'll need to be able to set and change them. To do that, you'll need to use the svn propset and svn propedit commands. svn propset sets the value of a specific property on a versioned entity. You specify the property as its first argument, and then the second argument can be the value or, if you're dealing with a value that would be inconvenient to deal with on the command line, you can specify a file that holds the contents of the property via the -F filename argument. Subsequent arguments are the targets on which the property will be set.

$ svn add logo.png
A  (bin)  logo.png
$ svn commit -m "added logo.png"
Adding (bin)web/logo.png
Transmitting file data .
Committed revision 35.
$ svn propget svn:mime-type logo.png
$ svn propset svn:mime-type image/png logo.png
property 'svn:mime-type'set on 'logo.png'
$ svn status
 M     logo.png
$svn propget svn:mime-type logo.png
$ svn commit -m "set mime-type on logo.png to image/png"
Sending        web/logo.png
Committed revision 36.

Note that the mime type of logo.png was set to application/octet-stream when you first added it. This is the default behavior when Subversion determines that the file isn't plain text, and it will prevent Subversion from doing things like end-of-line conversion or keyword substitution, which would be destructive when applied to a binary file. It also keeps Subversion from attempting to display textual diffs in the output of svn diff or from automatically merging in changes during svn update, both of which aren't possible with binary files. Later, when you set the svn:mime-type to image/png, you'll see yet another new kind of output from svn status. The M in the second column of the output indicates that the file's properties have been modified. Also note that you had to commit the change back to the repository, because like most other things in Subversion, properties that are set on files and directories are versioned.

Similar to svn propset is svn propedit, which allows you to edit the contents of a property in your default text editor. Let's take a look at how this works.

$ svn proplist .
Properties on '':
$ svn propget svn:ignore .
$ svn propedit svn:ignore .
   editor pops up with contents of svn:ignore in it.
   we edit it,save,and exit
$ svn status
 M .
$svn diff
Property changes on:
$ svn commit -m "added .DS_store to svn:ignore"
Sending .
Committed revision 50.

This example shows how you can use svn propedit to edit the svn:ignore property. Also note that the svn diff command shows you the changes you make to properties as well as to the contents of files. Don't focus too much on the specifics of the value of the svn:ignore property (I'll discuss that in a minute)—just remember that the svn propedit command allows you to modify a property with an editor and that svn diff will show you the difference once you do.

As you can see by the long help message for svn propset, Subversion has several special properties, some of which you've already seen. You can set these special properties on your files and directories to control Subversion's behavior in certain ways, as shown in Table 2-3.

Table 2-3. Special Properties

Name Purpose
svn:ignore Indicates which files in a directory should be ignored by svn status
svn:keywords Indicates which RCS style keywords should be expanded in a given file
svn:executable Indicates that a given file should be made executable, if such a thing is possible on the operating system in question
svn:eol-style Indicates what style line endings should be used for a given textual file
svn:mime-type Indicates what mime type should be used when a given file is served from a mod_dav_svn enabled Apache server
svn:externals Lists directories within a given directory that should be retrieved from alternate URLs

Page 3 of 6

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Sitemap | Contact Us

Rocket Fuel