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=, #destroy_working_copy, #edit, #file, #poll_new_revisions, #update_commandline
Constructor Details
#initialize(url = "", path = "") ⇒ Subversion
Returns a new instance of Subversion.
22
23
24
25
26
|
# File 'lib/rscm/scm/subversion.rb', line 22
def initialize(url="", path="")
@url, @path = url, path
@username = ""
@password = ""
end
|
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
20
21
22
|
# File 'lib/rscm/scm/subversion.rb', line 20
def password
@password
end
|
#path ⇒ Object
Returns the value of attribute path.
18
19
20
|
# File 'lib/rscm/scm/subversion.rb', line 18
def path
@path
end
|
#url ⇒ Object
Returns the value of attribute url.
17
18
19
|
# File 'lib/rscm/scm/subversion.rb', line 17
def url
@url
end
|
#username ⇒ Object
Returns the value of attribute username.
19
20
21
|
# File 'lib/rscm/scm/subversion.rb', line 19
def username
@username
end
|
Instance Method Details
#add(relative_filename) ⇒ Object
32
33
34
|
# File 'lib/rscm/scm/subversion.rb', line 32
def add(relative_filename)
svn(@checkout_dir, "add #{relative_filename}")
end
|
#can_create_central? ⇒ Boolean
109
110
111
|
# File 'lib/rscm/scm/subversion.rb', line 109
def can_create_central?
local?
end
|
#central_exists? ⇒ Boolean
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/rscm/scm/subversion.rb', line 121
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
205
206
207
208
209
|
# File 'lib/rscm/scm/subversion.rb', line 205
def checked_out?
rootentries = File.expand_path("#{checkout_dir}/.svn/entries")
result = File.exists?(rootentries)
result
end
|
#checkout(to_identifier = nil) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/rscm/scm/subversion.rb', line 44
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
86
87
88
89
90
|
# File 'lib/rscm/scm/subversion.rb', line 86
def commit(message)
svn(@checkout_dir, commit_command(message))
svn(@checkout_dir, "update")
end
|
#create_central ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/rscm/scm/subversion.rb', line 146
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
113
114
115
116
117
118
119
|
# File 'lib/rscm/scm/subversion.rb', line 113
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
96
97
98
99
100
101
|
# File 'lib/rscm/scm/subversion.rb', line 96
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
179
180
181
182
|
# File 'lib/rscm/scm/subversion.rb', line 179
def import_central(dir, message)
import_cmd = "import #{url} -m \"#{message}\""
svn(dir, import_cmd)
end
|
#install_trigger(trigger_command, damagecontrol_install_dir) ⇒ Object
161
162
163
164
165
166
167
|
# File 'lib/rscm/scm/subversion.rb', line 161
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
|
#label ⇒ Object
92
93
94
|
# File 'lib/rscm/scm/subversion.rb', line 92
def label
local_revision_identifier.to_s
end
|
#move(relative_src, relative_dest) ⇒ Object
36
37
38
|
# File 'lib/rscm/scm/subversion.rb', line 36
def move(relative_src, relative_dest)
svn(@checkout_dir, "mv #{relative_src} #{relative_dest}")
end
|
#open(revision_file, &block) ⇒ Object
103
104
105
106
107
|
# File 'lib/rscm/scm/subversion.rb', line 103
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
|
#repourl ⇒ Object
url pointing to the root of the repo
200
201
202
203
|
# File 'lib/rscm/scm/subversion.rb', line 200
def repourl
last = (path.nil? || path == "") ? -1 : -(path.length)-2
url[0..last]
end
|
#revisions(from_identifier, to_identifier = Time.infinity, relative_path = "") ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/rscm/scm/subversion.rb', line 184
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
139
140
141
142
143
144
|
# File 'lib/rscm/scm/subversion.rb', line 139
def supports_trigger?
true
end
|
#to_yaml_properties ⇒ Object
28
29
30
|
# File 'lib/rscm/scm/subversion.rb', line 28
def to_yaml_properties
["@url", "@path", "@username", "@password"]
end
|
#transactional? ⇒ Boolean
40
41
42
|
# File 'lib/rscm/scm/subversion.rb', line 40
def transactional?
true
end
|
#trigger_installed?(trigger_command, trigger_files_checkout_dir) ⇒ Boolean
173
174
175
176
177
|
# File 'lib/rscm/scm/subversion.rb', line 173
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
169
170
171
|
# File 'lib/rscm/scm/subversion.rb', line 169
def uninstall_trigger(trigger_command, trigger_files_checkout_dir)
File.(post_commit_file, /#{Regexp.escape(trigger_command)}/, nil)
end
|
#uptodate?(identifier) ⇒ Boolean
77
78
79
80
81
82
83
84
|
# File 'lib/rscm/scm/subversion.rb', line 77
def uptodate?(identifier)
if(!checked_out?)
false
else
rev = identifier ? identifier : head_revision_identifier
local_revision_identifier == rev
end
end
|