Tracking deployed svn revision

Sometimes it’s useful to know which subversion revision is installed on your website.

I propose simple solution for this. Each time you or somebody update your website, run the command:

svnversion /path/to/your/working/copy > version && scp version login@domain.tld:./version

It will get global revision from your working copy and uploads a file to website, so you can check revision anytime just by opening http://domain.tld/version

Saturday, April 5th, 2008

Copying changed files since some revision under Subversion

I continue my previous post about getting changed files with subversion. I needed to get all changed and committed files since some revision till HEAD revision and upload them to production server. I don’t want to copy all working copy nor exporting entire repository on server. Just changed files. First solution will be filtering files by modification date. But what if you have a lot of other unversioned files in your working copy, which are changed frequently?

So the solution is to look at svn log and get affected files for each revision we are interested in. But this is boring. Use this command instead:

svn log -vq -r 104:HEAD | grep '^   [AM]' | cut -b 6- | sed 's/ (from .*:[0-9]*)$//' | sed 's|^/path/prefix/in/repository/||' | sort -u | xargs -I '{}' cp --parents {} /temporary/destination/dir

Note, there should be three spaces before [AM] in grep regex.

It will do the same. First, get log with list of changed files and without your comments for revision from 104 to HEAD (as an example). Then get only modified and added files, we don’t need deleted. After that remove first column with status indication, remove with sed “(from …:103)” svn note, if we have moved or copied resource. I used sed once more to make remote path relative to my working copy, so I can use cp command on list of files. sort -u is required to get unique list, as some files could be changed in several revisions

Saturday, August 11th, 2007

Copying only modified files under SVN

If you are web developer and you are working with Subversion, then you probably did this thousand of times. You have modified some files (probably a lot of them), and after that you have to update your dev/prod server. It can be pain in the ass, if you have large repository with complex directory structure.

The best solution will be to have working copy on dev/prod server and use svn checkout or svn export. But sometimes it won’t work, e.g. if your repository is not accessible from your server, or you don’t want to commit your files without testing them on server or whatever else.

If you are working under *nix, here’s useful command that will facilitate this tedious task:

svn status | grep '^[ADMR]' | cut -b 8- | xargs -I '{}' cp --parents {} /temporary/destination/dir

Let’s see what it means. First, we take status of each file/directory in the working copy, then filter only modified/added/deleted/replaced files (it’s /^[ADMR]/ regex for the first column in svn status result). Then remove column with files statuses and pass it to copy command preserving directory structure. That’s it.

Sunday, August 5th, 2007