Blog Post:

Selective Directory Checkout With TortoiseSVN

TortoiseSVNWe primarily are a Subversion shop at Sparx. Sure all the cool kernel kids use Git but we have a slightly different use case. Plus our electrical CAD tool of choice supports Subversion natively. So we use Subversion for all aspects of collaboration, configuration management, and version control. If you looked inside our project repositories, you would see datasheets, documentation, SolidWorks models, source code, schematics, and anything else associated with a project. But this created a problem for me until I recently stumbled on the solution. If I checked out all the files for a particular project, I would end up filling my SSD with tons of huge SolidWorks models. If I separately checked out just the directories I wanted, it was a pain to keep them all in sync with separate updates and I would often break relative paths between folders. So I was faced with two bad choices… bloated directories of unneeded files or extra headache to remember to update each directory separately and to keep their relative paths intact by hand.

But there’s a simple solution. I imagine it will work for any SVN client but I’m going to demonstrate on TortoiseSVN, the excellent Windows SVN client. The idea is simple, you can simply set the checkout depth for any folder and then override that depth later.

TortoiseSVN Repository Browser
Folders in the top level of the repository as seen with TortoiseSVN repository browser

The screenshot shows the subfolders in the top level of the project folder. I’m not interested in having the ME folders full of solid models or the hundreds of photos taking up space on my hard drive. So when I do my initial check out of that project from the svn repo with TortoiseSVN, I am going to change the checkout depth drop down menu from “Fully recursive” to “Immediate children, including folders” as shown in the second screenshot. This will give you only the immediate folders and files at the top most level. Those folders will be empty for now. And if you do an update, TortoiseSVN remembers that you want them empty and they will stay that way (until you override the ones you want in the final step).

A screen shot of TortoiseSVN showing changing the checkout depth
Change the checkout depth from the drop down menu

So now I want the CS folder to actually pull in all the sub-folders and files. To do that, I need to tell TortoiseSVN that I changed my mind and that folder should now be fully recursive when I do an SVN update. To do that, I just right click on the CS folder and choose the “TortoiseSVN->Update to Revision” context menu as shown below.

Context menu in TortoiseSVN for Update to Revision
Update to Revision context menu

That will bring up a dialog where you have the option to select a particular version from history or change the checkout depth. Now we can change the checkout depth of just the folder or folders we want.

TortoiseSVN Dialog showing how to change the checkout depth of a single folder after checkout.
Change the depth of the checkout for this one folder

We get to have our cake and eat it too, a single directory checkout for the whole project but we get to skip the directories we don’t care about. And the best part is you can change your mind as much or as often as you want. If you need to tweak one file, you can simply change the depth of the containing folder, update, make your change, commit, and then update your depth back to a shallow checkout. Very, very handy for me. Note that the final screenshot is obscuring a checkbox under the drop down menu that lets you decide if this change is sticky or temporary. So far I have just left it sticky and change it back when I want. But I suppose if you were sure you just wanted to do a quick change and then back to shallow checkout you could un-check that box.

One Response

  1. Thank you very much! I always asked myself if there was some way to do it. I knew the first step (to check out the immediate children), but didn’t know how to do the same thing to a subfolder, wich is useful when I usually need to change all the pom.xml from a multi-module project, and nothing more.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get in Touch

If you have a product design that you would like to discuss, a technical problem in need of a solution, or if you just wish you could add more capabilities to your existing engineering team, please contact us.