Class: Svn
- Inherits:
-
Object
- Object
- Svn
- Defined in:
- lib/apps/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(destination, source_dir, source_filelist = FileList.new("**/*")) ⇒ 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
39 40 41 42 43 44 45 46 47 |
# File 'lib/apps/svn.rb', line 39 def self.add(source, directory = "") directory = Dir.pwd if directory.empty? Dir.chdir(directory) do source.each do |f| puts `svn add #{f} --parents` if `svn status #{f}`.include?("?") puts `svn add #{f} --parents` unless system("svn status #{f}") end end end |
.append_commit_message(_message, directory = "") ⇒ Object
49 50 51 52 53 |
# File 'lib/apps/svn.rb', line 49 def self.(, directory = "") directory = Dir.pwd if directory.empty? Dir.chdir(directory) do end end |
.commit(_message, directory = "") ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/apps/svn.rb', line 55 def self.commit(, directory = "") directory = Dir.pwd if directory.empty? Dir.chdir(directory) do # svn commit -F commit_message_filename puts `svn commit -m"commit all"` `svn update` end end |
.export(url, destination) ⇒ Object
27 28 29 |
# File 'lib/apps/svn.rb', line 27 def self.export(url, destination) `svn export #{url} #{destination}` unless File.exist?(destination.chomp("@")) end |
.has_changes?(directory = "") ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/apps/svn.rb', line 31 def self.has_changes?(directory = "") directory = Dir.pwd if directory.length.zero? Dir.chdir(directory) do return true if File.exist?(".svn") && `svn status`.scan(/^[MA]/).length.positive? end false end |
.latest_revision ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/apps/svn.rb', line 8 def self.latest_revision if Dir.exist?(".svn") `svn update` `svn info`.scan(/Last Changed Rev: (\d+)/).each do |m| return m.first.to_s end end "0" end |
.publish(destination, source_dir, source_filelist = FileList.new("**/*")) ⇒ 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
69 70 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/apps/svn.rb', line 69 def self.publish(destination, source_dir, source_filelist = FileList.new("**/*")) # Support for legacy argument order if source_dir.include?("svn:") || source_dir.include?("http:") || source_dir.include?("https:") puts "warning arguments are in legacy order" if Environment.default.debug? # swap arguments tmp = source_dir source_dir = destination destination = tmp end unless source_filelist.is_a?(FileList) puts "converting files array into FileList" if Environment.default.debug? list = FileList.new source_filelist.each { |item| list.include(item) } source_fileList = list end output = "\n" if `svn info #{destination} 2>&1`.include?("Revision:") puts "Svn.publish: destination #{destination} already exists" else # create subversion directory output += "svn mkdir #{destination} --parents --message mkdir_for_publishing" unless `svn mkdir #{destination} --parents --message mkdir_for_publishing`.include?("Committed") raise "failure 'svn mkdir #{destination} --parents --message mkdir_for_publishing'" end Dir.chdir(source_dir) do files = source_filelist.to_a end files = source_filelist output = "#{output}\nfiles: " files.each do |f| output = "#{output}#{f} " end pwd = Dir.pwd dir = "#{Environment.default.tmp_dir}/svn_publish" Dir.remove dir if File.exist? dir FileUtils.mkdir dir Dir.chdir(dir) do # Dir.mktmpdir{|dir| # checkout new subversion directory output += "\nsvn checkout #{destination} #{dir}/to_publish_checkout" unless `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" unless File.exist?("#{dir}/to_publish_checkout") Dir.chdir("#{dir}/to_publish_checkout") do File.open("add.txt", "w") do |add_file| files.each do |f| fdir = File.dirname(f) FileUtils.mkdir_p(fdir) if fdir.length.positive? && !File.exist?(fdir) FileUtils.cp("#{source_dir}/#{f}", f.to_s) add_file.puts f end add_file.close end 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 += "\n#{commit_output}" raise "failure 'svn commit -m'added files''#{output}" unless commit_output.include?("Committed") end # begin # Dir.remove "#{dir}/to_publish_checkout" output end Dir.remove(dir) end end |
.url ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/apps/svn.rb', line 18 def self.url if Dir.exist?(".svn") `svn info`.scan(%r{URL: ([:/.\-\d\w]+)}).each do |m| return m.first.to_s end end "" end |