From: Michael Weller Date: 2004-10-08T21:31:21+09:00 Subject: [ANN] svn_auto_add 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: 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 # File.separatorChar ? path = mp.gsub(/\//, '\\') `svn add \"#{path}\"` end end 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