Adding all new files with SVN
June 1, 2005
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
June 1, 2005 at 2:51 pm
you can also do script/generate –svn
and it will add everything it generates to svn
June 1, 2005 at 2:51 pm
Strange that the recursive flag is a subset of –force.
June 1, 2005 at 2:51 pm
simple and elegant. nicely done
June 1, 2005 at 2:51 pm
does not handle files or directories with spaces in their names. bad!
June 1, 2005 at 2:51 pm
files with spaces in them, bad!
But ok
(updated post)
June 1, 2005 at 2:51 pm
what about Windows….without grep….
June 1, 2005 at 2:51 pm
Just wrote a little script employing WScript.Shell to execute svn commands and add newly created files/dirs to svn repository.
#####################
# Author:Yufan Shi
# Email:yufanshi AT gmail.com
#####################
require ‘win32ole’
shell = WIN32OLE.new(’Wscript.Shell’)
objExec = shell.exec("svn status")
while !objExec.stdout.atendofstream
l = objExec.stdout.readline
if l =~ /^\?/
l = l.sub(/^\?( )*/,’svn add ‘)
objResult = shell.exec(l)
while !objResult.stdout.atendofstream
print objResult.stdout.readline,"\n"
end
end
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.
June 1, 2005 at 2:51 pm
Sorry for bad format…A better readable one here:
http://wiki.rubyonrails.com/rails/show/HowtoUseRailsWithSubversion
June 1, 2005 at 2:51 pm
Sorry, but is it not easier to use this:
svn add * –force
June 1, 2005 at 2:51 pm
Welll…It seems much much easier…using ‘force’
March 30, 2009 at 2:59 pm
[...] about this.. most of the time people consider that the only way is using a nice little script (see here for example). But the –force flag induces recursivity, so this command does the stuff [...]