Class: Svn
- Inherits:
-
Object
- Object
- Svn
- Defined in:
- lib/svn.rb
Class Method Summary collapse
- .latest_revision ⇒ Object
-
.publish(source_dir, destination, source_glob = '**/*') ⇒ Object
publish a directory to a new subversion path source_dir is the directory with the files to be published destination is the new subversion path URL source_glob is a string or array of glob directives to specify files in source_dir to be publish source_glob defaults to ‘*/’ to publish all files in the source_dir.
Class Method Details
.latest_revision ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/svn.rb', line 5 def self.latest_revision if(Dir.exists?(".svn")) `svn info`.scan(/Last Changed Rev: ([\d]+)/).each{|m| return m.first.to_s } end "0" end |
.publish(source_dir, destination, source_glob = '**/*') ⇒ Object
publish a directory to a new subversion path source_dir is the directory with the files to be published destination is the new subversion path URL source_glob is a string or array of glob directives to specify files in source_dir to be publish source_glob defaults to ‘*/’ to publish all files in the source_dir
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/svn.rb', line 19 def self.publish source_dir, destination, source_glob='**/*' raise "Svn.publish: destination #{destination} already exists" if(`svn info #{destination} 2>&1`.include?('Revision:')) # create subversion directory if(!`svn mkdir #{destination} --parents --message mkdir_for_publishing`.include?('Committed')) raise "failure 'svn mkdir #{destination} --parents --message mkdir_for_publishing'" end files=nil Dir.chdir(source_dir) do files=FileList.new(source_glob).to_a end pwd=Dir.pwd Dir.mktmpdir{|dir| # checkout new subversion directory if(!`svn checkout #{destination} to_publish_checkout`.include?('Checked out')) raise "failure 'svn checkout #{destination} to_publish_checkout'" end # copy files into the checkout out subversion directory to_publish raise "to_publish_checkout does not exist" if(!File.exists?('to_publish_checkout')) Dir.chdir('to_publish_checkout') do File.open('add.txt','w'){|add_file| files.each{|f| fdir=File.dirname(f) FileUtils.mkdir_p(fdir) if(fdir.length > 0 && !File.exists?(fdir)) FileUtils.cp("#{source_dir}/#{f}","#{f}") add_file.puts f } add_file.close } `svn add --parents --targets add.txt 2>&1` commit_output = `svn commit -m"add" 2>&1` if(!commit_output.include?("Committed")) raise "failure 'svn commit -m'added files''" end end FileUtils.rm_r 'to_publish_checkout' } end |