Class: Redmine::Scm::Adapters::AbstractAdapter
- Inherits:
-
Object
- Object
- Redmine::Scm::Adapters::AbstractAdapter
show all
- Includes:
- Utils::Shell
- Defined in:
- lib/redmine/scm/adapters/abstract_adapter.rb
Defined Under Namespace
Classes: ScmCommandAborted
Class Method Summary
collapse
Instance Method Summary
collapse
-
#adapter_name ⇒ Object
-
#branches ⇒ Object
-
#cat(path, identifier = nil) ⇒ Object
-
#default_branch ⇒ Object
-
#diff(path, identifier_from, identifier_to = nil) ⇒ Object
-
#entries(path = nil, identifier = nil, options = {}) ⇒ Object
Returns an Entries collection or nil if the given path doesn’t exist in the repository.
-
#entry(path = nil, identifier = nil) ⇒ Object
Returns the entry identified by path and revision identifier or nil if entry doesn’t exist in the repository.
-
#info ⇒ Object
get info about the svn repository.
-
#initialize(url, root_url = nil, login = nil, password = nil, path_encoding = nil) ⇒ AbstractAdapter
constructor
A new instance of AbstractAdapter.
-
#path_encoding ⇒ Object
-
#properties(path, identifier = nil) ⇒ Object
-
#revisions(path = nil, identifier_from = nil, identifier_to = nil, options = {}) ⇒ Object
-
#root_url ⇒ Object
-
#supports_annotate? ⇒ Boolean
-
#supports_cat? ⇒ Boolean
-
#tags ⇒ Object
-
#url ⇒ Object
-
#valid_name?(name) ⇒ Boolean
-
#with_leading_slash(path) ⇒ Object
-
#with_trailing_slash(path) ⇒ Object
-
#with_trailling_slash(path) ⇒ Object
-
#without_leading_slash(path) ⇒ Object
-
#without_trailing_slash(path) ⇒ Object
-
#without_trailling_slash(path) ⇒ Object
Constructor Details
#initialize(url, root_url = nil, login = nil, password = nil, path_encoding = nil) ⇒ AbstractAdapter
Returns a new instance of AbstractAdapter.
72
73
74
75
76
77
78
79
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 72
def initialize(url, root_url=nil, login=nil, password=nil,
path_encoding=nil)
@url = url
@login = login if login.present?
@password = (password || "") if @login
@root_url = root_url.presence || retrieve_root_url
@path_encoding = path_encoding.presence || 'UTF-8'
end
|
Class Method Details
.client_available ⇒ Object
67
68
69
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 67
def client_available
true
end
|
.client_command ⇒ Object
34
35
36
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 34
def client_command
""
end
|
.client_version ⇒ Object
Returns the version of the scm client Eg: [1, 5, 0] or [] if unknown
48
49
50
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 48
def client_version
[]
end
|
.client_version_above?(v, options = {}) ⇒ Boolean
Returns true if the current client version is above or equals the given one If option is :unknown is set to true, it will return true if the client version is unknown
63
64
65
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 63
def client_version_above?(v, options={})
((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown])
end
|
.client_version_string ⇒ Object
Returns the version string of the scm client Eg: ‘1.5.0’ or ‘Unknown version’ if unknown
54
55
56
57
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 54
def client_version_string
v = client_version || 'Unknown version'
v.is_a?(Array) ? v.join('.') : v.to_s
end
|
.logger ⇒ Object
254
255
256
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 254
def logger
Rails.logger
end
|
.shell_quote(str) ⇒ Object
.shell_quote_command ⇒ Object
.shellout(cmd, options = {}, &block) ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 258
def shellout(cmd, options = {}, &block)
if logger && logger.debug?
logger.debug "Shelling out: #{strip_credential(cmd)}"
if stderr_log_file
cmd = "#{cmd} 2>>#{shell_quote(stderr_log_file)}"
end
end
begin
mode = "r+"
IO.popen(cmd, mode) do |io|
io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
io.close_write unless options[:write_stdin]
yield(io) if block
end
rescue => e
msg = strip_credential(e.message)
logmsg = "SCM command failed, "
logmsg += "make sure that your SCM command (e.g. svn) is "
logmsg += "in PATH (#{ENV['PATH']})\n"
logmsg += "You can configure your scm commands in config/configuration.yml.\n"
logmsg += "#{strip_credential(cmd)}\n"
logmsg += "with: #{msg}"
logger.error(logmsg)
raise CommandFailed.new(msg)
end
end
|
Instance Method Details
#adapter_name ⇒ Object
81
82
83
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 81
def adapter_name
'Abstract'
end
|
#branches ⇒ Object
132
133
134
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 132
def branches
return nil
end
|
#cat(path, identifier = nil) ⇒ Object
156
157
158
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 156
def cat(path, identifier=nil)
return nil
end
|
#default_branch ⇒ Object
140
141
142
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 140
def default_branch
return nil
end
|
#diff(path, identifier_from, identifier_to = nil) ⇒ Object
152
153
154
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 152
def diff(path, identifier_from, identifier_to=nil)
return nil
end
|
#entries(path = nil, identifier = nil, options = {}) ⇒ Object
Returns an Entries collection or nil if the given path doesn’t exist in the repository
128
129
130
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 128
def entries(path=nil, identifier=nil, options={})
return nil
end
|
#entry(path = nil, identifier = nil) ⇒ Object
Returns the entry identified by path and revision identifier or nil if entry doesn’t exist in the repository
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 112
def entry(path=nil, identifier=nil)
parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
search_path = parts[0..-2].join('/')
search_name = parts[-1]
if search_path.blank? && search_name.blank?
Entry.new(:path => '', :kind => 'dir')
else
es = entries(search_path, identifier)
es ? es.detect {|e| e.name == search_name} : nil
end
end
|
#info ⇒ Object
get info about the svn repository
106
107
108
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 106
def info
return nil
end
|
#path_encoding ⇒ Object
101
102
103
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 101
def path_encoding
nil
end
|
#properties(path, identifier = nil) ⇒ Object
144
145
146
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 144
def properties(path, identifier=nil)
return nil
end
|
#revisions(path = nil, identifier_from = nil, identifier_to = nil, options = {}) ⇒ Object
148
149
150
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 148
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
return nil
end
|
#root_url ⇒ Object
93
94
95
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 93
def root_url
@root_url
end
|
#supports_annotate? ⇒ Boolean
89
90
91
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 89
def supports_annotate?
respond_to?(:annotate)
end
|
#supports_cat? ⇒ Boolean
85
86
87
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 85
def supports_cat?
true
end
|
136
137
138
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 136
def tags
return nil
end
|
#url ⇒ Object
97
98
99
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 97
def url
@url
end
|
#valid_name?(name) ⇒ Boolean
192
193
194
195
196
197
198
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 192
def valid_name?(name)
return true if name.nil?
return true if name.is_a?(Integer) && name > 0
return true if name.is_a?(String) && name =~ /\A[0-9]*\z/
false
end
|
#with_leading_slash(path) ⇒ Object
160
161
162
163
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 160
def with_leading_slash(path)
path ||= ''
path.start_with?('/') ? path : "/#{path}"
end
|
#with_trailing_slash(path) ⇒ Object
165
166
167
168
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 165
def with_trailing_slash(path)
path ||= ''
path.end_with?('/') ? path : "#{path}/"
end
|
#with_trailling_slash(path) ⇒ Object
170
171
172
173
174
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 170
def with_trailling_slash(path)
ActiveSupport::Deprecation.warn 'Redmine::Scm::Adapters::AbstractAdapter#with_trailling_slash is ' \
'deprecated and will be removed in Redmine 6.0. Please use #with_trailing_slash instead.'
with_trailing_slash(path)
end
|
#without_leading_slash(path) ⇒ Object
176
177
178
179
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 176
def without_leading_slash(path)
path ||= ''
path.gsub(%r{^/+}, '')
end
|
#without_trailing_slash(path) ⇒ Object
181
182
183
184
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 181
def without_trailing_slash(path)
path ||= ''
path.end_with?('/') ? path[0..-2] : path
end
|
#without_trailling_slash(path) ⇒ Object
186
187
188
189
190
|
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 186
def without_trailling_slash(path)
ActiveSupport::Deprecation.warn 'Redmine::Scm::Adapters::AbstractAdapter#without_trailling_slash is ' \
'deprecated and will be removed in Redmine 6.0. Please use #without_trailing_slash instead.'
without_trailing_slash(path)
end
|