Preventing Commits with Unadded Files

Posted on August 17, 2007

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!

ARGF

Posted on August 16, 2007

Every few months or so, I get to help email out the Amani newsletters by taking everyone’s address books and merging them together. (It’s not ideal; requiring unsubscribing to be a manual process makes it all too easy to forget and annoy some people. Changes are afoot.)

Playing with files like this, it’s fun to drop to the command line and see how quickly I can get it done. This time around, I remembered Ruby’s ARGF, which is a synonym for $<, which clearly came from Perl.

From the Pickaxe, $< is:

An object that provides access to the concatenation of all the files given as command-line arguments or $stdin (in the case where there are no arguments). $< supports methods similar to a File object…

So, here we go:

ruby -rcsv -e 'CSV::Reader.parse(ARGF) { |row| puts row[4] }' *.csv
  | sort | uniq > final.csv

In English, that’s “loading the csv library, parse the given files (*.csv), printing only column 4 of each row. Sort the results, removing duplicates, and save as final.csv.”

I love this stuff.

A Few of My Favorite Things

Posted on August 14, 2007

These are a few of my favorite things

  • Drinking water
  • Having short hair
  • Making dumb faces for the camera
  • Drinking Guinness
  • Spreading butter on toast from the Butter Bell.
  • Eating homemade pizza! (Really, the whole point of this post. It was good!)