Class RSCM::Subversion
In: lib/rscm/scm/subversion.rb
Parent: Base

RSCM implementation for Subversion.

You need the svn/svnadmin executable on the PATH in order for it to work.

NOTE: On Cygwin these have to be the win32 builds of svn/svnadmin and not the Cygwin ones.

Methods

Included Modules

FileUtils PathConverter

Attributes

password  [RW] 
path  [RW]  Must be specified in order to create repo and install triggers. Must also be specified as "" if the url represents the root of the repository, or files in revisions will not be detected.
url  [RW] 
username  [RW] 

Public Class methods

[Source]

    # File lib/rscm/scm/subversion.rb, line 26
26:     def initialize(url="", path="")
27:       @url, @path = url, path
28:       @username = ""
29:       @password = ""
30:     end

Public Instance methods

[Source]

    # File lib/rscm/scm/subversion.rb, line 49
49:     def add(relative_filename, options={})
50:       svn("add #{checkout_dir}/#{relative_filename}", options)
51:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 95
95:     def can_create_central?
96:       local? && !path.nil? && !(path == "")
97:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 107
107:     def central_exists?
108:       if(local?)
109:         File.exists?("#{svnrootdir}/db")
110:       else
111:         # Do a simple command over the network
112:         # If the repo/path doesn't exist, we'll get zero output
113:         # on stdout (and an error msg on std err).
114:         exists = false
115:         cmd = "svn log #{url} -r HEAD"
116:         execute(cmd) do |stdout|
117:           stdout.each_line do |line|
118:             exists = true
119:           end
120:         end
121:         exists
122:       end
123:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 203
203:     def checked_out?
204:       rootentries = File.expand_path("#{checkout_dir}/.svn/entries")
205:       result = File.exists?(rootentries)
206:       result
207:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 70
70:     def commit(message, options={})
71:       svn(commit_command(message), options)
72:       # We have to do an update to get the local revision right
73:       checkout_silent(nil, options)
74:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 136
136:     def create_central(options={})
137:       options = options.dup.merge({:dir => svnrootdir})
138:       native_path = PathConverter.filepath_to_nativepath(svnrootdir, false)
139:       mkdir_p(PathConverter.nativepath_to_filepath(native_path))
140:       svnadmin("create #{native_path}", options)
141:       if(path != "")
142:         options = options.dup.merge({:dir => "."})
143:         # create the directories
144:         paths = path.split("/")
145:         paths.each_with_index do |p,i|
146:           p = paths[0..i]
147:           u = "#{repourl}/#{p.join('/')}"
148:           svn("mkdir #{u} -m \"Adding directories\"", options)
149:         end
150:       end
151:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 99
 99:     def destroy_central
100:       if(File.exist?(svnrootdir) && local?)
101:         FileUtils.rm_rf(svnrootdir)
102:       else
103:         raise "Cannot destroy central repository. '#{svnrootdir}' doesn't exist or central repo isn't local to this machine"
104:       end
105:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 80
80:     def diff(path, from, to, options={}, &block)
81:       cmd = "svn diff --revision #{from}:#{to} \"#{url}/#{path}\""
82:       execute(cmd, options) do |io|
83:         return(block.call(io))
84:       end
85:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 171
171:     def import_central(dir, options={})
172:       import_cmd = "import #{dir} #{url} -m \"#{options[:message]}\""
173:       svn(import_cmd, options)
174:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 153
153:     def install_trigger(trigger_command, trigger_files_checkout_dir, options={})
154:       if (WINDOWS)
155:         install_win_trigger(trigger_command, trigger_files_checkout_dir, options)
156:       else
157:         install_unix_trigger(trigger_command, trigger_files_checkout_dir, options)
158:       end
159:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 36
36:     def installed?
37:       begin
38:         svn("--version", {}) 
39:         true
40:       rescue
41:         false
42:       end
43:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 76
76:     def label
77:       local_revision_identifier.to_s
78:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 53
53:     def move(relative_src, relative_dest, options={})
54:       svn("mv #{checkout_dir}/#{relative_src} #{checkout_dir}/#{relative_dest}", options)
55:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 87
87:     def open(path, native_revision_identifier, options={}, &block)
88:       raise "native_revision_identifier cannot be nil" if native_revision_identifier.nil?
89:       cmd = "svn cat #{url}/#{path}@#{native_revision_identifier}"
90:       execute(cmd, options) do |io|
91:         return(block.call(io))
92:       end
93:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 32
32:     def path
33:       @path ||= ""
34:     end

url pointing to the root of the repo

[Source]

     # File lib/rscm/scm/subversion.rb, line 198
198:     def repourl
199:       last = (path.nil? || path == "") ? -1 : -(path.length)-2
200:       url[0..last]
201:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 176
176:     def revisions(from_identifier=Time.new.utc, options={})
177:       raise "from_identifer cannot be nil" if from_identifier.nil?
178:       options = {
179:         :from_identifier => from_identifier,
180:         :to_identifier => Time.infinity, 
181:         :relative_path => "",
182:         :dir => Dir.pwd
183:       }.merge(options)
184:       
185:       checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
186:       revisions = nil
187:       command = "svn #{changes_command(options[:from_identifier], options[:to_identifier], options[:relative_path])}"
188:       execute(command, options) do |stdout|
189:         stdout = StringIO.new(stdout.read)
190:         parser = SubversionLogParser.new(stdout, @url, options[:from_identifier], options[:to_identifier], path)
191:         revisions = parser.parse_revisions
192:       end
193:       revisions.cmd = command if store_revisions_command?
194:       revisions
195:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 125
125:     def supports_trigger?
126:       true
127:       # we'll assume it supports trigger even if not local. this is to ensure user interfaces
128:       # can display appropriate options, even if the object is not 'fully initialised'
129:       # local?
130:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 45
45:     def to_identifier(raw_identifier)
46:       raw_identifier.to_i
47:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 57
57:     def transactional?
58:       true
59:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 165
165:     def trigger_installed?(trigger_command, trigger_files_checkout_dir, options={})
166:       return false unless File.exist?(post_commit_file)
167:       not_already_commented = LineEditor.comment_out(File.new(post_commit_file), /#{Regexp.escape(trigger_command)}/, "# ", "")
168:       not_already_commented
169:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 132
132:     def trigger_mechanism
133:       "hooks/post-commit"
134:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 161
161:     def uninstall_trigger(trigger_command, trigger_files_checkout_dir, options={})
162:       File.comment_out(post_commit_file, /#{Regexp.escape(trigger_command)}/, nil)
163:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 61
61:     def uptodate?(identifier, options={})
62:       if(!checked_out?)
63:         false
64:       else
65:         rev = identifier.nil? ? head_revision_identifier(options) : identifier 
66:         local_revision_identifier(options) == rev
67:       end
68:     end

Protected Instance methods

[Source]

     # File lib/rscm/scm/subversion.rb, line 211
211:     def checkout_silent(to_identifier, options)
212:       checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
213:       mkdir_p(@checkout_dir)
214:       if(checked_out?)
215:         svn(update_command(to_identifier), options)
216:       else
217:         svn(checkout_command(to_identifier), options)
218:       end
219:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 221
221:     def ignore_paths
222:       [/\.svn\/.*/]
223:     end

[Validate]