Managing svn:ignore with impunity

Managing svn:ignore has always annoyed me. After using git for the past few months, it bugs me even more now.

I think I've come up with a simple way of coping. That, or I totally stole it from someone else on the internet, without realizing it. It's hard to keep track of these kinds of things.

The trick

Here's what you do:

  • Create a .svnignore in the top of your project.
  • Make a list of files/wildcards you care to ignore
  • Save it

Now, from the top of your project, you can do:

$ svn propset svn:ignore -F .svnignore  .

If one were to wordify this command, it's be something like "Set the svn:ignore property from the contents of the .svnignore onto the current directory." It can really be any file, but I kinda like this convention.

It is also likely you will want to keep .svnignore under source control.

Now automate it

It's usually best to automate when possible, since even this simplied way of managing ignored files might get tedious. Or maybe someone coming onto the project doesn't have our level svn-fu.

We already have a lib/tasks/svn.rake that has a few tricks in it, so I figured on expanding it. Here's the original:

namespace :svn do
  desc "Adds all files with an svn status flag of '?'"
  task(:add) { system %q(svn status | awk '/\\?/ {print $2}' | xargs svn add) }

  desc "Deletes all files with an svn status flag of '!'"
  task(:delete) { system %q(svn status | awk '/\\!/ {print $2}' | xargs svn delete) }

  desc "Writes the log file to doc/svn_log.txt"
  task(:log) do
    File.delete("#{RAILS_ROOT}/doc/svn_log.txt") if File::exists?("#{RAILS_ROOT}/doc/svn_log.txt")
    File.new("#{RAILS_ROOT}/doc/svn_log.txt", "w+")
    system("svn log >> doc/svn_log.txt")
  end
end
I added a new task that looks like:
desc 'Updates svn:ignore from .svnignore'
task(:update_svn_ignore) do
  system %q(svn propset svn:ignore -F .svnignore .)
end
Now we can tweak `.svnignore` to our hearts' content, and then just run:
$ rake svn:update_svn_ignore
(in /Users/nichoj/Projects/boston_rb)
property 'svn:ignore' set on '.'

Awesome.

Tell Hoe what tests to run

I've been recently playing around with a Ruby frontend to the del.ico.us API. I decided to use Hoe to get things rolling with a proper project layout.

It's pretty straightforward to use initially:

$ sow deliciousr

This generates everything you need to start.

$ cd deliciousr
$ rake -T
rake announce         # Create news email file and post to rubyforge.
rake audit            # Run ZenTest against the package.
rake check_manifest   # Verify the manifest.
rake clean            # Clean up all the extras.
rake clobber_docs     # Remove rdoc products
rake clobber_package  # Remove package products
rake config_hoe       # Create a fresh ~/.hoerc file.
rake debug_gem        # Show information about the gem.
rake default          # Run the default tasks.
rake docs             # Build the docs HTML Files
rake email            # Generate email announcement file.
rake gem              # Build the gem file deliciousr-1.0.0.gem
rake generate_key     # Generate a key for signing your gems.
rake install_gem      # Install the package as a gem.
rake multi            # Run the test suite using multiruby.
rake package          # Build all the packages
rake post_blog        # Post announcement to blog.
rake post_news        # Post announcement to rubyforge.
rake publish_docs     # Publish RDoc to RubyForge.
rake redocs           # Force a rebuild of the RDOC files
rake release          # Package and upload the release to rubyforge.
rake repackage        # Force a rebuild of the package files
rake ridocs           # Generate ri locally for testing.
rake test             # Run the test suite.
rake test_deps        # Show which test files fail when run alone.

You get a lot of stuff for free here. So I went about happily coding, and of course, testing. Initially, I was just running the tests by invoking them directly, or using TextMate's Ruby bundle. But, I figured it'd be best to be running it by using the free rake task.

$ rake test
(in /Users/nichoj/Projects/deliciousr)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -w -Ilib:ext:bin:test -e 'require "test/unit"; require "test/test_helper.rb"' 
./test/../lib/deliciousr/v1/api_call.rb:64: warning: method redefined; discarding old http
Loaded suite .
Started

Finished in 0.000223 seconds.

0 tests, 0 assertions, 0 failures, 0 errors

Uh, why aren't my tests running???

The short of it is that hoe looks for a certain filename pattern, specifically, it likes tests to be like:

test/**/test_*.rb

My tests? They might be named more like:

test/**/*_test.rb

So, ideally I would rename my tests, but fortunately there is a quick fix. In your Rakefile, you need to add a line to the Hoe configuration.

Hoe.new('deliciousr', Deliciousr::VERSION) do |p|
  # snip
  p.test_globs = 'test/**/*_test.rb'
  # snip
end

It was only by digging into the source that I found it.

Remember kiddies, the source shall set you free.