Manage vendor/rails with Git on a Subversion Project
Here is something I’ve been experimenting with over the last week or so, and it’s working out very nicely so far:
Use Git to manage vendor/rails when your project is using Subversion.
Here’s how:
First time freezing? Easy:
- cd vendor
- git clone git://github.com/rails/rails.git
- svn add -N rails; svn ps svn:ignore .git rails
- cd rails; git checkout v2.3.3.1 (or whatever version you want)
- svn add *
Switching to a different version of Rails is now as simple as:
- cd vendor/rails
- git checkout master
- git pull origin master
- git checkout whatever
- svn add `svn st | grep ^\? | cut -f7 -d" "`
- svn rm `svn st | grep ^\! | cut -f7 -d" "`
- svn commit
If you already have a vendor/rails and you want to try this technique out, you should first clone the Git repository to a temporary directory, git checkout the version that matches what is already in your vendor/rails, then copy (or move) the .git directory into vendor/rails. Add the svn:ignore property as above and you’re all set.
Here’s why I’m doing this: when a new Rails release comes out, some files are changed, some added and others deleted. Because Subversion litters a checked-out project with its .svn directories, you can’t just delete the entire thing and re-freeze without losing local patches (yes, I’ve had to do this) and history (which isn’t terribly important, but can be nice). Even ignoring those two reasons, completely deleting and adding vendor/rails will cause your Subversion repository to grow more than necessary (Rails 2.3.3 checks in at 35 MB).
Git, by putting everything in a top-level .git directory, makes itself easy for Subversion to ignore. Checking out a tag to switch to a different release is simple, and Git deletes files, unlike applying a patch, which truncates deleted files to 0 bytes, requiring a find to actually remove them.