21 November 2007
Remove SVN files with automator
We’ve been using subversion pretty extensively recently and loving the idea of it (though it is rather finicky). When reusing files for multiple projects, often you’ll want to just copy and paste folders and files right into another project. This poses a problem when using subversion because if the folder already contains .svn files, you won’t be able to add it to another repository. So, you first must delete those files. This is the command line script we’ve been using to remove them (recursively from the directory you are currently in):
find . -name .svn -print0 | xargs -0 rm -rf
It’s a pain having to open terminal though, so here’s a nice way of accomplishing the same result using Automator:

You can find all of these actions under “Applications” in the Automator Library. Starting with (1) Ask for confirmation, we prompt the user to make sure they want to continue. (2) Gets a list of selected finder items [if you had a group of directories selected, it makes a list of those]. At (3), the script we were using before is run on each item (removing the “.svn” file in each directory):
for f in "$@" do find "$f" -name .svn -print0 | xargs -0 rm -rf echo "$f" done
Then at (4) it outputs the list of items cleared to a text file on the desktop. When compiling to a plug-in (explained further down) I have this “disabled” so I don’t get that textfile every time. Perhaps you could do something like output the results to the console.
You can then go to File > Save As Plugin… Save the file (I called it “ClearSVN”) as a Plug-in for: Finder. This enables you to right click a directory, go to Automator… and select “ClearSVN” which would clear the .svn files inside that directory!
NOTE that this is for OS Tiger. In Leopard, the actions seem to be slightly different, but could be updated to work the same way.

Comments
Thank you so much for this. I have been struggling with finding a way to delete the svn files and I was just about to give up and start manually going through each directory.
Thanks again!
Great use of automator!
All you need to do is drag the folder with the right mouse button and it will copy it without the .svn directories!
While this is a great way to use Automator to do this, Subversion has a built in feature to do this. “svn export” will take a repository url or a working copy path and create a working-copy like structure but without the .svn directories. Oh…while I’m here, checkout my complete and up-to-date Universal Subversion OS X Binary: http://www.open.collab.net/downloads/community/. Excellent way to easily install Subversion and have as complete a Subversion installation as you’ll find.
very handy ! thank you
@Jeremy Whitlock
I’m confused – OS X already comes with Subversion built-in (version 1.6.2 I believe); why would I need a binary package?
Good advice about the export though – I can’t believe people were coming up with scripts to manually delete those .svn directories!
What I’d love automator to be able to do is allow me to label any directories that contain .svn directories a different color so I can easily identify checkouts in Finder. Unfortunately, the Finder utilities in Automator can’t see those directories as they start with a ‘.’ and are therefore hidden.