Class: Svn
- Inherits:
-
Object
- Object
- Svn
- Defined in:
- lib/dev_svn.rb
Class Method Summary collapse
- .add(source, directory = '') ⇒ Object
- .append_commit_message(message, directory = '') ⇒ Object
- .commit(message, directory = '') ⇒ Object
- .export(url, destination) ⇒ Object
- .has_changes?(directory = '') ⇒ Boolean
- .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.
- .url ⇒ Object
Class Method Details
.add(source, directory = '') ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/dev_svn.rb', line 40 def self.add source, directory='' directory=Dir.pwd if directory.length < 1 Dir.chdir(directory) do source.each{|f| puts `svn add #{f} --parents` if `svn status #{f}`.include?('?') puts `svn add #{f} --parents` if !system("svn status #{f}") } end end |
.append_commit_message(message, directory = '') ⇒ Object
50 51 52 53 54 55 |
# File 'lib/dev_svn.rb', line 50 def self. ,directory='' directory=Dir.pwd if directory.length < 1 Dir.chdir(directory) do end end |
.commit(message, directory = '') ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/dev_svn.rb', line 57 def self.commit , directory='' directory=Dir.pwd if directory.length < 1 Dir.chdir(directory) do # svn commit -F commit_message_filename puts `svn commit -m"commit all"` `svn update` end end |
.export(url, destination) ⇒ Object
24 25 26 27 28 |
# File 'lib/dev_svn.rb', line 24 def self.export url, destination if(!File.exists?(destination.chomp('@'))) `svn export #{url} #{destination}` end end |
.has_changes?(directory = '') ⇒ Boolean
30 31 32 33 34 35 36 37 38 |
# File 'lib/dev_svn.rb', line 30 def self.has_changes? directory='' directory=Dir.pwd if directory.length==0 Dir.chdir(directory) do if(File.exists?('.svn')) return true if `svn status`.scan(/^[MA]/).length>0 end end false end |
.latest_revision ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/dev_svn.rb', line 5 def self.latest_revision if(Dir.exists?(".svn")) `svn update` `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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/dev_svn.rb', line 71 def self.publish source_dir, destination, source_glob='**/*' output = "\n" raise "Svn.publish: destination #{destination} already exists" if(`svn info #{destination} 2>&1`.include?('Revision:')) # create subversion directory output = output + "svn mkdir #{destination} --parents --message mkdir_for_publishing" 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 output = output + "\nfiles: #{files}.to_s" pwd=Dir.pwd Dir.mktmpdir{|dir| # checkout new subversion directory output = output + "\nsvn checkout #{destination} #{dir}/to_publish_checkout" if(!`svn checkout #{destination} #{dir}/to_publish_checkout`.include?('Checked out')) raise "failure 'svn checkout #{destination} #{dir}/to_publish_checkout'" end # copy files into the checkout out subversion directory to_publish raise "#{dir}/to_publish_checkout does not exist" if(!File.exists?("#{dir}/to_publish_checkout")) Dir.chdir("#{dir}/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 } output = output + "\nsvn add --parents --targets add.txt 2>&1" `svn add --parents --targets add.txt 2>&1` commit_output = `svn commit -m"add" 2>&1` output = output + "\n#{commit_output}" if(!commit_output.include?("Committed")) raise "failure 'svn commit -m'added files''" + output end end #begin FileUtils.rm_r "#{dir}/to_publish_checkout" output } end |
.url ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/dev_svn.rb', line 15 def self.url if(Dir.exists?(".svn")) `svn info`.scan(/URL: ([:\/\.\-\d\w]+)/).each{|m| return m.first.to_s } end '' end |