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, default_branch, #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
139
140
141
142
143
144
145
146
|
# File 'lib/externals/scms/svn_project.rb', line 139
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
134
135
136
|
# File 'lib/externals/scms/svn_project.rb', line 134
def self.detected?
File.exists? ".svn"
end
|
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/externals/scms/svn_project.rb', line 167
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
126
127
128
129
130
131
132
|
# File 'lib/externals/scms/svn_project.rb', line 126
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
261
262
263
264
265
266
267
|
# File 'lib/externals/scms/svn_project.rb', line 261
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/externals/scms/svn_project.rb', line 110
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/externals/scms/svn_project.rb', line 201
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
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/externals/scms/svn_project.rb', line 36
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
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
|
# File 'lib/externals/scms/svn_project.rb', line 10
def co *args
rmdir_ie path
if File.exists? path
up
else
opts = resolve_opts "co"
url = repository
if branch
require_repository
url = [url, branch].join("/")
end
puts(svncocmd = "svn #{opts} co #{url} #{path}")
puts `#{svncocmd}`
unless $? == 0
raise
end
change_to_revision "co"
end
end
|
#current_branch ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/externals/scms/svn_project.rb', line 152
def current_branch
require_repository
branch = info_url.gsub(/\/+/, "/").gsub(repository.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
253
254
255
256
257
258
259
|
# File 'lib/externals/scms/svn_project.rb', line 253
def current_revision
Dir.chdir path do
if `svn #{scm_opts} info` =~ /Revision:\s*(\d+)\s*$/
$1
end
end
end
|
#default_branch ⇒ Object
5
6
7
|
# File 'lib/externals/scms/svn_project.rb', line 5
def default_branch
raise "There is no default_branch for SvnProject"
end
|
#drop_from_ignore(path) ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# File 'lib/externals/scms/svn_project.rb', line 217
def drop_from_ignore path
parent = File.dirname(path)
child = File.basename(path).strip
ir = ignore_rows(path)
rows = ir.select {|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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/externals/scms/svn_project.rb', line 47
def ex *args
rmdir_ie path
url = repository
if branch
require_repository
url = [url, branch].join("/")
end
if revision
url += "@#{revision}"
end
puts(svncocmd = "svn #{scm_opts_ex} export #{url} #{path}")
puts `#{svncocmd}`
end
|
#ignore_contains?(path) ⇒ Boolean
148
149
150
|
# File 'lib/externals/scms/svn_project.rb', line 148
def ignore_contains? path
ignore_text(path) =~ Regexp.new("^\\s*#{File.basename(path)}\\s*$")
end
|
#ignore_rows(path) ⇒ Object
237
238
239
240
241
242
243
|
# File 'lib/externals/scms/svn_project.rb', line 237
def ignore_rows(path)
rows = ignore_text(path).split(/\n/)
rows.delete_if {|row| row =~ /^\s*$/}
rows
end
|
#ignore_text(path) ⇒ Object
245
246
247
248
249
250
251
|
# File 'lib/externals/scms/svn_project.rb', line 245
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
269
270
271
272
273
|
# File 'lib/externals/scms/svn_project.rb', line 269
def info_url
Dir.chdir path do
self.class.info_url scm_opts
end
end
|
#require_repository ⇒ Object
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
# File 'lib/externals/scms/svn_project.rb', line 180
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
103
104
105
106
107
108
|
# File 'lib/externals/scms/svn_project.rb', line 103
def st *args
puts "\nstatus for #{path}:"
Dir.chdir path do
puts `svn #{scm_opts_st} status`
end
end
|
#switch(branch_name, options = {}) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/externals/scms/svn_project.rb', line 66
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/externals/scms/svn_project.rb', line 80
def up *args
rmdir_if_empty_ie path
if File.exists? 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
|