Working with iWork and Subversion

So I’m a big fan of iWork ‘08, pages is nice enough, doesn’t get in my way, etc. Numbers is pretty awesome. It’s been a while since someone did something revolutionary in the spreadsheet world. Numbers is it.

I do have a couple gripes.

1) if I open a word or excel file, when I save, it should be saved back to that same word or excel file. Not all my friends have macs, let alone iWork, why can’t I save back to the file I opened? And if I have to do the extra export step, why does iWork forget where the file came from? Grr.

2) I am a total excel power user, and numbers is still missing a bunch of features for addins, macros, etc. It doesn’t even have applescript support yet as far as I can tell (I’m sure it will, though, and I am glad they released before they had it) I’ve been getting by on a manual export to csv so I can munge data.

3) and what this blog post is about, is that iWork does not play nice w/ subversion.

iWork stores it’s files in “bundles” which are actually directories even though they look like files from finder. When you have stored one of these bundles in subversion, there will be .svn directories inside of it, containing subversion metadata. The problem comes that every time you save a file in iWork, the entire bundle is replaced w/ the new copy…and ALL .svn directories are destroyed.

This basically renders subversion useless for iWork files. This is no good, there are some pretty painful workarounds on the net, and there are a few scripts that turned up, but I wrote my own.

This script (I call it svn_restore_dirs) will search any subdirectories of the current working directory for files ending in .numbers, .pages, etc. It will then redownload .svn directories for any of these that are missing theirs.

Seems to work, and is simple enough. I wish apple would get their act together.

Enjoy the script

#!/usr/bin/env ruby
 
require 'fileutils'
 
EXTENSIONS_TO_SEARCH = %w(numbers pages key graffle)
TMP_DIR = "/tmp/missing_svn"
 
def find_directories_without_svn_dirs
  search_pattern = EXTENSIONS_TO_SEARCH.map {|ext| "-name \"*.#{ext}\""}.join(" -or ")
  dirs = `find . \\( #{search_pattern} \\) -type d`.split("\n")
  dirs.reject {|dir| File.exists?(File.join(dir, ".svn"))}
end  
 
def get_url_for(file)
  info = `svn info "#{file}"`
  raise "can't parse #{info}" unless info =~ /URL\: (.*)/
  return $1
end
 
def copy_svn_dirs(from, to)
  to = File.expand_path(to)
  Dir.chdir from do
    Dir["**/.svn"].each do |svn_dir|
      FileUtils.mv svn_dir, File.join(to, svn_dir)
    end
  end
end
 
find_directories_without_svn_dirs.each do |dir|
  url = get_url_for(File.dirname(dir))
 
  puts "replacing svn dirs for #{dir} from #{url}/#{File.basename(dir)}"
 
  FileUtils.rm_rf(TMP_DIR) if File.exists?(TMP_DIR)
  `svn co "#{url}/#{File.basename(dir)}" #{TMP_DIR}`
 
  copy_svn_dirs(TMP_DIR, dir) if $? == 0
end

Tags: ,

4 Responses to “Working with iWork and Subversion”

  1. Wes Maldonado Says:

    I knew something was wrong when I saw that check in… Elisabeth Hendrickson wrote about [the same keynote problem](http://www.testobsessed.com/2007/10/16/oh-the-irony/) a while back… as did [Brian Marik](http://www.exampler.com/blog/2007/10/16/im-looking-at-you-keynote/)

  2. Trevor Says:

    Regarding #1, I believe there’s a method to iWork’s madness. Its Microsoft Office importers/exports are far from perfect, so they really can’t handle round-trip saves. If you were to open, say, a Word file, make a few small edits, and then save it back to Word, the results might not be what you expect. You’ll get progressive defects the more you do this, kind of like what happens when you make a copy of a copy of a copy of an analog recording. Forcing you to do an explicit export instead of a simple save is a reminder that your file is about to embark on a one-way trip.

    By the way: “stores it’s files” –> “stores its files”

  3. Anders Says:

    Thanks for your very nice Ruby script. This bug in iWork has been annoying me for ages. Thanks again!

    /Anders, Denmark

  4. jon Says:

    Thanks much! I wish apple would get it together as well. Just modify the existing bundle and only replace what changes…

    jc