In-place import using Subversion

Thanks to the helpful folks on the #svn IRC channel I learned that it is possible to turn a directory into a svn checkout in-place, i.e. without having to replace the directory itself with a fresh checkout after you svn import. This is very handy for things like /etc files and other stuff that you’d rather not be shuffling around unnecessarily.

The key nugget of info is here in the svn FAQ.

I used this on a production website which formerly used a simple test/live setup: changes in the test copy were pushed to the live copy via rsync. I wanted this upgrade to work with that model; I didn’t want all the timestamps on the test copy to change, as they would with a svn import + checkout.

The sequence of commands I used (edited for clarity) was:

svn mkdir file:///svn/sites/foo -m "Foo repo directory creation"
cd /www/test
svn co file:///svn/sites/foo .
svn add * 
svn ci -m "Initial import"

After that, I ran my rsync script (which I updated with --exclude .svn). It did touch each directory in the target site, because strictly speaking they had changed (they all now had that .svn subdirectory that rsync was otherwise ignoring). But it worked perfectly, and now the site’s under version control, which always brings huge piece of mind.

Update: You can also use svn add . --force in the fourth line above if you have certain files or directories that you’re ignoring via the svn:ignore property.

frEEk commented :

Just what I needed. The third command in the sequence was the magic one.

Thx for the tip. This was driving me crazy, altho in my case it was for wanting to import a live site but skipping alot of log files and user-generated images, etc. Sadly you can’t exclude files during an import or specify a list of files to import. This however lets me selectively add the branches I want to include and do a single revision for the import, instead of importing each branch and file one at a time.


Paul Vernon commented :

Hey guys - here is a method I use for initial checkins/checkouts in the same folder:

tar -cvzf ../backup.tgz . svn import -m “New import for my app” . http://repository.yoursite.com/repos/your_app cd .. mv www/ www-old/ mkdir www cd www svn co http://repository.yoursite.com/repos/your_app . tar -xvzf ../backup.tgz

This will make it so you don’t have to hunt down any file permissions issues.

Paul



Share: