Preventing Commits with Unadded Files

Update, 17 April 2009: doh lives as a gem on github now.

Today I added a new file to an in-progress Rails app, watched all the tests pass, and committed. Except I forgot to svn add the new file. Again.

Doh.

Never Again

Subversion should prevent me from checking in if I’ve got unadded files in a project, right?

But looking through the Subversion book and man pages, I couldn’t find how to make it so. (Pre-commit hooks run on the repository side, so they don’t have access to your working copy.)

So, I’ve written a short Ruby script to help.

Introducing Doh

Whenever you svn ci with unadded files lying around, doh stops your commit:

Doh

Cool, huh?

Installation

wget http://matthewtodd.org/svn/public/doh/bin/doh

And then create an alias, you know the drill:

alias svn='/full/path/to/doh'

Usage

Most of the time doh just does “exec 'svn', *ARGV”, so it’s safe as your full-time svn wrapper. It only kicks in if “ci” is one of the command-line arguments, and only then if there are unadded files in the current directory.

To temporarily override doh’s behavior and commit anyway, just prefix the svn with a backslash:

\svn ci -m "don't worry, I know what I'm doing"

Feedback

I’d love to hear if you decide to give doh a try—or if there’s some built-in way to achieve the same goal in Subversion! I’ll be glad to turn this into a gem if there’s any demand for it.

Enjoy!