Hi!
I wrote a little script for svn users. It will detect any file added to a working copy which svn doesn't know about. In other words: it calls 'svn add' for any newly added file.
I thought I share it,just in case it might be helpful to somebody... (I actually don't think so because I'm a Nuby and everybody could write this script, but you never know 
So here it is:
<code lang="ruby">
require 'find'
require 'rexml/document'
def list_dir_files(path)
Dir.new(path).to_a - [".","..",".svn"]
end
def list_svn_files(entries)
doc = REXML::Document.new(IO.read(entries))
files =[]
# don't know why, but "wc-entries/entry" won't work
doc.root.elements.each("//entry") do |el|
val = el.attributes["name"]
files << val unless val.nil? || ""==val
end
return files
end
def check_missing(path, svn_entries)
dir_files = list_dir_files(path)
svn_files = list_svn_files(svn_entries)
(dir_files - svn_files).collect! {|e| path+"/"+e}
end
missing_paths = []
Find.find(".") do |path|
if path =~ /.svn/
Find.prune
end
if FileTest.directory?(path) then
svn_dir = path + "\\.svn"
if File.exists? svn_dir then
missing = check_missing(path, svn_dir+"\\entries")
missing_paths << missing unless missing.nil? || missing.length==0
else
missing_paths << path
end
end
end
missing_paths -= ["."]
missing_paths.flatten!
p "\n\n\t Found missing:"
missing_paths.each do |mp|
# this should be customized, this is for files you never want added
# for me (usually a Java head) these are bak-files, class-files and
# anything in .\classes
unless mp =~ /(.bak)|(.class)/ then
# this is windows only, is there sth. like
# <code lang="Java">File.separatorChar</code> ?
path = mp.gsub(/\//, '\\')
`svn add \"#{path}\"`
end
end
</code>
If somebody reads the script and thinks "Why is he doing this that way?" feel free to comment, I'm always open for improvements...
Michael
I wrote a little script for svn users. It will detect any file added to
a working copy which svn doesn't know about. In other words: it calls
'svn add' for any newly added file.
I thought I share it,just in case it might be helpful to somebody... (I
actually don't think so because I'm a Nuby and everybody could write
this script, but you never know 
[snip code]
If somebody reads the script and thinks "Why is he doing this that way?"
feel free to comment, I'm always open for improvements...
I wonder whether it might be simpler to just ask the command line tool
what files it doesn't know about (which will take into account the
relevant ignore settings for *.o, *.class etc). For example:
$ svn status
? somefile
? otherfile
M modifiedfile
By looking for lines that begin with a '?', we get precisely the list that
needs to be added. These lines could be turned into the appropriate 'svn
add' commands.
One way (not particularly pleasant to look at) using ruby would be:
$ svn status | ruby -ne 'puts $_[7..-2] if $_[0] == ??'
to actually run the 'svn add' command you could use:
$ svn status | ruby -e 'system("svn","add",$_[7..-2]) if $_[0] == ??'
I think I would normally do it with a shell pipeline, since I find it
easier to compose the simpler steps than come up with the ruby script for
the whole thing:
$ svn add `svn status | grep '^?' | cut -c8-`
(assuming no spaces in the names of the files to be added)
Hope this makes sense!
···
On Fri, 08 Oct 2004 21:31:21 +0900, Michael Weller wrote:
Sorry to break this to you but, svn add --force foo is recursive and
skips already added files too... at least on svn 1.1.0rc1 it does
···
On Fri, 8 Oct 2004 21:31:21 +0900, Michael Weller <michael@gutschi.de> wrote:
Hi!
I wrote a little script for svn users. It will detect any file added to
a working copy which svn doesn't know about. In other words: it calls
'svn add' for any newly added file.
--
Cristi BALAN
But like I said I'm a nuby and happy that I got my script working my
(much more complicated) way...
Yeah, I have often found that I've made a complicated script that
later turns out to be doable in some simpler way. However, it's usually
a good learning experience 
Thanks for your input!
No problem. Sorry if I was a bit terse in my original reply.
···
On Fri, 08 Oct 2004 22:38:51 +0900, Michael Weller wrote: