>A (very) simple ruby script to add files to your repository

>You’re developing a ruby on rails site and, as a dutiful developer, you’ve set up versioning on your code. As you probably already know, when you generate a new object there are quite a few files that get created — so every time you want add a new model, you have to type that “svn add [filename]” command… A bit boring if you ask me.

In Windows, all you really need to do is use a graphic interface like TortoiseSVN; it’s a bit clunky at times but it definitely does the trick. In Mac OS X and Linux, the most powerful and flexible tools are already at your disposal in your command line — so why go through the fuss of a GUI?

I’m sure there are plenty of elegant, easy solutions to this — but here’s mine:

  • Open up your favorite text editor
  • Copy &Paste this code into it:


delim = “? “

results = `svn stat | grep #{ARGV[0]}`.split “n”

results.each do |result|

`svn add #{result.gsub delim, “”}`


  • Save the file in, say, the same directory as the project that you have under SVN (don’t save it in the project directory — that wouldn’t be clean). I call mine svnaddfiles.rb
  • For convenience, make that file executable with a “chmod u+x svnaddfiles.rb”
  • From your project directory, you can use it like this: “../svnaddfiles.rb [file prefix]”

VoilĂ  — easy adding of many files, using just ruby, svn and grep!