SVN Problem (with Solution): svn: Cannot replace a directory from within

You have a working copy that you’re trying to update, but SVN (Subversion) just produced a message that is not terribly helpful:

$ svn up my_project/
svn: Cannot replace a directory from within

Why has this happened?

Suppose that you have a working copy mapped to a fairly old location in the repository:

$ svn info my_project
Path: my_project
URL: http://repos/my_project/Trunk
Repository Root: http://repos
Revision: 7100
Node Kind: directory

Note that a later revision in the repository is a rename:

$ svn log http://repos/ -vr7572
------------------------------------------------------------------------
r7572 | someone-else | 2008-11-13 11:31:18 +0000 (Thu, 13 Nov 2008)
Changed paths:
   D /my_project/Trunk
   A /my_project/trunk (from /my_project/Trunk:7571)
------------------------------------------------------------------------

Here, the case of the “Trunk” directory has changed. SVN (as at version 1.5) still deals with renames as an add followed by a delete.

What SVN was saying was that the directory you’re trying to update has been deleted, and it can’t delete in-place.

The solution is to help SVN by switching across to the new directory (effectively a branch):

$ svn switch http://repos/my_project/trunk -r7572 my_project/
At revision 7572.

$ svn up my_project/
  (...)
At revision 8113.

The switch also performs an update to the HEAD unless you specify a revision. Thus the above could simply have been performed in a single simpler operation:

$ svn switch http://repos/my_project/trunk my_project/
  (...)
At revision 8113.

Now you should be able to continue as usual.

Normally, looking backwards through the revisions past the rename should not present any difficulties, as SVN traverses the copy/add-with-history transparently. Sometimes, however, you might need to “peg” the revision (see the SVN book for details).

Advertisements

One Response to “SVN Problem (with Solution): svn: Cannot replace a directory from within”

  1. sm4jl Says:

    Good explanation. Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: