Bill Lovett

Smartening Subversion with Perl

One thing I've never liked about using Subversion from the command line is that it's tedious to add and remove files. Although the svn status command tells you the state of the files in your current checkout, its output is not used when doing svn add or svn remove. You end up retyping files paths, or copying and pasting. That's not efficient.

A little interactivity would be much more helpful, and that's what svnask.pl provides. It's a short and very simple Perl script that runs svn status, looks for files with a state of "?" or "!", and prompts for a yes-no on whether to add or remove each one from the checkout. Since "yes" is the default, you can operate on a whole mess of files with barely any effort.

Another efficiency problem I've come across with Subversion involves keeping track of multiple checkouts from multiple repositories. I have numerous projects in various states and bounce around from one to another. Sometimes I forget to do a check in, especially if I've only made a trivial change to one file. Weeks can pass before I notice I have outstanding revisions. With svnstatus.pl run daily via cron, this is no longer a problem. The script examines one or more directories and runs svn status, producing an accumulated status report of all known repositories. If there are outstanding changes, cron will deliver the details in an email.