Class: Externals::SvnProject
Instance Attribute Summary
Attributes inherited from Project
#parent
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Project
#assert_e_dne_i_ni, attr_attr_accessor, #attributes, #checkout, #export, #extract_name, inherited, #initialize, #main_project?, #name, scm, #scm, #scm_opts, #scm_opts=, #update_ignore
Class Method Details
.add_all ⇒ Object
this is a test helper method
TODO: can we move it to the test suite, then?
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/externals/scms/svn_project.rb', line 156
def self.add_all
status = `svn st`
status.split("\n").grep(/^\?/).each do |to_add|
puts `svn add #{to_add.gsub(/^\?\s*/, "")}`
raise unless $? == 0
end
end
|
.detected? ⇒ Boolean
150
151
152
|
# File 'lib/externals/scms/svn_project.rb', line 150
def self.detected?
File.exist?(".svn")
end
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
# File 'lib/externals/scms/svn_project.rb', line 190
def self. url, branch
repository = url.gsub(branch, "")
if url == repository
raise "Could not determine repository from URL #{info_url}.
Does not appear to have the branch #{branch} as a substring"
end
if repository !~ /\/$/
raise "Was expecting the branch and repository to be separated by '/'
Please file an issue about this at http://github.com/azimux/externals"
end
repository.gsub(/\/$/, "")
end
|
.fill_in_opts(opts, main_options, sub_options, options = {}) ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/externals/scms/svn_project.rb', line 142
def self.fill_in_opts opts, main_options, sub_options, options = {}
opts.on("--svn", "--subversion",
Integer,
*"same as '--scm svn' Uses subversion to
checkout/export the main project".lines_by_width(options[:summary_width])
) {sub_options[:scm] = main_options[:scm] = 'svn'}
end
|
.info_url(scm_opts = "") ⇒ Object
296
297
298
299
300
301
302
303
304
|
# File 'lib/externals/scms/svn_project.rb', line 296
def self.info_url scm_opts = ""
if `svn #{scm_opts} info` =~ /^\s*URL:\s*([^\s]+)\s*$/
$1
else
raise "Could not get URL from svn info"
end
end
|
.scm_path?(path) ⇒ Boolean
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/externals/scms/svn_project.rb', line 123
def self.scm_path? path
return true if path =~ /^svn(\+ssh)?:/
if path =~ /^https?:\/\/([\w+-]+)\.(?:[\w+-]+\.)*[\w-]+(?:\/|$)/
return true if $1.downcase == "svn"
end
if path =~ /^https?:\/\/(?:[\w+-]+\.?)+\/(\w+)/
return true if $1.downcase.include? "svn"
end
false
end
|
Instance Method Details
#append_ignore(path) ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/externals/scms/svn_project.rb', line 232
def append_ignore path
parent = File.dirname(path)
child = File.basename(path)
rows = ignore_rows(path)
return if rows.detect {|row| row.strip == child.strip}
rows << child.strip
Dir.chdir(parent) do
puts `svn #{scm_opts} propset svn:ignore "#{rows.compact.join("\n")}\n" .`
raise "Could not ignore path, something went wrong in svn." unless $? == 0
end
end
|
#change_to_revision(command = "") ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/externals/scms/svn_project.rb', line 37
def change_to_revision command = ""
opts = resolve_opts(command)
if revision
Dir.chdir path do
puts `svn #{opts} up -r #{revision}`
raise unless $? == 0
end
end
end
|
#co(*_args) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/externals/scms/svn_project.rb', line 5
def co *_args
rmdir_if_empty_ie path unless path == "."
if path != "." && File.exist?(path)
up
else
opts = resolve_opts "co"
url = repository
if branch
require_repository
url = [url, branch].join("/")
end
dest = path
dest = '' if dest == '.'
dest = "\"#{dest}\"" if dest && !dest.empty?
puts(svncocmd = "svn #{opts} co #{url} #{dest}")
puts `#{svncocmd}`
unless $? == 0
raise "Failed to run #{svncocmd}"
end
change_to_revision "co"
end
end
|
#current_branch ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/externals/scms/svn_project.rb', line 171
def current_branch
require_repository
branch = info_url.downcase.gsub(/\/+/, "/").gsub(repository.downcase.gsub(/\/+/, "/"), "")
if branch == repository
raise "Could not determine branch from URL #{info_url}.
Does not appear have a substring of #{repository}"
end
if branch !~ /^\//
raise "Was expecting the branch and repository to be separated by '/'
Please file an issue about this at http://github.com/azimux/externals"
end
branch.gsub(/^\//, "")
end
|
#current_revision ⇒ Object
288
289
290
291
292
293
294
|
# File 'lib/externals/scms/svn_project.rb', line 288
def current_revision
Dir.chdir path do
if `svn #{scm_opts} info` =~ /Revision:\s*(\d+)\s*$/
$1
end
end
end
|
#drop_from_ignore(path) ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/externals/scms/svn_project.rb', line 248
def drop_from_ignore path
parent = File.dirname(path)
child = File.basename(path).strip
ir = ignore_rows(path)
rows = ir.reject {|row| row.strip == child}
if rows.size == ir.size
raise "row not found matching #{path} in svn propget svn:ignore"
end
if ir.size - rows.size != 1
raise "More than one row found matching #{path} in svn propget svn:ignore"
end
Dir.chdir(parent) do
puts `svn #{scm_opts} propset svn:ignore "#{rows.compact.join("\n")}\n" .`
end
end
|
#ex(*_args) ⇒ Object
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
|
# File 'lib/externals/scms/svn_project.rb', line 48
def ex *_args
rmdir_ie path unless path == "."
dest = path
dest = '' if dest == '.'
dest = "\"#{dest}\"" if dest && !dest.empty?
url = repository
if branch
require_repository
url = [url, branch].join("/")
end
if revision
url += "@#{revision}"
end
puts(svncocmd = "svn #{scm_opts_ex} export #{url} #{dest}")
puts `#{svncocmd}`
end
|
#ignore_contains?(path) ⇒ Boolean
167
168
169
|
# File 'lib/externals/scms/svn_project.rb', line 167
def ignore_contains? path
ignore_text(path) =~ Regexp.new("^\\s*#{File.basename(path)}\\s*$")
end
|
#ignore_rows(path) ⇒ Object
272
273
274
275
276
277
278
|
# File 'lib/externals/scms/svn_project.rb', line 272
def ignore_rows(path)
rows = ignore_text(path).split("\n")
rows.delete_if {|row| row =~ /^\s*$/}
rows
end
|
#ignore_text(path) ⇒ Object
280
281
282
283
284
285
286
|
# File 'lib/externals/scms/svn_project.rb', line 280
def ignore_text(path)
ignore_text = ''
Dir.chdir File.dirname(path) do
ignore_text = `svn #{scm_opts} propget svn:ignore`
end
ignore_text
end
|
#info_url ⇒ Object
306
307
308
309
310
|
# File 'lib/externals/scms/svn_project.rb', line 306
def info_url
Dir.chdir path do
self.class.info_url scm_opts
end
end
|
#require_repository ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/externals/scms/svn_project.rb', line 208
def require_repository
if repository.nil? || repository.empty?
url = info_url
info_url = "svn+ssh://server/path/repository" unless url
puts "to use any branching features with a subversion project, the
repository must be present in the .externals file.
See http://nopugs.com/ext-svn-branches for more info
The name of the branch should be excluded from the repository URL.
You might need to change your .externals file to contain something like this:
[.]
scm = svn
repository = #{info_url}
"
raise "Cannot use subversion branching features without a repository in .externals file"
end
end
|
#st(*_args) ⇒ Object
113
114
115
116
117
118
119
120
121
|
# File 'lib/externals/scms/svn_project.rb', line 113
def st *_args
puts "\nstatus for #{path}:"
Dir.chdir path do
puts `svn #{scm_opts_st} status`
end
end
|
#switch(branch_name, _options = {}) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/externals/scms/svn_project.rb', line 74
def switch branch_name, _options = {}
require_repository
if current_branch != branch_name
Dir.chdir path do
url = [repository, branch_name].join("/")
`svn #{scm_opts} switch #{url}`
unless $? == 0
raise "Could not switch to #{url}"
end
end
end
end
|
#up(*_args) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/externals/scms/svn_project.rb', line 90
def up *_args
rmdir_if_empty_ie path unless path == "."
if File.exist?(path)
puts "updating #{path}:"
if branch
switch branch
end
if revision
change_to_revision "up"
else
Dir.chdir path do
puts `svn #{scm_opts_up} up .`
end
end
else
co
end
end
|