Fixing backslashes in SVN from windows

At Iminent someone did something horrible:
The trunk pretty much contained:

  • file a
  • dir b
    • dir c
      • file d
    • file e

And someone ,on presumably a mac or a *nix machine, added the directory “b\c”. In *nix, where the SVN server was run, this was a perfectly valid directory name. On Windows, what most of us run on, the backslash is a directory seperator.

So when TortoiseSVN tries update or check-out, it fails to create a directory like that. Even worse, when you try to delete the offending directory from the “Browse Repository”, it actually interpreted the \ as a directory seperator, so while you wanted to delete directory “b\c”, it ended up deleting directory c in b. My boss had fixed this by completely removing the trunk, and putting in a new one from his working copy, but this way you lose all history of the files, and any changes that he had made to the working set were not visible anywhere.

I fixed it by doing the following:

  • First, you branch from the Trunk revision just before those faulty directories were added.
  • Then you carefully merge all changes from trunk from that point to HEAD to that branch, while excluding all revisions that add those offending directories.
  • Then you branch the current trunk to a branch like “MessedUpTrunkBackup” using TortoiseSVN Repository browser (You can’t do it by checkout + branch, as checkout fails)
  • Then you delete the current trunk, again using the repository browser.
  • Then you copy the clean branch you made earlier to trunk, using either the repository browser or by using normal branching methods.

Tada: You now have a new trunk, without the offending changes, but with full history on all files, and you can safely issue a checkout, or an update on an earlier working copy 🙂

I am aware it’s probably possible to cleanly revert those changes from a *nix box, but we didn’t have any available at the moment, so I had to do it this way.