Friday, September 29, 2006

Remove Subversion from a tree

The following code will remove all the .svn folders from a tree (starting at the current file's directory).
Find.find(File.dirname(__FILE__)) { |path| `rm -rf #{path}` if path =~ /\.svn$/}
I've needed this enough times that I thought it might save someone else some time.

When did I use this? Every time I start a new project I check it into a local subversion repository. After working on the code for a bit, if I decide that it's a project worth distributing I register it somewhere else (such as RubyForge). If my project is accepted, I'll transfer the code to the projects repository. The easiest way, I've found, to move the code is to remove the local .svn directories and check out version 0 of the new repository into the project's root. At this point, I can svn add everything and check in.

I'm sure there's a better way, but this is simple and it works.

9 comments:

  1. From the command line this also works:

    find ./ -name .svn -exec rm -fr {} \;

    ReplyDelete
  2. find . -name ".svn" -exec rm '{}' \;

    ReplyDelete
  3. Ah, ships crossing in the night. He's right, though. I forgot -rf.

    ReplyDelete
  4. @jonathan and evan

    Thanks, my command line-fu is weak. =)

    ReplyDelete
  5. You could just use 'svn export'. It basically checks out the repository without all of the .svn files.

    ReplyDelete
  6. require 'fileutils'
    FileUtils.rm_rf(Dir["**/*.svn"])

    Regards,

    Dan

    ReplyDelete
  7. Anonymous1:26 AM

    I use this in my Apache config:
    RewriteRule \.svn .nosvnallowed

    Then I just have a current checkout in my DocumentRoot dir and when I want to update my website I just do an svn up in place. Since the .svn components are rewrtten there's no way anybody can access those files from outside. This is faster than the other options especially for bigger sites because you don't have to recopy the entire website, but instead just update the pages that have changed.

    Best regards,

    Rudi Cilibrasi

    ReplyDelete
  8. svn export {url of project tree} {local directory}

    ReplyDelete
  9. Corey G9:46 PM

    find . -type d -name ".svn" -exec rm -rf {} \;

    ReplyDelete

Note: Only a member of this blog may post a comment.