With rails, whenever you run a generate script, it often creates large numbers of new files in many different directories. You then may want to commit all of these to a subversion repository.
Unfortunately, ‘svn add *’ is not recursive. Luckily, we can accomplish this with good ol’ shell scripting:
svn status | grep "^\?" | awk '{print $2}' | xargs svn add
And much less pretty, but for files with spaces in them:
svn status | grep "^\?" | sed -e 's/? *//' | sed -e 's/ /\\ /g' | xargs svn add
simple and elegant. nicely done ;)
does not handle files or directories with spaces in their names. bad!
files with spaces in them, bad! But ok :)
(updated post)
what about Windows….without grep….
Just wrote a little script employing WScript.Shell to execute svn commands and add newly created files/dirs to svn repository.
#
shell = WIN32OLE.new(‘Wscript.Shell’) objExec = shell.exec(“svn status”) while !objExec.stdout.atendofstream l = objExec.stdout.readline end
#
Save above script to a file(etc. svn_addgenerated.rb) and drop it into your rails app’s script directory. And every time after rails generate some files, you can type in command shell:ruby script/svn_addgenerated.rb and enter , script will automatically find new files need to be added and run ‘svn add’ against them.
Sorry for bad format…A better readable one here:
http://wiki.rubyonrails.com/rails/show/HowtoUseRailsWithSubversion
Sorry, but is it not easier to use this:
svn add *—force
Welll…It seems much much easier…using ‘force’
Strange that the recursive flag is a subset of—force.
you can also do script/generate—svn and it will add everything it generates to svn
Here is a small python code I wrote to add all files to svn.
! /usr/bin/env python
””” Adding all files with a question mark to svn Asks if you want to add all or want to confirm each file ””“
import os
a = os.popen(‘svn st | grep ”?”’) b = a.read() c = b.split(’\n’)
if fch == 1: for fc in c: print fc
for f in c: if f.find(”?”) != -1: