Class: RSCM::Subversion
Overview
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.
Constant Summary
Constants inherited
from Base
Base::DEFAULT_QUIET_PERIOD, Base::THIRTY_TWO_WEEKS_AGO, Base::TWO_WEEKS_AGO
Instance Attribute Summary collapse
Attributes inherited from Base
#logger
Instance Method Summary
collapse
-
#add(relative_filename) ⇒ Object
-
#can_create_central? ⇒ Boolean
-
#central_exists? ⇒ Boolean
-
#checked_out? ⇒ Boolean
-
#checkout(to_identifier = nil) ⇒ Object
-
#commit(message) ⇒ Object
-
#create_central ⇒ Object
-
#destroy_central ⇒ Object
-
#diff(file, &block) ⇒ Object
-
#import_central(dir, message) ⇒ Object
-
#initialize(url = "", path = "") ⇒ Subversion
constructor
A new instance of Subversion.
-
#install_trigger(trigger_command, damagecontrol_install_dir) ⇒ Object
-
#label ⇒ Object
-
#move(relative_src, relative_dest) ⇒ Object
-
#open(revision_file, &block) ⇒ Object
-
#repourl ⇒ Object
url pointing to the root of the repo.
-
#revisions(from_identifier, to_identifier = Time.infinity, relative_path = "") ⇒ Object
-
#supports_trigger? ⇒ Boolean
-
#to_yaml_properties ⇒ Object
-
#transactional? ⇒ Boolean
-
#trigger_installed?(trigger_command, trigger_files_checkout_dir) ⇒ Boolean
-
#uninstall_trigger(trigger_command, trigger_files_checkout_dir) ⇒ Object
-
#uptodate?(identifier) ⇒ Boolean
ensure_trailing_slash, filepath_to_nativepath, filepath_to_nativeurl, nativepath_to_filepath
Methods inherited from Base
#==, #checkout_commandline, #checkout_dir, #checkout_dir=, classes, #destroy_working_copy, #edit, #file, #poll_new_revisions, register, #update_commandline
Constructor Details
#initialize(url = "", path = "") ⇒ Subversion
Returns a new instance of Subversion.
35
36
37
38
39
|
# File 'lib/rscm/scm/subversion.rb', line 35
def initialize(url="", path="")
@url, @path = url, path
@username = ""
@password = ""
end
|
Instance Attribute Details
Returns the value of attribute password.
33
34
35
|
# File 'lib/rscm/scm/subversion.rb', line 33
def password
@password
end
|
Returns the value of attribute path.
25
26
27
|
# File 'lib/rscm/scm/subversion.rb', line 25
def path
@path
end
|
Returns the value of attribute url.
21
22
23
|
# File 'lib/rscm/scm/subversion.rb', line 21
def url
@url
end
|
Returns the value of attribute username.
29
30
31
|
# File 'lib/rscm/scm/subversion.rb', line 29
def username
@username
end
|
Instance Method Details
#add(relative_filename) ⇒ Object
45
46
47
|
# File 'lib/rscm/scm/subversion.rb', line 45
def add(relative_filename)
svn(@checkout_dir, "add #{relative_filename}")
end
|
#can_create_central? ⇒ Boolean
122
123
124
|
# File 'lib/rscm/scm/subversion.rb', line 122
def can_create_central?
local?
end
|
#central_exists? ⇒ Boolean
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/rscm/scm/subversion.rb', line 134
def central_exists?
if(local?)
File.exists?("#{svnrootdir}/db")
else
exists = false
cmd = "svn log #{url} -r HEAD"
Better.popen(cmd) do |stdout|
stdout.each_line do |line|
exists = true
end
end
exists
end
end
|
#checked_out? ⇒ Boolean
218
219
220
221
222
|
# File 'lib/rscm/scm/subversion.rb', line 218
def checked_out?
rootentries = File.expand_path("#{checkout_dir}/.svn/entries")
result = File.exists?(rootentries)
result
end
|
#checkout(to_identifier = nil) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/rscm/scm/subversion.rb', line 57
def checkout(to_identifier=nil)
checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
mkdir_p(@checkout_dir)
checked_out_files = []
path_regex = /^[A|D|U]\s+(.*)/
if(checked_out?)
svn(@checkout_dir, update_command(to_identifier)) do |line|
if(line =~ path_regex)
absolute_path = "#{checkout_dir}/#{$1}"
relative_path = $1.chomp
relative_path = relative_path.gsub(/\\/, "/") if WINDOWS
checked_out_files << relative_path
yield relative_path if block_given?
end
end
else
svn(@checkout_dir, checkout_command(to_identifier)) do |line|
if(line =~ path_regex)
native_absolute_path = $1
absolute_path = PathConverter.nativepath_to_filepath(native_absolute_path)
if(File.exist?(absolute_path) && !File.directory?(absolute_path))
native_checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
relative_path = native_absolute_path[native_checkout_dir.length+1..-1].chomp
relative_path = relative_path.gsub(/\\/, "/")
checked_out_files << relative_path
yield relative_path if block_given?
end
end
end
end
checked_out_files
end
|
#commit(message) ⇒ Object
99
100
101
102
103
|
# File 'lib/rscm/scm/subversion.rb', line 99
def commit(message)
svn(@checkout_dir, commit_command(message))
svn(@checkout_dir, "update")
end
|
#create_central ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/rscm/scm/subversion.rb', line 159
def create_central
native_path = PathConverter.filepath_to_nativepath(svnrootdir, true)
mkdir_p(PathConverter.nativepath_to_filepath(native_path))
svnadmin(svnrootdir, "create #{native_path}")
if(@path && @path != "")
paths = @path.split("/")
paths.each_with_index do |p,i|
p = paths[0..i]
u = "#{repourl}/#{p.join('/')}"
svn(".", "mkdir #{u} -m \"Adding directories\"")
end
end
end
|
#destroy_central ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/rscm/scm/subversion.rb', line 126
def destroy_central
if(File.exist?(svnrootdir) && local?)
FileUtils.rm_rf(svnrootdir)
else
raise "Cannot destroy central repository. '#{svnrootdir}' doesn't exist or central repo isn't local to this machine"
end
end
|
#diff(file, &block) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/rscm/scm/subversion.rb', line 109
def diff(file, &block)
cmd = "svn diff --revision #{file.previous_native_revision_identifier}:#{file.native_revision_identifier} \"#{url}/#{file.path}\""
Better.popen(cmd) do |io|
return(yield(io))
end
end
|
#import_central(dir, message) ⇒ Object
192
193
194
195
|
# File 'lib/rscm/scm/subversion.rb', line 192
def import_central(dir, message)
import_cmd = "import #{url} -m \"#{message}\""
svn(dir, import_cmd)
end
|
#install_trigger(trigger_command, damagecontrol_install_dir) ⇒ Object
174
175
176
177
178
179
180
|
# File 'lib/rscm/scm/subversion.rb', line 174
def install_trigger(trigger_command, damagecontrol_install_dir)
if (WINDOWS)
install_win_trigger(trigger_command, damagecontrol_install_dir)
else
install_unix_trigger(trigger_command, damagecontrol_install_dir)
end
end
|
105
106
107
|
# File 'lib/rscm/scm/subversion.rb', line 105
def label
local_revision_identifier.to_s
end
|
#move(relative_src, relative_dest) ⇒ Object
49
50
51
|
# File 'lib/rscm/scm/subversion.rb', line 49
def move(relative_src, relative_dest)
svn(@checkout_dir, "mv #{relative_src} #{relative_dest}")
end
|
#open(revision_file, &block) ⇒ Object
116
117
118
119
120
|
# File 'lib/rscm/scm/subversion.rb', line 116
def open(revision_file, &block)
Better.popen("svn cat --revision #{revision_file.native_revision_identifier} #{url}/#{revision_file.path}") do |io|
return(yield(io))
end
end
|
url pointing to the root of the repo
213
214
215
216
|
# File 'lib/rscm/scm/subversion.rb', line 213
def repourl
last = (path.nil? || path == "") ? -1 : -(path.length)-2
url[0..last]
end
|
#revisions(from_identifier, to_identifier = Time.infinity, relative_path = "") ⇒ Object
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/rscm/scm/subversion.rb', line 197
def revisions(from_identifier, to_identifier=Time.infinity, relative_path="")
return Revisions.new if(from_identifier.is_a?(Integer) && head_revision_identifier <= from_identifier)
checkout_dir = PathConverter.filepath_to_nativepath(@checkout_dir, false)
revisions = nil
command = "svn #{changes_command(from_identifier, to_identifier, relative_path)}"
Better.popen(command) do |stdout|
parser = SubversionLogParser.new(stdout, @url)
revisions = parser.parse_revisions
end
revisions
end
|
#supports_trigger? ⇒ Boolean
152
153
154
155
156
157
|
# File 'lib/rscm/scm/subversion.rb', line 152
def supports_trigger?
true
end
|
#to_yaml_properties ⇒ Object
41
42
43
|
# File 'lib/rscm/scm/subversion.rb', line 41
def to_yaml_properties
["@url", "@path", "@username", "@password"]
end
|
#transactional? ⇒ Boolean
53
54
55
|
# File 'lib/rscm/scm/subversion.rb', line 53
def transactional?
true
end
|
#trigger_installed?(trigger_command, trigger_files_checkout_dir) ⇒ Boolean
186
187
188
189
190
|
# File 'lib/rscm/scm/subversion.rb', line 186
def trigger_installed?(trigger_command, trigger_files_checkout_dir)
return false unless File.exist?(post_commit_file)
= LineEditor.(File.new(post_commit_file), /#{Regexp.escape(trigger_command)}/, "# ", "")
end
|
#uninstall_trigger(trigger_command, trigger_files_checkout_dir) ⇒ Object
182
183
184
|
# File 'lib/rscm/scm/subversion.rb', line 182
def uninstall_trigger(trigger_command, trigger_files_checkout_dir)
File.(post_commit_file, /#{Regexp.escape(trigger_command)}/, nil)
end
|
#uptodate?(identifier) ⇒ Boolean
90
91
92
93
94
95
96
97
|
# File 'lib/rscm/scm/subversion.rb', line 90
def uptodate?(identifier)
if(!checked_out?)
false
else
rev = identifier ? identifier : head_revision_identifier
local_revision_identifier == rev
end
end
|