919 - 926 - 9847

How I use Subversion for Web Development part 2 - SVN2WEB

I tried to get into ANT.  I really did.  I'm hoping to eventually get to a TACFUG meeting where they do an ANT setup tutorial (I think Jim Priest has done those before).  I did discover this nifty little SVN hook script in the meantime, SVN2WEB.  Walk through the installation guide, and come on back.

So how do I use this, and why?  Let's get to the why first.  I loath FTP.  Really, really, really cannot stand it.  Why?  I've been bitten in the arse far too many times to count overwriting files that should not pushed to production.  You also run into issues with multiple developers touching files on the server, and essentially doing their development on the server (instead of locally).  For that reason, I ONLY allow file pushes from the SVN server to production.  That's where this script comes in.

So let's get this set up.  First, read the tutorial on how I use SVN for development.  On our TRUNK folder, we're going to create a new SVN property.

  • Right click anywhere, and choose TortoiseSVN->Repo Browser.
  • Browse to your Test project, and right click the trunk folder and choose Properties.
  •  Create a new property.  Use the name svn2web, and the property value is something like ftp:www.mysite.com:<password>@<username>:<path on server>.  There's also options for local file system copy or SFTP.
  • This should point to your staging/development/test server.
  • Do the same for the PROD_100 branch, but point it at your production server.

So, every time you make a change to TRUNK or PROD, it's automatically reflected in your environments.  As an added plus, you can make just ONE person in charge of PROD, and all merges must go through that single point of entry.
I find it to be a great system.  Everyone on the team develops locally, does acceptance testing on internet staging, and then deploy to production once the acceptance testing is done.

The only real downside?  Small changes can be a bit more time consuming.  You  need to follow the flow of make the change in TRUNK, merge the change into PROD, then commit that change up.  But it does force everyone to follow a procedure, there's no shortcuts, and no code cowboys mucking about with live code.

How I use Subversion for Web Development

Take this with a grain of salt.  I've read over various how-to's, and although this isn't 100% consistent with some of that, it's worked well for me.

I'm not going to document creating a server, and presuppose you've already done this.  I'll show an example using subClipse and an example using Tortoise SVN client.  The other "gotcha" is you'll need two separate copies of your codebase, or you'll need to "switch" your working copy.  I prefer to have a separate codebase, so that's what you'll see here.  I'll also show you a great little SVN hook, svn2web.

First, some client agnostic instructions:

  • Create a new repo, or create a new project within an existing one.  We'll call ours "MySite"
  • Create a branches folder, and a trunk folder within this new project.  Fairly standard stuff here.
  • In the branches folder, create a PROD_100 folder. 

This is we part ways with "the norm".  We're going to be using the PROD folder to hold our current production site code.  In the end, we'll use svn2web to push changes to our production server.  TRUNK is going to hold all of our current (and on going) development.  We'll be pushing TRUNK to our development server.
Toirtoise SVN

  • Check out your new TRUNK, I put mine in c:\cf_dev\projects\mysite_dev.  After creating the folder to hold your project, right click and choose SVN Checkout… and browse to the SVN server where you created the trunk.
  • Check out your new PROD, I put mine in c:\cf_dev\projects\mysite_prod.  After creating the folder to hold your project, right click and choose SVN Checkout… and browse to the SVN server where you created the PROD_100.
  • Create a new text/html/whatever file in c:\cf_dev\projects\mysite_dev.  I made a test.cfm file.
  • Commit this file.  Right click the file, SVN Commit.  Follow through the prompts, give a comment if you wish.  You now have a file sitting in your TRUNK folder.
  • IMPORTANT: Before you can get this change into PROD, you will need to SVN Update on the c:\cf_dev\projects\mysite_prod folder.  Right click this folder, and choose SVN Update.  This will need to be done EVERY SINGLE TIME!
  • Right click the c:\cf_dev\projects\mysite_prod folder, and choose TortoiseSVN-> Merge…  Choose to merge a range of revisions.  On the next screen, point the URL at where your current TRUNK folder is located.  Then, use the show log to choose your revision ranges, and click next.  Leave the defaults, and choose merge.
  •  Provided you have no conflicts, and at this point you shouldn't as it's a new file, it's time to commit the changes.  You won't be able to merge any other files into this working copy until you commit the current changes!  So, go ahead and right click the c:\cf_dev\projects\mysite_prod\test.cfm file and SVN Commit.
  • Congrats!  You've now merged a change into your production environment!


  • I tend create a new eclipse project for production and development.  So go ahead and create a project for production and development, c:\cf_dev\projects\mysite_dev and c:\cf_dev\projects\mysite_prod.
  • Right click the project, and select Team-> Share Project.  Choose SVN, and the URL to your repository.  Follow through the prompts.  Do this for each project, TRUNK and PROD_100
  • Create a new file in the mysite_dev project. 
  • Right-click the project, and team -> Commit… your changes up
  • On your PROD project, right click and Team-> Update to Head.
  • On your PROD project, right click and Team -> Merge.  Choose to Merge a range of revisions.  Chose the URL to your SVN TRUNK.  After clicking next, you get a nice table view of the available ranges of revisions, along with the comments.  When it finishes, it'll display a dialog of changes.
  • IMPORTANT: You MUST update the PROD project with Team-> Update to head… every single time you wish to do a merge.  You also MUST commit pending changes before you can do any further merges.
  • Commit the merged changes with Team-> Commit.
  • Congrats!  You've now merged a change into your production environment!

Now, the caveats. 

The concept the of merging is thus, at least according to the docs.  You're supposed to create a branch to work on from trunk.  After you're done working with this branch, ideally you would then re-integrate with trunk.  We will not do this.  Ever. 

The idea that I go by is trunk is for all current and future dev, and these branches (PROD_100, PROD_200) match major revisions in my deployment.  I realize that "tags" are typically used for releases, however, that makes are more sense to me when you're talking about Java/C++/insert language here.  For web development, I just don't see this as viable.  Add to that the inclusion of the svn2web hooks that I use, it'd be a tremendous pain to create a hook for every single tag that I'd add.  There's times I make 20-50 commits a week across my various client base.

Next post I'll detail svn2web, but for now, this is how I (and my team) leverage SVN to publish content to our websites.