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] 
url  [RW] 
username  [RW] 

Public Class methods

[Source]

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

Public Instance methods

[Source]

    # File lib/rscm/scm/subversion.rb, line 29
29:     def add(relative_filename)
30:       svn(@checkout_dir, "add #{relative_filename}")
31:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 123
123:     def can_create_central?
124:       local?
125:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 135
135:     def central_exists?
136:       if(local?)
137:         File.exists?("#{svnrootdir}/db")
138:       else
139:         # Do a simple command over the network
140:         # If the repo/path doesn't exist, we'll get zero output
141:         # on stdout (and an error msg on std err).
142:         exists = false
143:         cmd = "svn log #{url} -r HEAD"
144:         Better.popen(cmd) do |stdout|
145:           stdout.each_line do |line|
146:             exists = true
147:           end
148:         end
149:         exists
150:       end
151:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 223
223:     def checked_out?
224:       rootentries = File.expand_path("#{checkout_dir}/.svn/entries")
225:       result = File.exists?(rootentries)
226:       result
227:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 41
41:     def checkout(to_identifier=nil)
42:       checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
43:       mkdir_p(@checkout_dir)
44:       checked_out_files = []
45:       path_regex = /^[A|D|U]\s+(.*)/
46:       if(checked_out?)
47:         svn(@checkout_dir, update_command(to_identifier)) do |line|
48:           if(line =~ path_regex)
49:             absolute_path = "#{checkout_dir}/#{$1}"
50:             relative_path = $1.chomp
51:             relative_path = relative_path.gsub(/\\/, "/") if WINDOWS
52:             checked_out_files << relative_path
53:             yield relative_path if block_given?
54:           end
55:         end
56:       else
57:         svn(@checkout_dir, checkout_command(to_identifier)) do |line|
58:           if(line =~ path_regex)
59:             native_absolute_path = $1
60:             absolute_path = PathConverter.nativepath_to_filepath(native_absolute_path)
61:             if(File.exist?(absolute_path) && !File.directory?(absolute_path))
62:               native_checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
63:               relative_path = native_absolute_path[native_checkout_dir.length+1..-1].chomp
64:               relative_path = relative_path.gsub(/\\/, "/")
65:               checked_out_files << relative_path
66:               yield relative_path if block_given?
67:             end
68:           end
69:         end
70:       end
71:       checked_out_files
72:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 83
83:     def commit(message)
84:       svn(@checkout_dir, commit_command(message))
85:       # We have to do an update to get the local revision right
86:       svn(@checkout_dir, "update")
87:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 164
164:     def create_central
165:       native_path = PathConverter.filepath_to_nativepath(svnrootdir, true)
166:       mkdir_p(PathConverter.nativepath_to_filepath(native_path))
167:       svnadmin(svnrootdir, "create #{native_path}")
168:       if(@path && @path != "")
169:         # create the directories
170:         paths = @path.split("/")
171:         paths.each_with_index do |p,i|
172:           p = paths[0..i]
173:           u = "#{repourl}/#{p.join('/')}"
174:           svn(".", "mkdir #{u} -m \"Adding directories\"")
175:         end
176:       end
177:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 127
127:     def destroy_central
128:       if(File.exist?(svnrootdir) && local?)
129:         FileUtils.rm_rf(svnrootdir)
130:       else
131:         raise "Cannot destroy central repository. '#{svnrootdir}' doesn't exist or central repo isn't local to this machine"
132:       end
133:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 93
93:     def diff(file, &block)
94:       cmd = "svn diff --revision #{file.previous_native_revision_identifier}:#{file.native_revision_identifier} \"#{url}/#{file.path}\""
95:       Better.popen(cmd) do |io|
96:         return(yield(io))
97:       end
98:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 197
197:     def import_central(dir, message)
198:       import_cmd = "import #{url} -m \"#{message}\""
199:       svn(dir, import_cmd)
200:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 179
179:     def install_trigger(trigger_command, trigger_files_checkout_dir)
180:       if (WINDOWS)
181:         install_win_trigger(trigger_command, trigger_files_checkout_dir)
182:       else
183:         install_unix_trigger(trigger_command, trigger_files_checkout_dir)
184:       end
185:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 89
89:     def label
90:       local_revision_identifier.to_s
91:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 107
107:     def ls(relative_path)
108:       prefix = relative_path == "" ? relative_path : "#{relative_path}/"
109:       cmd = "svn ls #{url}/#{relative_path}"
110:       Better.popen(cmd) do |io|
111:         io.collect do |line|
112:           name = line.strip
113:           dir = false
114:           if(name =~ /(.*)\/$/)
115:             name = $1
116:             dir = true
117:           end
118:           HistoricFile.new("#{prefix}#{name}", dir, self)
119:         end
120:       end
121:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 33
33:     def move(relative_src, relative_dest)
34:       svn(@checkout_dir, "mv #{relative_src} #{relative_dest}")
35:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 100
100:     def open(revision_file, &block)
101:       cmd = "svn cat #{url}/#{revision_file.path}@#{revision_file.native_revision_identifier}"
102:       Better.popen(cmd) do |io|
103:         return(yield(io))
104:       end
105:     end

url pointing to the root of the repo

[Source]

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

[Source]

     # File lib/rscm/scm/subversion.rb, line 202
202:     def revisions(from_identifier, to_identifier=Time.infinity, relative_path="")
203:       # Return empty revision if the requested revision doesn't exist yet.
204:       return Revisions.new if(from_identifier.is_a?(Integer) && head_revision_identifier <= from_identifier)
205: 
206:       checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
207:       revisions = nil
208:       command = "svn #{changes_command(from_identifier, to_identifier, relative_path)}"
209: 
210:       Better.popen(command) do |stdout|
211:         parser = SubversionLogParser.new(stdout, @url)
212:         revisions = parser.parse_revisions
213:       end
214:       revisions
215:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 153
153:     def supports_trigger?
154:       true
155:       # we'll assume it supports trigger even if not local. this is to ensure user interfaces
156:       # can display appropriate options, even if the object is not 'fully initialised'
157:       # local?
158:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 37
37:     def transactional?
38:       true
39:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 191
191:     def trigger_installed?(trigger_command, trigger_files_checkout_dir)
192:       return false unless File.exist?(post_commit_file)
193:       not_already_commented = LineEditor.comment_out(File.new(post_commit_file), /#{Regexp.escape(trigger_command)}/, "# ", "")
194:       not_already_commented
195:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 160
160:     def trigger_mechanism
161:       "hooks/post-commit"
162:     end

[Source]

     # File lib/rscm/scm/subversion.rb, line 187
187:     def uninstall_trigger(trigger_command, trigger_files_checkout_dir)
188:       File.comment_out(post_commit_file, /#{Regexp.escape(trigger_command)}/, nil)
189:     end

[Source]

    # File lib/rscm/scm/subversion.rb, line 74
74:     def uptodate?(identifier)
75:       if(!checked_out?)
76:         false
77:       else
78:         rev = identifier ? identifier : head_revision_identifier
79:         local_revision_identifier == rev
80:       end
81:     end

[Validate]